Ejemplo n.º 1
0
        def future(self, request, **kwargs):
            inspector = Inspector(self.client.stub)

            cardinality = inspector.cardinality_for_method(self.name)

            command = Command(self.name, cardinality, kwargs, self.client.transport)
            command.issue()
            threading.Thread(target=command.send_request, args=(request,)).start()
            return Result(command)
Ejemplo n.º 2
0
    def future(self, request, timeout=None, compression=None, metadata=None):
        inspector = Inspector(self.client.stub)

        cardinality = inspector.cardinality_for_method(self.name)
        input_type = inspector.input_type_for_method(self.name)
        output_type = inspector.output_type_for_method(self.name)
        service_name = inspector.service_name

        compression = compression or self.client.default_compression
        if compression not in SUPPORTED_ENCODINGS:
            log.warning(
                "Invalid compression algorithm: '{}'. Ignoring.".format(compression)
            )
            compression = self.client.default_compression

        scheme = "https" if self.client.ssl else "http"

        request_headers = [
            (":method", "POST"),
            (":scheme", scheme),
            (":authority", urlparse(self.client.target).hostname),
            (":path", "/{}/{}".format(inspector.service_name, self.name)),
            ("te", "trailers"),
            ("content-type", CONTENT_TYPE),
            ("user-agent", USER_AGENT),
            ("grpc-encoding", compression),
            ("grpc-message-type", "{}.{}".format(service_name, input_type.__name__)),
            ("grpc-accept-encoding", ",".join(SUPPORTED_ENCODINGS)),
        ]

        if metadata is not None:
            metadata = metadata[:]
        else:
            metadata = []

        metadata.extend(self.extra_metadata)

        for key, value in metadata:
            request_headers.append((key, value))

        if timeout is not None:
            request_headers.append(("grpc-timeout", bucket_timeout(timeout)))

        if cardinality in (Cardinality.UNARY_UNARY, Cardinality.UNARY_STREAM):
            request = (request,)

        response_stream = self.client.invoke(request_headers, request, timeout)

        return Future(response_stream, output_type, cardinality)
Ejemplo n.º 3
0
 def inspector(self, stubs):
     return Inspector(stubs.exampleStub)
Ejemplo n.º 4
0
    def test_cache_is_keyed_on_stub(self, load_stubs):
        inspector1 = Inspector(load_stubs("example").exampleStub)
        inspector2 = Inspector(load_stubs("advanced").advancedStub)

        assert inspector1.service_name == "nameko.example"
        assert inspector2.service_name == "nameko.advanced"
Ejemplo n.º 5
0
 def cardinality(self):
     if self.is_bound():
         return Inspector(self.stub).cardinality_for_method(self.method_name)
Ejemplo n.º 6
0
 def output_type(self):
     if self.is_bound():
         return Inspector(self.stub).output_type_for_method(self.method_name)
Ejemplo n.º 7
0
 def method_path(self):
     if self.is_bound():
         return Inspector(self.stub).path_for_method(self.method_name)