From 162a44f725484940845c70f4c39b62d11e6ef032 Mon Sep 17 00:00:00 2001 From: Python3pkg Date: Wed, 17 May 2017 23:03:08 -0700 Subject: [PATCH 1/4] Convert to python3 --- batbelt/__init__.py | 10 +++++----- batbelt/parallel.py | 2 +- batbelt/strings.py | 12 ++++++------ batbelt/structs.py | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/batbelt/__init__.py b/batbelt/__init__.py index c45e927..8af658e 100644 --- a/batbelt/__init__.py +++ b/batbelt/__init__.py @@ -5,10 +5,10 @@ __version__ = "0.5.2" -from strings import (slugify, normalize, escape_html, +from .strings import (slugify, normalize, escape_html, unescape_html, json_dumps, json_loads) -from structs import (chunks, get, dmerge, sset, dswap, window, +from .structs import (chunks, get, dmerge, sset, dswap, window, subdict, iget, flatten, skip_duplicates) -from objects import attr, import_from_path, Null -from utils import to_timestamp -from hack import decorator_with_args +from .objects import attr, import_from_path, Null +from .utils import to_timestamp +from .hack import decorator_with_args diff --git a/batbelt/parallel.py b/batbelt/parallel.py index cf656a4..c944886 100644 --- a/batbelt/parallel.py +++ b/batbelt/parallel.py @@ -9,7 +9,7 @@ import threading import multiprocessing from functools import wraps -from Queue import Queue, Empty +from queue import Queue, Empty __all__ = ['process', 'thread'] diff --git a/batbelt/strings.py b/batbelt/strings.py index 3e3d9b4..6dcefc8 100644 --- a/batbelt/strings.py +++ b/batbelt/strings.py @@ -60,7 +60,7 @@ from datetime import datetime, timedelta, date, time from xml.sax.saxutils import escape, unescape -from utils import CLASSIC_DATETIME_FORMAT, CLASSIC_DATETIME_PATTERN +from .utils import CLASSIC_DATETIME_FORMAT, CLASSIC_DATETIME_PATTERN @@ -81,7 +81,7 @@ def unicode_slugify(string, separator=r'-'): string = re.sub(r'[^\w\s' + separator + ']', '', string, flags=re.U) string = string.strip().lower() - return unicode(re.sub(r'[' + separator + '\s]+', + return str(re.sub(r'[' + separator + '\s]+', separator, string, flags=re.U)) @@ -101,7 +101,7 @@ def unicodedata_slugify(string, separator=r'-'): string = unicodedata.normalize('NFKD', string).encode('ascii', 'ignore') string = re.sub(r'[^\w\s' + separator + ']', '', string).strip().lower() - return unicode(re.sub(r'[' + separator + '\s]+', separator, string)) + return str(re.sub(r'[' + separator + '\s]+', separator, string)) def unidecode_slugify(string, separator=r'-'): @@ -120,7 +120,7 @@ def unidecode_slugify(string, separator=r'-'): string = unidecode.unidecode(string) string = re.sub(r'[^\w\s' + separator + ']', '', string).strip().lower() - return unicode(re.sub(r'[' + separator + '\s]+', separator, string)) + return str(re.sub(r'[' + separator + '\s]+', separator, string)) def unicodedata_normalize(string): @@ -270,7 +270,7 @@ def decode_on_match(self, obj): parse it and returns a Python object. """ - string = unicode(obj) + string = str(obj) match = re.search(self.datetime_pattern, string) if match: @@ -418,7 +418,7 @@ def write(path, *args, **kwargs): if isinstance(line, str): line = line.decode(encoding, errors) - if not isinstance(line, unicode): + if not isinstance(line, str): line = repr(line) f.write(line + os.linesep) diff --git a/batbelt/structs.py b/batbelt/structs.py index 8b72cf9..d9495bf 100644 --- a/batbelt/structs.py +++ b/batbelt/structs.py @@ -18,7 +18,7 @@ def chunks(seq, chunksize, process=tuple): """ it = iter(seq) while True: - yield process(chain([it.next()], islice(it, chunksize - 1))) + yield process(chain([next(it)], islice(it, chunksize - 1))) @@ -52,7 +52,7 @@ def dmerge(d1, d2, merge_func=None): d.update(d2) return d - for k, v in d2.iteritems(): + for k, v in d2.items(): if k in d: d[k] = merge_func(d[k], v) else: @@ -75,7 +75,7 @@ def dswap(dct): >>> sorted(dswap({'a': 1, 'b': 2}).items()) [(1, 'a'), (2, 'b')] """ - return dict((value, key) for key, value in dct.iteritems()) + return dict((value, key) for key, value in dct.items()) def get(data, *keys, **kwargs): @@ -189,9 +189,9 @@ def subdict(dct, include=(), exclude=()): """ if include: - return dict((k, v) for k, v in dct.iteritems() if k in include) + return dict((k, v) for k, v in dct.items() if k in include) - return dict((k, v) for k, v in dct.iteritems() if k not in exclude) + return dict((k, v) for k, v in dct.items() if k not in exclude) @@ -381,7 +381,7 @@ def remove_duplicates(lst, equals=lambda x, y: x == y): -KEY, PREV, NEXT = range(3) +KEY, PREV, NEXT = list(range(3)) class sset(MutableSet): From f76da58b16b2ace65b26f52149e10bca05253b96 Mon Sep 17 00:00:00 2001 From: ralic Date: Sat, 30 Sep 2017 08:34:46 +0800 Subject: [PATCH 2/4] Bug fixing --- batbelt/structs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/batbelt/structs.py b/batbelt/structs.py index d9495bf..4b84d63 100644 --- a/batbelt/structs.py +++ b/batbelt/structs.py @@ -52,7 +52,7 @@ def dmerge(d1, d2, merge_func=None): d.update(d2) return d - for k, v in d2.items(): + for k, v in list(d2.items()): if k in d: d[k] = merge_func(d[k], v) else: @@ -75,7 +75,7 @@ def dswap(dct): >>> sorted(dswap({'a': 1, 'b': 2}).items()) [(1, 'a'), (2, 'b')] """ - return dict((value, key) for key, value in dct.items()) + return dict((value, key) for key, value in list(dct.items())) def get(data, *keys, **kwargs): @@ -189,9 +189,9 @@ def subdict(dct, include=(), exclude=()): """ if include: - return dict((k, v) for k, v in dct.items() if k in include) + return dict((k, v) for k, v in list(dct.items()) if k in include) - return dict((k, v) for k, v in dct.items() if k not in exclude) + return dict((k, v) for k, v in list(dct.items()) if k not in exclude) @@ -509,7 +509,7 @@ class Flattener(object): tuple, set, (x for x in ()).__class__, - xrange, + range, deque, MutableSet, # Sequence # warning, a string is a subclass of Sequence From 239a4bb50d8d01305f189bd0b18f730a9a6f6486 Mon Sep 17 00:00:00 2001 From: ralic Date: Sat, 30 Sep 2017 18:06:10 +0800 Subject: [PATCH 3/4] Update travis.yml --- .travis.yml | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ helpTest.py | 2 ++ requirements.txt | 1 + 3 files changed, 58 insertions(+) create mode 100644 .travis.yml create mode 100644 helpTest.py create mode 100644 requirements.txt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eed45d2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,55 @@ +os: + - linux +python: + - "2.7" + - "3.6" + - "nightly" # currently points to 3.7-dev + +dist: trusty +sudo: required +language: python + + +before_install: + # Show build setup + - uname -a + - cat /etc/os-release + - pwd + - free -tm + - python --version + - git --version + - pip install -r requirements.txt + +install: + # git describe requires complete history + # - travis_retry git fetch --unshallow + - python setup.py install + # - pytest > test.log + # - cat test.log + +script: + - python helpTest.py | grep AllTheDots + +after_success: + - echo "OK, all done." + +notifications: + email: + recipients: + - ralic.lo.eng@ieee.org + on_success: always # default: change + on_failure: never # default: always + +before_deploy: + - pip install gitchangelog + - gitchangelog >> README.rst + +deploy: + provider: pypi + user: cjrk + password: + secure: dqR5LrQgQ4xmWOJCpyvaTFXg7Q35yI5gw6yJypA90Pmz+R3pHLhiq2+3uOeYFIDQoe6CzcwPh1Uvu2SQV3PdDhB1ZjbccsWQQ9WOF4kOkt0ZUoyQlDB+VwiO/nEpjFze7n4VZFFtEVSwd1wmkEAmwDxl5iFvOqDzVkFhDjn3Abp+yZL28vofYaDuwFjCCRPY5L6CQUAE73JixeK7kQNRbIvNsRSZauxNEYPNd9ofdiyyiObY1haWsbVRxMMI+bvnuJWcnNromEEqBfsmsf4PrVZeO8kTRmVYmGhHx87b/OGOkjIMadxAm8tmgh2wjkJuGq+th/Gt7A2CD1H90h85RbRVNwxgU/QJh7ehNsLIMJaJ0iXD3qvQXtpz1YWY/O+Q6I8inaWjU58z2dbdNFShq2NflLNn9ls4k4RmIMn78SI0QzhCYC9FFBYLXe92x3mqonD3zYXc09Z1p7kzqXu6mhGwpk77qK+AIJIwnHE98VgD5UMnfBtxAF0qZ3HGGfWm0gonGRHIhKTccAl/bQ3aLtrAYEm29RMK4TXw5DZI6n/ODLMqXH7RBwE89hUoeVyNg1zNxdka7reDrymI4hJYzhTMljEGS5SUWyo3OZmheJlJ6FUIQiULpNhO8NusLXilknzSMGaHNdiVwklw5Vrs7cDHWx1oxokGWIIW7Y6ZJlk= + on: + tags: true + repo: Python3pkg/AllTheDots + diff --git a/helpTest.py b/helpTest.py new file mode 100644 index 0000000..fe88887 --- /dev/null +++ b/helpTest.py @@ -0,0 +1,2 @@ +help("modules") + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..55b033e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest \ No newline at end of file From 03b65db92050cb195d8389c1139ec6786a0e1538 Mon Sep 17 00:00:00 2001 From: ralic Date: Sat, 30 Sep 2017 18:10:10 +0800 Subject: [PATCH 4/4] Fixing travis-ci --- .travis.yml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index eed45d2..427189c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,11 +24,8 @@ install: # git describe requires complete history # - travis_retry git fetch --unshallow - python setup.py install - # - pytest > test.log - # - cat test.log - script: - - python helpTest.py | grep AllTheDots + - python helpTest.py | grep batbelt after_success: - echo "OK, all done." @@ -40,16 +37,4 @@ notifications: on_success: always # default: change on_failure: never # default: always -before_deploy: - - pip install gitchangelog - - gitchangelog >> README.rst - -deploy: - provider: pypi - user: cjrk - password: - secure: dqR5LrQgQ4xmWOJCpyvaTFXg7Q35yI5gw6yJypA90Pmz+R3pHLhiq2+3uOeYFIDQoe6CzcwPh1Uvu2SQV3PdDhB1ZjbccsWQQ9WOF4kOkt0ZUoyQlDB+VwiO/nEpjFze7n4VZFFtEVSwd1wmkEAmwDxl5iFvOqDzVkFhDjn3Abp+yZL28vofYaDuwFjCCRPY5L6CQUAE73JixeK7kQNRbIvNsRSZauxNEYPNd9ofdiyyiObY1haWsbVRxMMI+bvnuJWcnNromEEqBfsmsf4PrVZeO8kTRmVYmGhHx87b/OGOkjIMadxAm8tmgh2wjkJuGq+th/Gt7A2CD1H90h85RbRVNwxgU/QJh7ehNsLIMJaJ0iXD3qvQXtpz1YWY/O+Q6I8inaWjU58z2dbdNFShq2NflLNn9ls4k4RmIMn78SI0QzhCYC9FFBYLXe92x3mqonD3zYXc09Z1p7kzqXu6mhGwpk77qK+AIJIwnHE98VgD5UMnfBtxAF0qZ3HGGfWm0gonGRHIhKTccAl/bQ3aLtrAYEm29RMK4TXw5DZI6n/ODLMqXH7RBwE89hUoeVyNg1zNxdka7reDrymI4hJYzhTMljEGS5SUWyo3OZmheJlJ6FUIQiULpNhO8NusLXilknzSMGaHNdiVwklw5Vrs7cDHWx1oxokGWIIW7Y6ZJlk= - on: - tags: true - repo: Python3pkg/AllTheDots