aboutsummaryrefslogtreecommitdiffstats
path: root/github3/converters.py
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2011-11-17 00:10:30 +0100
committerDavid Medina <davidmedina9@gmail.com>2011-11-17 00:10:30 +0100
commit1dfda97b3f1146cd7df47f68d6f700da59ffabd5 (patch)
treed2d32a622116c3704f0408cbbc962b716e15d78c /github3/converters.py
parentWip on AuthUser handler tests (diff)
downloadpython-github3-1dfda97b3f1146cd7df47f68d6f700da59ffabd5.tar.xz
python-github3-1dfda97b3f1146cd7df47f68d6f700da59ffabd5.zip
PEP8
Diffstat (limited to 'github3/converters.py')
-rw-r--r--github3/converters.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/github3/converters.py b/github3/converters.py
index 58eb6b5..9f975be 100644
--- a/github3/converters.py
+++ b/github3/converters.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
-#
-# author: David Medina
+
from .core import Converter
+
class Rawlizer(Converter):
""" Raw converter """
@@ -16,6 +16,7 @@ class Rawlizer(Converter):
def dumps(self):
pass
+
class Json(Converter):
""" Json converter """
@@ -32,6 +33,7 @@ class Json(Converter):
def dumps(self):
pass
+
class Modelizer(Converter):
""" Own model converter """
@@ -52,18 +54,18 @@ class Modelizer(Converter):
self.model = model
def _parse_map(self, model, raw_resource):
- if getattr(raw_resource, 'items', False):
+ if hasattr(raw_resource, 'items'):
return Modelizer(model).loads(raw_resource)
def _parse_collection_map(self, model, raw_resources):
# Dict of resources (Ex: Gist file)
- if getattr(raw_resources, 'items', False):
+ if hasattr(raw_resources, 'items'):
dict_map = {}
for key, raw_resource in raw_resources.items():
dict_map[key] = Modelizer(model).loads(raw_resource)
return dict_map
# list of resources
- elif getattr(raw_resources, '__iter__', False):
+ elif hasattr(raw_resources, '__iter__'):
return [Modelizer(model).loads(raw_resource)
for raw_resource in raw_resources]
@@ -74,24 +76,24 @@ class Modelizer(Converter):
self.__class__.__name__)
idl = self.model.idl()
attrs.update(
- {attr: raw_resource[attr] for attr in idl.get('strs',())
+ {attr: raw_resource[attr] for attr in idl.get('strs', ())
if attr in raw_resource})
attrs.update(
- {attr: raw_resource[attr] for attr in idl.get('ints',())
+ {attr: raw_resource[attr] for attr in idl.get('ints', ())
if attr in raw_resource})
attrs.update(
{attr: self._parse_date(raw_resource[attr])
- for attr in idl.get('dates',()) if attr in raw_resource})
+ for attr in idl.get('dates', ()) if attr in raw_resource})
attrs.update(
- {attr: raw_resource[attr] for attr in idl.get('bools',())
+ {attr: raw_resource[attr] for attr in idl.get('bools', ())
if attr in raw_resource})
attrs.update(
{attr: self._parse_map(model, raw_resource[attr])
- for attr, model in idl.get('maps',{}).items()
+ for attr, model in idl.get('maps', {}).items()
if attr in raw_resource})
attrs.update(
{attr: self._parse_collection_map(model, raw_resource[attr])
- for attr, model in idl.get('collection_maps',{}).items()
+ for attr, model in idl.get('collection_maps', {}).items()
if attr in raw_resource})
return self.model(attrs)