summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Hemsted <leohemsted@gmail.com>2017-12-20 13:34:39 +0000
committerGitHub <noreply@github.com>2017-12-20 13:34:39 +0000
commitf55765a6929c981b44622def53038a39e565b6b2 (patch)
tree4b9a4ea7065c876b7d81774d7661debab8b68621
parent655dd138b9592219a0937b83ed76af69d42b1c37 (diff)
parent4b5ab3344cc88c69c1045e2c488173dfa867bb7f (diff)
downloadsmartypants-git-f55765a6929c981b44622def53038a39e565b6b2.tar.gz
Merge pull request #2 from leohemsted/regex-match
Use match instead of search.
-rw-r--r--.gitignore8
-rw-r--r--CHANGES.rst1
-rw-r--r--COPYING7
-rwxr-xr-xsetup.py2
-rwxr-xr-xsmartypants2
-rwxr-xr-xsmartypants.py13
-rw-r--r--tests/test.py13
-rw-r--r--tests/test_cli.py2
-rw-r--r--tests/test_deprecated.py2
-rw-r--r--tests/test_setup.py2
10 files changed, 37 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..00fc953
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+syntax: glob
+build
+docs/_build
+dist
+MANIFEST
+PKG-INFO
+smartypants_command.py
+*.pyc
diff --git a/CHANGES.rst b/CHANGES.rst
index 133dc8c..2627e49 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -46,6 +46,7 @@ Releases 2.0 and greater
Development
-----------
+* use `re.match` instead of `re.search` to improve performance on large strings
Release 2.0.0 (2016-12-28T06:18:42Z)
------------------------------------
diff --git a/COPYING b/COPYING
index 45e78a5..328ea82 100644
--- a/COPYING
+++ b/COPYING
@@ -23,7 +23,7 @@ SmartyPants
the documentation and/or other materials provided with the
distribution.
- * Neither the name "SmartyPants" nor the names of its contributors
+ * Neither the name "SmartyPants" nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
@@ -46,8 +46,9 @@ smartypants
::
smartypants is a derivative work of SmartyPants.
-
- Copyright (c) 2013, 2014 Yu-Jie Lin
+
+ Copyright (c) 2017, Leo Hemsted
+ Copyright (c) 2013, 2014, 2015, 2016 Yu-Jie Lin
Copyright (c) 2004, 2005, 2007, 2013 Chad Miller
Redistribution and use in source and binary forms, with or without
diff --git a/setup.py b/setup.py
index ff1ea76..6418be0 100755
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (C) 2013, 2014 by Yu-Jie Lin
+# Copyright (C) 2017 by Leo Hemsted
# For detail license information, See COPYING
from __future__ import print_function
diff --git a/smartypants b/smartypants
index 189adf5..b5af1c0 100755
--- a/smartypants
+++ b/smartypants
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (c) 2013, 2014 Yu-Jie Lin
+# Copyright (c) 2017 Leo Hemsted
# Licensed under the BSD License, for detailed license information, see COPYING
"""
diff --git a/smartypants.py b/smartypants.py
index a70575b..c39f409 100755
--- a/smartypants.py
+++ b/smartypants.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
+# Copyright (c) 2017 Leo Hemsted
# Copyright (c) 2013, 2014, 2016 Yu-Jie Lin
# Copyright (c) 2004, 2005, 2007, 2013 Chad Miller
# Copyright (c) 2003 John Gruber
@@ -12,11 +13,11 @@ smartypants module
:func:`smartypants` is the core of smartypants module.
"""
-__author__ = 'Yu-Jie Lin'
-__author_email__ = 'livibetter@gmail.com'
-__version__ = '2.0.0'
+__author__ = 'Leo Hemsted'
+__author_email__ = 'leohemsted@gmail.com'
+__version__ = '2.0.1'
__license__ = 'BSD License'
-__url__ = 'https://bitbucket.org/livibetter/smartypants.py'
+__url__ = 'https://github.com/leohemsted/smartypants.py'
__description__ = 'Python with the SmartyPants'
import re
@@ -569,7 +570,7 @@ def _tokenize(text):
tag_soup = re.compile(r'([^<]*)(<!--.*?--\s*>|<[^>]*>)', re.S)
- token_match = tag_soup.search(text)
+ token_match = tag_soup.match(text)
previous_end = 0
while token_match:
@@ -599,7 +600,7 @@ def _tokenize(text):
tokens.append([type_, tag])
previous_end = token_match.end()
- token_match = tag_soup.search(text, token_match.end())
+ token_match = tag_soup.match(text, token_match.end())
if previous_end < len(text):
tokens.append(['text', text[previous_end:]])
diff --git a/tests/test.py b/tests/test.py
index a16178b..2c1a0ea 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (c) 2013, 2016 Yu-Jie Lin
+# Copyright (c) 2017 Leo Hemsted
# Licensed under the BSD License, for detailed license information, see COPYING
import doctest
import unittest
+from time import time
import smartypants
from smartypants import smartypants as sp
@@ -147,6 +148,16 @@ document.write('<a href="' + href + '">' + linktext + "</a>");
self.assertEqual(sp('"quote here"', Attr.set1 | Attr.s),
'"quote here"')
+ def test_incredibly_long_string(self):
+ # make sure it doesn't take too long with a long string
+ start = time()
+
+ sp("a" * 10000)
+
+ end = time()
+
+ self.assertLess(end - start, 0.2)
+
def load_tests(loader, tests, pattern):
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 263f319..e85545a 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2013 Yu-Jie Lin
+# Copyright (c) 2017 Leo Hemsted
# Licensed under the BSD License, for detailed license information, see COPYING
from __future__ import unicode_literals
diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py
index 8d4fc7e..0f554e9 100644
--- a/tests/test_deprecated.py
+++ b/tests/test_deprecated.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (c) 2013, 2016 Yu-Jie Lin
+# Copyright (c) 2017 Leo Hemsted
# Licensed under the BSD License, for detailed license information, see COPYING
import unittest
diff --git a/tests/test_setup.py b/tests/test_setup.py
index e5eb654..20e4678 100644
--- a/tests/test_setup.py
+++ b/tests/test_setup.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2013 Yu-Jie Lin
+# Copyright (c) 2017 Leo Hemsted
# Licensed under the BSD License, for detailed license information, see COPYING
import unittest