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
+ from itertools import chain
21
+
18
22
import json
19
23
import requests
20
24
import sys
21
25
26
+ if sys .version_info [0 ] < 3 :
27
+ PY2 = True
28
+ str_types = (str , unicode ,)
29
+ else :
30
+ PY2 = False
31
+ str_types = (str ,)
32
+
22
33
__title__ = 'python-gitlab'
23
34
__version__ = '0.7'
24
35
__author__ = 'Gauvain Pocentek'
@@ -312,7 +323,7 @@ def update(self, obj):
312
323
d [k ] = str (v )
313
324
elif type (v ) == bool :
314
325
d [k ] = 1 if v else 0
315
- elif type (v ) == unicode :
326
+ elif PY2 and type (v ) == unicode :
316
327
d [k ] = str (v .encode (self .gitlab_encoding , "replace" ))
317
328
318
329
try :
@@ -462,7 +473,7 @@ def _get_display_encoding():
462
473
463
474
464
475
def _sanitize (value ):
465
- if type (value ) in ( str , unicode ) :
476
+ if type (value ) in str_types :
466
477
return value .replace ('/' , '%2F' )
467
478
return value
468
479
@@ -562,7 +573,7 @@ def delete(self):
562
573
def __init__ (self , gl , data = None , ** kwargs ):
563
574
self .gitlab = gl
564
575
565
- if data is None or type (data ) in [ int , str , unicode ] :
576
+ if data is None or type (data ) in chain (( int ,), str_types ) :
566
577
data = self .gitlab .get (self .__class__ , data , ** kwargs )
567
578
568
579
self ._setFromDict (data )
@@ -598,7 +609,7 @@ def _obj_to_str(obj):
598
609
elif isinstance (obj , list ):
599
610
s = ", " .join ([GitlabObject ._obj_to_str (x ) for x in obj ])
600
611
return "[ %s ]" % s
601
- elif isinstance (obj , unicode ):
612
+ elif PY2 and isinstance (obj , unicode ):
602
613
return obj .encode (_get_display_encoding (), "replace" )
603
614
else :
604
615
return str (obj )
@@ -611,7 +622,8 @@ def pretty_print(self, depth=0):
611
622
continue
612
623
v = self .__dict__ [k ]
613
624
pretty_k = k .replace ('_' , '-' )
614
- pretty_k = pretty_k .encode (_get_display_encoding (), "replace" )
625
+ if PY2 :
626
+ pretty_k = pretty_k .encode (_get_display_encoding (), "replace" )
615
627
if isinstance (v , GitlabObject ):
616
628
if depth == 0 :
617
629
print ("%s:" % pretty_k )
0 commit comments