本文整理匯總了Python中google.protobuf.empty_pb2.Empty方法的典型用法代碼示例。如果您正苦於以下問題:Python empty_pb2.Empty方法的具體用法?Python empty_pb2.Empty怎麽用?Python empty_pb2.Empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.protobuf.empty_pb2
的用法示例。
在下文中一共展示了empty_pb2.Empty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def run(host, port, api_key, auth_token, timeout, use_tls):
"""Makes a basic ListShelves call against a gRPC Bookstore server."""
if use_tls:
with open('../roots.pem', 'rb') as f:
creds = grpc.ssl_channel_credentials(f.read())
channel = grpc.secure_channel('{}:{}'.format(host, port), creds)
else:
channel = grpc.insecure_channel('{}:{}'.format(host, port))
stub = bookstore_pb2_grpc.BookstoreStub(channel)
metadata = []
if api_key:
metadata.append(('x-api-key', api_key))
if auth_token:
metadata.append(('authorization', 'Bearer ' + auth_token))
shelves = stub.ListShelves(empty_pb2.Empty(), timeout, metadata=metadata)
print('ListShelves: {}'.format(shelves))
示例2: test_unary_reply_error
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def test_unary_reply_error(cardinality, method_cls, method_arg):
class Service:
async def Case(self, stream):
await stream.send_initial_metadata()
await stream.send_trailing_metadata(status=Status.PERMISSION_DENIED)
def __mapping__(self):
return {
'/test.Test/Case': Handler(
self.Case,
cardinality,
Empty,
Empty,
)
}
async with ChannelFor([Service()]) as channel:
method = method_cls(channel, '/test.Test/Case', Empty, Empty)
with pytest.raises(GRPCError) as err:
await method(method_arg)
assert err.value.status is Status.PERMISSION_DENIED
示例3: test_empty_streaming_request
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def test_empty_streaming_request(cardinality, method_cls, method_res):
class Service:
async def Case(self, stream):
await stream.send_message(Empty())
def __mapping__(self):
return {
'/test.Test/Case': Handler(
self.Case,
cardinality,
Empty,
Empty,
)
}
async with ChannelFor([Service()]) as channel:
method = method_cls(channel, '/test.Test/Case', Empty, Empty)
assert await method([]) == method_res
示例4: test_servicer_persistence
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def test_servicer_persistence(self):
"""Basic test which ensures the servicer state persists."""
headers = self.make_headers(encoding.Encoding.BINARY)
req = test_pb2.GiveRequest(m=3333)
raw_resp = self.app.post(
'/prpc/test.Test/Give',
req.SerializeToString(),
headers,
).body
self.assertEqual(len(raw_resp), 0)
req = empty_pb2.Empty()
raw_resp = self.app.post(
'/prpc/test.Test/Take',
req.SerializeToString(),
headers,
).body
resp = test_pb2.TakeResponse()
test_pb2.TakeResponse.ParseFromString(resp, raw_resp)
self.assertEqual(resp.k, 3333)
示例5: test__rollback
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def test__rollback(self):
from google.protobuf import empty_pb2
from google.cloud.firestore_v1.gapic import firestore_client
# Create a minimal fake GAPIC with a dummy result.
firestore_api = mock.create_autospec(
firestore_client.FirestoreClient, instance=True
)
firestore_api.rollback.return_value = empty_pb2.Empty()
# Attach the fake GAPIC to a real client.
client = _make_client()
client._firestore_api_internal = firestore_api
# Actually make a transaction and roll it back.
transaction = self._make_one(client)
txn_id = b"to-be-r\x00lled"
transaction._id = txn_id
ret_val = transaction._rollback()
self.assertIsNone(ret_val)
self.assertIsNone(transaction._id)
# Verify the called mock.
firestore_api.rollback.assert_called_once_with(
client._database_string, txn_id, metadata=client._rpc_metadata
)
示例6: _make_transaction
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def _make_transaction(txn_id, **txn_kwargs):
from google.protobuf import empty_pb2
from google.cloud.firestore_v1.gapic import firestore_client
from google.cloud.firestore_v1.proto import firestore_pb2
from google.cloud.firestore_v1.proto import write_pb2
from google.cloud.firestore_v1.transaction import Transaction
# Create a fake GAPIC ...
firestore_api = mock.create_autospec(
firestore_client.FirestoreClient, instance=True
)
# ... with a dummy ``BeginTransactionResponse`` result ...
begin_response = firestore_pb2.BeginTransactionResponse(transaction=txn_id)
firestore_api.begin_transaction.return_value = begin_response
# ... and a dummy ``Rollback`` result ...
firestore_api.rollback.return_value = empty_pb2.Empty()
# ... and a dummy ``Commit`` result.
commit_response = firestore_pb2.CommitResponse(
write_results=[write_pb2.WriteResult()]
)
firestore_api.commit.return_value = commit_response
# Attach the fake GAPIC to a real client.
client = _make_client()
client._firestore_api_internal = firestore_api
return Transaction(client, **txn_kwargs)
示例7: test__rollback
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def test__rollback(self):
from google.protobuf import empty_pb2
from google.cloud.firestore_v1beta1.gapic import firestore_client
# Create a minimal fake GAPIC with a dummy result.
firestore_api = mock.create_autospec(
firestore_client.FirestoreClient, instance=True
)
firestore_api.rollback.return_value = empty_pb2.Empty()
# Attach the fake GAPIC to a real client.
client = _make_client()
client._firestore_api_internal = firestore_api
# Actually make a transaction and roll it back.
transaction = self._make_one(client)
txn_id = b"to-be-r\x00lled"
transaction._id = txn_id
ret_val = transaction._rollback()
self.assertIsNone(ret_val)
self.assertIsNone(transaction._id)
# Verify the called mock.
firestore_api.rollback.assert_called_once_with(
client._database_string, txn_id, metadata=client._rpc_metadata
)
示例8: _make_transaction
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def _make_transaction(txn_id, **txn_kwargs):
from google.protobuf import empty_pb2
from google.cloud.firestore_v1beta1.gapic import firestore_client
from google.cloud.firestore_v1beta1.proto import firestore_pb2
from google.cloud.firestore_v1beta1.proto import write_pb2
from google.cloud.firestore_v1beta1.transaction import Transaction
# Create a fake GAPIC ...
firestore_api = mock.create_autospec(
firestore_client.FirestoreClient, instance=True
)
# ... with a dummy ``BeginTransactionResponse`` result ...
begin_response = firestore_pb2.BeginTransactionResponse(transaction=txn_id)
firestore_api.begin_transaction.return_value = begin_response
# ... and a dummy ``Rollback`` result ...
firestore_api.rollback.return_value = empty_pb2.Empty()
# ... and a dummy ``Commit`` result.
commit_response = firestore_pb2.CommitResponse(
write_results=[write_pb2.WriteResult()]
)
firestore_api.commit.return_value = commit_response
# Attach the fake GAPIC to a real client.
client = _make_client()
client._firestore_api_internal = firestore_api
return Transaction(client, **txn_kwargs)
示例9: test_import_documents
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def test_import_documents(self):
# Setup Expected Response
expected_response = {}
expected_response = empty_pb2.Empty(**expected_response)
operation = operations_pb2.Operation(
name="operations/test_import_documents", done=True
)
operation.response.Pack(expected_response)
# Mock the API response
channel = ChannelStub(responses=[operation])
patch = mock.patch("google.api_core.grpc_helpers.create_channel")
with patch as create_channel:
create_channel.return_value = channel
client = firestore_admin_v1.FirestoreAdminClient()
# Setup Request
name = client.database_path("[PROJECT]", "[DATABASE]")
response = client.import_documents(name)
result = response.result()
assert expected_response == result
assert len(channel.requests) == 1
expected_request = firestore_admin_pb2.ImportDocumentsRequest(name=name)
actual_request = channel.requests[0][1]
assert expected_request == actual_request
示例10: bufferize
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def bufferize(worker: AbstractWorker, obj: type(None)) -> Empty:
"""
This method converts None into an empty Protobuf message.
Args:
obj (None): makes signature match other bufferize methods
Returns:
protobuf_obj: Empty Protobuf message
"""
return Empty()
示例11: unbufferize
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def unbufferize(worker: AbstractWorker, obj: Empty) -> type(None):
"""
This method converts an empty Protobuf message back into None.
Args:
obj (Empty): Empty Protobuf message
Returns:
obj: None
"""
return None
示例12: get_protobuf_schema
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def get_protobuf_schema() -> Empty:
"""
Method that returns the protobuf schema for the current wrapped type.
"""
return Empty
示例13: delete
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def delete(self, djangoClass, user, id):
try:
obj = djangoClass.objects.get(id=id)
self.xos_security_gate(obj, user, write_access=True)
obj.delete()
return Empty()
except BaseException:
log.exception("Exception in apihelper.delete")
raise
示例14: main
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def main(): # self-test
client = InsecureClient("xos-core.cord.lab")
print(client.stub.ListUser(Empty()))
client = SecureClient(
"xos-core.cord.lab", username="padmin@vicci.org", password="letmein"
)
print(client.stub.ListUser(Empty()))
示例15: Logout
# 需要導入模塊: from google.protobuf import empty_pb2 [as 別名]
# 或者: from google.protobuf.empty_pb2 import Empty [as 別名]
def Logout(self, request, context):
for (k, v) in context.invocation_metadata():
if k.lower() == "x-xossession":
s = SessionStore(session_key=v)
if "_auth_user_id" in s:
del s["_auth_user_id"]
s.save()
REQUEST_COUNT.labels("xos-core", "Utilities", "Login", grpc.StatusCode.OK).inc()
return Empty()