##// END OF EJS Templates
httppeer: always produce native str header keys and values...
Augie Fackler -
r34733:67e9678e default
parent child Browse files
Show More
@@ -39,16 +39,24 b' def encodevalueinheaders(value, header, '
39 ``header-<N>`` where ``<N>`` is an integer starting at 1. Each header
39 ``header-<N>`` where ``<N>`` is an integer starting at 1. Each header
40 name + value will be at most ``limit`` bytes long.
40 name + value will be at most ``limit`` bytes long.
41
41
42 Returns an iterable of 2-tuples consisting of header names and values.
42 Returns an iterable of 2-tuples consisting of header names and
43 values as native strings.
43 """
44 """
44 fmt = header + '-%s'
45 # HTTP Headers are ASCII. Python 3 requires them to be unicodes,
45 valuelen = limit - len(fmt % '000') - len(': \r\n')
46 # not bytes. This function always takes bytes in as arguments.
47 fmt = pycompat.strurl(header) + r'-%s'
48 # Note: it is *NOT* a bug that the last bit here is a bytestring
49 # and not a unicode: we're just getting the encoded length anyway,
50 # and using an r-string to make it portable between Python 2 and 3
51 # doesn't work because then the \r is a literal backslash-r
52 # instead of a carriage return.
53 valuelen = limit - len(fmt % r'000') - len(': \r\n')
46 result = []
54 result = []
47
55
48 n = 0
56 n = 0
49 for i in xrange(0, len(value), valuelen):
57 for i in xrange(0, len(value), valuelen):
50 n += 1
58 n += 1
51 result.append((fmt % str(n), value[i:i + valuelen]))
59 result.append((fmt % str(n), pycompat.strurl(value[i:i + valuelen])))
52
60
53 return result
61 return result
54
62
General Comments 0
You need to be logged in to leave comments. Login now