def break_down_invocation(method_descriptions):
    """Derives an InvocationBreakdown from several RPC method descriptions.

  Args:
    method_descriptions: A dictionary from RPC method name to
      interfaces.RpcMethodInvocationDescription describing the RPCs.

  Returns:
    An InvocationBreakdown corresponding to the given method descriptions.
  """
    cardinalities = {}
    implementations = {}
    request_serializers = {}
    response_deserializers = {}
    for name, method_description in method_descriptions.iteritems():
        cardinality = method_description.cardinality()
        cardinalities[name] = cardinality
        if cardinality is interfaces.Cardinality.UNARY_UNARY:
            implementations[name] = assembly_utilities.unary_unary_inline(None)
        elif cardinality is interfaces.Cardinality.UNARY_STREAM:
            implementations[name] = assembly_utilities.unary_stream_inline(
                None)
        elif cardinality is interfaces.Cardinality.STREAM_UNARY:
            implementations[name] = assembly_utilities.stream_unary_inline(
                None)
        elif cardinality is interfaces.Cardinality.STREAM_STREAM:
            implementations[name] = assembly_utilities.stream_stream_inline(
                None)
        request_serializers[name] = method_description.serialize_request
        response_deserializers[name] = method_description.deserialize_response
    return _EasyInvocationBreakdown(cardinalities, implementations,
                                    request_serializers,
                                    response_deserializers)
Exemple #2
0
def break_down_invocation(method_descriptions):
  """Derives an InvocationBreakdown from several RPC method descriptions.

  Args:
    method_descriptions: A dictionary from RPC method name to
      interfaces.RpcMethodInvocationDescription describing the RPCs.

  Returns:
    An InvocationBreakdown corresponding to the given method descriptions.
  """
  cardinalities = {}
  implementations = {}
  request_serializers = {}
  response_deserializers = {}
  for name, method_description in six.iteritems(method_descriptions):
    cardinality = method_description.cardinality()
    cardinalities[name] = cardinality
    if cardinality is interfaces.Cardinality.UNARY_UNARY:
      implementations[name] = assembly_utilities.unary_unary_inline(None)
    elif cardinality is interfaces.Cardinality.UNARY_STREAM:
      implementations[name] = assembly_utilities.unary_stream_inline(None)
    elif cardinality is interfaces.Cardinality.STREAM_UNARY:
      implementations[name] = assembly_utilities.stream_unary_inline(None)
    elif cardinality is interfaces.Cardinality.STREAM_STREAM:
      implementations[name] = assembly_utilities.stream_stream_inline(None)
    request_serializers[name] = method_description.serialize_request
    response_deserializers[name] = method_description.deserialize_response
  return _EasyInvocationBreakdown(
      cardinalities, implementations, request_serializers,
      response_deserializers)
def early_adopter_create_RouteGuide_stub(host, port):
  method_implementations = {
    "GetFeature": utilities.unary_unary_inline(None),
    "ListFeatures": utilities.unary_stream_inline(None),
    "RecordRoute": utilities.stream_unary_inline(None),
    "RouteChat": utilities.stream_stream_inline(None),
  }
  import route_guide_pb2
  import route_guide_pb2
  import route_guide_pb2
  import route_guide_pb2
  response_deserializers = {
    "GetFeature": route_guide_pb2.Feature.FromString,
    "ListFeatures": route_guide_pb2.Feature.FromString,
    "RecordRoute": route_guide_pb2.RouteSummary.FromString,
    "RouteChat": route_guide_pb2.RouteNote.FromString,
  }
  request_serializers = {
    "GetFeature": lambda x: x.SerializeToString(),
    "ListFeatures": lambda x: x.SerializeToString(),
    "RecordRoute": lambda x: x.SerializeToString(),
    "RouteChat": lambda x: x.SerializeToString(),
  }
  link = rear.activated_rear_link(host, port, request_serializers, response_deserializers)
  return implementations.assemble_dynamic_inline_stub(method_implementations, link)
def early_adopter_create_RouteGuide_server(servicer, port, root_certificates, key_chain_pairs):
  method_implementations = {
    "GetFeature": utilities.unary_unary_inline(servicer.GetFeature),
    "ListFeatures": utilities.unary_stream_inline(servicer.ListFeatures),
    "RecordRoute": utilities.stream_unary_inline(servicer.RecordRoute),
    "RouteChat": utilities.stream_stream_inline(servicer.RouteChat),
  }
  import route_guide_pb2
  import route_guide_pb2
  import route_guide_pb2
  import route_guide_pb2
  request_deserializers = {
    "GetFeature": route_guide_pb2.Point.FromString,
    "ListFeatures": route_guide_pb2.Rectangle.FromString,
    "RecordRoute": route_guide_pb2.Point.FromString,
    "RouteChat": route_guide_pb2.RouteNote.FromString,
  }
  response_serializers = {
    "GetFeature": lambda x: x.SerializeToString(),
    "ListFeatures": lambda x: x.SerializeToString(),
    "RecordRoute": lambda x: x.SerializeToString(),
    "RouteChat": lambda x: x.SerializeToString(),
  }
  link = fore.activated_fore_link(port, request_deserializers, response_serializers, root_certificates, key_chain_pairs)
  return implementations.assemble_service(method_implementations, link)
Exemple #5
0
def early_adopter_create_RouteGuide_stub(host, port):
    method_implementations = {
        "GetFeature": utilities.unary_unary_inline(None),
        "ListFeatures": utilities.unary_stream_inline(None),
        "RecordRoute": utilities.stream_unary_inline(None),
        "RouteChat": utilities.stream_stream_inline(None),
    }
    import route_guide_pb2
    import route_guide_pb2
    import route_guide_pb2
    import route_guide_pb2
    response_deserializers = {
        "GetFeature": route_guide_pb2.Feature.FromString,
        "ListFeatures": route_guide_pb2.Feature.FromString,
        "RecordRoute": route_guide_pb2.RouteSummary.FromString,
        "RouteChat": route_guide_pb2.RouteNote.FromString,
    }
    request_serializers = {
        "GetFeature": lambda x: x.SerializeToString(),
        "ListFeatures": lambda x: x.SerializeToString(),
        "RecordRoute": lambda x: x.SerializeToString(),
        "RouteChat": lambda x: x.SerializeToString(),
    }
    link = rear.activated_rear_link(host, port, request_serializers,
                                    response_deserializers)
    return implementations.assemble_dynamic_inline_stub(
        method_implementations, link)
Exemple #6
0
def early_adopter_create_RouteGuide_server(servicer, port, root_certificates,
                                           key_chain_pairs):
    method_implementations = {
        "GetFeature": utilities.unary_unary_inline(servicer.GetFeature),
        "ListFeatures": utilities.unary_stream_inline(servicer.ListFeatures),
        "RecordRoute": utilities.stream_unary_inline(servicer.RecordRoute),
        "RouteChat": utilities.stream_stream_inline(servicer.RouteChat),
    }
    import route_guide_pb2
    import route_guide_pb2
    import route_guide_pb2
    import route_guide_pb2
    request_deserializers = {
        "GetFeature": route_guide_pb2.Point.FromString,
        "ListFeatures": route_guide_pb2.Rectangle.FromString,
        "RecordRoute": route_guide_pb2.Point.FromString,
        "RouteChat": route_guide_pb2.RouteNote.FromString,
    }
    response_serializers = {
        "GetFeature": lambda x: x.SerializeToString(),
        "ListFeatures": lambda x: x.SerializeToString(),
        "RecordRoute": lambda x: x.SerializeToString(),
        "RouteChat": lambda x: x.SerializeToString(),
    }
    link = fore.activated_fore_link(port, request_deserializers,
                                    response_serializers, root_certificates,
                                    key_chain_pairs)
    return implementations.assemble_service(method_implementations, link)
Exemple #7
0
def break_down_service(method_descriptions):
  """Derives a ServiceBreakdown from several RPC method descriptions.

  Args:
    method_descriptions: A dictionary from RPC method name to
      interfaces.RpcMethodServiceDescription describing the RPCs.

  Returns:
    A ServiceBreakdown corresponding to the given method descriptions.
  """
  implementations = {}
  request_deserializers = {}
  response_serializers = {}
  for name, method_description in six.iteritems(method_descriptions):
    cardinality = method_description.cardinality()
    if cardinality is interfaces.Cardinality.UNARY_UNARY:
      def service(
          request, face_rpc_context,
          service_behavior=method_description.service_unary_unary):
        return service_behavior(
            request, _reexport.rpc_context(face_rpc_context))
      implementations[name] = assembly_utilities.unary_unary_inline(service)
    elif cardinality is interfaces.Cardinality.UNARY_STREAM:
      def service(
          request, face_rpc_context,
          service_behavior=method_description.service_unary_stream):
        return service_behavior(
            request, _reexport.rpc_context(face_rpc_context))
      implementations[name] = assembly_utilities.unary_stream_inline(service)
    elif cardinality is interfaces.Cardinality.STREAM_UNARY:
      def service(
          request_iterator, face_rpc_context,
          service_behavior=method_description.service_stream_unary):
        return service_behavior(
            request_iterator, _reexport.rpc_context(face_rpc_context))
      implementations[name] = assembly_utilities.stream_unary_inline(service)
    elif cardinality is interfaces.Cardinality.STREAM_STREAM:
      def service(
          request_iterator, face_rpc_context,
          service_behavior=method_description.service_stream_stream):
        return service_behavior(
            request_iterator, _reexport.rpc_context(face_rpc_context))
      implementations[name] = assembly_utilities.stream_stream_inline(service)
    request_deserializers[name] = method_description.deserialize_request
    response_serializers[name] = method_description.serialize_response

  return _EasyServiceBreakdown(
      implementations, request_deserializers, response_serializers)
def break_down_service(method_descriptions):
    """Derives a ServiceBreakdown from several RPC method descriptions.

  Args:
    method_descriptions: A dictionary from RPC method name to
      interfaces.RpcMethodServiceDescription describing the RPCs.

  Returns:
    A ServiceBreakdown corresponding to the given method descriptions.
  """
    implementations = {}
    request_deserializers = {}
    response_serializers = {}
    for name, method_description in method_descriptions.iteritems():
        cardinality = method_description.cardinality()
        if cardinality is interfaces.Cardinality.UNARY_UNARY:

            def service(
                    request,
                    face_rpc_context,
                    service_behavior=method_description.service_unary_unary):
                return service_behavior(
                    request, _reexport.rpc_context(face_rpc_context))

            implementations[name] = assembly_utilities.unary_unary_inline(
                service)
        elif cardinality is interfaces.Cardinality.UNARY_STREAM:

            def service(
                    request,
                    face_rpc_context,
                    service_behavior=method_description.service_unary_stream):
                return service_behavior(
                    request, _reexport.rpc_context(face_rpc_context))

            implementations[name] = assembly_utilities.unary_stream_inline(
                service)
        elif cardinality is interfaces.Cardinality.STREAM_UNARY:

            def service(
                    request_iterator,
                    face_rpc_context,
                    service_behavior=method_description.service_stream_unary):
                return service_behavior(
                    request_iterator, _reexport.rpc_context(face_rpc_context))

            implementations[name] = assembly_utilities.stream_unary_inline(
                service)
        elif cardinality is interfaces.Cardinality.STREAM_STREAM:

            def service(
                    request_iterator,
                    face_rpc_context,
                    service_behavior=method_description.service_stream_stream):
                return service_behavior(
                    request_iterator, _reexport.rpc_context(face_rpc_context))

            implementations[name] = assembly_utilities.stream_stream_inline(
                service)
        request_deserializers[name] = method_description.deserialize_request
        response_serializers[name] = method_description.serialize_response

    return _EasyServiceBreakdown(implementations, request_deserializers,
                                 response_serializers)
Exemple #9
0
  for number in _fibbonacci(request.limit):
    yield math_pb2.Num(num=number)


def _sum(request_iterator, unused_context):
  accumulation = 0
  for request in request_iterator:
    accumulation += request.num
  return math_pb2.Num(num=accumulation)


_IMPLEMENTATIONS = {
    DIV: utilities.unary_unary_inline(_div),
    DIV_MANY: utilities.stream_stream_inline(_div_many),
    FIB: utilities.unary_stream_inline(_fib),
    SUM: utilities.stream_unary_inline(_sum),
}

_TIMEOUT = 10


class PipeLink(tickets_interfaces.ForeLink, tickets_interfaces.RearLink):

  def __init__(self):
    self._fore_lock = threading.Lock()
    self._fore_link = null.NULL_FORE_LINK
    self._rear_lock = threading.Lock()
    self._rear_link = null.NULL_REAR_LINK

  def __enter__(self):
    return self
    for number in _fibbonacci(request.limit):
        yield math_pb2.Num(num=number)


def _sum(request_iterator, unused_context):
    accumulation = 0
    for request in request_iterator:
        accumulation += request.num
    return math_pb2.Num(num=accumulation)


_IMPLEMENTATIONS = {
    DIV: utilities.unary_unary_inline(_div),
    DIV_MANY: utilities.stream_stream_inline(_div_many),
    FIB: utilities.unary_stream_inline(_fib),
    SUM: utilities.stream_unary_inline(_sum),
}

_TIMEOUT = 10


class PipeLink(tickets_interfaces.ForeLink, tickets_interfaces.RearLink):
    def __init__(self):
        self._fore_lock = threading.Lock()
        self._fore_link = null.NULL_FORE_LINK
        self._rear_lock = threading.Lock()
        self._rear_link = null.NULL_REAR_LINK

    def __enter__(self):
        return self