Skip to content

Commit 4b5ace5

Browse files
committed
src - Make attribute modifiers global
- move attribute modifiers from class var to global var - allow pickle the Result() object
1 parent daa6a72 commit 4b5ace5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

overpy/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
XML_PARSER_DOM = 1
2020
XML_PARSER_SAX = 2
2121

22+
# Try to convert some common attributes
23+
# http://wiki.openstreetmap.org/wiki/Elements#Common_attributes
24+
GLOBAL_ATTRIBUTE_MODIFIERS = {
25+
"changeset": int,
26+
"timestamp": lambda ts: datetime.strptime(ts, "%Y-%m-%dT%H:%M:%SZ"),
27+
"uid": int,
28+
"version": int,
29+
"visible": lambda v: v.lower() == "true"
30+
}
31+
2232
if PY2:
2333
from urllib2 import urlopen
2434
from urllib2 import HTTPError
@@ -608,17 +618,10 @@ def __init__(self, attributes=None, result=None, tags=None):
608618
"""
609619

610620
self._result = result
611-
# Try to convert some common attributes
612-
# http://wiki.openstreetmap.org/wiki/Elements#Common_attributes
613-
self._attribute_modifiers = {
614-
"changeset": int,
615-
"timestamp": lambda ts: datetime.strptime(ts, "%Y-%m-%dT%H:%M:%SZ"),
616-
"uid": int,
617-
"version": int,
618-
"visible": lambda v: v.lower() == "true"
619-
}
620621
self.attributes = attributes
621-
for n, m in self._attribute_modifiers.items():
622+
# ToDo: Add option to modify attribute modifiers
623+
attribute_modifiers = dict(GLOBAL_ATTRIBUTE_MODIFIERS.items())
624+
for n, m in attribute_modifiers.items():
622625
if n in self.attributes:
623626
self.attributes[n] = m(self.attributes[n])
624627
self.id = None

0 commit comments

Comments
 (0)