| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,19 +17,12 @@ | |||
| 17 | 17 | ||
| 18 | 18 | from __future__ import print_function, division, absolute_import | |
| 19 | 19 | ||
| 20 | - from itertools import chain | ||
| 20 | + import six | ||
| 21 | 21 | ||
| 22 | 22 | import json | |
| 23 | 23 | import requests | |
| 24 | 24 | import sys | |
| 25 | 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 | - | ||
| 33 | 26 | __title__ = 'python-gitlab' | |
| 34 | 27 | __version__ = '0.7' | |
| 35 | 28 | __author__ = 'Gauvain Pocentek' | |
@@ -292,7 +285,7 @@ def create(self, obj): | |||
| 292 | 285 | url = obj._url % args | |
| 293 | 286 | url = '%s%s' % (self._url, url) | |
| 294 | 287 | ||
| 295 | - for k, v in obj.__dict__.items(): | ||
| 288 | + for k, v in list(obj.__dict__.items()): | ||
| 296 | 289 | if type(v) == bool: | |
| 297 | 290 | obj.__dict__[k] = 1 if v else 0 | |
| 298 | 291 | ||
@@ -318,12 +311,12 @@ def update(self, obj): | |||
| 318 | 311 | ||
| 319 | 312 | # build a dict of data that can really be sent to server | |
| 320 | 313 | d = {} | |
| 321 | - for k, v in obj.__dict__.items(): | ||
| 314 | + for k, v in list(obj.__dict__.items()): | ||
| 322 | 315 | if type(v) in (int, str): | |
| 323 | 316 | d[k] = str(v) | |
| 324 | 317 | elif type(v) == bool: | |
| 325 | 318 | d[k] = 1 if v else 0 | |
| 326 | - elif PY2 and type(v) == unicode: | ||
| 319 | + elif six.PY2 and type(v) == six.text_type: | ||
| 327 | 320 | d[k] = str(v.encode(self.gitlab_encoding, "replace")) | |
| 328 | 321 | ||
| 329 | 322 | try: | |
@@ -473,7 +466,7 @@ def _get_display_encoding(): | |||
| 473 | 466 | ||
| 474 | 467 | ||
| 475 | 468 | def _sanitize(value): | |
| 476 | - if type(value) in str_types: | ||
| 469 | + if isinstance(value, six.string_types): | ||
| 477 | 470 | return value.replace('/', '%2F') | |
| 478 | 471 | return value | |
| 479 | 472 | ||
@@ -573,7 +566,8 @@ def delete(self): | |||
| 573 | 566 | def __init__(self, gl, data=None, **kwargs): | |
| 574 | 567 | self.gitlab = gl | |
| 575 | 568 | ||
| 576 | - if data is None or type(data) in chain((int,), str_types): | ||
| 569 | + if data is None or isinstance(data, six.integer_types) or\ | ||
| 570 | + isinstance(data, six.string_types): | ||
| 577 | 571 | data = self.gitlab.get(self.__class__, data, **kwargs) | |
| 578 | 572 | ||
| 579 | 573 | self._setFromDict(data) | |
@@ -609,7 +603,7 @@ def _obj_to_str(obj): | |||
| 609 | 603 | elif isinstance(obj, list): | |
| 610 | 604 | s = ", ".join([GitlabObject._obj_to_str(x) for x in obj]) | |
| 611 | 605 | return "[ %s ]" % s | |
| 612 | - elif PY2 and isinstance(obj, unicode): | ||
| 606 | + elif six.PY2 and isinstance(obj, six.text_type): | ||
| 613 | 607 | return obj.encode(_get_display_encoding(), "replace") | |
| 614 | 608 | else: | |
| 615 | 609 | return str(obj) | |
@@ -622,7 +616,7 @@ def pretty_print(self, depth=0): | |||
| 622 | 616 | continue | |
| 623 | 617 | v = self.__dict__[k] | |
| 624 | 618 | pretty_k = k.replace('_', '-') | |
| 625 | - if PY2: | ||
| 619 | + if six.PY2: | ||
| 626 | 620 | pretty_k = pretty_k.encode(_get_display_encoding(), "replace") | |
| 627 | 621 | if isinstance(v, GitlabObject): | |
| 628 | 622 | if depth == 0: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1 +1,2 @@ | |||
| 1 | 1 | requests>1.0 | |
| 2 | + six | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ def get_version(): | |||
| 22 | 22 | url='https://github.com/gpocentek/python-gitlab', | |
| 23 | 23 | py_modules=['gitlab'], | |
| 24 | 24 | scripts=['gitlab'], | |
| 25 | - install_requires=['requests'], | ||
| 25 | + install_requires=['requests', 'six'], | ||
| 26 | 26 | classifiers=[ | |
| 27 | 27 | 'Development Status :: 5 - Production/Stable', | |
| 28 | 28 | 'Environment :: Console', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments