1515# You should have received a copy of the GNU Lesser General Public License
1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18+ from __future__ import print_function , division , absolute_import
19+
20+ import six
21+
1822import json
1923import requests
2024import sys
@@ -292,7 +296,7 @@ def create(self, obj):
292296
293297 url = self .constructUrl (id_ = None , obj = obj , parameters = obj .__dict__ )
294298
295- for k , v in obj .__dict__ .items ():
299+ for k , v in list ( obj .__dict__ .items () ):
296300 if type (v ) == bool :
297301 obj .__dict__ [k ] = 1 if v else 0
298302
@@ -317,12 +321,12 @@ def update(self, obj):
317321
318322 # build a dict of data that can really be sent to server
319323 d = {}
320- for k , v in obj .__dict__ .items ():
324+ for k , v in list ( obj .__dict__ .items () ):
321325 if type (v ) in (int , str ):
322326 d [k ] = str (v )
323327 elif type (v ) == bool :
324328 d [k ] = 1 if v else 0
325- elif type (v ) == unicode :
329+ elif six . PY2 and type (v ) == six . text_type :
326330 d [k ] = str (v .encode (self .gitlab_encoding , "replace" ))
327331
328332 try :
@@ -473,7 +477,7 @@ def _get_display_encoding():
473477
474478
475479def _sanitize (value ):
476- if type (value ) in ( str , unicode ):
480+ if isinstance (value , six . string_types ):
477481 return value .replace ('/' , '%2F' )
478482 return value
479483
@@ -573,7 +577,8 @@ def delete(self):
573577 def __init__ (self , gl , data = None , ** kwargs ):
574578 self .gitlab = gl
575579
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 ):
577582 data = self .gitlab .get (self .__class__ , data , ** kwargs )
578583
579584 self ._setFromDict (data )
@@ -609,7 +614,7 @@ def _obj_to_str(obj):
609614 elif isinstance (obj , list ):
610615 s = ", " .join ([GitlabObject ._obj_to_str (x ) for x in obj ])
611616 return "[ %s ]" % s
612- elif isinstance (obj , unicode ):
617+ elif six . PY2 and isinstance (obj , six . text_type ):
613618 return obj .encode (_get_display_encoding (), "replace" )
614619 else :
615620 return str (obj )
@@ -622,7 +627,8 @@ def pretty_print(self, depth=0):
622627 continue
623628 v = self .__dict__ [k ]
624629 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" )
626632 if isinstance (v , GitlabObject ):
627633 if depth == 0 :
628634 print ("%s:" % pretty_k )
0 commit comments