diff options
author | Harel Ben-Attia <harelba@gmail.com> | 2020-09-14 15:43:52 +0300 |
---|---|---|
committer | Harel Ben-Attia <harelba@gmail.com> | 2020-09-14 15:43:52 +0300 |
commit | 5b428b60d63b50c17faf68a5969961a67bdd3467 (patch) | |
tree | f535c054523820ae96ce33b6e9c7e331abc47bc7 | |
parent | e11c3a1659d4a74c93dc65ec89023a896fbd1383 (diff) |
reintroduce old sha1 for backward compat + version bumps
-rwxr-xr-x | bin/q.py | 20 | ||||
-rwxr-xr-x | do-manual-release.sh | 2 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rwxr-xr-x | test/test-suite | 2 |
4 files changed, 14 insertions, 12 deletions
@@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright (C) 2012-2019 Harel Ben-Attia +# Copyright (C) 2012-2020 Harel Ben-Attia # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ from __future__ import print_function from collections import OrderedDict -q_version = '2.0.16' +q_version = '2.0.17' __all__ = [ 'QTextAsData' ] @@ -89,9 +89,11 @@ def sha(data,algorithm,encoding): except Exception as e: print(e) -# For backward compatibility -def sha1(data,encoding): - return sha(data,1,encoding) +# For backward compatibility only (doesn't handle encoding well enough) +def sha1(data): + if not isinstance(data,str) and not isinstance(data,unicode): + return hashlib.sha1(str(data)).hexdigest() + return hashlib.sha1(data).hexdigest() # TODO Add caching of compiled regexps - Will be added after benchmarking capability is baked in def regexp(regular_expression, data): @@ -217,10 +219,10 @@ user_functions = [ sha, 3), UserFunctionDef(FunctionType.REGULAR, - "sha1","sha1(<expr>,<encoding>) = <hex-string-of-sha>", - "Calculate sha1 of some expression. For now encoding must be manually provided. Will be taken automatically from the input encoding in the future.", + "sha1","sha1(<expr>) = <hex-string-of-sha>", + "Exists for backward compatibility only, since it doesn't handle encoding properly. Calculates sha1 of some expression", sha1, - 2), + 1), UserFunctionDef(FunctionType.REGULAR, "md5","md5(<expr>,<encoding>) = <hex-string-of-md5>", "Calculate md5 of expression. Returns a hex-string of the result. Currently requires to manually provide the encoding of the data. Will be taken automatically from the input encoding in the future.", @@ -1296,7 +1298,7 @@ def determine_max_col_lengths(m,output_field_quoting_func,output_delimiter): def print_credentials(): print("q version %s" % q_version, file=sys.stderr) print("Python: %s" % " // ".join([str(x).strip() for x in sys.version.split("\n")]), file=sys.stderr) - print("Copyright (C) 2012-2019 Harel Ben-Attia (harelba@gmail.com, @harelba on twitter)", file=sys.stderr) + print("Copyright (C) 2012-2020 Harel Ben-Attia (harelba@gmail.com, @harelba on twitter)", file=sys.stderr) print("http://harelba.github.io/q/", file=sys.stderr) print(file=sys.stderr) diff --git a/do-manual-release.sh b/do-manual-release.sh index 5147061..1111677 100755 --- a/do-manual-release.sh +++ b/do-manual-release.sh @@ -2,7 +2,7 @@ set -e -VERSION=2.0.16 +VERSION=2.0.17 if [[ "$TRAVIS_BRANCH" != "master" ]] then @@ -2,7 +2,7 @@ from setuptools import setup -q_version = '2.0.16' +q_version = '2.0.17' setup( name='q', diff --git a/test/test-suite b/test/test-suite index 7efa3fe..b44b357 100755 --- a/test/test-suite +++ b/test/test-suite @@ -1601,7 +1601,7 @@ class UserFunctionTests(AbstractQTestCase): self.assertEqual(o[4],six.b('55.9016994375')) def test_sha1_function(self): - cmd = 'seq 1 4 | %s -c 1 -d , "select c1,sha1(c1,\'utf-8\') from -"' % Q_EXECUTABLE + cmd = 'seq 1 4 | %s -c 1 -d , "select c1,sha1(c1) from -"' % Q_EXECUTABLE retcode, o, e = run_command(cmd) self.assertEqual(retcode,0) |