Beispiel #1
0
    def __call__(self, environ, start_response):
        try:
            return super(Firewood, self).__call__(environ, start_response)

        except:
            logger.tb()
            start_response('500 Internal Server Error', [])
            return [compat.non_unicode_str('')]
Beispiel #2
0
    def _b64decode(self, b64msgstr):
        try:
            padding = (4 - len(b64msgstr) % 4) % 4
            b64msg = compat.non_unicode_str(b64msgstr + '=' * padding)
            return base64.urlsafe_b64decode(b64msg).decode('utf8')

        except (TypeError, UnicodeDecodeError) as e:
            raise MalformedSigendMessage(e.args[0])
Beispiel #3
0
    def __init__(self, secret_key, hash_f=hashlib.sha256):
        """ Initialize.

        :param secret_key: Key for data signing/unsigning
        :param hash_f: Hash function
        :type secret_key: str
        :type hash_f: callable
        """
        self._secret_key = compat.non_unicode_str(secret_key)
        self._hash_f = hash_f
Beispiel #4
0
def test_basics():
    class StartResponse(object):
        def __call__(self, status, headerlist):
            self.status = status
            self.headerlist = headerlist

    start_response = StartResponse()
    response = rsp().header('test', 1).code(404).body('abc')
    assert response(start_response) == [compat.non_unicode_str('abc')]
    assert start_response.status == '404 Not Found'
    assert start_response.headerlist == [('test', 1)]
Beispiel #5
0
 def _create_signature(self, msgstr):
     b = compat.non_unicode_str(msgstr)
     return hmac.new(self._secret_key, b, self._hash_f).hexdigest()
Beispiel #6
0
 def _b64encode(self, msgstr):
     msg = compat.non_unicode_str(msgstr)
     return base64.urlsafe_b64encode(msg).rstrip(b'=').decode('utf8')