From a464383c6393075ef4468edc99f4f56e1bc46694 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Tue, 31 Jul 2018 23:23:31 +0300 Subject: [PATCH] Move get_base_utils helper to entity base utils --- federation/entities/diaspora/utils.py | 14 -------------- federation/entities/utils.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 federation/entities/utils.py diff --git a/federation/entities/diaspora/utils.py b/federation/entities/diaspora/utils.py index 75a6f34..5f7cfb8 100644 --- a/federation/entities/diaspora/utils.py +++ b/federation/entities/diaspora/utils.py @@ -35,20 +35,6 @@ def struct_to_xml(node, struct): etree.SubElement(node, k).text = v -def get_base_attributes(entity): - """Build a dict of attributes of an entity. - - Returns attributes and their values, ignoring any properties, functions and anything that starts - with an underscore. - """ - attributes = {} - cls = entity.__class__ - for attr, _ in inspect.getmembers(cls, lambda o: not isinstance(o, property) and not inspect.isroutine(o)): - if not attr.startswith("_"): - attributes[attr] = getattr(entity, attr) - return attributes - - def get_full_xml_representation(entity, private_key): """Get full XML representation of an entity. diff --git a/federation/entities/utils.py b/federation/entities/utils.py new file mode 100644 index 0000000..33594db --- /dev/null +++ b/federation/entities/utils.py @@ -0,0 +1,15 @@ +import inspect + + +def get_base_attributes(entity): + """Build a dict of attributes of an entity. + + Returns attributes and their values, ignoring any properties, functions and anything that starts + with an underscore. + """ + attributes = {} + cls = entity.__class__ + for attr, _ in inspect.getmembers(cls, lambda o: not isinstance(o, property) and not inspect.isroutine(o)): + if not attr.startswith("_"): + attributes[attr] = getattr(entity, attr) + return attributes