示例#1
0
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method,
                                        split.netloc,
                                        path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         # Any previous signature should not be a part of this
         # one, so we skip that particular key. This prevents
         # issues during retries.
         if key == 'Signature':
             continue
         value = six.text_type(params[key])
         pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
                      quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
示例#2
0
 def _type_check(param, errors, name):
     if not isinstance(param, valid_types):
         valid_type_names = [six.text_type(t) for t in valid_types]
         errors.report(name, 'invalid type', param=param,
                       valid_types=valid_type_names)
         return False
     return True
示例#3
0
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method, split.netloc, path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         # Any previous signature should not be a part of this
         # one, so we skip that particular key. This prevents
         # issues during retries.
         if key == 'Signature':
             continue
         value = six.text_type(params[key])
         pairs.append(
             quote(key.encode('utf-8'), safe='') + '=' +
             quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
示例#4
0
 def _type_check(param, errors, name):
     if not isinstance(param, valid_types):
         valid_type_names = [six.text_type(t) for t in valid_types]
         errors.report(name, 'invalid type', param=param,
                       valid_types=valid_type_names)
         return False
     return True
示例#5
0
 def _validate_timestamp(self, param, shape, errors, name):
     # We don't use @type_check because datetimes are a bit
     # more flexible.  You can either provide a datetime
     # object, or a string that parses to a datetime.
     is_valid_type = self._type_check_datetime(param)
     if not is_valid_type:
         valid_type_names = [six.text_type(datetime), "timestamp-string"]
         errors.report(name, "invalid type", param=param, valid_types=valid_type_names)
示例#6
0
 def _validate_timestamp(self, param, shape, errors, name):
     # We don't use @type_check because datetimes are a bit
     # more flexible.  You can either provide a datetime
     # object, or a string that parses to a datetime.
     is_valid_type = self._type_check_datetime(param)
     if not is_valid_type:
         valid_type_names = [six.text_type(datetime), 'timestamp-string']
         errors.report(name, 'invalid type', param=param,
                       valid_types=valid_type_names)
示例#7
0
 def __exit__(self, exc_type, exc_value, *args):
     cancel = False
     cancel_msg = ''
     cancel_exc_type = FatalError
     # If a exception was raised in the context handler, signal to cancel
     # all of the inprogress futures in the shutdown.
     if exc_type:
         cancel = True
         cancel_msg = six.text_type(exc_value)
         if not cancel_msg:
             cancel_msg = repr(exc_value)
         # If it was a KeyboardInterrupt, the cancellation was initiated
         # by the user.
         if isinstance(exc_value, KeyboardInterrupt):
             cancel_exc_type = CancelledError
     self._shutdown(cancel, cancel_msg, cancel_exc_type)
示例#8
0
 def __exit__(self, exc_type, exc_value, *args):
     cancel = False
     cancel_msg = ''
     cancel_exc_type = FatalError
     # If a exception was raised in the context handler, signal to cancel
     # all of the inprogress futures in the shutdown.
     if exc_type:
         cancel = True
         cancel_msg = six.text_type(exc_value)
         if not cancel_msg:
             cancel_msg = repr(exc_value)
         # If it was a KeyboardInterrupt, the cancellation was initiated
         # by the user.
         if isinstance(exc_value, KeyboardInterrupt):
             cancel_exc_type = CancelledError
     self._shutdown(cancel, cancel_msg, cancel_exc_type)
示例#9
0
    def _validate_document(self, params, shape, errors, name):
        if params is None:
            return

        if isinstance(params, dict):
            for key in params:
                self._validate_document(params[key], shape, errors, key)
        elif isinstance(params, list):
            for index, entity in enumerate(params):
                self._validate_document(entity, shape, errors,
                                        '%s[%d]' % (name, index))
        elif not isinstance(params, (six.string_types, int, bool, float)):
            valid_types = (str, int, bool, float, list, dict)
            valid_type_names = [six.text_type(t) for t in valid_types]
            errors.report(name, 'invalid type for document',
                          param=params,
                          param_type=type(params),
                          valid_types=valid_type_names)
示例#10
0
def percent_encode(input_str, safe=SAFE_CHARS):
    """Urlencodes a string.

    Whereas percent_encode_sequence handles taking a dict/sequence and
    producing a percent encoded string, this function deals only with
    taking a string (not a dict/sequence) and percent encoding it.

    If given the binary type, will simply URL encode it. If given the
    text type, will produce the binary type by UTF-8 encoding the
    text. If given something else, will convert it to the text type
    first.
    """
    # If its not a binary or text string, make it a text string.
    if not isinstance(input_str, (six.binary_type, six.text_type)):
        input_str = six.text_type(input_str)
    # If it's not bytes, make it bytes by UTF-8 encoding it.
    if not isinstance(input_str, six.binary_type):
        input_str = input_str.encode('utf-8')
    return quote(input_str, safe=safe)
示例#11
0
def percent_encode(input_str, safe=SAFE_CHARS):
    """Urlencodes a string.

    Whereas percent_encode_sequence handles taking a dict/sequence and
    producing a percent encoded string, this function deals only with
    taking a string (not a dict/sequence) and percent encoding it.

    If given the binary type, will simply URL encode it. If given the
    text type, will produce the binary type by UTF-8 encoding the
    text. If given something else, will convert it to the text type
    first.
    """
    # If its not a binary or text string, make it a text string.
    if not isinstance(input_str, (six.binary_type, six.text_type)):
        input_str = six.text_type(input_str)
    # If it's not bytes, make it bytes by UTF-8 encoding it.
    if not isinstance(input_str, six.binary_type):
        input_str = input_str.encode('utf-8')
    return quote(input_str, safe=safe)
示例#12
0
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method, split.netloc, path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         value = six.text_type(params[key])
         pairs.append(
             quote(key.encode('utf-8'), safe='') + '=' +
             quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
示例#13
0
文件: auth.py 项目: ballagas/botocore
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method,
                                        split.netloc,
                                        path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         value = six.text_type(params[key])
         pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
                      quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
示例#14
0
 def _document_str(self, section, value, path):
     # We do the string conversion because this might accept a type that
     # we don't specifically address.
     section.write(u"'%s'," % six.text_type(value))
 def _default_serialize(self, xmlnode, params, shape, name):
     node = ElementTree.SubElement(xmlnode, name)
     node.text = six.text_type(params)
示例#16
0
 def _document_str(self, section, value, path):
     # We do the string conversion because this might accept a type that
     # we don't specifically address.
     section.write(u"'%s'," % six.text_type(value))
示例#17
0
 def _default_serialize(self, xmlnode, params, shape, name):
     node = ElementTree.SubElement(xmlnode, name)
     node.text = six.text_type(params)