From beb6a26ddc459ea5e2effa20bc2a63f983448f4b Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Sun, 25 Dec 2016 11:37:01 +0800 Subject: doc8 fix --- CHANGES.rst | 3 +++ docs/usage.rst | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3042a92..ad0fe8c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -61,6 +61,7 @@ Development * Makefile + test packages build in ``test_setup`` target + * rename target ``install_test`` to ``test_setup`` @@ -70,6 +71,7 @@ Release 1.8.6: 2014-07-19T11:20:52Z * Makefile + add ``LC_ALL=C`` test for locale setting on ``setup.py`` wrt #5 + * change virtualenv invocation method in ``install_test`` target * fix UnicodeDecodeError on opening ``smartypants.py``, which includes Unicode @@ -89,6 +91,7 @@ Release 1.8.4: 2014-06-29T04:39:59Z + add missing ``COPYING`` and ``CHANGES.rst`` to package (#3) + add ``bdist_wheel`` to the building process for Python Wheel format + add ``test_doc8`` target + * fix ``install_test`` on missing of Wheel package * fix argparse version option breaks CLI on Python 3 diff --git a/docs/usage.rst b/docs/usage.rst index 18f716e..9edea34 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -97,7 +97,7 @@ Backslash escapes ================= If you need to use literal straight quotes (or plain hyphens and periods), for -example, text like ``6'2"`` may become ``6‘2”``. To avoid such situation, you -can use backslash escapes like ``6\'2\"``. +example, text like ``6'2"`` may become ``6‘2”``. To avoid such situation, +you can use backslash escapes like ``6\'2\"``. .. seealso:: :func:`smartypants.process_escapes` for a complete list of backslash escapes. -- cgit v1.2.1 From 9256ff538e842af3e3d4f95462a32946ed4ae232 Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Sun, 25 Dec 2016 11:41:27 +0800 Subject: remove deprecations --- CHANGES.rst | 6 +- smartypants | 31 ++++++++- smartypants.py | 175 +---------------------------------------------- tests/test_deprecated.py | 49 +------------ 4 files changed, 37 insertions(+), 224 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ad0fe8c..2cf15cf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -46,6 +46,9 @@ Releases 1.7 and greater Release 2.0.0 ------------- +Development +----------- + - drop Pyblosxom support - drop str-type ``attr`` @@ -55,9 +58,6 @@ Release 2.0.0 - drop fooBarXyz functions, such as ``smartyPants``, ``educateQuotes``, and ``processEscapes`` -Development ------------ - * Makefile + test packages build in ``test_setup`` target diff --git a/smartypants b/smartypants index 0b822df..189adf5 100755 --- a/smartypants +++ b/smartypants @@ -73,6 +73,35 @@ import warnings import smartypants +def _str_attr_to_int(str_attr): + """ + Convert str-type attr into int + + >>> f = _str_attr_to_int + >>> f('q') == Attr.q + True + >>> f('1') == Attr.set1 + True + >>> with warnings.catch_warnings(record=True) as w: + ... f('bz') + ... len(w) + ... print(w[-1].message) + 2 + 1 + Unknown attribute: z + """ + attr = 0 + for c in str_attr: + if '0' <= c <= '3': + c = 'set' + c + if not hasattr(smartypants.Attr, c): + warnings.warn('Unknown attribute: %s' % c, Warning) + continue + attr |= getattr(smartypants.Attr, c) + + return attr + + def main(): parser = argparse.ArgumentParser(description=smartypants.__description__) @@ -88,7 +117,7 @@ def main(): args = parser.parse_args() with warnings.catch_warnings(record=True) as w: - attr = smartypants._str_attr_to_int(args.attr) + attr = _str_attr_to_int(args.attr) if len(w): print(w[-1].message) sys.exit(1) diff --git a/smartypants.py b/smartypants.py index 3202e4d..b5a5a97 100755 --- a/smartypants.py +++ b/smartypants.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Copyright (c) 2013, 2014 Yu-Jie Lin +# Copyright (c) 2013, 2014, 2016 Yu-Jie Lin # Copyright (c) 2004, 2005, 2007, 2013 Chad Miller # Copyright (c) 2003 John Gruber # Licensed under the BSD License, for detailed license information, see COPYING @@ -14,13 +14,12 @@ smartypants module __author__ = 'Yu-Jie Lin' __author_email__ = 'livibetter@gmail.com' -__version__ = '1.8.6' +__version__ = '2.0.0dev' __license__ = 'BSD License' __url__ = 'https://bitbucket.org/livibetter/smartypants.py' __description__ = 'Python with the SmartyPants' import re -import warnings class _Attr(object): @@ -166,89 +165,6 @@ def _tags_to_skip_regex(tags=None): return re.compile('<(/)?(%s)[^>]*>' % tags, re.I) -def verify_installation(request): - - msg = 'Pyblosxom support will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - return 1 - # assert the plugin is functional - - -def cb_story(args): - - msg = 'Pyblosxom support will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - global default_smartypants_attr - - try: - forbidden_flavours = args["entry"]["smartypants_forbidden_flavours"] - except KeyError: - forbidden_flavours = ["rss"] - - try: - attributes = args["entry"]["smartypants_attributes"] - except KeyError: - attributes = default_smartypants_attr - - if attributes is None: - attributes = default_smartypants_attr - - entryData = args["entry"].getData() - - try: - if args["request"]["flavour"] in forbidden_flavours: - return - except KeyError: - if "<" in args["entry"]["body"][0:15]: # sniff the stream - return # abort if it looks like escaped HTML. FIXME - - # FIXME: make these configurable, perhaps? - args["entry"]["body"] = smartypants(entryData, attributes) - args["entry"]["title"] = smartypants(args["entry"]["title"], attributes) - - -def _str_attr_to_int(str_attr): - """ - Convert deprecated str-type attr into int - - >>> f = _str_attr_to_int - >>> f('q') == Attr.q - True - >>> f('1') == Attr.set1 - True - >>> with warnings.catch_warnings(record=True) as w: - ... f('bz') - ... len(w) - ... print(w[-1].message) - 2 - 1 - Unknown attribute: z - """ - attr = 0 - for c in str_attr: - if '0' <= c <= '3': - c = 'set' + c - if not hasattr(Attr, c): - warnings.warn('Unknown attribute: %s' % c, Warning) - continue - attr |= getattr(Attr, c) - - return attr - - -def smartyPants(text, attr=None): - - msg = ('smartyPants function will be removed at Version 2.0.0, ' - 'use smartypants, instead') - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return smartypants(text, attr) - - def smartypants(text, attr=None): """ SmartyPants function @@ -263,12 +179,6 @@ def smartypants(text, attr=None): if attr is None: attr = Attr.default - if isinstance(attr, str): - msg = 'str-type attr will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - attr = _str_attr_to_int(attr) - do_quotes = attr & Attr.q do_backticks = attr & Attr.mask_b do_dashes = attr & Attr.mask_d @@ -366,15 +276,6 @@ def smartypants(text, attr=None): return "".join(result) -def educateQuotes(text): - - msg = 'educateQuotes will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_quotes(text) - - def convert_quotes(text): """ Convert quotes in *text* into HTML curly quote entities. @@ -469,15 +370,6 @@ def convert_quotes(text): return text -def educateBackticks(text): - - msg = 'educateBackticks will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_backticks(text) - - def convert_backticks(text): """ Convert ````backticks''``-style double quotes in *text* into HTML curly @@ -492,15 +384,6 @@ def convert_backticks(text): return text -def educateSingleBackticks(text): - - msg = 'educateSingleBackticks will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_single_backticks(text) - - def convert_single_backticks(text): """ Convert ```backticks'``-style single quotes in *text* into HTML curly @@ -515,15 +398,6 @@ def convert_single_backticks(text): return text -def educateDashes(text): - - msg = 'educateDashes will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_dashes(text) - - def convert_dashes(text): """ Convert ``--`` in *text* into em-dash HTML entities. @@ -537,15 +411,6 @@ def convert_dashes(text): return text -def educateDashesOldSchool(text): - - msg = 'educateDashesOldSchool will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_dashes_oldschool(text) - - def convert_dashes_oldschool(text): """ Convert ``--`` and ``---`` in *text* into en-dash and em-dash HTML @@ -561,15 +426,6 @@ def convert_dashes_oldschool(text): return text -def educateDashesOldSchoolInverted(text): - - msg = 'educateDashesOldSchoolInverted will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_dashes_oldschool_inverted(text) - - def convert_dashes_oldschool_inverted(text): """ Convert ``--`` and ``---`` in *text* into em-dash and en-dash HTML @@ -595,15 +451,6 @@ def convert_dashes_oldschool_inverted(text): return text -def educateEllipses(text): - - msg = 'educateEllipses will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return convert_ellipses(text) - - def convert_ellipses(text): """ Convert ``...`` in *text* into ellipsis HTML entities @@ -617,15 +464,6 @@ def convert_ellipses(text): return text -def stupefyEntities(text): - - msg = 'stupefyEntities will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return stupefy_entities(text) - - def stupefy_entities(text): """ Convert SmartyPants HTML entities in *text* into their ASCII counterparts. @@ -648,15 +486,6 @@ def stupefy_entities(text): return text -def processEscapes(text): - - msg = 'processEscapes will be removed at Version 2.0.0' - warnings.filterwarnings('once', msg, DeprecationWarning) - warnings.warn(msg, DeprecationWarning) - - return process_escapes(text) - - def process_escapes(text): r""" Processe the following backslash escape sequences in *text*. This is useful diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 32e2fbd..8d4fc7e 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -1,55 +1,10 @@ #!/usr/bin/env python -# Copyright (c) 2013 Yu-Jie Lin +# Copyright (c) 2013, 2016 Yu-Jie Lin # Licensed under the BSD License, for detailed license information, see COPYING import unittest -import warnings - -import smartypants as sps -from smartypants import smartypants as sp -from smartypants import smartyPants as sP -from smartypants import Attr class SmartyPantsDeprecatedTestCase(unittest.TestCase): - def test_str_attr(self): - - TEXT = '"foo" -- bar' - - with warnings.catch_warnings(record=True) as w: - - T = sp(TEXT, 'q') - E = '“foo” -- bar' - self.assertEquals(T, E) - - T = sp(TEXT, 'qd') - E = '“foo” — bar' - self.assertEquals(T, E) - - # should only get warning 'once' - self.assertEquals(len(w), 1) - - def test_smartyPants(self): - - TEXT = '"foo" -- bar' - - with warnings.catch_warnings(record=True) as w: - - T = sP(TEXT, Attr.q) - E = '“foo” -- bar' - self.assertEquals(T, E) - - self.assertEquals(len(w), 1) - - def test_educateQuotes(self): - - TEXT = '"foo" -- bar' - - with warnings.catch_warnings(record=True) as w: - - T = sps.educateQuotes(TEXT) - E = '“foo” -- bar' - self.assertEquals(T, E) - - self.assertEquals(len(w), 1) + pass -- cgit v1.2.1 From bede08d8f6c3d28f7009501f5dafbbf30345ee39 Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Sun, 25 Dec 2016 11:48:52 +0800 Subject: use shift operator to form attr instead of binary literal --- smartypants.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/smartypants.py b/smartypants.py index b5a5a97..975297b 100755 --- a/smartypants.py +++ b/smartypants.py @@ -26,20 +26,20 @@ class _Attr(object): """ class for instantiation of module attribute :attr:`Attr`. """ - q = 0b000000001 + q = 1 << 0 """ flag for normal quotes (``"``) and (``'``) to curly ones. .. seealso:: :func:`convert_quotes` """ - b = 0b000000010 + b = 1 << 1 """ flag for double quotes (````backticks''``) to curly ones. .. seealso:: :func:`convert_backticks` """ - B = 0b000000110 + B = 1 << 2 | b """ flag for double quotes (````backticks''``) and single quotes (```single'``) to curly ones. @@ -48,20 +48,20 @@ class _Attr(object): """ mask_b = b | B - d = 0b000001000 + d = 1 << 3 """ flag for dashes (``--``) to em-dashes. .. seealso:: :func:`convert_dashes` """ - D = 0b000011000 + D = 1 << 4 | d """ flag for old-school typewriter dashes (``--``) to en-dashes and dashes (``---``) to em-dashes. .. seealso:: :func:`convert_dashes_oldschool` """ - i = 0b000101000 + i = 1 << 5 | d """ flag for inverted old-school typewriter dashes (``--``) to em-dashes and dashes (``---``) to en-dashes. @@ -70,13 +70,13 @@ class _Attr(object): """ mask_d = d | D | i - e = 0b001000000 + e = 1 << 6 """ flag for dashes (``...``) to ellipses. .. seealso:: :func:`convert_ellipses` """ - w = 0b010000000 + w = 1 << 7 """ flag for dashes (``"``) to ASCII double quotes (``"``). @@ -92,7 +92,7 @@ class _Attr(object): regular quotes so SmartyPants can educate them. """ - s = 0b100000000 + s = 1 << 8 """ Stupefy mode. Reverses the SmartyPants transformation process, turning the HTML entities produced by SmartyPants into their ASCII equivalents. -- cgit v1.2.1 From bb08b484aed7edf121c219f903fdf07a47457c08 Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Sun, 25 Dec 2016 14:02:32 +0800 Subject: add Attr.u (Unicode) and Attr.h (HTML named entities) output options (#6) --- CHANGES.rst | 4 ++++ smartypants.py | 69 +++++++++++++++++++++++++++++++++++++++++----------------- tests/test.py | 16 +++++++++++++- 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2cf15cf..195f75c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -58,6 +58,10 @@ Development - drop fooBarXyz functions, such as ``smartyPants``, ``educateQuotes``, and ``processEscapes`` ++ add ``Attr.u`` and ``Attr.h`` for Unicode characters and HTML named entities + outputs, respectively. The ``stupefy_entities`` has become + ``convert_entities`` to support all three types of conversions. (#6) + * Makefile + test packages build in ``test_setup`` target diff --git a/smartypants.py b/smartypants.py index 975297b..7078547 100755 --- a/smartypants.py +++ b/smartypants.py @@ -92,13 +92,28 @@ class _Attr(object): regular quotes so SmartyPants can educate them. """ - s = 1 << 8 + u = 0 << 9 | 1 << 8 """ - Stupefy mode. Reverses the SmartyPants transformation process, turning - the HTML entities produced by SmartyPants into their ASCII equivalents. - E.g. ``“`` is turned into a simple double-quote ("), ``—`` is - turned into two dashes, etc. + Output Unicode characters instead of numeric character references, for + example, from ``“`` to left double quotation mark (``“``) (U+201C). + + .. seealso:: :func:`convert_entities` + """ + h = 1 << 9 | 0 << 8 + """ + Output HTML named entities instead of numeric character references, for + example, from ``“`` to ``“``. + + .. seealso:: :func:`convert_entities` + """ + s = 1 << 9 | 1 << 8 """ + Output ASCII equivalents instead of numeric character references, for + example, from ``—`` to ``--``. + + .. seealso:: :func:`convert_entities` + """ + mask_o = u | h | s set0 = 0 "suppress all transformations. (Do nothing.)" @@ -183,7 +198,7 @@ def smartypants(text, attr=None): do_backticks = attr & Attr.mask_b do_dashes = attr & Attr.mask_d do_ellipses = attr & Attr.e - do_stupefy = attr & Attr.s + do_entities = attr & Attr.mask_o convert_quot = attr & Attr.w tokens = _tokenize(text) @@ -267,8 +282,12 @@ def smartypants(text, attr=None): # Normal case: t = convert_quotes(t) - if do_stupefy: - t = stupefy_entities(t) + if do_entities: + mode = (0 if do_entities == Attr.u else + 1 if do_entities == Attr.h else + 2 if do_entities == Attr.s else + 3) # would result in key error + t = convert_entities(t, mode) prev_token_last_char = last_char result.append(t) @@ -464,24 +483,34 @@ def convert_ellipses(text): return text -def stupefy_entities(text): +def convert_entities(text, mode): """ - Convert SmartyPants HTML entities in *text* into their ASCII counterparts. + Convert numeric character references to, if *mode* is + + - *0*: Unicode characters + - *1*: HTML named entities + - *2*: ASCII equivalents - >>> print(stupefy_entities('“Hello — world.”')) + >>> print(convert_entities('‘', 0)) + ‘ + >>> print(convert_entities('‘SmartyPants’', 1)) + ‘SmartyPants’ + >>> print(convert_entities('“Hello — world.”', 2)) "Hello -- world." """ - text = re.sub('–', '-', text) # en-dash - text = re.sub('—', '--', text) # em-dash - - text = re.sub('‘', "'", text) # open single quote - text = re.sub('’', "'", text) # close single quote - - text = re.sub('“', '"', text) # open double quote - text = re.sub('”', '"', text) # close double quote + CTBL = { + '–': ('–', '–', '-'), + '—': ('—', '—', '--'), + '‘': ('‘', '‘', "'"), + '’': ('’', '’', "'"), + '“': ('“', '“', '"'), + '”': ('”', '”', '"'), + '…': ('…', '…', '...'), + } - text = re.sub('…', '...', text) # ellipsis + for k, v in CTBL.items(): + text = text.replace(k, v[mode]) return text diff --git a/tests/test.py b/tests/test.py index c9451ac..a16178b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -# Copyright (c) 2013 Yu-Jie Lin +# -*- coding: utf-8 -*- +# Copyright (c) 2013, 2016 Yu-Jie Lin # Licensed under the BSD License, for detailed license information, see COPYING import doctest @@ -133,6 +134,19 @@ document.write('' + linktext + ""); self.assertEqual(sp('"Isn\'t this fun?"'), '“Isn’t this fun?”') + def test_convert_entities(self): + + self.assertEqual(sp('"quote here"', Attr.set1 | Attr.u), + '“quote here”') + self.assertEqual(sp('"quote–here"', Attr.set1 | Attr.u), + '“quote–here”') + + self.assertEqual(sp('"quote here"', Attr.set1 | Attr.h), + '“quote here”') + + self.assertEqual(sp('"quote here"', Attr.set1 | Attr.s), + '"quote here"') + def load_tests(loader, tests, pattern): -- cgit v1.2.1 From bf39e623015787b150f94fceed4f57e924415842 Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Wed, 28 Dec 2016 13:46:17 +0800 Subject: add looking for new maintainer notice --- README.rst | 5 +++++ docs/index.rst | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/README.rst b/README.rst index 9eb9afe..fb752f2 100644 --- a/README.rst +++ b/README.rst @@ -7,6 +7,11 @@ smartypants_ is a Python fork of SmartyPants__. __ SmartyPantsPerl_ .. _SmartyPantsPerl: http://daringfireball.net/projects/smartypants/ +.. important:: + + As of 2016-12-28, smartypants is looking for new maintainer to take over, + please contact project owner on Bitbucket. + Installation ------------ diff --git a/docs/index.rst b/docs/index.rst index f614fe5..75fff8d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,6 +6,12 @@ Welcome to smartypants documentation! ===================================== +.. important:: + + As of 2016-12-28, smartypants is looking for new maintainer to take over, + please contact project owner on Bitbucket. + + Contents: .. toctree:: -- cgit v1.2.1 From 2d96412af3e93e4eae0bd7b121012b1b200d1e73 Mon Sep 17 00:00:00 2001 From: Yu-Jie Lin Date: Wed, 28 Dec 2016 13:50:55 +0800 Subject: drop bdist_wininst build per PEP 527 [1] [1] https://www.python.org/dev/peps/pep-0527/#bdist-dmg-bdist-msi-and-bdist-wininst --- CHANGES.rst | 3 +++ Makefile | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 195f75c..6b7125a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -64,6 +64,9 @@ Development * Makefile + - do not build ``bdist_wininst --plat-name win32`` per + :pep:`527#bdist-dmg-bdist-msi-and-bdist-wininst` + + test packages build in ``test_setup`` target * rename target ``install_test`` to ``test_setup`` diff --git a/Makefile b/Makefile index 7b43989..7789ef2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2013, 2014 Yu-Jie Lin +# Copyright (c) 2013, 2014, 2016 Yu-Jie Lin # Licensed under the BSD License, for detailed license information, see COPYING PACKAGE=smartypants @@ -8,7 +8,7 @@ PY2_CMD=python2 PY3_CMD=python3 INSTALL_TEST_DIR=/tmp/$(PACKAGE)_install_test -BUILD_CMD=./setup.py sdist --formats gztar,zip bdist_wheel bdist_wininst --plat-name win32 +BUILD_CMD=./setup.py sdist --formats gztar,zip bdist_wheel DOC_FILES = CHANGES.rst COPYING docs/conf.py $(wildcard docs/*.rst) -- cgit v1.2.1