示例#1
0
def message_callback(bot, event):
    log.debug("Message received, replying.")

    source_uin = event.data["source"]["aimId"]
    try:
        bot.set_typing(target=source_uin, typing_status=TypingStatus.TYPING)
        bot.send_im(target=source_uin, message=urlparse.quote_plus(event.data["message"]))
    finally:
        bot.set_typing(target=source_uin, typing_status=TypingStatus.NONE)
示例#2
0
 def get_uris(self):
     out = []
     name = self.name if self.name else ''
     proto = "ssl" if self.ssl else "telnet"
     if not self.users:
         uri = '{proto}://{host}:{port}/{muck}'.format(
             proto=proto, host=self.host, port=self.port, muck=name
         )
         out.append(uri)
     for user in self.users:
         username = quote_plus(user.user, encoding='utf8', errors='ignore')
         if user.password:
             username += ":" + quote_plus(
                 user.password, encoding='utf8', errors='ignore')
         uri = '{proto}://{user}@{host}:{port}/{muck}'.format(
             proto=proto,
             host=self.host,
             port=self.port,
             muck=name,
             user=username
         )
         out.append(uri)
     return out
示例#3
0
文件: auth.py 项目: Galimberti/odoo12
 def compare_signature(self, params, method, base_url):
     """
         Compare generated signature with user provided signature.
     """
     oauth_signature = params.get('oauth_signature')
     oauth_signature = urlparse.quote_plus(oauth_signature).replace('+','%2B').replace('/', '%2F')
     if oauth_signature:
         del params['oauth_signature']
         generated_signature = self.generate_oauth_signature(
             params, method, base_url)
         if generated_signature and oauth_signature == generated_signature:
             return True
         elif urlparse.unquote(oauth_signature)==generated_signature:
             return True
     return False
示例#4
0
    def generate_oauth_signature(self, params, method, base_url):
        """
            Generate Signature using HMAC algorithm of key/secret.
        """
        oauth_consumer_secret = None
        if params.get('oauth_consumer_key'):
            user = self.get_authorize_user(params['oauth_consumer_key'])
            oauth_consumer_secret = user.consumer_secret + '&'
            if not user:
                return False
            if params.get('for_access_token'):
                verifier = self.env['auth.request.token'].sudo().search([
                    ('request_token', '=', params['oauth_token'])
                ])
                oauth_consumer_secret += verifier.request_token_secret
                del params['for_access_token']
            if params.get('for_request_data'):
                oauth_consumer_secret += user.access_token_secret
                del params['for_request_data']
        if dict(params).get('oauth_signature_method') == 'PLAINTEXT':
            return oauth_consumer_secret

        parse_url = urlparse.urlparse(base_url)
        scheme = parse_url.scheme
        if request.httprequest.environ.get(
                'HTTP_X_FORWARDED_PROTO'
        ) and request.httprequest.environ['HTTP_X_FORWARDED_PROTO'] == 'https':
            scheme = 'https'
        base_url = "%s://%s%s%s" % (
        scheme,
        parse_url.hostname,
        "" if not parse_url.port or {"http":80,"https":443}[parse_url.scheme]\
                == parse_url.port else ":%d" % parse_url.port,
        parse_url.path,)
        base_url = urlparse.quote(base_url).replace('+',
                                                    '%20').replace('/', '%2F')
        for key, val in list(params.items()):
            params[key] = urlparse.unquote(val)
        params = self.normalize_params(params)
        query_string = ''
        query_string = params
        base_str = method + '&' + base_url + '&' + query_string
        _hash = hmac.new(oauth_consumer_secret.encode('utf-8'),
                         base_str.encode('utf-8'), hashlib.sha1).digest()
        _hash = binascii.b2a_base64(_hash).decode('utf-8')
        signature = urlparse.quote_plus(_hash.rstrip('\n'))
        return signature
示例#5
0
def generate(uri, key, ttl, policy_name=None):
    """
.. function:: generate(uri, key, ttl, policy_name=None)

    Generate a SAS for target :samp:`uri` signed with :samp:`key` valid till :samp:`ttl` (passed as epoch) and with optional :samp:`policy_name`.

    """
    sign_key = urlparse.quote_plus(uri) + '\n' + str(int(ttl))
    hh = hmac.HMAC(base64.standard_b64decode(key),
                   sha2.SHA2(hashtype=sha2.SHA256))
    hh.update(sign_key)
    signature = base64.standard_b64encode(hh.digest())

    rawtoken = {'sr': uri, 'sig': signature, 'se': str(int(ttl))}
    if policy_name is not None:
        rawtoken['skn'] = policy_name

    return 'SharedAccessSignature ' + urlparse.urlencode(rawtoken)
示例#6
0
 def _fix_name(self, vals):
     if 'name' in vals:
         vals['name'] = urlparse.quote_plus(vals['name'].lower())
     return vals