Skip to content

Commit 23f7b8f

Browse files
committed
update code base from python2 to python3
1 parent a4fdca3 commit 23f7b8f

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

maestro/aws/s3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def __parse_kwargs__(self, kwargs):
203203
return True
204204
if len(kwargs) == 0 and self.bucket_name is None and self.source_url is None:
205205
return self.help()
206-
for key, val in kwargs.iteritems():
206+
for key, val in list(kwargs.items()):
207207
if key in HELP_KEYS:
208208
return self.help()
209209
elif key in BUCKET_KEYS:
@@ -324,7 +324,7 @@ def download(self):
324324
else:
325325
keyvals[current_key] = None
326326
current_key = arg.lstrip('-')
327-
if current_key is not None and current_key not in keyvals.keys():
327+
if current_key is not None and current_key not in list(keyvals.keys()):
328328
keyvals[current_key] = ""
329329

330330
s3dl = AsyncS3Downloader(None)

maestro/core/execute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from ioc import SingleObjectContainer
2-
from module import Module
1+
from .ioc import SingleObjectContainer
2+
from .module import Module
33
import sys
44

55

maestro/core/ioc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def register(self, id, obj):
3232
if id is None:
3333
raise TypeError("You cannot use a None type as an id.")
3434

35-
if not isinstance(id, basestring):
35+
if not isinstance(id, str):
3636
raise TypeError("You must pass a valid string for the id!")
3737

3838
if self.object_type is None:
@@ -41,7 +41,7 @@ def register(self, id, obj):
4141
if not isinstance(obj, self.object_type):
4242
raise TypeError("The object passed to the Container was not of type " + str(self.object_type) + ".")
4343

44-
if id in self.__objects.keys():
44+
if id in list(self.__objects.keys()):
4545
raise ValueError("ID " + str(id) + " is already registered with this container.")
4646

4747
self.__objects[id] = obj
@@ -51,7 +51,7 @@ def deregister(self, id):
5151
Deregisters object with id. Will raise ValueError if the id does not exist.
5252
"""
5353

54-
if id not in self.__objects.keys():
54+
if id not in list(self.__objects.keys()):
5555
raise ValueError("ID " + str(id) + " is not registered with this container.")
5656

5757
del self.__objects[id]
@@ -60,7 +60,7 @@ def getinstance(self, id):
6060
"""
6161
Returns a new instance of an object with the provided id. The container does not track this object.
6262
"""
63-
if id not in self.__objects.keys():
63+
if id not in list(self.__objects.keys()):
6464
raise ValueError("ID " + str(id) + " is not registered with this container.")
6565
item_type = type(self[id])
6666

@@ -70,7 +70,7 @@ def unregister(self, id):
7070
return self.deregister(id)
7171

7272
def __getitem__(self, id):
73-
if id not in self.__objects.keys():
73+
if id not in list(self.__objects.keys()):
7474
raise KeyError("A " + str(self.object_type) + " object with id " + str(id) + " is not registered with this container.")
7575

7676
return self.__objects[id]
@@ -79,4 +79,4 @@ def get(self, id):
7979
return self.__getitem__(id)
8080

8181
def list(self):
82-
return self.__objects.items()
82+
return list(self.__objects.items())

maestro/core/module.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Modules are meant to help build modular tools.
77
"""
88
import types
9-
import copy_reg
9+
import copyreg
1010
import sys
1111
import traceback
1212
from multiprocessing import Process, log_to_stderr
@@ -70,23 +70,23 @@ def start(self, kwargs={}):
7070

7171
def help(self):
7272
try:
73-
print (self.HELPTEXT)
73+
print(self.HELPTEXT)
7474
except NameError:
75-
print ("No help defined for module " + str(type(self)))
75+
print("No help defined for module " + str(type(self)))
7676
return True
7777

7878

7979
def __pickle_method__(m):
8080
"""
8181
Pickling override for using pickle with instance methods.
8282
"""
83-
if m.im_self is None:
84-
return getattr, (m.im_class, m.im_func.func_name)
83+
if m.__self__ is None:
84+
return getattr, (m.__self__.__class__, m.__func__.__name__)
8585
else:
86-
return getattr, (m.im_self, m.im_func.func_name)
86+
return getattr, (m.__self__, m.__func__.__name__)
8787

8888

89-
copy_reg.pickle(types.MethodType, __pickle_method__)
89+
copyreg.pickle(types.MethodType, __pickle_method__)
9090

9191

9292
class AsyncModule(Module):
@@ -129,7 +129,7 @@ def __setup__(self, kwargs):
129129
exc.traceback = "".join(traceback.format_exception(*sys.exc_info()))
130130
return exc
131131
except Exception as e:
132-
print ("FATAL ERROR -- " + str(e))
132+
print("FATAL ERROR -- " + str(e))
133133

134134
def __finish_internal__(self, callback_args):
135135
"""

maestro/tools/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def symlink(source, link_name):
7979
def purge(pattern, path, match_directories=False):
8080
for root, dirs, files in os.walk(path):
8181
if match_directories is True:
82-
for dir in filter(lambda x: re.match(pattern, x), dirs):
82+
for dir in [x for x in dirs if re.match(pattern, x)]:
8383
shutil.rmtree(os.path.join(root, dir))
84-
for file in filter(lambda x: re.match(pattern, x), files):
84+
for file in [x for x in files if re.match(pattern, x)]:
8585
os.remove(os.path.join(root, file))
8686

8787

maestro/tools/string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ def replaceall(replace_dict, string):
55
"""
66
replaceall will take the keys in replace_dict and replace string with their corresponding values. Keys can be regular expressions.
77
"""
8-
replace_dict = dict((re.escape(k), v) for k, v in replace_dict.iteritems())
9-
pattern = re.compile("|".join(replace_dict.keys()))
8+
replace_dict = dict((re.escape(k), v) for k, v in list(replace_dict.items()))
9+
pattern = re.compile("|".join(list(replace_dict.keys())))
1010
return pattern.sub(lambda m: replace_dict[re.escape(m.group(0))], string)

0 commit comments

Comments
 (0)