Ejemplo n.º 1
0
 def do_filter(self, data, direction):
     from hippy.module.standard.strings.funcs import _str_rot13
     from hippy.module.standard.strings.funcs import _chunk_split
     from hippy.module.base64 import b64_decode
     from hippy.module.base64 import b64_encode
     filters = self.write_filters
     params = self.write_filters_params
     if direction == READ:
         filters = self.read_filters
         params = self.read_filters_params
     for i, filter in enumerate(filters):
         w_params = params[i]
         for f in filter.split('|'):
             if f == 'string.rot13':
                 data = _str_rot13(data)
             elif f == 'string.toupper':
                 data = data.upper()
             elif f == 'string.tolower':
                 data = data.lower()
             elif f in ['convert.base64-encode', 'convert.base64-decode']:
                 line_length = 0
                 line_break = None
                 with self.space.iter(w_params) as w_iter:
                     while not w_iter.done():
                         w_key, w_val = w_iter.next_item(self.space)
                         if self.space.str_w(w_key) == 'line-length':
                             line_length = self.space.int_w(w_val)
                         if self.space.str_w(w_key) == 'line-break-chars':
                             line_break = self.space.str_w(w_val)
                 if f == 'convert.base64-encode':
                     data = b64_encode(data).rstrip()
                 else:
                     data = b64_decode(data).rstrip()
                 if line_length > 0:
                     data = _chunk_split(data,
                                         line_length,
                                         line_break,
                                         last_end=False)
     return data
Ejemplo n.º 2
0
 def do_filter(self, data, direction):
     from hippy.module.standard.strings.funcs import _str_rot13
     from hippy.module.standard.strings.funcs import _chunk_split
     from hippy.module.base64 import b64_decode
     from hippy.module.base64 import b64_encode
     filters = self.write_filters
     params = self.write_filters_params
     if direction == READ:
         filters = self.read_filters
         params = self.read_filters_params
     for i, filter in enumerate(filters):
         w_params = params[i]
         for f in filter.split('|'):
             if f == 'string.rot13':
                 data = _str_rot13(data)
             elif f == 'string.toupper':
                 data = data.upper()
             elif f == 'string.tolower':
                 data = data.lower()
             elif f in ['convert.base64-encode', 'convert.base64-decode']:
                 line_length = 0
                 line_break = None
                 with self.space.iter(w_params) as w_iter:
                     while not w_iter.done():
                         w_key, w_val = w_iter.next_item(self.space)
                         if self.space.str_w(w_key) == 'line-length':
                             line_length = self.space.int_w(w_val)
                         if self.space.str_w(w_key) == 'line-break-chars':
                             line_break = self.space.str_w(w_val)
                 if f == 'convert.base64-encode':
                     data = b64_encode(data).rstrip()
                 else:
                     data = b64_decode(data).rstrip()
                 if line_length > 0:
                     data = _chunk_split(data, line_length,
                                         line_break, last_end=False)
     return data
Ejemplo n.º 3
0
def base64_decode(space, data, strict=False):
    res = b64_decode(data, strict)
    if res is None:
        return space.w_False
    return space.wrap(res)
Ejemplo n.º 4
0
def base64_decode(space, data, strict=False):
    res = b64_decode(data, strict)
    if res is None:
        return space.w_False
    return space.wrap(res)