Skip to content

Commit 20a6e87

Browse files
committed
Fixed UFT8 problems since Python3 handles strings differently
1 parent f8106dc commit 20a6e87

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

scripts/smart_dispatch.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def main():
126126
jobs_id = []
127127
for pbs_filename in pbs_filenames:
128128
qsub_output = check_output('{launcher} {pbs_filename}'.format(launcher=LAUNCHER if args.launcher is None else args.launcher, pbs_filename=pbs_filename), shell=True)
129+
130+
if isinstance(qsub_output, bytes):
131+
qsub_output = qsub_output.decode("utf-8")
132+
129133
jobs_id += [qsub_output.strip()]
130134

131135
with open_with_lock(pjoin(path_job, "jobs_id.txt"), 'a') as jobs_id_file:

smartdispatch/utils.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22

33
import re
4+
import binascii
45
import hashlib
56
import unicodedata
67
import json
@@ -37,13 +38,13 @@ def yes_no_prompt(query, default=None):
3738

3839
def chunks(sequence, n):
3940
""" Yield successive n-sized chunks from sequence. """
40-
for i in xrange(0, len(sequence), n):
41+
for i in range(0, len(sequence), n):
4142
yield sequence[i:i + n]
4243

4344

4445
def generate_uid_from_string(value):
4546
""" Create unique identifier from a string. """
46-
return hashlib.sha256(value).hexdigest()
47+
return hashlib.sha256(value.encode()).hexdigest()
4748

4849

4950
def slugify(value):
@@ -56,15 +57,21 @@ def slugify(value):
5657
---------
5758
https://github.com/django/django/blob/1.7c3/django/utils/text.py#L436
5859
"""
59-
value = unicodedata.normalize('NFKD', unicode(value, "UTF-8")).encode('ascii', 'ignore').decode('ascii')
60+
try:
61+
value = unicode(value, "UTF-8")
62+
except NameError:
63+
pass # In Python 3 all strings are already unicode.
64+
65+
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
6066
value = re.sub('[^\w\s-]', '', value).strip().lower()
6167
return str(re.sub('[-\s]+', '_', value))
6268

6369

6470
def encode_escaped_characters(text, escaping_character="\\"):
6571
""" Escape the escaped character using its hex representation """
6672
def hexify(match):
67-
return "\\x{0}".format(match.group()[-1].encode("hex"))
73+
# Reference: http://stackoverflow.com/questions/18298251/python-hex-values-to-convert-to-a-string-integer
74+
return "\\x" + binascii.hexlify(match.group()[-1].encode()).decode()
6875

6976
return re.sub(r"\\.", hexify, text)
7077

@@ -75,7 +82,7 @@ def decode_escaped_characters(text):
7582
return ''
7683

7784
def unhexify(match):
78-
return match.group()[2:].decode("hex")
85+
return binascii.unhexlify(match.group()[2:]).decode()
7986

8087
return re.sub(r"\\x..", unhexify, text)
8188

0 commit comments

Comments
 (0)