MCPcopy Index your code
hub / github.com/python/cpython / getdelimited

Method getdelimited

Lib/email/_parseaddr.py:426–461  ·  view source on GitHub ↗

Parse a header fragment delimited by special characters. 'beginchar' is the start character for the fragment. If self is not looking at an instance of 'beginchar' then getdelimited returns the empty string. 'endchars' is a sequence of allowable end-delimiting charac

(self, beginchar, endchars, allowcomments=True)

Source from the content-addressed store, hash-verified

424 return EMPTYSTRING.join(sdlist)
425
426 def getdelimited(self, beginchar, endchars, allowcomments=True):
427 """Parse a header fragment delimited by special characters.
428
429 'beginchar' is the start character for the fragment.
430 If self is not looking at an instance of 'beginchar' then
431 getdelimited returns the empty string.
432
433 'endchars' is a sequence of allowable end-delimiting characters.
434 Parsing stops when one of these is encountered.
435
436 If 'allowcomments' is non-zero, embedded RFC 2822 comments are allowed
437 within the parsed fragment.
438 """
439 if self.field[self.pos] != beginchar:
440 return ''
441
442 slist = ['']
443 quote = False
444 self.pos += 1
445 while self.pos < len(self.field):
446 if quote:
447 slist.append(self.field[self.pos])
448 quote = False
449 elif self.field[self.pos] in endchars:
450 self.pos += 1
451 break
452 elif allowcomments and self.field[self.pos] == '(':
453 slist.append(self.getcomment())
454 continue # have already advanced pos from getcomment
455 elif self.field[self.pos] == '\\':
456 quote = True
457 else:
458 slist.append(self.field[self.pos])
459 self.pos += 1
460
461 return EMPTYSTRING.join(slist)
462
463 def getquote(self):
464 """Get a quote-delimited fragment from self's field."""

Callers 3

getquoteMethod · 0.95
getcommentMethod · 0.95
getdomainliteralMethod · 0.95

Calls 3

getcommentMethod · 0.95
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected