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