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

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') | no next file with comments »
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 if label:
166 raise UnicodeError("input (%s) contains an empty label" % label.decode())
167 else:
168 raise UnicodeError("label (%s) is empty" % result.decode ())
166 if len(labels[-1]) >= 64: 169 if len(labels[-1]) >= 64:
167 raise UnicodeError("label too long") 170 raise UnicodeError("label (%r) is too long" % labels[-1].decode( ))
168 return result, len(input) 171 return result, len(input)
169 172
170 result = bytearray() 173 result = bytearray()
171 labels = dots.split(input) 174 labels = dots.split(input)
172 if labels and not labels[-1]: 175 if labels and not labels[-1]:
173 trailing_dot = b'.' 176 trailing_dot = b'.'
174 del labels[-1] 177 del labels[-1]
175 else: 178 else:
176 trailing_dot = b'' 179 trailing_dot = b''
177 for label in labels: 180 for label in labels:
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 def getregentry(): 303 def getregentry():
301 return codecs.CodecInfo( 304 return codecs.CodecInfo(
302 name='idna', 305 name='idna',
303 encode=Codec().encode, 306 encode=Codec().encode,
304 decode=Codec().decode, 307 decode=Codec().decode,
305 incrementalencoder=IncrementalEncoder, 308 incrementalencoder=IncrementalEncoder,
306 incrementaldecoder=IncrementalDecoder, 309 incrementaldecoder=IncrementalDecoder,
307 streamwriter=StreamWriter, 310 streamwriter=StreamWriter,
308 streamreader=StreamReader, 311 streamreader=StreamReader,
309 ) 312 )
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_unicode.py » ('j') | no next file with comments »

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