# Path: src/petmail/netstring.py
# def netstring(msg):
#     assert isinstance(msg, str)
#     return "%d:%s," % (len(msg), msg)
# 
# def split_netstrings(s):
#     p = _NetstringParser()
#     p.messages = messages = []
#     p.makeConnection(_EmptyTransport())
#     p.dataReceived(s)
#     if p._remainingData:
#         raise ValueError("leftover data: %d bytes" % len(p._remainingData))
#     return messages
# 
# def split_netstrings_and_trailer(s):
#     p = _NetstringParser()
#     p.messages = messages = []
#     p.makeConnection(_EmptyTransport())
#     p.dataReceived(s)
#     return (messages, p._remainingData)


import unittest
from ..netstring import (netstring, split_netstrings,
                         split_netstrings_and_trailer)


class Netstring(unittest.TestCase):
    def test_create(self):
        self.failUnlessEqual(netstring("abc"), "3:abc,")
    def test_split(self):
        a1 = netstring("abc")
        a2 = netstring("def")
        a3 = netstring("")
        a4 = netstring(":,")
        a5 = netstring("ghi")
        self.failUnlessEqual(split_netstrings(a1+a2+a3+a4+a5),
                             ["abc", "def", "", ":,", "ghi"])
    def test_leftover(self):
        a1 = netstring("abc")
        a2 = netstring("def")
        self.failUnlessEqual(split_netstrings_and_trailer(a1+a2+"stuff"),
                             (["abc", "def"], "stuff"))
    def test_no_leftover(self):
        self.failUnlessRaises(ValueError,

# Path: src/petmail/netstring.py
# def netstring(msg):
#     assert isinstance(msg, str)
#     return "%d:%s," % (len(msg), msg)
# 
# def split_netstrings(s):
#     p = _NetstringParser()
#     p.messages = messages = []
#     p.makeConnection(_EmptyTransport())
#     p.dataReceived(s)
#     if p._remainingData:
#         raise ValueError("leftover data: %d bytes" % len(p._remainingData))
#     return messages
# 
# def split_netstrings_and_trailer(s):
#     p = _NetstringParser()
#     p.messages = messages = []
#     p.makeConnection(_EmptyTransport())
#     p.dataReceived(s)
#     return (messages, p._remainingData)


# Path: src/petmail/test/test_netstring.py
import unittest
from ..netstring import (netstring, split_netstrings,
                         split_netstrings_and_trailer)



class Netstring(unittest.TestCase):
    def test_create(self):
        self.failUnlessEqual(netstring("abc"), "3:abc,")
    def test_split(self):
        a1 = netstring("abc")
        a2 = netstring("def")
        a3 = netstring("")
        a4 = netstring(":,")
        a5 = netstring("ghi")
        self.failUnlessEqual(split_netstrings(a1+a2+a3+a4+a5),
                             ["abc", "def", "", ":,", "ghi"])
    def test_leftover(self):
        a1 = netstring("abc")
        a2 = netstring("def")
        self.failUnlessEqual(split_netstrings_and_trailer(a1+a2+"stuff"),
                             (["abc", "def"], "stuff"))
    def test_no_leftover(self):
        self.failUnlessRaises(ValueError,

                              split_netstrings, "3:abc,extra")