Пример #1
0
def parameterStatus(name, value):
    """
    Constructs a new ParameterStatus message holding the given name and value. 
    """
    m = BackendMessage()
    l = pack_int32(len(name) + len(value) + 2 + 4)
    m.consume('S%s%s\x00%s\x00' % (l, name, value))
    return m
Пример #2
0
def startup(user):
    """
    Constructs a new Startup message. 
    """
    m = FrontendMessage()
    payload = ('\x00\x03\x00\x00' 'user\x00%s\x00' % user)
    m.consume(pack_int32(len(payload) + 4) + payload)
    return m
Пример #3
0
def parameterStatus(name, value):
    """
    Constructs a new ParameterStatus message holding the given name and value. 
    """
    m = BackendMessage()
    l = pack_int32(len(name) + len(value) + 2 + 4)
    m.consume('S%s%s\x00%s\x00' % (l, name, value))
    return m
Пример #4
0
def startup(user):
    """
    Constructs a new Startup message. 
    """
    m = FrontendMessage()
    payload = ('\x00\x03\x00\x00' 
               'user\x00%s\x00' % user)
    m.consume(pack_int32(len(payload)+4) + payload)
    return m
Пример #5
0
def errorResponse(*fields):
    """
    Creates an ErrorResponse message. Fields should be a list of 2-tuples
    consisting of a single-byte field type and a string. 
    """
    m = BackendMessage()

    # convert fields to strings
    fields = [(b, str(f)) for b, f in fields]

    # four bytes for the length, one byte plus string length plus \0 for
    # each field, one terminating \0.
    length = pack_int32(4 + sum([1 + 1 + len(f) for _, f in fields]) + 1)
    m.consume('E' + length)
    for b, f in fields:
        m.consume(b + f + '\x00')
    m.consume('\x00')
    return m
Пример #6
0
def errorResponse(*fields):
    """
    Creates an ErrorResponse message. Fields should be a list of 2-tuples
    consisting of a single-byte field type and a string. 
    """
    m = BackendMessage()
    
    # convert fields to strings 
    fields = [(b, str(f)) for b, f in fields]

    # four bytes for the length, one byte plus string length plus \0 for
    # each field, one terminating \0. 
    length = pack_int32(4 + sum([1+1+len(f) for _, f in fields]) + 1)
    m.consume('E' + length)
    for b, f in fields:
        m.consume(b+f+'\x00')
    m.consume('\x00')
    return m
Пример #7
0
def _int_message(t, intval, cls):
    m = cls()
    m.consume('%s%s%s' % (t, eight_packed, pack_int32(intval)))
    return m
Пример #8
0
def _string_message(s, t, cls):
    m = cls()
    m.consume('%s%s%s\x00' % (t, pack_int32(len(s) + 5), s))
    return m
Пример #9
0
"""
This module is responsible for parsing and serializing messages for the postgres
frontend/backend protocol. 

The Message class handles parsing messages, and the exported functions can be 
used to construct new messages. 

See here:
http://developer.postgresql.org/pgdocs/postgres/protocol-message-formats.html

"""
from fifobuffer import FIFOBuffer
from data import pack_int32

# constant values
eight_packed = pack_int32(8)
five_packed = pack_int32(5)


class Message(object):
    """
    Base class that for frontend or backend messages. Data is parsed 
    via the consume() method, and the message can be persisted for the wire
    using the serialize() method. 

    Instances of this class will have a variable set of properties, as 
    determined by the self.type field. Messages that are not yet completely 
    parsed will also have an inconsistent set of properties. 

    """
    def __init__(self):
Пример #10
0
def _int_message(t, intval, cls):
    m = cls()
    m.consume('%s%s%s' % (t, eight_packed, pack_int32(intval)))
    return m
Пример #11
0
def _string_message(s, t, cls):
    m = cls()
    m.consume('%s%s%s\x00' % (t, pack_int32(len(s)+5), s))
    return m
Пример #12
0
This module is responsible for parsing and serializing messages for the postgres
frontend/backend protocol. 

The Message class handles parsing messages, and the exported functions can be 
used to construct new messages. 

See here:
http://developer.postgresql.org/pgdocs/postgres/protocol-message-formats.html

"""
from fifobuffer import FIFOBuffer
from data import pack_int32


# constant values
eight_packed = pack_int32(8)
five_packed = pack_int32(5)


class Message(object):
    """
    Base class that for frontend or backend messages. Data is parsed 
    via the consume() method, and the message can be persisted for the wire
    using the serialize() method. 

    Instances of this class will have a variable set of properties, as 
    determined by the self.type field. Messages that are not yet completely 
    parsed will also have an inconsistent set of properties. 

    """