[Python-modules-commits] [smartypants] 01/07: New upstream version 2.0.0

Andrew Starr-Bochicchio asb at moszumanska.debian.org
Mon Jul 3 00:06:51 UTC 2017


This is an automated email from the git hooks/post-receive script.

asb pushed a commit to branch master
in repository smartypants.

commit 49278b4f376f7a810a49eece9c17344264bdc2ac
Author: Andrew Starr-Bochicchio <asb at debian.org>
Date:   Sun Jul 2 18:44:19 2017 -0500

    New upstream version 2.0.0
---
 CHANGES.rst    |  20 ++++-
 PKG-INFO       |   7 +-
 README.rst     |   5 ++
 smartypants    |  31 ++++++-
 smartypants.py | 260 +++++++++++++--------------------------------------------
 5 files changed, 118 insertions(+), 205 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index f440f9d..6b7125a 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,8 +58,19 @@ Release 2.0.0
 - drop fooBarXyz functions, such as  ``smartyPants``, ``educateQuotes``,
   and ``processEscapes``
 
-Development
------------
++ 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
+
+  - 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``
+
 
 Release 1.8.6: 2014-07-19T11:20:52Z
 -----------------------------------
@@ -64,6 +78,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
@@ -83,6 +98,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/PKG-INFO b/PKG-INFO
index 7123c2d..e9bc620 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: smartypants
-Version: 1.8.6
+Version: 2.0.0
 Summary: Python with the SmartyPants
 Home-page: https://bitbucket.org/livibetter/smartypants.py
 Author: Yu-Jie Lin
@@ -15,6 +15,11 @@ Description: 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/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/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..a70575b 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,33 +14,32 @@ smartypants module
 
 __author__ = 'Yu-Jie Lin'
 __author_email__ = 'livibetter at gmail.com'
-__version__ = '1.8.6'
+__version__ = '2.0.0'
 __license__ = 'BSD License'
 __url__ = 'https://bitbucket.org/livibetter/smartypants.py'
 __description__ = 'Python with the SmartyPants'
 
 import re
-import warnings
 
 
 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.
@@ -49,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.
@@ -71,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 (``"``).
 
@@ -93,13 +92,28 @@ class _Attr(object):
     regular quotes so SmartyPants can educate them.
     """
 
-    s = 0b100000000
+    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.)"
@@ -166,89 +180,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,17 +194,11 @@ 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
     do_ellipses = attr & Attr.e
-    do_stupefy = attr & Attr.s
+    do_entities = attr & Attr.mask_o
     convert_quot = attr & Attr.w
 
     tokens = _tokenize(text)
@@ -357,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)
@@ -366,15 +295,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 +389,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 +403,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 +417,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 +430,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 +445,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 +470,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,46 +483,38 @@ 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):
+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
 
 
-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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/smartypants.git



More information about the Python-modules-commits mailing list