@@ -40,11 +40,11 @@ def process_args_and_login(parser=None, client=None, showparameter=None, fields=
40
40
debug = True
41
41
if (debug or __debug__ ) and args .log_file is not None :
42
42
try :
43
- log_file = open (args .log_file , "wb " )
43
+ log_file = open (args .log_file [ 0 ] , "w " )
44
44
except IOError :
45
45
debug_log ("Could not open given log file for writing, sending debug information to stderr." )
46
46
# open the output file if given one
47
- output_file = open (args .output [0 ], "wb " ) if args .output else None
47
+ output_file = open (args .output [0 ], "w " ) if args .output else None
48
48
output_file_format = args .format [0 ].lower ()
49
49
user_created = (args .user_created [0 ].lower () == "true" ) if args .user_created else True
50
50
@@ -141,7 +141,7 @@ def export_json(data, fields, output_file, output_file_format, user_created, app
141
141
142
142
# getting the raw JSON data from the management server for commands such as show-...s
143
143
def get_raw_data (param , payload = None , container_keys = "objects" , client = None ):
144
- if isinstance (container_keys , basestring ):
144
+ if isinstance (container_keys , str ):
145
145
container_keys = [container_keys ]
146
146
# trying to log in to the management server
147
147
if not payload :
@@ -213,7 +213,7 @@ def format_objects(data, fields_dict, output_file_format, user_created=True, dum
213
213
res = {}
214
214
215
215
# this loop removes unnecessary dicts and lists and adds the good values to extracted_fields
216
- for key in flat .keys ():
216
+ for key in flat .copy (). keys ():
217
217
try :
218
218
if isinstance (flat [key ], (list , dict )):
219
219
del flat [key ]
@@ -232,7 +232,7 @@ def format_objects(data, fields_dict, output_file_format, user_created=True, dum
232
232
if "whitelist" in fields_dict :
233
233
if len (fields_dict ["whitelist" ]) > 0 :
234
234
for pattern in fields_dict ["whitelist" ]:
235
- for key in flat .keys ():
235
+ for key in flat .copy (). keys ():
236
236
# match keys with the given patterns
237
237
if key_matches (key , pattern ):
238
238
res [key ] = flat [key ]
@@ -329,7 +329,7 @@ def format_objects(data, fields_dict, output_file_format, user_created=True, dum
329
329
# searches for values that are matched with keys that match the regex
330
330
def search_dict (dictionary , regex ):
331
331
result = []
332
- if isinstance (regex , basestring ):
332
+ if isinstance (regex , str ):
333
333
regex = re .compile (regex )
334
334
for key in dictionary :
335
335
if key_matches (key , regex ):
@@ -385,8 +385,8 @@ def key_matches(key, pattern):
385
385
386
386
def key_matches (key , pattern ):
387
387
if pattern :
388
- if isinstance (pattern , basestring ):
389
- return re .search (re . escape ( pattern ) if isinstance ( pattern , unicode ) else pattern , key )
388
+ if isinstance (pattern , str ):
389
+ return re .search (pattern , key )
390
390
else :
391
391
return pattern .search (key )
392
392
return False
@@ -476,7 +476,7 @@ def get_dict_len(d):
476
476
# unravels a json tree into a dict with all the key-value pairs on the first level, with keys written as follows: 'k1.k2.7.k3' (7 for signifying the 8th element in the list k2)
477
477
def flatten_json (jsondata ):
478
478
if isinstance (jsondata , dict ):
479
- jdkeys = jsondata .keys ()
479
+ jdkeys = jsondata .copy (). keys ()
480
480
for key in jdkeys :
481
481
merge_flat_dicts (jsondata , flatten_json (jsondata [key ]), key + '.' )
482
482
return jsondata
@@ -512,8 +512,8 @@ def flat_json_to_csv(jsondata, fields_order, print_column_names=True):
512
512
for key in ordered_keys :
513
513
var_to_append = ""
514
514
if len (jsondata [key ]) > i and jsondata [key ][i ] is not None :
515
- if isinstance (jsondata [key ][i ], unicode ):
516
- var_to_append = jsondata [key ][i ]. encode ( "utf-8" )
515
+ if isinstance (jsondata [key ][i ], str ):
516
+ var_to_append = jsondata [key ][i ]
517
517
else :
518
518
# var is int
519
519
var_to_append = str (jsondata [key ][i ])
@@ -572,7 +572,7 @@ def get_fields_order_and_replace(fields, whitelist, translate):
572
572
temp_keys .append (zfill_key (key ))
573
573
fields_order += sorted (temp_keys )
574
574
# iterate over the list of remaining items in indexer, those that don't fit in a specific whitelisted field. general replacer
575
- for k , v in indexer .iteritems ():
575
+ for k , v in indexer .items ():
576
576
for i in range (len (fields_order )):
577
577
if key_matches (fields_order [i ], k ):
578
578
for sub_pair in translate [v ][1 ]:
@@ -691,14 +691,14 @@ def get_username_and_password(username=None, password=None):
691
691
debug_log ("Trying to get username and password." )
692
692
# getting username and password if nothing else worked
693
693
if username is None :
694
- username = raw_input ("Enter username: " )
694
+ username = input ("Enter username: " )
695
695
if password is None :
696
696
# getpass only works in a tty:
697
697
if sys .stdin .isatty ():
698
698
password = getpass .getpass ("Enter password: " )
699
699
else :
700
700
print ("Attention! Your password will be shown on the screen!" , file = sys .stderr )
701
- password = raw_input ("Enter password: " )
701
+ password = input ("Enter password: " )
702
702
return username , password
703
703
704
704
@@ -736,7 +736,7 @@ def order_data(self):
736
736
uidlist = []
737
737
result = []
738
738
extras = []
739
- for k , v in self .treenodes_map .iteritems ():
739
+ for k , v in self .treenodes_map .items ():
740
740
# it has no parents -> it is a root of a tree
741
741
if not v .parents :
742
742
uidlist += v .postorder_traverse ()
0 commit comments