Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15c0da5

Browse files
committed
Python3 compatibility
1 parent4664ebd commit15c0da5

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

‎gitlab.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@
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__importprint_function,division,absolute_import
19+
20+
fromitertoolsimportchain
21+
1822
importjson
1923
importrequests
2024
importsys
2125

26+
ifsys.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
eliftype(v)==bool:
314325
d[k]=1ifvelse0
315-
eliftype(v)==unicode:
326+
elifPY2andtype(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

464475
def_sanitize(value):
465-
iftype(value)in(str,unicode):
476+
iftype(value)instr_types:
466477
returnvalue.replace('/','%2F')
467478
returnvalue
468479

@@ -562,7 +573,7 @@ def delete(self):
562573
def__init__(self,gl,data=None,**kwargs):
563574
self.gitlab=gl
564575

565-
ifdataisNoneortype(data)in[int,str,unicode]:
576+
ifdataisNoneortype(data)inchain((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
elifisinstance(obj,list):
599610
s=", ".join([GitlabObject._obj_to_str(x)forxinobj])
600611
return"[ %s ]"%s
601-
elifisinstance(obj,unicode):
612+
elifPY2andisinstance(obj,unicode):
602613
returnobj.encode(_get_display_encoding(),"replace")
603614
else:
604615
returnstr(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+
ifPY2:
626+
pretty_k=pretty_k.encode(_get_display_encoding(),"replace")
615627
ifisinstance(v,GitlabObject):
616628
ifdepth==0:
617629
print("%s:"%pretty_k)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp