Skip to content

Commit

Permalink
Extracted duplicated from init to regester adapters. (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Dec 21, 2017
1 parent 3b5c59f commit c75341b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions bunq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,28 @@ def initialize_converter():
converter.register_adapter(object_.ShareDetail, adapters.ShareDetailAdapter)
converter.register_adapter(datetime.datetime, adapters.DateTimeAdapter)
converter.register_adapter(client.Pagination, adapters.PaginationAdapter)
# converter.register_adapter(core.AnchoredObjectInterface,
# adapters.AnchoredObjectModelAdapter)

for class_string in dir(object_):
class_ = getattr(object_, class_string)

if not inspect.isclass(class_):
continue

if issubclass(class_, core.AnchoredObjectInterface):
def register_anchor_adapter(class_to_regsiter):
if issubclass(class_to_regsiter, core.AnchoredObjectInterface):
converter.register_adapter(
class_,
class_to_regsiter,
adapters.AnchoredObjectModelAdapter
)

for class_string in dir(endpoint):
class_ = getattr(endpoint, class_string)
def get_class(class_string_to_get):
if hasattr(object_, class_string_to_get):
return getattr(object_, class_string_to_get)

if hasattr(endpoint, class_string_to_get):
return getattr(endpoint, class_string_to_get)

for class_string in list(dir(object_) + dir(endpoint)):
class_ = get_class(class_string)

if not inspect.isclass(class_):
continue

if issubclass(class_, core.AnchoredObjectInterface):
converter.register_adapter(
class_,
adapters.AnchoredObjectModelAdapter
)
register_anchor_adapter(class_)


converter.set_initializer_function(initialize_converter)

0 comments on commit c75341b

Please sign in to comment.