[Python-modules-commits] [python-hashids] 01/03: Import python-hashids_1.2.0.orig.tar.gz
Edward Betts
edward at moszumanska.debian.org
Sun Jan 22 14:11:08 UTC 2017
This is an automated email from the git hooks/post-receive script.
edward pushed a commit to branch master
in repository python-hashids.
commit d59f433b09ea53c58a02ee11a5df1d75b229366e
Author: Edward Betts <edward at 4angle.com>
Date: Thu Jan 19 17:03:33 2017 +0000
Import python-hashids_1.2.0.orig.tar.gz
---
CHANGELOG | 6 +++++-
PKG-INFO | 13 +++++++++++--
hashids.py | 51 ++++++++++++++++++++-------------------------------
setup.py | 15 +++++++++++++--
test/test_hashids.py | 8 ++++++--
5 files changed, 55 insertions(+), 38 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index cf82ded..34a635a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+v1.2.0 / 2017-01-06
+ - performance optimizations (Jakub Kramarz)
+ - version classifiers (Patrick Mézard)
+
v1.1.0 / 2015-03-31
- add encode_hex() / decode_hex()
@@ -17,4 +21,4 @@ v0.8.4 / 2014-02-04
- Make setup.py compatible with older python versions
v0.8.3 / 2013-06-02
- - initial release, compatible with JS version 0.1.x
\ No newline at end of file
+ - initial release, compatible with JS version 0.1.x
diff --git a/PKG-INFO b/PKG-INFO
index d739a51..5654345 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
Name: hashids
-Version: 1.1.0
+Version: 1.2.0
Summary: Python implementation of hashids (http://www.hashids.org).Compatible with python 2.6-3.
Home-page: https://github.com/davidaurelio/hashids-python
Author: David Aurelio
@@ -174,3 +174,12 @@ Description: ========================
MIT license, see the LICENSE file. You can use hashids in open source projects and commercial products.
Platform: UNKNOWN
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
diff --git a/hashids.py b/hashids.py
index 817ab88..12e34bc 100644
--- a/hashids.py
+++ b/hashids.py
@@ -5,7 +5,7 @@ import warnings
from functools import wraps
from math import ceil
-__version__ = '1.1.0'
+__version__ = '1.2.0'
RATIO_SEPARATORS = 3.5
RATIO_GUARDS = 12
@@ -55,12 +55,11 @@ def _hash(number, alphabet):
def _unhash(hashed, alphabet):
"""Restores a number tuple from hashed using the given `alphabet` index."""
number = 0
- len_hash = len(hashed)
len_alphabet = len(alphabet)
- for i, character in enumerate(hashed):
+ for character in hashed:
position = alphabet.index(character)
- number += position * len_alphabet ** (len_hash - i - 1)
-
+ number *= len_alphabet
+ number += position
return number
@@ -68,23 +67,16 @@ def _reorder(string, salt):
"""Reorders `string` according to `salt`."""
len_salt = len(salt)
- if len_salt == 0:
- return string
-
- i, index, integer_sum = len(string) - 1, 0, 0
- while i > 0:
- index %= len_salt
- integer = ord(salt[index])
- integer_sum += integer
- j = (integer + index + integer_sum) % i
-
- temp = string[j]
- trailer = string[j+1:] if j + 1 < len(string) else ''
- string = string[0:j] + string[i] + trailer
- string = string[0:i] + temp + string[i+1:]
-
- i -= 1
- index += 1
+ if len_salt != 0:
+ string = list(string)
+ index, integer_sum = 0, 0
+ for i in range(len(string) - 1, 0, -1):
+ integer = ord(salt[index])
+ integer_sum += integer
+ j = (integer + index + integer_sum) % i
+ string[i], string[j] = string[j], string[i]
+ index = (index + 1) % len_salt
+ string = ''.join(string)
return string
@@ -124,7 +116,6 @@ def _encode(values, salt, min_length, alphabet, separators, guards):
values_hash = sum(x % (i + 100) for i, x in enumerate(values))
encoded = lottery = alphabet[values_hash % len(alphabet)]
- last = None
for i, value in enumerate(values):
alphabet_salt = (lottery + salt + alphabet)[:len_alphabet]
alphabet = _reorder(alphabet, alphabet_salt)
@@ -199,14 +190,12 @@ class Hashids(object):
separators = _reorder(separators, salt)
min_separators = _index_from_ratio(len_alphabet, RATIO_SEPARATORS)
- if not separators or len_separators < min_separators:
- if min_separators == 1:
- min_separators = 2
- if min_separators > len_separators:
- split_at = min_separators - len_separators
- separators += alphabet[:split_at]
- alphabet = alphabet[split_at:]
- len_alphabet = len(alphabet)
+
+ number_of_missing_separators = min_separators - len_separators
+ if number_of_missing_separators > 0:
+ separators += alphabet[:number_of_missing_separators]
+ alphabet = alphabet[number_of_missing_separators:]
+ len_alphabet = len(alphabet)
alphabet = _reorder(alphabet, salt)
num_guards = _index_from_ratio(len_alphabet, RATIO_GUARDS)
diff --git a/setup.py b/setup.py
index c47417d..2555abd 100755
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ from os.path import dirname, join
from codecs import open
setup(name='hashids',
- version='1.1.0',
+ version='1.2.0',
description='Python implementation of hashids (http://www.hashids.org).'
'Compatible with python 2.6-3.',
long_description=open(join(dirname(__file__), 'README.rst'), encoding='utf-8').read(),
@@ -12,4 +12,15 @@ setup(name='hashids',
author_email='dev at david-aurelio.com',
url='https://github.com/davidaurelio/hashids-python',
license='MIT License',
- py_modules=('hashids',))
+ py_modules=('hashids',),
+ classifiers=[
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.2',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.6',
+ ],)
diff --git a/test/test_hashids.py b/test/test_hashids.py
index d0e5542..12ed09a 100644
--- a/test/test_hashids.py
+++ b/test/test_hashids.py
@@ -1,9 +1,13 @@
from hashids import Hashids
import pytest
+
class TestConstructor(object):
- def test_small_alphabet(self):
- pytest.raises(ValueError, Hashids, alphabet='abcabc')
+ def test_small_alphabet_with_no_repeating_characters(self):
+ pytest.raises(ValueError, Hashids, alphabet='abcdefghijklmno')
+
+ def test_small_alphabet_with_repeating_characters(self):
+ pytest.raises(ValueError, Hashids, alphabet='abcdecfghijklbmnoa')
class TestEncoding(object):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-hashids.git
More information about the Python-modules-commits
mailing list