Exemplo n.º 1
0
 def _InvokeMethod(self, name, args):
     request = CybosPlusProxyService_pb2.MethodRequest()
     request.prog = self._progid
     request.name = name
     for arg in args:
         AssignPrimitive(request.arguments.add().value, arg)  # pylint: disable=no-member
     should_stop = False
     while not should_stop:
         response_future = self._proxy._stub.Method.future(
             request, timeout=self._proxy._timeout)  # pylint: disable=protected-access
         try:
             response = response_future.result()
         except grpc.RpcError:
             if response_future.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
                 self.logger.warning(
                     "Method invocation %s(%s) timed out, retrying...",
                     name,
                     ", ".join(map(repr, args)),
                 )
             else:
                 raise
         else:
             should_stop = True
     result = ExtractPrimitive(response.return_value)
     return result
Exemplo n.º 2
0
 def Event(self, request_iterator, context):
     start_request = next(request_iterator)
     assert start_request.HasField('start')
     prog = start_request.start.prog
     handler = self._GetHandler(prog)
     response = CybosPlusProxyService_pb2.EventResponse()
     response.started  # pylint: disable=no-member,pointless-statement
     yield response
     for event in handler:
         response = CybosPlusProxyService_pb2.EventResponse()
         response.fired  # pylint: disable=no-member,pointless-statement
         yield response
         done_request = next(request_iterator)
         event.done()
         if done_request.HasField('stop'):
             break
Exemplo n.º 3
0
 def Property(self, request, context):
     prog = request.prog
     dispatch = self._EnsureDispatch(prog)
     name = request.name
     value = getattr(dispatch, name)
     response = CybosPlusProxyService_pb2.PropertyResponse()
     AssignPrimitive(response.value, value)  # pylint: disable=no-member
     return response
Exemplo n.º 4
0
 def Method(self, request, context):
     prog = request.prog
     dispatch = self._EnsureDispatch(prog)
     name = request.name
     method = getattr(dispatch, name)
     arguments = [ExtractPrimitive(arg.value) for arg in request.arguments]
     return_value = method(*arguments)
     response = CybosPlusProxyService_pb2.MethodResponse()
     AssignPrimitive(response.return_value, return_value)  # pylint: disable=no-member
     return response
Exemplo n.º 5
0
    def __init__(self, proxy, progid):
        self._proxy = proxy
        self._progid = progid

        self._is_trade_related = self._progid.startswith("CpTrade.")

        request = CybosPlusProxyService_pb2.DispatchRequest()
        request.prog = self._progid

        self._dispatch = self._proxy._stub.Dispatch(request)
Exemplo n.º 6
0
 def Dispatch(self, request, context):
     prog = request.prog
     dispatch = self._EnsureDispatch(prog)
     properties = [p for p in dispatch._prop_map_get_.keys()]
     methods = [
         m for m in dir(dispatch)
         if not m.startswith('_') and m not in ['CLSID', 'coclass_clsid']
     ]
     response = CybosPlusProxyService_pb2.DispatchResponse()
     response.prog = prog
     response.properties.extend(properties)  # pylint: disable=no-member
     response.methods.extend(methods)  # pylint: disable=no-member
     return response
Exemplo n.º 7
0
 def _GetProperty(self, name):
     request = CybosPlusProxyService_pb2.PropertyRequest()
     request.prog = self._progid
     request.name = name
     should_stop = False
     while not should_stop:
         response_future = self._proxy._stub.Property.future(
             request, timeout=self._proxy._timeout)  # pylint: disable=protected-access
         try:
             response = response_future.result()
         except grpc.RpcError:
             if response_future.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
                 self.logger.warning(
                     "Property %s lookup failed, retrying...", name)
             else:
                 raise
         else:
             should_stop = True
     result = ExtractPrimitive(response.value)
     return result