rask  Check-in [838692c7fc]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:838692c7fcc6e084f6d099c4aad66334c3cada1b
Date: 2017-04-28 20:16:55
User: fpaolozze
Comment:fix utcode b64 encode
Tags And Properties
  • branch=hf/try-encode inherited from [920a942f51]
  • sym-hf/try-encode inherited from [920a942f51]
Context
2017-04-28
20:18
[0832f98520] merge from hf/try-encode (user: umgeher, tags: rask/master)
20:16
[838692c7fc] Leaf: fix utcode b64 encode (user: fpaolozze, tags: hf/try-encode)
20:14
[920a942f51] Create new branch named "hf/try-encode" (user: fpaolozze, tags: hf/try-encode)
Changes

Changes to rask/rask/parser/utcode/__init__.py.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
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
...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
...
300
301
302
303
304
305
306
307
308
309
310
311
312



313
314
315
316
                'n':self.decoder_none,
                's':self.decoder_string,
                'u':self.decoder_unicode
            }
        except:
            raise
        return self.__decode_types
    
    @property
    def encode_types(self):
        try:
            assert self.__encode_types
        except (AssertionError,AttributeError):
            self.__encode_types = {
                BooleanType:self.encoder_bool,
................................................................................
            assert _[:3] == 'ut:'
        except (AssertionError,TypeError):
            future.set_result(None)
            self.log.error('Invalid UTCode')
            return False
        except:
            raise
        
        def on_future(r):
            future.set_result(r.result()[0])
            return True

        self.ioengine.loop.add_callback(
            self.decode_type[_[3]],
            _=_[3:],
................................................................................
                self.ioengine.loop.add_callback(
                    self.decoder_dict_consumer,
                    _=result.result()[1],
                    f=f,
                    r=r
                )
                return True
            
            self.ioengine.loop.add_callback(
                self.decode_type[_[0]],
                _=_,
                f=self.ioengine.future(on_future)
            )
        except:
            raise
................................................................................
        f.set_result(
            (
                float(_[_.index(':')+1:_.index('z')]),
                _[_.index('z')+1:]
            )
        )
        return True
    
    def decoder_int(self,_,f):
        f.set_result(
            (
                int(_[_.index(':')+1:_.index('e')]),
                _[_.index('e')+1:]
            )
        )
................................................................................
            assert _[:2] == 'l:'
        except:
            raise
        else:
            def on_end(result):
                f.set_result(result.result())
                return True
            
            self.ioengine.loop.add_callback(
                self.decoder_list_consumer,
                _=_[2:],
                f=self.ioengine.future(on_end),
                r=[]
            )
        return True
................................................................................
                _=_,
                f=self.ioengine.future(on_future)
            )
        except:
            raise
        else:
            f.set_result((r,_[1:]))
        return True    

    def decoder_none(self,_,f):
        f.set_result((None,_[3:]))
        return True
    
    def decoder_string(self,_,f):
        c = _.index(':')
        l = int(_[1:c])
        f.set_result((_[c+1:l+c+1],_[l+c+1:]))
        return True

    def decoder_unicode(self,_,f):
        c = _.index(':')
        l = int(_[1:c])
        f.set_result((b64decode(_[c+1:l+c+1]).decode('utf-8'),_[l+c+1:]))
        return True
    
    def encode(self,_,future,result=None):
        def on_future(r):
            result = ['ut:']
            result.append(r.result())
            future.set_result(''.join(result))
            return True
        
        self.ioengine.loop.add_callback(
            self.encode_types[type(_)],
            _=_,
            f=self.ioengine.future(on_future)
        )
        return True

    def encoder_bool(self,_,f):
        f.set_result('b:%s' % [0,1][_])
        return True
    
    def encoder_dict(self,_,f,i=None,r=None):
        try:
            k = i.next()
        except AttributeError:
            self.ioengine.loop.add_callback(
                self.encoder_dict,
                _=_,
................................................................................
                f=self.ioengine.future(on_future)
            )
        return None

    def encoder_float(self,_,f):
        f.set_result('f:%sz' % _)
        return True
    
    def encoder_list(self,_,f,i=None,r=None):
        try:
            k = i.next()
        except AttributeError:
            self.ioengine.loop.add_callback(
                self.encoder_list,
                _=_,
................................................................................
                    self.encoder_list,
                    _=_,
                    f=f,
                    i=i,
                    r=r
                )
                return True
            
            self.ioengine.loop.add_callback(
                self.encode_types[type(k)],
                _=k,
                f=self.ioengine.future(on_future)
            )
        return None

................................................................................
    def encoder_int(self,_,f):
        f.set_result('i:%se' % _)
        return True

    def encoder_none(self,_,f):
        f.set_result('n:e')
        return True
    
    def encoder_string(self,_,f):
        f.set_result('s%s:%s' % (len(_),_))
        return True
    
    def encoder_unicode(self,_,f):



        b = b64encode(_)
        f.set_result('u%s:%s' % (len(b),b))
        return True








|







 







|







 







|







 







|







 







|







 







|




|











|






|










|







 







|







 







|







 







|



|

>
>
>
|


<
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
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
...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

                'n':self.decoder_none,
                's':self.decoder_string,
                'u':self.decoder_unicode
            }
        except:
            raise
        return self.__decode_types

    @property
    def encode_types(self):
        try:
            assert self.__encode_types
        except (AssertionError,AttributeError):
            self.__encode_types = {
                BooleanType:self.encoder_bool,
................................................................................
            assert _[:3] == 'ut:'
        except (AssertionError,TypeError):
            future.set_result(None)
            self.log.error('Invalid UTCode')
            return False
        except:
            raise

        def on_future(r):
            future.set_result(r.result()[0])
            return True

        self.ioengine.loop.add_callback(
            self.decode_type[_[3]],
            _=_[3:],
................................................................................
                self.ioengine.loop.add_callback(
                    self.decoder_dict_consumer,
                    _=result.result()[1],
                    f=f,
                    r=r
                )
                return True

            self.ioengine.loop.add_callback(
                self.decode_type[_[0]],
                _=_,
                f=self.ioengine.future(on_future)
            )
        except:
            raise
................................................................................
        f.set_result(
            (
                float(_[_.index(':')+1:_.index('z')]),
                _[_.index('z')+1:]
            )
        )
        return True

    def decoder_int(self,_,f):
        f.set_result(
            (
                int(_[_.index(':')+1:_.index('e')]),
                _[_.index('e')+1:]
            )
        )
................................................................................
            assert _[:2] == 'l:'
        except:
            raise
        else:
            def on_end(result):
                f.set_result(result.result())
                return True

            self.ioengine.loop.add_callback(
                self.decoder_list_consumer,
                _=_[2:],
                f=self.ioengine.future(on_end),
                r=[]
            )
        return True
................................................................................
                _=_,
                f=self.ioengine.future(on_future)
            )
        except:
            raise
        else:
            f.set_result((r,_[1:]))
        return True

    def decoder_none(self,_,f):
        f.set_result((None,_[3:]))
        return True

    def decoder_string(self,_,f):
        c = _.index(':')
        l = int(_[1:c])
        f.set_result((_[c+1:l+c+1],_[l+c+1:]))
        return True

    def decoder_unicode(self,_,f):
        c = _.index(':')
        l = int(_[1:c])
        f.set_result((b64decode(_[c+1:l+c+1]).decode('utf-8'),_[l+c+1:]))
        return True

    def encode(self,_,future,result=None):
        def on_future(r):
            result = ['ut:']
            result.append(r.result())
            future.set_result(''.join(result))
            return True

        self.ioengine.loop.add_callback(
            self.encode_types[type(_)],
            _=_,
            f=self.ioengine.future(on_future)
        )
        return True

    def encoder_bool(self,_,f):
        f.set_result('b:%s' % [0,1][_])
        return True

    def encoder_dict(self,_,f,i=None,r=None):
        try:
            k = i.next()
        except AttributeError:
            self.ioengine.loop.add_callback(
                self.encoder_dict,
                _=_,
................................................................................
                f=self.ioengine.future(on_future)
            )
        return None

    def encoder_float(self,_,f):
        f.set_result('f:%sz' % _)
        return True

    def encoder_list(self,_,f,i=None,r=None):
        try:
            k = i.next()
        except AttributeError:
            self.ioengine.loop.add_callback(
                self.encoder_list,
                _=_,
................................................................................
                    self.encoder_list,
                    _=_,
                    f=f,
                    i=i,
                    r=r
                )
                return True

            self.ioengine.loop.add_callback(
                self.encode_types[type(k)],
                _=k,
                f=self.ioengine.future(on_future)
            )
        return None

................................................................................
    def encoder_int(self,_,f):
        f.set_result('i:%se' % _)
        return True

    def encoder_none(self,_,f):
        f.set_result('n:e')
        return True

    def encoder_string(self,_,f):
        f.set_result('s%s:%s' % (len(_),_))
        return True

    def encoder_unicode(self,_,f):
        try:
            b = b64encode(_.encode('utf-8'))
        except:
            b = b64encode(_)
        f.set_result('u%s:%s' % (len(b),b))
        return True