-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml_objects.py
More file actions
executable file
·251 lines (195 loc) · 6.37 KB
/
Copy pathxml_objects.py
File metadata and controls
executable file
·251 lines (195 loc) · 6.37 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from elementtree.ElementTree import *
import urllib
import string
class URL(object):
"""Gnip URL container class.
value: string representation of the URL
meta_url: string representation of the meta_url
"""
def __init__(self, value=None, meta_url=None):
self.value = value
self.meta_url = meta_url
def __str__(self):
return "[" + str(self.value) + ", " + str(self.meta_url) + "]"
def __cmp__(self, other):
if isinstance(other, URL):
ret = cmp(self.value, other.value)
if ret == 0:
ret = cmp(self.meta_url, other.meta_url)
else:
ret = 1
return ret
class MediaURL(object):
"""Gnip Media URL container class.
value: string representation of the media URL
height: string the height
width: string the width
duration: string the duration of the linked media
type: string the Gnip normalized type of the linked media
mimeType: string the mimeType of the linked media
"""
def __init__(self, value=None, height=None, width=None, duration=None, type=None, mimetype=None):
self.value = value
self.height = height
self.width = width
self.duration = duration
self.type = type
self.mimetype = mimetype
def __str__(self):
return "[" + str(self.value) + ", " \
+ str(self.height) + ", "\
+ str(self.width) + ", "\
+ str(self.duration) + ", "\
+ str(self.type) + ", "\
+ str(self.mimetype) \
+ "]"
def __cmp__(self, other):
if isinstance(other, MediaURL):
ret = cmp(self.value, other.value)
if ret == 0:
ret = cmp(self.height, other.height)
if ret == 0:
ret = cmp(self.width, other.width)
if ret == 0:
ret = cmp(self.duration, other.duration)
if ret == 0:
ret = cmp(self.type, other.type)
if ret == 0:
ret = cmp(self.mimetype, other.mimetype)
else:
ret = 1
return ret
class Actor(object):
"""Gnip Actor container class
value: string representation of the Actor
uid: string representation of the uid
meta_url: string representation of the meta_url
"""
def __init__(self, value=None, uid=None, meta_url=None):
self.value = value
self.uid = uid
self.meta_url = meta_url
def __str__(self):
return "[" + str(self.value) + ", " + str(self.uid) + ", " + str(self.meta_url) + "]"
class Tag(object):
"""Gnip Tag container class
value: string representation of the Tag
meta_url: string representation of the meta_url
"""
def __init__(self, value=None, meta_url=None):
self.value = value
self.meta_url = meta_url
def __str__(self):
return "[" + str(self.value) + ", " + str(self.meta_url) + "]"
def __cmp__(self, other):
if isinstance(other, Tag):
ret = cmp(self.value, other.value)
if ret == 0:
ret = cmp(self.meta_url, other.meta_url)
else:
ret = 1
return ret
class To(object):
"""Gnip To container class
value: string representation of the To
meta_url: string representation of the meta_url
"""
def __init__(self, value=None, meta_url=None):
self.value = value
self.meta_url = meta_url
def __str__(self):
return "[" + str(self.value) + ", " + str(self.meta_url) + "]"
def __cmp__(self, other):
if isinstance(other, To):
ret = cmp(self.value, other.value)
if ret == 0:
ret = cmp(self.meta_url, other.meta_url)
else:
ret = 1
return ret
class Point(object):
"""Gnip Point container class
x: float representation of the x coordinate
y: float representation of the y coordinate
"""
def __init__(self, x=None, y=None):
self.x = x
self.y = y
def __str__(self):
return "[" + str(self.x) + ", " + str(self.y) + "]"
def __cmp__(self, other):
if isinstance(other, Point):
if self.x < other.x:
ret = -1
elif self.x > other.x:
ret = 1
elif self.y < other.y:
ret = -1
elif self.y > other.y:
ret = 1
else:
ret = 0
else:
ret = 1
return ret
class Rule(object):
"""Gnip Rule container class
type: string representation of the rule type
value: string representation of the rule value
"""
def __init__(self, type=None, value=None):
self.type = type
self.value = value
def to_delete_query_string(self):
return urllib.urlencode([("type",self.type),("value",self.value)])
def to_xml(self):
rule_node = Element("rule")
rule_node.text = self.value
rule_node.set("type", self.type)
return tostring(rule_node)
def __str__(self):
return "[" + str(self.type) + ", " + str(self.value) + "]"
def __cmp__(self, other):
if isinstance(other, Rule):
ret = cmp(self.type, other.type)
if ret is 0:
ret = cmp(self.value, other.value)
else:
ret = 1
return ret
class Result(object):
"""Gnip Result container class
message: string
"""
def __init__(self, message=None):
self.message = message
def from_xml(self, xml):
node = fromstring(xml)
if node is not None:
self.message = node.text
else:
self.message = ""
def __cmp__(self, other):
if isinstance(other, Result):
ret = cmp(self.message, other.message)
else:
ret = 1
return ret
class Error(object):
"""Gnip error container class
message: string
"""
def __init__(self, message=None):
self.message = message
def from_xml(self, xml):
node = fromstring(xml)
if node is not None:
self.message = node.text
else:
self.message = ""
def __cmp__(self, other):
if isinstance(other, Error):
ret = cmp(self.message, other.message)
else:
ret = 1
return ret