Exemplo n.º 1
0
    def _rfc2231_and_continuation_params(cls, params):  # TODO: complexity
        count = set()
        continuations = dict()
        for key, value, quoted in params:
            if key in count:
                raise InvalidHeader(_(u'Parameter given twice: %r'),
                                    key.decode('ISO8859-1'))
            count.add(key)
            if '*' in key:
                if key.endswith('*') and not quoted:
                    charset, language, value_ = decode_rfc2231(
                        value.encode('ISO8859-1'))
                    if not charset:
                        yield key, value
                        continue
                    encoding = sanitize_encoding(charset)
                    if encoding is None:
                        raise InvalidHeader(_(u'Unknown encoding: %r'),
                                            charset)
                    try:
                        key, value = key[:-1], Percent.unquote(value_).decode(
                            encoding)
                    except UnicodeDecodeError as exc:
                        raise InvalidHeader(_(u'%s') % (exc, ))
                key_, asterisk, num = key.rpartition('*')
                if asterisk:
                    try:
                        if num != '0' and num.startswith('0'):
                            raise ValueError
                        num = int(num)
                    except ValueError:
                        yield key, value
                        continue
                    continuations.setdefault(key_, {})[num] = value
                    continue
            yield key, value

        for key, lines in iteritems(continuations):
            value = b''
            for i in xrange(len(lines)):
                try:
                    value += lines.pop(i)
                except KeyError:
                    break
            if not key:
                raise InvalidHeader(_(u'...'))
            if value:
                yield key, value
            for k, v in iteritems(lines):
                yield '%s*%d' % (key, k), v
Exemplo n.º 2
0
	def _rfc2231_and_continuation_params(cls, params):  # TODO: complexity
		count = set()
		continuations = dict()
		for key, value, quoted in params:
			if key in count:
				raise InvalidHeader(_(u'Parameter given twice: %r'), key.decode('ISO8859-1'))
			count.add(key)
			if '*' in key:
				if key.endswith('*') and not quoted:
					charset, language, value_ = decode_rfc2231(value.encode('ISO8859-1'))
					if not charset:
						yield key, value
						continue
					encoding = sanitize_encoding(charset)
					if encoding is None:
						raise InvalidHeader(_(u'Unknown encoding: %r'), charset)
					try:
						key, value = key[:-1], Percent.unquote(value_).decode(encoding)
					except UnicodeDecodeError as exc:
						raise InvalidHeader(_(u'%s') % (exc,))
				key_, asterisk, num = key.rpartition('*')
				if asterisk:
					try:
						if num != '0' and num.startswith('0'):
							raise ValueError
						num = int(num)
					except ValueError:
						yield key, value
						continue
					continuations.setdefault(key_, {})[num] = value
					continue
			yield key, value

		for key, lines in iteritems(continuations):
			value = b''
			for i in xrange(len(lines)):
				try:
					value += lines.pop(i)
				except KeyError:
					break
			if not key:
				raise InvalidHeader(_(u'...'))
			if value:
				yield key, value
			for k, v in iteritems(lines):
				yield '%s*%d' % (key, k), v
Exemplo n.º 3
0
 def quote(cls, data, charset=None):
     data = data.encode(charset or 'ISO8859-1')
     return Percent.quote(data, Percent.QUERY.replace(b'+', b''))
Exemplo n.º 4
0
	def quote(self, data, charset):
		return Percent.quote(unicode(data).encode(self.encoding), charset)
Exemplo n.º 5
0
	def unquote(self, data):
		return Percent.unquote(bytes(data)).decode(self.encoding)
Exemplo n.º 6
0
 def quote(cls, data, charset=None):
     data = data.encode(charset or 'ISO8859-1')
     return Percent.quote(data, cls.UNRESERVED)
Exemplo n.º 7
0
 def unquote(cls, data, charset=None):
     return Percent.unquote(data).decode(charset or 'ISO8859-1')
Exemplo n.º 8
0
	def quote(self, data, charset):
		return Percent.quote(Unicode(data).encode(self.encoding), charset)
Exemplo n.º 9
0
	def unquote(self, data):
		return Percent.unquote(bytes(data)).decode(self.encoding)
Exemplo n.º 10
0
	def quote(cls, data, charset=None):
		data = data.encode(charset or 'ISO8859-1')
		return Percent.quote(data, cls.UNRESERVED)
Exemplo n.º 11
0
	def unquote(cls, data, charset=None):
		return Percent.unquote(data).decode(charset or 'ISO8859-1')
Exemplo n.º 12
0
	def quote(cls, data, charset=None):
		data = data.encode(charset or 'ISO8859-1')
		return Percent.quote(data, Percent.QUERY.replace(b'+', b''))