diff --git a/bin/q.py b/bin/q.py index 5e165c85..c259588f 100755 --- a/bin/q.py +++ b/bin/q.py @@ -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 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 @@ def __init__(self,func_type,name,usage,description,func_or_obj,param_count): sha, 3), UserFunctionDef(FunctionType.REGULAR, - "sha1","sha1(,) = ", - "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() = ", + "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(,) = ", "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 51470617..11116778 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 diff --git a/setup.py b/setup.py index f672d1c4..49092722 100644 --- a/setup.py +++ b/setup.py @@ -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 7efa3fea..b44b357c 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)