Skip to content

Commit

Permalink
reintroduce old sha1 for backward compat + version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
harelba committed Sep 14, 2020
1 parent e11c3a1 commit 5b428b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
20 changes: 11 additions & 9 deletions bin/q.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,7 +33,7 @@

from collections import OrderedDict

q_version = '2.0.16'
q_version = '2.0.17'

__all__ = [ 'QTextAsData' ]

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -217,10 +219,10 @@ def __init__(self,func_type,name,usage,description,func_or_obj,param_count):
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.",
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion do-manual-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

VERSION=2.0.16
VERSION=2.0.17

if [[ "$TRAVIS_BRANCH" != "master" ]]
then
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

q_version = '2.0.16'
q_version = '2.0.17'

setup(
name='q',
Expand Down
2 changes: 1 addition & 1 deletion test/test-suite
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5b428b6

Please sign in to comment.