Esempio n. 1
0
class MessageBuilder(object):
    def __init__(self):
        self.envelope = Envelope()
        self.terminator = self.envelope.delimiter() * 2
        # Note that order is reversed so pop() gets first.
        self.writers = [self.write_body, self.write_head]
        super(MessageBuilder, self).__init__()

    def write(self, bytes):
        writemethod = self.writers.pop()
        return writemethod(bytes)

    def get_terminator(self):
        return self.terminator

    def write_head(self, head):
        self.envelope.parse_head(head)
        self.terminator = int(self.envelope.content_length())

    def write_body(self, body):
        self.envelope.parse_body(body)
        self.terminator = 0

    def message(self):
        return self.envelope.getvalue()

    def iscomplete(self):
        return not self.writers
Esempio n. 2
0
class MessageProducer(object):
    def __init__(self, message=None):
        self.spent = False
        self.envelope = Envelope(message)
        super(MessageProducer, self).__init__()
    def more(self):
        if self.spent:
            return ""
        self.spent = True
        return self.envelope.serialize()
Esempio n. 3
0
class MessageBuilder(object):
    def __init__(self):
        self.envelope = Envelope()
        self.terminator = self.envelope.delimiter() * 2
        # Note that order is reversed so pop() gets first.
        self.writers = [self.write_body, self.write_head]
        super(MessageBuilder, self).__init__()
    def write(self, bytes):
        writemethod = self.writers.pop()
        return writemethod(bytes)
    def get_terminator(self):
        return self.terminator
    def write_head(self, head):
        self.envelope.parse_head(head)
        self.terminator = int(self.envelope.content_length())
    def write_body(self, body):
        self.envelope.parse_body(body)
        self.terminator = 0
    def message(self):
        return self.envelope.getvalue()
    def iscomplete(self):
        return not self.writers
Esempio n. 4
0
 def __init__(self, message=None):
     self.spent = False
     self.envelope = Envelope(message)
     super(MessageProducer, self).__init__()
Esempio n. 5
0
 def __init__(self):
     self.envelope = Envelope()
     self.terminator = self.envelope.delimiter() * 2
     # Note that order is reversed so pop() gets first.
     self.writers = [self.write_body, self.write_head]
     super(MessageBuilder, self).__init__()
Esempio n. 6
0
 def __init__(self):
     self.envelope = Envelope()
     self.terminator = self.envelope.delimiter() * 2
     # Note that order is reversed so pop() gets first.
     self.writers = [self.write_body, self.write_head]
     super(MessageBuilder, self).__init__()