Example #1
0
 def datareader(url, unquote=unquote):
     """Use "data" URL."""
     # ignore POSTed data
     #
     # syntax of data URLs:
     # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
     # mediatype := [ type "/" subtype ] *( ";" parameter )
     # data      := *urlchar
     # parameter := attribute "=" value
     try:
         typ, data = url.split(',', 1)
     except ValueError:
         raise IOError('data error', 'bad data URL')
     if not typ:
         typ = 'text/plain;charset=US-ASCII'
     semi = typ.rfind(';')
     if semi >= 0 and '=' not in typ[semi:]:
         encoding = typ[semi+1:]
         typ = typ[:semi]
     else:
         encoding = ''
     if encoding == 'base64':
         # XXX is this encoding/decoding ok?
         data = base64_decodebytes(data.encode('ascii'))
     else:
         data = unquote(data).encode('latin-1')
     return data
Example #2
0
File: xmldom.py Project: srand/jolt
 def attr_get(self):
     if attribute not in self.attrib:
         return ''
     value = self.get(attribute)
     if base64:
         value = base64_decodebytes(value.encode())
         if zlib:
             value = codecs.decode(value, "zlib")
         value = value.decode()
     return value
Example #3
0
File: xmldom.py Project: srand/jolt
 def child_get(self):
     if not hasattr(self, '_' + varname):
         e = SubElement(attribute, elem=self._elem.find(attribute))
         setattr(self, '_' + varname, e)
     value = getattr(self, '_' + varname).text
     if value is None:
         return None
     if base64:
         try:
             value = base64_decodebytes(value.encode())
             if zlib:
                 value = codecs.decode(value, "zlib")
             value = value.decode()
         except Exception:
             value = getattr(self, '_' + varname).text
     return str(value)
Example #4
0
def decode_label(label):
    return pickle.loads(base64_decodebytes(label.encode('latin1')))
Example #5
0
def _parseBasicAuthorization(auth_params):
    auth_params = auth_params.encode("utf-8")
    username, password = base64_decodebytes(auth_params).split(b":", 1)
    username = username.decode("utf-8")
    password = password.decode("utf-8")
    return {"username": username, "password": password}
Example #6
0
def _parseBasicAuthorization(auth_params):
    auth_params = auth_params.encode("utf-8")
    username, password = base64_decodebytes(auth_params).split(b":", 1)
    username = username.decode("utf-8")
    password = password.decode("utf-8")
    return {"username": username, "password": password}