-
Notifications
You must be signed in to change notification settings - Fork 421
/
column_item.py
71 lines (55 loc) · 1.93 KB
/
column_item.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from defusedxml.ElementTree import fromstring
from .property_decorators import property_not_empty
class ColumnItem(object):
def __init__(self, name, description=None):
self._id = None
self.description = description
self.name = name
def __repr__(self):
return f"<{self.__class__.__name__} {self._id} {self.name} {self.description}>"
@property
def id(self):
return self._id
@property
def name(self):
return self._name
@name.setter
@property_not_empty
def name(self, value):
self._name = value
@property
def description(self):
return self._description
@description.setter
def description(self, value):
self._description = value
@property
def remote_type(self):
return self._remote_type
def _set_values(self, id, name, description, remote_type):
if id is not None:
self._id = id
if name:
self._name = name
if description:
self.description = description
if remote_type:
self._remote_type = remote_type
@classmethod
def from_response(cls, resp, ns):
all_column_items = list()
parsed_response = fromstring(resp)
all_column_xml = parsed_response.findall(".//t:column", namespaces=ns)
for column_xml in all_column_xml:
(id, name, description, remote_type) = cls._parse_element(column_xml, ns)
column_item = cls(name)
column_item._set_values(id, name, description, remote_type)
all_column_items.append(column_item)
return all_column_items
@staticmethod
def _parse_element(column_xml, ns):
id = column_xml.get("id", None)
name = column_xml.get("name", None)
description = column_xml.get("description", None)
remote_type = column_xml.get("remoteType", None)
return id, name, description, remote_type