def recv_sasl_msg(self):
     header = readall(self.transport.read, 5)
     status, length = unpack(">BI", header)
     if length > 0:
         payload = readall(self.transport.read, length)
     else:
         payload = ""
     return status, payload
Exemplo n.º 2
0
if PY2:
  from cStringIO import StringIO
  from thrift.transport.TTransport import (
    TTransportException, TTransportBase, CReadableTransport)

  is_open_compat = lambda trans: trans.isOpen()
  read_all_compat = lambda trans, sz: trans.readAll(sz)


if PY3:
  # TODO: consider contributing this to thriftpy instead
  class CReadableTransport(object):
    @property
    def cstringio_buf(self):
      pass
    def cstringio_refill(self, partialread, reqlen):
      pass

  # TODO: make this more explicit for maintainability sake
  from io import BytesIO as StringIO
  from thriftpy.transport import TTransportException, TTransportBase, readall

  def is_open_compat(trans):
    try:
      is_open = trans.is_open()
    except AttributeError:
      is_open = trans.isOpen()
    return is_open

  read_all_compat = lambda trans, sz: readall(trans.read, sz)
Exemplo n.º 3
0
 def _trans_readall(self, sz):
     try:
         return self._trans.readAll(sz)  # Thrift
     except AttributeError:
         from thriftpy.transport import readall
         return readall(self._trans.read, sz)  # thriftpy
Exemplo n.º 4
0
    def cstringio_buf(self):
      pass
    def cstringio_refill(self, partialread, reqlen):
      pass

  # TODO: make this more explicit for maintainability sake
  from io import BytesIO as StringIO
  from thriftpy.transport import readall, TTransportException, TTransportBase


if PY2:
  six_is_open = lambda trans: trans.isOpen()
  six_read_all = lambda trans, sz: trans.readAll(sz)
elif PY3:
  six_is_open = lambda trans: trans.is_open()
  six_read_all = lambda trans, sz: readall(trans.read, sz)


class TSaslClientTransport(TTransportBase, CReadableTransport):
  START = 1
  OK = 2
  BAD = 3
  ERROR = 4
  COMPLETE = 5

  def __init__(self, sasl_client_factory, mechanism, trans):
    """
    @param sasl_client_factory: a callable that returns a new sasl.Client object
    @param mechanism: the SASL mechanism (e.g. "GSSAPI")
    @param trans: the underlying transport over which to communicate.
    """
Exemplo n.º 5
0
    from cStringIO import StringIO
    from thrift.transport.TTransport import (TTransportException,
                                             TTransportBase,
                                             CReadableTransport)

    is_open_compat = lambda trans: trans.isOpen()
    read_all_compat = lambda trans, sz: trans.readAll(sz)

if PY3:
    # TODO: consider contributing this to thriftpy instead
    class CReadableTransport(object):
        @property
        def cstringio_buf(self):
            pass

        def cstringio_refill(self, partialread, reqlen):
            pass

    # TODO: make this more explicit for maintainability sake
    from io import BytesIO as StringIO
    from thriftpy.transport import TTransportException, TTransportBase, readall

    def is_open_compat(trans):
        try:
            is_open = trans.is_open()
        except AttributeError:
            is_open = trans.isOpen()
        return is_open

    read_all_compat = lambda trans, sz: readall(trans.read, sz)
 def _read_frame(self):
     header = readall(self.transport.read, 4)
     length, = unpack('!i', header)
     encoded = readall(self.transport.read, length)
     self.__rbuf = BufferIO(self.sasl.unwrap(encoded))