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+ from itertools import chain
21+
1822import json
1923import requests
2024import sys
2125
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+
2233__title__ = 'python-gitlab'
2334__version__ = '0.7'
2435__author__ = 'Gauvain Pocentek'
@@ -312,7 +323,7 @@ def update(self, obj):
312323 d [k ] = str (v )
313324 elif type (v ) == bool :
314325 d [k ] = 1 if v else 0
315- elif type (v ) == unicode :
326+ elif PY2 and type (v ) == unicode :
316327 d [k ] = str (v .encode (self .gitlab_encoding , "replace" ))
317328
318329 try :
@@ -462,7 +473,7 @@ def _get_display_encoding():
462473
463474
464475def _sanitize (value ):
465- if type (value ) in ( str , unicode ) :
476+ if type (value ) in str_types :
466477 return value .replace ('/' , '%2F' )
467478 return value
468479
@@ -562,7 +573,7 @@ def delete(self):
562573 def __init__ (self , gl , data = None , ** kwargs ):
563574 self .gitlab = gl
564575
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 ) :
566577 data = self .gitlab .get (self .__class__ , data , ** kwargs )
567578
568579 self ._setFromDict (data )
@@ -598,7 +609,7 @@ def _obj_to_str(obj):
598609 elif isinstance (obj , list ):
599610 s = ", " .join ([GitlabObject ._obj_to_str (x ) for x in obj ])
600611 return "[ %s ]" % s
601- elif isinstance (obj , unicode ):
612+ elif PY2 and isinstance (obj , unicode ):
602613 return obj .encode (_get_display_encoding (), "replace" )
603614 else :
604615 return str (obj )
@@ -611,7 +622,8 @@ def pretty_print(self, depth=0):
611622 continue
612623 v = self .__dict__ [k ]
613624 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" )
615627 if isinstance (v , GitlabObject ):
616628 if depth == 0 :
617629 print ("%s:" % pretty_k )
0 commit comments