コード例 #1
0
ファイル: messages.py プロジェクト: pombredanne/pgproxy
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
ファイル: messages.py プロジェクト: pombredanne/pgproxy
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
ファイル: messages.py プロジェクト: BT-csanchez/pgproxy
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
ファイル: messages.py プロジェクト: BT-csanchez/pgproxy
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
ファイル: messages.py プロジェクト: pombredanne/pgproxy
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
ファイル: messages.py プロジェクト: BT-csanchez/pgproxy
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
ファイル: messages.py プロジェクト: pombredanne/pgproxy
def _int_message(t, intval, cls):
    m = cls()
    m.consume('%s%s%s' % (t, eight_packed, pack_int32(intval)))
    return m
コード例 #8
0
ファイル: messages.py プロジェクト: pombredanne/pgproxy
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
ファイル: messages.py プロジェクト: pombredanne/pgproxy
"""
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
ファイル: messages.py プロジェクト: BT-csanchez/pgproxy
def _int_message(t, intval, cls):
    m = cls()
    m.consume('%s%s%s' % (t, eight_packed, pack_int32(intval)))
    return m
コード例 #11
0
ファイル: messages.py プロジェクト: BT-csanchez/pgproxy
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
ファイル: messages.py プロジェクト: BT-csanchez/pgproxy
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. 

    """