grr/test/grr_response_test/lib/shared_fake_data_store.py
def DelegatedMethod(mname):
  """Class decorator delegating given method to a remote data store server."""

  def Impl(self, *src_args, **src_kwargs):
    """Method implementation to add."""
    del self  # unused

    # Make sure positional arguments are pickleable (i.e. have no generators
    # or iterators).
    args = []
    for a in src_args:
      args.append(ConvertToListIfIterator(a))

    # Make sure keyword arguments are pickleable (i.e. have no generators
    # or iterators).
    kwargs = {}
    for n, a in src_kwargs.items():
      kwargs[n] = ConvertToListIfIterator(a)

    port = config.CONFIG["SharedFakeDataStore.port"]
    sock = socket.create_connection(("localhost", port))
    sock.settimeout(30.0)
    try:
      # Send pickled request.
      sock.sendall(pickle.dumps((mname, args, kwargs)))

      # Read pickled response.
      data = []
      while True:
        chunk = sock.recv(_FILE_READ_CHUNK_SIZE)
        if not chunk:
          break
        data.append(chunk)

      # Unpickle the response combined from read chunks.
      result = pickle.loads(b"".join(data))
    finally:
      sock.close()

    # If returned object is an exception, simply raise it.
    if isinstance(result, Exception):
      raise result

    return result

  def MethodAdder(cls):
    setattr(cls, mname, Impl)
    return cls

  return MethodAdder
Class decorator delegating given method to a remote data store server.
Class decorator delegating given method to a remote data store server.
Class decorator delegating given method to a remote data store server .
def DelegatedMethod(mname):
  def Impl(self, *src_args, **src_kwargs):
    del self  
    args = []
    for a in src_args:
      args.append(ConvertToListIfIterator(a))
    kwargs = {}
    for n, a in src_kwargs.items():
      kwargs[n] = ConvertToListIfIterator(a)
    port = config.CONFIG["SharedFakeDataStore.port"]
    sock = socket.create_connection(("localhost", port))
    sock.settimeout(30.0)
    try:
      sock.sendall(pickle.dumps((mname, args, kwargs)))
      data = []
      while True:
        chunk = sock.recv(_FILE_READ_CHUNK_SIZE)
        if not chunk:
          break
        data.append(chunk)
      result = pickle.loads(b"".join(data))
    finally:
      sock.close()
    if isinstance(result, Exception):
      raise result
    return result
  def MethodAdder(cls):
    setattr(cls, mname, Impl)
    return cls
  return MethodAdder
def DelegatedMethod ( mname ) : def Impl ( self , * src_args , ** src_kwargs ) : """Method implementation to add.""" del self args = [ ] for a in src_args : args . append ( ConvertToListIfIterator ( a ) ) kwargs = { } for n , a in src_kwargs . items ( ) : kwargs [ n ] = ConvertToListIfIterator ( a ) port = config . CONFIG [ "SharedFakeDataStore.port" ] sock = socket . create_connection ( ( "localhost" , port ) ) sock . settimeout ( 30.0 ) try : sock . sendall ( pickle . dumps ( ( mname , args , kwargs ) ) ) data = [ ] while True : chunk = sock . recv ( _FILE_READ_CHUNK_SIZE ) if not chunk : break data . append ( chunk ) result = pickle . loads ( b"" . join ( data ) ) finally : sock . close ( ) if isinstance ( result , Exception ) : raise result return result def MethodAdder ( cls ) : setattr ( cls , mname , Impl ) return cls return MethodAdder
Class decorator delegating given method to a remote data store server.
Class decorator delegating given method to a remote data store server .
"""Class decorator delegating given method to a remote data store server.""" """Method implementation to add.""" # unused # Make sure positional arguments are pickleable (i.e. have no generators # or iterators). # Make sure keyword arguments are pickleable (i.e. have no generators # or iterators). # Send pickled request. # Read pickled response. # Unpickle the response combined from read chunks. # If returned object is an exception, simply raise it.
mname