diff --git a/.travis.yml b/.travis.yml index 4ab507db..dec1c730 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,11 @@ python: - "3.2" - "3.3" - "3.4" + - "pypy" # command to install dependencies install: - pip install -r requirements.txt - python setup.py -q install + - if [[ ! $TRAVIS_PYTHON_VERSION == pypy ]] ; then pip install regex; fi # command to run tests -script: nosetests \ No newline at end of file +script: nosetests diff --git a/README.textile b/README.textile index 5b40b021..b2cc5372 100644 --- a/README.textile +++ b/README.textile @@ -6,7 +6,9 @@ python-textile is a Python port of Textile, Dean Allen's humane web text generat h2. Installation -Install the 'textile' folder on your python path, or @pip install textile@ +Install the 'textile' folder on your python path, or @pip install textile@. +Optional dependencies include PIL/Pillow (for checking images size) +and regex (for faster unicode-aware string matching). h2. Usage diff --git a/setup.py b/setup.py index f779102e..386c7744 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,8 @@ import os import sys -install_requires = ['regex'] +install_requires = [] -try: - from collections import OrderedDict -except ImportError: - install_requires.extend(['ordereddict>=1.1']) if 'develop' in sys.argv: install_requires.extend([ @@ -39,6 +35,9 @@ def get_version(): ], keywords='textile,text', install_requires=install_requires, + extras_require={ + ':python_version=="2.6"': ['ordereddict>=1.1'], + }, test_suite='nose.collector', tests_require=['nose'], include_package_data=True, diff --git a/textile/core.py b/textile/core.py index c0877bea..d580bc6f 100644 --- a/textile/core.py +++ b/textile/core.py @@ -19,8 +19,6 @@ """ -import re -import regex import uuid from textile.tools import sanitizer, imagesize @@ -48,6 +46,18 @@ from HTMLParser import HTMLParser +try: + # Use regex module for matching uppercase characters if installed, + # otherwise fall back to finding all the uppercase chars in a loop. + import regex as re + upper_re_s = r'\p{Lu}' +except ImportError: + import re + from sys import maxunicode + upper_re_s = "".join([unichr(c) for c in + xrange(maxunicode) if unichr(c).isupper()]) + + def _normalize_newlines(string): out = string.strip() out = re.sub(r'\r\n', '\n', out) @@ -181,10 +191,10 @@ def __init__(self, restricted=False, lite=False, noimage=False, # plus/minus re.compile(r'[([]\+\/-[])]', re.I | re.U), # 3+ uppercase acronym - regex.compile(r'\b([\p{Lu}][\p{Lu}0-9]{2,})\b(?:[(]([^)]*)[)])'), + re.compile(r'\b([%s][%s0-9]{2,})\b(?:[(]([^)]*)[)])' % (upper_re_s, upper_re_s)), # 3+ uppercase - regex.compile(r"""(?:(?<=^)|(?<=\s)|(?<=[>\(;-]))([\p{Lu}]{3,})(\w*)(?=\s|%s|$)(?=[^">]*?(<|$))""" % - self.pnct_re_s), + re.compile(r"""(?:(?<=^)|(?<=\s)|(?<=[>\(;-]))([%s]{3,})(\w*)(?=\s|%s|$)(?=[^">]*?(<|$))""" % + (upper_re_s, self.pnct_re_s)), ] # These are the changes that need to be made for characters that occur diff --git a/tox.ini b/tox.ini index 6b44e57f..d1884662 100644 --- a/tox.ini +++ b/tox.ini @@ -8,3 +8,9 @@ deps = nose regex Pillow commands = nosetests --id-file=.noseids.{envname} + +[testenv:pypy] +deps = nose + coverage + html5lib + Pillow