Skip to content

Commit e74a37f

Browse files
committed
Merge branch 'release/0.7.3'
2 parents 3b4fdd9 + 1b818e5 commit e74a37f

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ License
3939
Changelog
4040
~~~~~~~~~
4141

42+
- v0.7.3
43+
44+
- Fix a couple crashes when certain functions that expect ``str`` were passed
45+
integers.
46+
4247
- v0.7.2
4348

4449
- Fix a couple inconsistencies with ``str`` vs ``bytes`` in Python 3 in

drmaa/helpers.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
drmaa_version, STRING)
4747

4848

49+
# Python 3 compatability help
50+
if sys.version_info < (3, 0):
51+
bytes = str
52+
str = unicode
53+
54+
4955
_BUFLEN = ATTR_BUFFER
5056

5157

@@ -54,10 +60,10 @@ class BoolConverter(object):
5460
"""Helper class to convert to/from bool attributes."""
5561

5662
def __init__(self, true=b'y', false=b'n'):
57-
if not isinstance(true, bytes):
63+
if isinstance(true, str):
5864
true = true.encode()
5965
self.true = true
60-
if not isinstance(false, bytes):
66+
if isinstance(false, str):
6167
false = false.encode()
6268
self.false = false
6369

@@ -132,15 +138,15 @@ def __init__(self, name, type_converter=None):
132138
a converter to translate attribute values to/from the underlying
133139
implementation. See BoolConverter for an example.
134140
"""
135-
if not isinstance(name, bytes):
141+
if isinstance(name, str):
136142
name = name.encode()
137143
self.name = name
138144
self.converter = type_converter
139145

140146
def __set__(self, instance, value):
141147
if self.converter:
142148
v = self.converter.to_drmaa(value)
143-
elif not isinstance(value, bytes):
149+
elif isinstance(value, str):
144150
v = value.encode()
145151
else:
146152
v = value
@@ -167,7 +173,7 @@ class VectorAttribute(object):
167173
"""
168174

169175
def __init__(self, name):
170-
if not isinstance(name, bytes):
176+
if isinstance(name, str):
171177
name = name.encode()
172178
self.name = name
173179

@@ -188,7 +194,7 @@ class DictAttribute(object):
188194
"""
189195

190196
def __init__(self, name):
191-
if not isinstance(name, bytes):
197+
if isinstance(name, str):
192198
name = name.encode()
193199
self.name = name
194200

@@ -290,7 +296,7 @@ def string_vector(v):
290296
vlen = len(v)
291297
values = (STRING * (vlen + 1))()
292298
for i, el in enumerate(v):
293-
values[i] = STRING(el.encode() if not isinstance(el, bytes) else el)
299+
values[i] = STRING(el.encode() if isinstance(el, str) else el)
294300
values[vlen] = STRING()
295301
return values
296302

drmaa/session.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from __future__ import absolute_import, print_function, unicode_literals
2424

25+
import sys
2526
from collections import namedtuple
2627
from ctypes import byref, c_int, create_string_buffer, pointer, POINTER, sizeof
2728

@@ -50,6 +51,12 @@
5051
py_drmaa_exit, py_drmaa_init)
5152

5253

54+
# Python 3 compatability help
55+
if sys.version_info < (3, 0):
56+
bytes = str
57+
str = unicode
58+
59+
5360
JobInfo = namedtuple("JobInfo",
5461
"""jobId hasExited hasSignal terminatedSignal hasCoreDump
5562
wasAborted exitStatus resourceUsage""")
@@ -368,8 +375,8 @@ def control(jobId, operation):
368375
jobs submitted by other DRMAA session in other DRMAA implementations
369376
or jobs submitted via native utilities.
370377
"""
371-
if not isinstance(jobId, bytes):
372-
jobId = jobId.encode()
378+
if isinstance(jobId, str):
379+
jobId = jobId.encode()
373380
c(drmaa_control, jobId, string_to_control_action(operation))
374381

375382
# takes string list, num value and boolean, no return value
@@ -453,9 +460,9 @@ def wait(jobId, timeout=-1):
453460
stat = c_int()
454461
jid_out = create_string_buffer(128)
455462
rusage = pointer(POINTER(drmaa_attr_values_t)())
456-
if not isinstance(jobId, bytes):
457-
jobId = jobId.encode()
458-
c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout,
463+
if isinstance(jobId, str):
464+
jobId = jobId.encode()
465+
c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout,
459466
rusage)
460467
res_usage = adapt_rusage(rusage)
461468
exited = c_int()
@@ -501,8 +508,8 @@ def jobStatus(jobId):
501508
jobs return a FAILED status.
502509
"""
503510
status = c_int()
504-
if not isinstance(jobId, bytes):
505-
jobId = jobId.encode()
511+
if isinstance(jobId, str):
512+
jobId = jobId.encode()
506513
c(drmaa_job_ps, jobId, byref(status))
507514
return status_to_string(status.value)
508515

drmaa/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
:author: Dan Blanchard (dblanchard@ets.org)
2323
'''
2424

25-
__version__ = '0.7.2'
25+
__version__ = '0.7.3'
2626
VERSION = tuple(int(x) for x in __version__.split('.'))

drmaa/wrappers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@
2424
from __future__ import absolute_import, print_function, unicode_literals
2525

2626
import os
27+
import sys
2728
from ctypes import (c_char_p, c_int, c_long, c_size_t, c_uint, c_ulong, CDLL,
2829
POINTER, RTLD_GLOBAL, sizeof, Structure)
2930
from ctypes.util import find_library
3031

3132
from drmaa.errors import error_check, error_buffer
3233

34+
35+
# Python 3 compatability help
36+
if sys.version_info < (3, 0):
37+
bytes = str
38+
str = unicode
39+
40+
3341
# the name of the OS environment variable optionally
3442
# containing the full path to the drmaa library
3543
_drmaa_lib_env_name = 'DRMAA_LIBRARY_PATH'
@@ -59,7 +67,7 @@
5967

6068

6169
def py_drmaa_init(contact=None):
62-
if not isinstance(contact, bytes) and contact is not None:
70+
if isinstance(contact, str):
6371
contact = contact.encode()
6472
return _lib.drmaa_init(contact, error_buffer, sizeof(error_buffer))
6573

0 commit comments

Comments
 (0)