pax_global_header00006660000000000000000000000064124410244240014507gustar00rootroot0000000000000052 comment=65aa438c7e0297b7edb5f729f3181e510f87efdf tonyseek-python-base36-65aa438/000077500000000000000000000000001244102442400163055ustar00rootroot00000000000000tonyseek-python-base36-65aa438/.bumpversion.cfg000066400000000000000000000001331244102442400214120ustar00rootroot00000000000000[bumpversion] files = setup.py base36.py commit = True tag = True current_version = 0.1.1 tonyseek-python-base36-65aa438/.editorconfig000066400000000000000000000002251244102442400207610ustar00rootroot00000000000000# http://editorconfig.org root = true [*] charset = utf-8 [*.py] indent_style = space indent_size = 4 [*.c] indent_style = space indent_size = 4 tonyseek-python-base36-65aa438/.gitignore000066400000000000000000000004441244102442400202770ustar00rootroot00000000000000*.py[cod] # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 __pycache__ # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox .cache # Translations *.mo # Editor *.sw[po] # Sphinx docs/_build tonyseek-python-base36-65aa438/.travis.yml000066400000000000000000000003451244102442400204200ustar00rootroot00000000000000language: python python: - "2.7" - "3.3" - "3.4" - "pypy" install: - "pip install ." - "pip install pytest pytest-cov pytest-pep8 coveralls" script: "py.test" after_success: "coveralls" branches: only: - master tonyseek-python-base36-65aa438/LICENSE000066400000000000000000000020671244102442400173170ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Jiangge Zhang 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. tonyseek-python-base36-65aa438/MANIFEST.in000066400000000000000000000000331244102442400200370ustar00rootroot00000000000000include LICENSE README.rst tonyseek-python-base36-65aa438/README.rst000066400000000000000000000025001244102442400177710ustar00rootroot00000000000000|Build Status| |Coverage Status| |PyPI Version| |Wheel Status| Base36 in Python ================ Yet another implementation for the positional numeral system using 36 as the radix. Installation ------------ .. code-block:: shell pip install base36 Usage ----- .. code-block:: python import base36 assert base36.dumps(19930503) == 'bv6h3' assert base36.loads('bv6h3') == 19930503 Issues ------ If you want to report bugs or request features, please create issues on `GitHub Issues `_. Contributes ----------- You can send a pull reueqst on `GitHub `_. .. |Build Status| image:: https://img.shields.io/travis/tonyseek/python-base36.svg?style=flat :target: https://travis-ci.org/tonyseek/python-base36 :alt: Build Status .. |Coverage Status| image:: https://img.shields.io/coveralls/tonyseek/python-base36.svg?style=flat :target: https://coveralls.io/r/tonyseek/python-base36 :alt: Coverage Status .. |Wheel Status| image:: https://pypip.in/wheel/base36/badge.svg?style=flat :target: https://warehouse.python.org/project/base36 :alt: Wheel Status .. |PyPI Version| image:: https://img.shields.io/pypi/v/base36.svg?style=flat :target: https://pypi.python.org/pypi/base36 :alt: PyPI Version tonyseek-python-base36-65aa438/base36.py000066400000000000000000000016161244102442400177460ustar00rootroot00000000000000import sys __version__ = '0.1.1' __all__ = ['dumps', 'loads'] if sys.version_info.major == 2: # pragma: no cover integer_types = (int, long) else: # pragma: no cover integer_types = (int,) alphabet = '0123456789abcdefghijklmnopqrstuvwxyz' def dumps(number): """Dumps an integer into a base36 string. :param number: the 10-based integer. :returns: the base36 string. """ if not isinstance(number, integer_types): raise TypeError('number must be an integer') if number < 0: return '-' + dumps(-number) value = '' while number != 0: number, index = divmod(number, len(alphabet)) value = alphabet[index] + value return value or '0' def loads(value): """Loads a base36 string and parse it into 10-based integer. :param value: the base36 string. :returns: the parsed integer. """ return int(value, 36) tonyseek-python-base36-65aa438/setup.cfg000066400000000000000000000001061244102442400201230ustar00rootroot00000000000000[pytest] addopts = --pep8 --cov base36.py [bdist_wheel] universal = 1 tonyseek-python-base36-65aa438/setup.py000066400000000000000000000016701244102442400200230ustar00rootroot00000000000000from setuptools import setup with open('README.rst') as readme: next(readme) long_description = ''.join(readme).strip() setup( name='base36', version='0.1.1', author='Jiangge Zhang', author_email='tonyseek@gmail.com', description='Yet another implementation for the positional numeral system ' 'using 36 as the radix.', long_description=long_description, url='https://github.com/tonyseek/python-base36', license='MIT', classifiers=[ 'Development Status :: 3 - Alpha', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: PyPy', ], py_modules=['base36'], platforms=['Any'], ) tonyseek-python-base36-65aa438/test_base36.py000066400000000000000000000011031244102442400207740ustar00rootroot00000000000000import pytest import base36 @pytest.mark.parametrize('number,value', [ (3951668550778163018, 'u0tplaqiv70q'), (1024, 'sg'), (1843067821, 'uhbc8d'), ]) def test_dumps_and_loads(number, value): assert base36.dumps(number) == value assert base36.dumps(-number) == '-' + value assert base36.loads(value) == number assert base36.loads('-' + value) == -number def test_dumps_and_loads_zero(): assert base36.dumps(0) == '0' assert base36.loads('0') == 0 def test_failure(): with pytest.raises(TypeError): base36.dumps('wrong type') tonyseek-python-base36-65aa438/tox.ini000066400000000000000000000001661244102442400176230ustar00rootroot00000000000000[tox] envlist = py27,py33,py34,pypy [testenv] deps = pytest pytest-cov pytest-pep8 commands = py.test