1
1
from __future__ import print_function
2
+ from six import string_types
2
3
3
4
import argparse
4
5
import jinja2
9
10
import re
10
11
import sys
11
12
13
+ import pprint
14
+ import traceback
12
15
13
16
def parseArgs (args ):
14
17
'''
@@ -100,7 +103,7 @@ def parseType(obj):
100
103
#
101
104
result = '?'
102
105
103
- if True == isinstance (obj , unicode ):
106
+ if True == isinstance (obj , string_types ):
104
107
result = ''
105
108
elif True == isinstance (obj , str ):
106
109
result = ''
@@ -135,24 +138,27 @@ def parseType(obj):
135
138
def convertToStringHook (item , ignoreDicts = False ):
136
139
'''
137
140
This function is passed to the json load function as an object hook. It
138
- converts any unicode strings into ASCII strings.
141
+ converts any string_types strings into ASCII strings.
139
142
140
143
item [in] An item passed in for processing.
141
144
ignoreDicts [in] If this is set to True ignore any dict objects passed in.
142
- returns Items with any unicode strings converted to ASCII.
145
+ returns Items with any string_types strings converted to ASCII.
143
146
'''
144
147
145
- # If this is a unicode string, convert it. If this is a list, convert any
146
- # contained unicode strings. If this is a dict and it hasn't been converted
147
- # already, convert any contained unicode strings. Otherwise, leave the item
148
+ # If this is a string_types string, convert it. If this is a list, convert any
149
+ # contained string_types strings. If this is a dict and it hasn't been converted
150
+ # already, convert any contained string_types strings. Otherwise, leave the item
148
151
# alone.
149
152
#
150
- if isinstance (item , unicode ):
151
- result = item .encode ('utf-8' )
153
+ if isinstance (item , string_types ):
154
+ if sys .version_info [0 ] < 3 :
155
+ result = item .encode ('utf-8' )
156
+ else :
157
+ result = item
152
158
elif isinstance (item , list ):
153
159
result = [ convertToStringHook (element , True ) for element in item ]
154
160
elif isinstance (item , dict ) and not ignoreDicts :
155
- result = { convertToStringHook (key , True ) : convertToStringHook (value , True ) for key , value in item .iteritems () }
161
+ result = { convertToStringHook (key , True ) : convertToStringHook (value , True ) for key , value in item .items () }
156
162
else :
157
163
result = item
158
164
@@ -294,7 +300,7 @@ def resolveValue(name, value, aliasDict):
294
300
295
301
# If the value is not a string, get a string representation.
296
302
#
297
- if False == isinstance (value , str ) and False == isinstance (value , unicode ):
303
+ if False == isinstance (value , str ) and False == isinstance (value , string_types ):
298
304
value = str (value )
299
305
300
306
# If the value starts with 'http', interpret the entire string as a
@@ -379,7 +385,7 @@ def parseAttributes(ncObj, aliasDict):
379
385
380
386
# If the value is a string, wrap it in '"' characters.
381
387
#
382
- if True == isinstance (attrValue , str ) or True == isinstance (attrValue , unicode ):
388
+ if True == isinstance (attrValue , str ) or True == isinstance (attrValue , string_types ):
383
389
attrValue = '"' + str (attrValue ) + '"'
384
390
385
391
valueEntry = { 'element' : attrValue }
@@ -424,7 +430,7 @@ def parseGroup(ncObj, aliasDict):
424
430
dimList = []
425
431
426
432
try :
427
- for dimName , dimObj in ncObj .dimensions .iteritems ():
433
+ for dimName , dimObj in ncObj .dimensions .items ():
428
434
dimEntry = {'name' : dimName }
429
435
430
436
if True == dimObj .isunlimited ():
@@ -445,7 +451,7 @@ def parseGroup(ncObj, aliasDict):
445
451
varList = []
446
452
447
453
try :
448
- for varName , varObj in ncObj .variables .iteritems ():
454
+ for varName , varObj in ncObj .variables .items ():
449
455
varType = parseDtype (varObj .dtype )
450
456
451
457
varEntry = {'name' : varName , 'type' : varType }
@@ -480,6 +486,8 @@ def parseGroup(ncObj, aliasDict):
480
486
481
487
varList .append (varEntry )
482
488
except :
489
+ #type_, value_, traceback_ = sys.exc_info()
490
+ #tb = traceback.format_tb(traceback_)
483
491
pass
484
492
485
493
if 0 < len (varList ):
@@ -522,7 +530,7 @@ def parseDataset(ncObj, aliasDict):
522
530
523
531
# If there are any other groups, add them as well.
524
532
#
525
- for groupName , groupObj in ncObj .groups .iteritems ():
533
+ for groupName , groupObj in ncObj .groups .items ():
526
534
groupEntry = parseGroup (groupObj , aliasDict )
527
535
528
536
groupEntry ['groupName' ] = groupName
0 commit comments