././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1614988831.970955 python-tr-0.1.2/0000755000175000017500000000000000000000000012775 5ustar00jelmerjelmer././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/.gitignore0000644000175000017500000000012100000000000014757 0ustar00jelmerjelmer.venv build/* dist/* *.egg-info *.pyc .svn *.swp *.swo *.un~ .DS_Store .coverage ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/.travis.yml0000644000175000017500000000052600000000000015111 0ustar00jelmerjelmerlanguage: python python: - "2.6" - "2.7" - "3.3" - "3.4" - "3.5" install: - "python setup.py install" - "pip install coveralls" script: - "nosetests --with-coverage --cover-package=tr" after_success: - coveralls notifications: email: recipients: - yukino0131@me.com on_success: always on_failure: always ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/CHANGES.rst0000644000175000017500000000062100000000000014576 0ustar00jelmerjelmerCHANGES ======= 0.1.2 (2016-03-11) ------------------ - Fix transliteration bugs in no option bug This bug is reported by id774. Many thanks. 0.1.1 (2015-02-11) ------------------ - Fix metacharcter bug in squeeze This bug is reported by Pierre Nugues. Many thanks. 0.1 (2014-11-24) ------------------ - Improve processing speed slightly 0.0.1 (2014-07-10) ------------------ First release. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/LICENSE0000644000175000017500000000207100000000000014002 0ustar00jelmerjelmerThe MIT License (MIT) Copyright (c) 2014 Yukino Ikegami Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/MANIFEST.in0000644000175000017500000000001600000000000014530 0ustar00jelmerjelmerinclude *.rst ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1614988831.970955 python-tr-0.1.2/PKG-INFO0000644000175000017500000001256200000000000014100 0ustar00jelmerjelmerMetadata-Version: 1.1 Name: python-tr Version: 0.1.2 Summary: A Pure-Python implementation of the tr algorithm Home-page: https://github.com/ikegami-yukino/python-tr Author: Yukino Ikegami Author-email: yknikgm@gmail.com License: MIT License Description: python-tr ========== |travis| |coveralls| |pyversion| |version| |landscape| |license| This module is a Python implementation of the tr algorithm. tr(string1, string2, source, option='') If not given option, then replace all characters in string1 with the character in the same position in string2. Following options are available: c Replace all complemented characters in string1 with the character in the same position in string2. d Delete all characters in string1. s Squeeze all characters in string1. cs Squeeze all the characters in string2 besides "c" replacement. ds Delete all characters in string1. Squeeze all characters in string2. cd Delete all complemented characters in string1. Params: - string1 - string2 - source - option Return: - translated_source Note =========== - If Python2.x, the type of paramaters (string1, string2 and source) must be unicode. - If Python3.3 or later, the type of paramaters (string1, string2 and source) must be str. Installation ============== :: pip install python-tr Example =========== Python2.x .. code:: python from tr import tr tr(u'bn', u'cr', u'bunny') # => u'curry' tr(u'n', '', u'bunny', 'd') # => u'buy' tr(u'n', u'u', u'bunny', 'c') # => u'uunnu' tr(u'n', u'', u'bunny', 's') # => u'buny' tr(u'bn', '', u'bunny', 'cd') # => u'bnn' tr(u'bn', u'cr', u'bunny', 'cs') # => u'brnnr' tr(u'bn', u'cr', u'bunny', 'ds') # => u'uy' Python3.3 or later .. code:: python from tr import tr tr('bn', 'cr', 'bunny') # => 'curry' tr('n', '', 'bunny', 'd') # => 'buy' tr('n', 'u', 'bunny', 'c') # => 'uunnu' tr('n', '', 'bunny', 's') # => 'buny' tr('bn', '', 'bunny', 'cd') # => 'bnn' tr('bn', 'cr', 'bunny', 'cs') # => 'brnnr' tr('bn', 'cr', 'bunny', 'ds') # => 'uy' Contributions are welcome. .. |travis| image:: https://travis-ci.org/ikegami-yukino/python-tr.svg?branch=master :target: https://travis-ci.org/ikegami-yukino/python-tr :alt: travis-ci.org .. |coveralls| image:: https://coveralls.io/repos/ikegami-yukino/python-tr/badge.svg?branch=master&service=github :target: https://coveralls.io/github/ikegami-yukino/python-tr?branch=master :alt: coveralls.io .. |version| image:: https://img.shields.io/pypi/v/python-tr.svg :target: http://pypi.python.org/pypi/python-tr/ :alt: latest version .. |pyversion| image:: https://img.shields.io/pypi/pyversions/python-tr.svg .. |landscape| image:: https://landscape.io/github/ikegami-yukino/python-tr/master/landscape.svg?style=flat :target: https://landscape.io/github/ikegami-yukino/python-tr/master :alt: Code Health .. |license| image:: https://img.shields.io/pypi/l/python-tr.svg :target: http://pypi.python.org/pypi/python-tr/ :alt: license CHANGES ======= 0.1.2 (2016-03-11) ------------------ - Fix transliteration bugs in no option bug This bug is reported by id774. Many thanks. 0.1.1 (2015-02-11) ------------------ - Fix metacharcter bug in squeeze This bug is reported by Pierre Nugues. Many thanks. 0.1 (2014-11-24) ------------------ - Improve processing speed slightly 0.0.1 (2014-07-10) ------------------ First release. Keywords: tr,transliterate,translate Platform: POSIX Platform: Windows Platform: Unix Platform: MacOS Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Information Technology Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: MacOS Classifier: Operating System :: Microsoft Classifier: Operating System :: POSIX Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Topic :: Text Processing :: General ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/README.rst0000644000175000017500000000553700000000000014476 0ustar00jelmerjelmerpython-tr ========== |travis| |coveralls| |pyversion| |version| |landscape| |license| This module is a Python implementation of the tr algorithm. tr(string1, string2, source, option='') If not given option, then replace all characters in string1 with the character in the same position in string2. Following options are available: c Replace all complemented characters in string1 with the character in the same position in string2. d Delete all characters in string1. s Squeeze all characters in string1. cs Squeeze all the characters in string2 besides "c" replacement. ds Delete all characters in string1. Squeeze all characters in string2. cd Delete all complemented characters in string1. Params: - string1 - string2 - source - option Return: - translated_source Note =========== - If Python2.x, the type of paramaters (string1, string2 and source) must be unicode. - If Python3.3 or later, the type of paramaters (string1, string2 and source) must be str. Installation ============== :: pip install python-tr Example =========== Python2.x .. code:: python from tr import tr tr(u'bn', u'cr', u'bunny') # => u'curry' tr(u'n', '', u'bunny', 'd') # => u'buy' tr(u'n', u'u', u'bunny', 'c') # => u'uunnu' tr(u'n', u'', u'bunny', 's') # => u'buny' tr(u'bn', '', u'bunny', 'cd') # => u'bnn' tr(u'bn', u'cr', u'bunny', 'cs') # => u'brnnr' tr(u'bn', u'cr', u'bunny', 'ds') # => u'uy' Python3.3 or later .. code:: python from tr import tr tr('bn', 'cr', 'bunny') # => 'curry' tr('n', '', 'bunny', 'd') # => 'buy' tr('n', 'u', 'bunny', 'c') # => 'uunnu' tr('n', '', 'bunny', 's') # => 'buny' tr('bn', '', 'bunny', 'cd') # => 'bnn' tr('bn', 'cr', 'bunny', 'cs') # => 'brnnr' tr('bn', 'cr', 'bunny', 'ds') # => 'uy' Contributions are welcome. .. |travis| image:: https://travis-ci.org/ikegami-yukino/python-tr.svg?branch=master :target: https://travis-ci.org/ikegami-yukino/python-tr :alt: travis-ci.org .. |coveralls| image:: https://coveralls.io/repos/ikegami-yukino/python-tr/badge.svg?branch=master&service=github :target: https://coveralls.io/github/ikegami-yukino/python-tr?branch=master :alt: coveralls.io .. |version| image:: https://img.shields.io/pypi/v/python-tr.svg :target: http://pypi.python.org/pypi/python-tr/ :alt: latest version .. |pyversion| image:: https://img.shields.io/pypi/pyversions/python-tr.svg .. |landscape| image:: https://landscape.io/github/ikegami-yukino/python-tr/master/landscape.svg?style=flat :target: https://landscape.io/github/ikegami-yukino/python-tr/master :alt: Code Health .. |license| image:: https://img.shields.io/pypi/l/python-tr.svg :target: http://pypi.python.org/pypi/python-tr/ :alt: license ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1614988831.966955 python-tr-0.1.2/python_tr.egg-info/0000755000175000017500000000000000000000000016515 5ustar00jelmerjelmer././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988831.0 python-tr-0.1.2/python_tr.egg-info/PKG-INFO0000644000175000017500000001256200000000000017620 0ustar00jelmerjelmerMetadata-Version: 1.1 Name: python-tr Version: 0.1.2 Summary: A Pure-Python implementation of the tr algorithm Home-page: https://github.com/ikegami-yukino/python-tr Author: Yukino Ikegami Author-email: yknikgm@gmail.com License: MIT License Description: python-tr ========== |travis| |coveralls| |pyversion| |version| |landscape| |license| This module is a Python implementation of the tr algorithm. tr(string1, string2, source, option='') If not given option, then replace all characters in string1 with the character in the same position in string2. Following options are available: c Replace all complemented characters in string1 with the character in the same position in string2. d Delete all characters in string1. s Squeeze all characters in string1. cs Squeeze all the characters in string2 besides "c" replacement. ds Delete all characters in string1. Squeeze all characters in string2. cd Delete all complemented characters in string1. Params: - string1 - string2 - source - option Return: - translated_source Note =========== - If Python2.x, the type of paramaters (string1, string2 and source) must be unicode. - If Python3.3 or later, the type of paramaters (string1, string2 and source) must be str. Installation ============== :: pip install python-tr Example =========== Python2.x .. code:: python from tr import tr tr(u'bn', u'cr', u'bunny') # => u'curry' tr(u'n', '', u'bunny', 'd') # => u'buy' tr(u'n', u'u', u'bunny', 'c') # => u'uunnu' tr(u'n', u'', u'bunny', 's') # => u'buny' tr(u'bn', '', u'bunny', 'cd') # => u'bnn' tr(u'bn', u'cr', u'bunny', 'cs') # => u'brnnr' tr(u'bn', u'cr', u'bunny', 'ds') # => u'uy' Python3.3 or later .. code:: python from tr import tr tr('bn', 'cr', 'bunny') # => 'curry' tr('n', '', 'bunny', 'd') # => 'buy' tr('n', 'u', 'bunny', 'c') # => 'uunnu' tr('n', '', 'bunny', 's') # => 'buny' tr('bn', '', 'bunny', 'cd') # => 'bnn' tr('bn', 'cr', 'bunny', 'cs') # => 'brnnr' tr('bn', 'cr', 'bunny', 'ds') # => 'uy' Contributions are welcome. .. |travis| image:: https://travis-ci.org/ikegami-yukino/python-tr.svg?branch=master :target: https://travis-ci.org/ikegami-yukino/python-tr :alt: travis-ci.org .. |coveralls| image:: https://coveralls.io/repos/ikegami-yukino/python-tr/badge.svg?branch=master&service=github :target: https://coveralls.io/github/ikegami-yukino/python-tr?branch=master :alt: coveralls.io .. |version| image:: https://img.shields.io/pypi/v/python-tr.svg :target: http://pypi.python.org/pypi/python-tr/ :alt: latest version .. |pyversion| image:: https://img.shields.io/pypi/pyversions/python-tr.svg .. |landscape| image:: https://landscape.io/github/ikegami-yukino/python-tr/master/landscape.svg?style=flat :target: https://landscape.io/github/ikegami-yukino/python-tr/master :alt: Code Health .. |license| image:: https://img.shields.io/pypi/l/python-tr.svg :target: http://pypi.python.org/pypi/python-tr/ :alt: license CHANGES ======= 0.1.2 (2016-03-11) ------------------ - Fix transliteration bugs in no option bug This bug is reported by id774. Many thanks. 0.1.1 (2015-02-11) ------------------ - Fix metacharcter bug in squeeze This bug is reported by Pierre Nugues. Many thanks. 0.1 (2014-11-24) ------------------ - Improve processing speed slightly 0.0.1 (2014-07-10) ------------------ First release. Keywords: tr,transliterate,translate Platform: POSIX Platform: Windows Platform: Unix Platform: MacOS Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Information Technology Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: MacOS Classifier: Operating System :: Microsoft Classifier: Operating System :: POSIX Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Topic :: Text Processing :: General ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988831.0 python-tr-0.1.2/python_tr.egg-info/SOURCES.txt0000644000175000017500000000037600000000000020407 0ustar00jelmerjelmer.gitignore .travis.yml CHANGES.rst LICENSE MANIFEST.in README.rst setup.py test_tr.py python_tr.egg-info/PKG-INFO python_tr.egg-info/SOURCES.txt python_tr.egg-info/dependency_links.txt python_tr.egg-info/top_level.txt tr/__init__.py tr/compat.py tr/tr.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988831.0 python-tr-0.1.2/python_tr.egg-info/dependency_links.txt0000644000175000017500000000000100000000000022563 0ustar00jelmerjelmer ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988831.0 python-tr-0.1.2/python_tr.egg-info/top_level.txt0000644000175000017500000000000300000000000021240 0ustar00jelmerjelmertr ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1614988831.970955 python-tr-0.1.2/setup.cfg0000644000175000017500000000004600000000000014616 0ustar00jelmerjelmer[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/setup.py0000644000175000017500000000264300000000000014514 0ustar00jelmerjelmer# -*- coding: utf-8 -*- from codecs import open import os import re from setuptools import setup with open(os.path.join('tr', '__init__.py'), 'r', encoding='utf8') as f: version = re.compile( r".*__version__ = '(.*?)'", re.S).match(f.read()).group(1) setup( name='python-tr', packages=['tr'], version=version, license='MIT License', platforms=['POSIX', 'Windows', 'Unix', 'MacOS'], description='A Pure-Python implementation of the tr algorithm', author='Yukino Ikegami', author_email='yknikgm@gmail.com', url='https://github.com/ikegami-yukino/python-tr', keywords=['tr', 'transliterate', 'translate'], classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Intended Audience :: Information Technology', 'License :: OSI Approved :: MIT License', 'Operating System :: MacOS', 'Operating System :: Microsoft', 'Operating System :: POSIX', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Topic :: Text Processing :: General' ], long_description='%s\n\n%s' % (open('README.rst', encoding='utf8').read(), open('CHANGES.rst', encoding='utf8').read()) ) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/test_tr.py0000644000175000017500000000235000000000000015033 0ustar00jelmerjelmer# -*- coding: utf-8 -*- from __future__ import unicode_literals from nose.tools import assert_equals, assert_raises from tr import tr def test_no_option(): assert_equals(tr('ab', 'cd', 'ab'), 'cd') assert_equals(tr('a-z', 'A-Z', 'ab'), 'AB') assert_equals(tr('a\-b', 'cde', 'a-b'), 'cde') assert_equals(tr('1-9', 'A-I', '8429503671'), 'HDBIE0CFGA') assert_equals(tr('1-9', 'ABC#', '8429503671'), '##B##0C##A') def test_complement(): assert_equals(tr('ab', '\-', '123', 'c'), '---') def test_delete(): assert_equals(tr('ab', '', 'abc', 'd'), 'c') assert_equals(tr('\\', '', '\\a\\', 'd'), 'a') def test_squeeze(): assert_equals(tr('a', '', 'aabcaa', 's'), 'abca') assert_equals(tr('$', '', '$$$$a', 's'), '$a') def test_cd(): assert_equals(tr('ab', '', 'abc', 'cd'), 'ab') assert_equals(tr('ab', '', 'abcabcabc', 'cd'), 'ababab') def test_cs(): assert_equals(tr('a', '0', 'aa11', 'cs'), 'aa0') assert_equals(tr('a', '0', '11aa11', 'cs'), '0aa0') def test_ds(): assert_equals(tr('a', '0', 'aa00', 'ds'), '0') assert_equals(tr('a-z', '0-9', 'aa00', 'ds'), '0') def test_invalid_value(): source = 'あ'.encode('utf8') assert_raises(TypeError, tr, *['a', 'b', source, 'd']) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1614988831.970955 python-tr-0.1.2/tr/0000755000175000017500000000000000000000000013422 5ustar00jelmerjelmer././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/tr/__init__.py0000644000175000017500000000037100000000000015534 0ustar00jelmerjelmer# -*- coding: utf-8 -*- from . import tr r"""Transliteration algorythm (TR) This module provides some operations for replacing or removing specific characters from source. """ VERSION = (0, 1, 2) __version__ = '0.1.2' __all__ = ['tr'] tr = tr.tr ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/tr/compat.py0000644000175000017500000000047100000000000015261 0ustar00jelmerjelmer# -*- coding: utf-8 -*- import sys if sys.version_info < (3, ): # for Python 2.x from itertools import imap, izip map = imap chr = unichr range = xrange zip = izip valid_source_type = unicode else: map = map chr = chr range = range zip = zip valid_source_type = str ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1614988814.0 python-tr-0.1.2/tr/tr.py0000644000175000017500000000635000000000000014425 0ustar00jelmerjelmerfrom __future__ import unicode_literals from .compat import valid_source_type, chr, map, range, zip import re def is_valid_type(source): return isinstance(source, valid_source_type) def make_char_list(source): char_list = [] back_slash = False hyphen = False for char in source: if char == '\\': if not back_slash: back_slash = True char_list.append(92) continue elif char == '-': if back_slash: # \- del char_list[-1] else: hyphen = True continue elif hyphen: start = char_list[-1] + 1 char_list += range(start, ord(char)) char_list.append(ord(char)) back_slash = False hyphen = False return char_list def to_unichr(char_list): return map(chr, char_list) def squeeze(from_list, source): for char in from_list: pattern = '%s{2,}' % re.escape(char) source = re.sub(pattern, char, source) return source def translate(from_list, to_list, source): translate_dict = dict(zip(from_list, to_list)) return source.translate(translate_dict) def tr(string1, string2, source, option=''): """Replace or remove specific characters. If not given option, then replace all characters in string1 with the character in the same position in string2. Following options are available: c Replace all complemented characters in string1 with the character in the same position in string2. d Delete all characters in string1. s Squeeze all characters in string1. cs Squeeze all the characters in string2 besides "c" replacement. ds Delete all characters in string1. Squeeze all characters in string2. cd Delete all complemented characters in string1. Params: string1 string2 source option Return: translated_source """ if not is_valid_type(source): raise TypeError('source must be unicode') from_list = make_char_list(string1) if option == 's': from_list = to_unichr(from_list) return squeeze(from_list, source) elif 'c' in option: from_list = to_unichr(from_list) from_list = [ord(c) for c in set(source) - set(from_list)] if 'd' in option: to_list = [None for i in from_list] else: to_list = [string2[-1] for i in from_list] source = translate(from_list, to_list, source) if 's' in option: source = squeeze(to_list, source) return source elif 'd' in option: to_list = [None for i in from_list] source = translate(from_list, to_list, source) if 's' in option: to_list = make_char_list(string2) to_list = to_unichr(to_list) source = squeeze(to_list, source) return source else: to_list = make_char_list(string2) length_diff = (len(from_list) - len(to_list)) if length_diff: to_list += [to_list[-1]] * length_diff to_list = to_unichr(to_list) return translate(from_list, to_list, source)