Skip to content

Commit

Permalink
Merge pull request #15 from rczajka/master
Browse files Browse the repository at this point in the history
Make regex optional, fix packaging, runs on pypy.
  • Loading branch information
ikirudennis committed Jan 21, 2015
2 parents ffd5c18 + fad1fb9 commit c109627
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
script: nosetests
4 changes: 3 additions & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 15 additions & 5 deletions textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"""

import re
import regex
import uuid

from textile.tools import sanitizer, imagesize
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ deps = nose
regex
Pillow
commands = nosetests --id-file=.noseids.{envname}

[testenv:pypy]
deps = nose
coverage
html5lib
Pillow

0 comments on commit c109627

Please sign in to comment.