def testPoppingLinesWithUnixAndWindowsStyleLinebreaksIsEqualent(self): line = "hai" self.assertEqual( popLine(line + linebreak), popLine(line + altLinebreak) )
def testPoppingLinesWithMultipleLineTerminators(self): text1 = "hello\nthere\r\nworld" text2 = "hello\r\nthere\nworld" p1, text1 = popLine(text1) p2, text2 = popLine(text2) self.assertEqual(p1, "hello") self.assertEqual(p2, "hello") self.assertEqual(text1, "there\r\nworld") self.assertEqual(text2, "there\nworld")
def testPoppingLines(self): text = "hello\nthere\nworld" self.assertEqual( popLine(text), ("hello", "there\nworld") )
def popHeaders(message, stripValues=True): """ Returns the headers as a tuple of (name, value) tuples, and the entity. Whitespace is stripped from the left of values, unless stripValues is false. """ headers = tuple() h, message = popLine(message) while h: if not headerDelimiter in h: raise ValueError("Bad header.") name, value = h.split(headerDelimiter, 1) if stripValues: value = value.lstrip() headers = appendPair(headers, name, value) h, message = popLine(message) entity = message return headers, entity
def _popTopLine(message): """ Pop off the top line and break it into three parts seperated by spaces. Spaces in the third part are preserved. Returns a tuple with the three parts, and the rest of the message. If there are not at least 2 spaces, a ValueError is raised. """ topLine, message = popLine(message) if topLine.count(topDelimiter) < 2: raise ValueError("Bad top line.") return tuple((topLine.split(topDelimiter, 2) + [message]))
def testPoppingEmptyText(self): self.assertEqual( popLine(""), (None, "") )