15
15
# You should have received a copy of the GNU Lesser General Public License
16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
18
+ from __future__ import print_function , division , absolute_import
19
+
20
+ import six
21
+
18
22
import json
19
23
import requests
20
24
import sys
@@ -292,7 +296,7 @@ def create(self, obj):
292
296
293
297
url = self .constructUrl (id_ = None , obj = obj , parameters = obj .__dict__ )
294
298
295
- for k , v in obj .__dict__ .items ():
299
+ for k , v in list ( obj .__dict__ .items () ):
296
300
if type (v ) == bool :
297
301
obj .__dict__ [k ] = 1 if v else 0
298
302
@@ -317,12 +321,12 @@ def update(self, obj):
317
321
318
322
# build a dict of data that can really be sent to server
319
323
d = {}
320
- for k , v in obj .__dict__ .items ():
324
+ for k , v in list ( obj .__dict__ .items () ):
321
325
if type (v ) in (int , str ):
322
326
d [k ] = str (v )
323
327
elif type (v ) == bool :
324
328
d [k ] = 1 if v else 0
325
- elif type (v ) == unicode :
329
+ elif six . PY2 and type (v ) == six . text_type :
326
330
d [k ] = str (v .encode (self .gitlab_encoding , "replace" ))
327
331
328
332
try :
@@ -473,7 +477,7 @@ def _get_display_encoding():
473
477
474
478
475
479
def _sanitize (value ):
476
- if type (value ) in ( str , unicode ):
480
+ if isinstance (value , six . string_types ):
477
481
return value .replace ('/' , '%2F' )
478
482
return value
479
483
@@ -573,7 +577,8 @@ def delete(self):
573
577
def __init__ (self , gl , data = None , ** kwargs ):
574
578
self .gitlab = gl
575
579
576
- if data is None or type (data ) in [int , str , unicode ]:
580
+ if data is None or isinstance (data , six .integer_types ) or \
581
+ isinstance (data , six .string_types ):
577
582
data = self .gitlab .get (self .__class__ , data , ** kwargs )
578
583
579
584
self ._setFromDict (data )
@@ -609,7 +614,7 @@ def _obj_to_str(obj):
609
614
elif isinstance (obj , list ):
610
615
s = ", " .join ([GitlabObject ._obj_to_str (x ) for x in obj ])
611
616
return "[ %s ]" % s
612
- elif isinstance (obj , unicode ):
617
+ elif six . PY2 and isinstance (obj , six . text_type ):
613
618
return obj .encode (_get_display_encoding (), "replace" )
614
619
else :
615
620
return str (obj )
@@ -622,7 +627,8 @@ def pretty_print(self, depth=0):
622
627
continue
623
628
v = self .__dict__ [k ]
624
629
pretty_k = k .replace ('_' , '-' )
625
- pretty_k = pretty_k .encode (_get_display_encoding (), "replace" )
630
+ if six .PY2 :
631
+ pretty_k = pretty_k .encode (_get_display_encoding (), "replace" )
626
632
if isinstance (v , GitlabObject ):
627
633
if depth == 0 :
628
634
print ("%s:" % pretty_k )
0 commit comments