Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(314)

Side by Side Diff: Lib/encodings/idna.py

Issue 9682: socket.create_connection error message for domain subpart with invalid length is very confusing
Patch Set: Created 6 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_unicode.py » ('j') | Lib/test/test_unicode.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This module implements the RFCs 3490 (IDNA) and 3491 (Nameprep) 1 # This module implements the RFCs 3490 (IDNA) and 3491 (Nameprep)
2 2
3 import stringprep, re, codecs 3 import stringprep, re, codecs
4 from unicodedata import ucd_3_2_0 as unicodedata 4 from unicodedata import ucd_3_2_0 as unicodedata
5 5
6 # IDNA section 3.1 6 # IDNA section 3.1
7 dots = re.compile("[\u002E\u3002\uFF0E\uFF61]") 7 dots = re.compile("[\u002E\u3002\uFF0E\uFF61]")
8 8
9 # IDNA section 5 9 # IDNA section 5
10 ace_prefix = b"xn--" 10 ace_prefix = b"xn--"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 try: 156 try:
157 result = input.encode('ascii') 157 result = input.encode('ascii')
158 except UnicodeEncodeError: 158 except UnicodeEncodeError:
159 pass 159 pass
160 else: 160 else:
161 # ASCII name: fast path 161 # ASCII name: fast path
162 labels = result.split(b'.') 162 labels = result.split(b'.')
163 for label in labels[:-1]: 163 for label in labels[:-1]:
164 if not (0 < len(label) < 64): 164 if not (0 < len(label) < 64):
165 raise UnicodeError("label empty or too long") 165 raise UnicodeError("label empty or too long in %s" % result. decode())
r.david.murray 2013/04/13 21:49:49 Once we've determined that there is an error, I th
AntoinePitrou 2013/04/13 22:59:32 I disagree about doing .decode() at all here, sinc
mmilkin 2013/04/13 23:16:53 So it looks like L157 converts the input into asci
166 if len(labels[-1]) >= 64: 166 if len(labels[-1]) >= 64:
167 raise UnicodeError("label too long") 167 raise UnicodeError("label too long %s" % labels[-1].decode())
AntoinePitrou 2013/04/13 22:59:32 Same here.
mmilkin 2013/04/13 23:18:04 Poke me if you disagree with my comment above On 2
168 return result, len(input) 168 return result, len(input)
169 169
170 result = bytearray() 170 result = bytearray()
171 labels = dots.split(input) 171 labels = dots.split(input)
172 if labels and not labels[-1]: 172 if labels and not labels[-1]:
173 trailing_dot = b'.' 173 trailing_dot = b'.'
174 del labels[-1] 174 del labels[-1]
175 else: 175 else:
176 trailing_dot = b'' 176 trailing_dot = b''
177 for label in labels: 177 for label in labels:
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 def getregentry(): 300 def getregentry():
301 return codecs.CodecInfo( 301 return codecs.CodecInfo(
302 name='idna', 302 name='idna',
303 encode=Codec().encode, 303 encode=Codec().encode,
304 decode=Codec().decode, 304 decode=Codec().decode,
305 incrementalencoder=IncrementalEncoder, 305 incrementalencoder=IncrementalEncoder,
306 incrementaldecoder=IncrementalDecoder, 306 incrementaldecoder=IncrementalDecoder,
307 streamwriter=StreamWriter, 307 streamwriter=StreamWriter,
308 streamreader=StreamReader, 308 streamreader=StreamReader,
309 ) 309 )
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_unicode.py » ('j') | Lib/test/test_unicode.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+