@@ -28,33 +28,43 @@ class CEVENTTIME(ctypes.Structure):
28
28
('server_upload' , ctypes .c_uint64 )
29
29
]
30
30
31
- __slots__ = (
32
- 'client_creation' , 'server_upload' ,
33
- 'dtime' , 'is_accurate'
34
- )
35
-
36
31
delta_past = datetime .timedelta (days = 6 * 30 )
37
32
delta_future = datetime .timedelta (days = 1 )
38
33
39
- def _setup_time (self ):
34
+ def get_approx_time (self ):
35
+ if not self .dtime :
36
+ self ._setup_time ()
37
+ return self .dtime , self .is_accurate
38
+
39
+ def make_object (self ):
40
40
client_dtime = SerializableDatetime .utcfromtimestamp (
41
41
self .client_creation / 1000. # timestamp is in millisecs
42
42
)
43
43
server_dtime = SerializableDatetime .utcfromtimestamp (
44
44
self .server_upload / 1000. # timestamp is in millisecs
45
45
)
46
46
47
- self .dtime = server_dtime
48
- self .is_accurate = False
47
+ dtime = server_dtime
49
48
if client_dtime >= server_dtime - CEVENTTIME .delta_past and \
50
49
client_dtime <= server_dtime + CEVENTTIME .delta_future :
51
- self .dtime = client_dtime
52
- self .is_accurate = True
50
+ dtime = client_dtime
53
51
54
- def get_approx_time (self ):
55
- if not self .dtime :
56
- self ._setup_time ()
57
- return self .dtime , self .is_accurate
52
+ pytime = PythonEventTime ()
53
+ pytime .client_creation = client_dtime
54
+ pytime .server_upload = server_dtime
55
+ pytime .dtime = dtime
56
+ return pytime
57
+
58
+
59
+ class PythonEventTime (object ):
60
+ __slots__ = (
61
+ 'client_creation' , 'server_upload' ,
62
+ 'dtime' , 'is_accurate'
63
+ )
64
+
65
+ @property
66
+ def is_accurate (self ):
67
+ return self .dtime == self .client_creation
58
68
59
69
def __dumpdict__ (self ):
60
70
return {
@@ -72,20 +82,6 @@ class IDInfo(ctypes.Structure):
72
82
73
83
__slots__ = ('os' , 'uid' )
74
84
75
- def __dumpdict__ (self ):
76
- return {
77
- 'os' : self .os
78
- }
79
-
80
- def is_on_android (self ):
81
- return self .os == 1
82
-
83
- def is_on_ios (self ):
84
- return self .os == 2
85
-
86
- def is_on_unknown_os (self ):
87
- return self .os == 0
88
-
89
85
def validate (self ):
90
86
if self .os not in IDInfo ._os_valid_range :
91
87
raise ValueError ('Incorrect os value: %s' % self .os )
@@ -113,13 +109,6 @@ def get_location(self):
113
109
return (self .lat , self .lon )
114
110
return None
115
111
116
- def __dumpdict__ (self ):
117
- dct = super (GeoIDInfo , self ).__dumpdict__ ()
118
- if self .has_geo ():
119
- dct ['lat' ] = round (self .lat , 6 )
120
- dct ['lon' ] = round (self .lon , 6 )
121
- return dct
122
-
123
112
124
113
class CUSERINFO (GeoIDInfo ):
125
114
_fields_ = [
@@ -128,19 +117,60 @@ class CUSERINFO(GeoIDInfo):
128
117
129
118
__slots__ = ('raw_uid' ,)
130
119
131
- def setup (self ):
120
+ def make_object (self ):
132
121
self .validate ()
133
- setattr (self , 'uid' , int (self .raw_uid , 16 ))
134
122
135
- def stripped (self ):
136
123
if self .has_geo ():
137
- return GeoIDInfo (
138
- uid = self .uid , os = self .os ,
139
- lat = self .lat , lon = self .lon
140
- )
141
- return IDInfo (
142
- uid = self .uid , os = self .os
143
- )
124
+ pyinfo = PythonGeoUserInfo ()
125
+ pyinfo .uid = int (self .raw_uid , 16 )
126
+ pyinfo .os = self .os
127
+ pyinfo .lat = round (self .lat , 6 )
128
+ pyinfo .lon = round (self .lon , 6 )
129
+ return pyinfo
130
+
131
+ pyinfo = PythonUserInfo ()
132
+ pyinfo .uid = int (self .raw_uid , 16 )
133
+ pyinfo .os = self .os
134
+ return pyinfo
135
+
136
+
137
+ class PythonUserInfo (object ):
138
+ __slots__ = ('uid' , 'os' )
139
+
140
+ @property
141
+ def has_geo (self ):
142
+ return False
143
+
144
+ def is_on_android (self ):
145
+ return self .os == 1
146
+
147
+ def is_on_ios (self ):
148
+ return self .os == 2
149
+
150
+ def is_on_unknown_os (self ):
151
+ return self .os == 0
152
+
153
+ def __dumpdict__ (self ):
154
+ return {
155
+ 'os' : self .os ,
156
+ 'uid' : self .uid
157
+ }
158
+
159
+
160
+ class PythonGeoUserInfo (PythonUserInfo ):
161
+ __slots__ = ('lat' , 'lon' )
162
+
163
+ @property
164
+ def has_geo (self ):
165
+ return True
166
+
167
+ def __dumpdict__ (self ):
168
+ d = super (PythonGeoUserInfo , self ).__dumpdict__ ()
169
+ d .update ({
170
+ 'lat' : self .lat ,
171
+ 'lon' : self .lon
172
+ })
173
+ return d
144
174
145
175
146
176
CCALLBACK = ctypes .CFUNCTYPE (
0 commit comments