-
Notifications
You must be signed in to change notification settings - Fork 6
Updated to work with python3 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| iso8601==0.1.10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| from .session import Session | ||
|
|
||
| import sys | ||
|
|
||
| __all__ = ['Reports'] | ||
|
|
||
|
|
||
|
|
@@ -16,31 +18,36 @@ def parse_val(v): | |
| else: | ||
| return v | ||
|
|
||
| for k, v in attribs.iteritems(): | ||
| try: | ||
| iteritems = dict.items # Python 3 | ||
| except AttributeError: | ||
| iteritems = dict.iteritems # Python 2 | ||
|
|
||
| for k, v in iteritems(attribs): | ||
| if isinstance(v, list): | ||
| attribs[k] = [parse_val(el) for el in v] | ||
| elif isinstance(v, dict): | ||
| attribs[k] = parse_val(v) | ||
| self.__dict__.update(attribs) | ||
|
|
||
| @property | ||
| def keys(self): | ||
| return self.__dict__.keys() | ||
|
|
||
| def __unicode__(self): | ||
| if hasattr(self, '_unicode_value'): | ||
| if self._unicode_value is None: | ||
| return '(none)' | ||
| if sys.version_info[0] < 3: | ||
| @property | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be missing (not defined) if Python3 is used. |
||
| def keys(self): | ||
| return self.__dict__.keys() | ||
|
|
||
| if sys.version_info[0] < 3: | ||
| def __unicode__(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it'd be cleaner if |
||
| if hasattr(self, '_unicode_value'): | ||
| if self._unicode_value is None: | ||
| return '(none)' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to have been removed so the tests are failing. |
||
| else: | ||
| return self._unicode_value | ||
| else: | ||
| return self._unicode_value | ||
| else: | ||
| return super(Node, self).__unicode__() | ||
| return super(Node, self).__unicode__() | ||
|
|
||
| def __str__(self): | ||
| return unicode(self).encode('utf-8') | ||
|
|
||
| def __contains__(self, key): | ||
| return key in self.__dict__ | ||
| if sys.version_info[0] < 3: | ||
| def __str__(self): | ||
| return self.__unicode__().encode('utf-8') | ||
|
|
||
|
|
||
| class Reports(object): | ||
|
|
@@ -68,15 +75,23 @@ def request(self, type, workspace_id=None, **params): | |
| raise ValueError('missing workspace ID') | ||
| workspace_id = self.workspace_id | ||
|
|
||
| for k, v in params.iteritems(): | ||
| try: | ||
| iteritems = dict.items # Python 3 | ||
| except AttributeError: | ||
| iteritems = dict.iteritems # Python 2 | ||
|
|
||
| for k, v in iteritems(params): | ||
| if isinstance(v, datetime) or isinstance(v, date): | ||
| params[k] = v.strftime('%Y-%m-%d') | ||
|
|
||
| params['workspace_id'] = workspace_id | ||
| params['user_agent'] = self.USER_AGENT | ||
|
|
||
| data = self.session.get(type, **params) | ||
| return Node(**data) | ||
| if sys.version_info[0] < 3: | ||
| data = self.session.get(type, **params) | ||
| return Node(**data) | ||
| else: | ||
| return self.session.get(type, **params) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python3 code should also be using |
||
|
|
||
| @classmethod | ||
| def _get_totals(cls, data): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid checking for items/iteritems everywhere, let's just use
itemseverywhere (it works in both 2 and 3, and for the amount of data that's likely to be handled here, just as well).