Repository URL to install this package:
|
Version:
1.0.5 ▾
|
# Code generated by protoc-gen-twirp_python v5.9.0, DO NOT EDIT.
# source: category.proto
try:
import httplib
from urllib2 import Request, HTTPError, urlopen
except ImportError:
import http.client as httplib
from urllib.request import Request, urlopen
from urllib.error import HTTPError
import json
from google.protobuf import symbol_database as _symbol_database
import sys
_sym_db = _symbol_database.Default()
class TwirpException(httplib.HTTPException):
def __init__(self, code, message, meta):
self.code = code
self.message = message
self.meta = meta
super(TwirpException, self).__init__(message)
@classmethod
def from_http_err(cls, err):
try:
jsonerr = json.load(err)
code = jsonerr["code"]
msg = jsonerr["msg"]
meta = jsonerr.get("meta")
if meta is None:
meta = {}
except:
code = "internal"
msg = "Error from intermediary with HTTP status code {} {}".format(
err.code, httplib.responses[err.code],
)
meta = {}
return cls(code, msg, meta)
class CategoryServiceClient(object):
def __init__(self, server_address, request_decorator=None):
"""Creates a new client for the CategoryService service.
Args:
server_address: The address of the server to send requests to, in
the full protocol://host:port form.
request_decorator: A function to modify the http request being
sent. Takes in a urllib.request.Request object and returns the
same request object
"""
if sys.version_info[0] > 2:
self.__target = server_address
else:
self.__target = server_address.encode('ascii')
self.__service_name = "category.CategoryService"
self.__request_decorator = request_decorator
def __make_request(self, body, full_method):
req = Request(
url=self.__target + "/twirp" + full_method,
data=body,
headers={"Content-Type": "application/protobuf"},
)
if self.__request_decorator:
req = self.__request_decorator(req)
try:
resp = urlopen(req)
except HTTPError as err:
raise TwirpException.from_http_err(err)
return resp.read()
def create_topic(self, create_topic_request):
"""
Adds a topic to an organization
"""
serialize = _sym_db.GetSymbol("category.CreateTopicRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.CreateTopicResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "CreateTopic")
body = serialize(create_topic_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def get_topic(self, get_topic_request):
"""
Gets the topic
"""
serialize = _sym_db.GetSymbol("category.GetTopicRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.GetTopicResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "GetTopic")
body = serialize(get_topic_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def update_topic(self, update_topic_request):
"""
Updates the topic in an organization
"""
serialize = _sym_db.GetSymbol("category.UpdateTopicRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.UpdateTopicResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "UpdateTopic")
body = serialize(update_topic_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def set_topic(self, set_topic_request):
"""
Classifies a dataset for a topic
"""
serialize = _sym_db.GetSymbol("category.SetTopicRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.SetTopicResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "SetTopic")
body = serialize(set_topic_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def unset_topic(self, unset_topic_request):
"""
Removes a dataset for a topic
"""
serialize = _sym_db.GetSymbol("category.UnsetTopicRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.UnsetTopicResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "UnsetTopic")
body = serialize(unset_topic_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def delete_topic(self, delete_topic_request):
"""
Deletes the topic
"""
serialize = _sym_db.GetSymbol("category.DeleteTopicRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.DeleteTopicResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "DeleteTopic")
body = serialize(delete_topic_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def get_topics(self, get_topics_request):
"""
Gets all topics for a dataset
"""
serialize = _sym_db.GetSymbol("category.GetTopicsRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.GetTopicsResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "GetTopics")
body = serialize(get_topics_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def list_topics(self, list_topics_request):
"""
Lists all topics for a dataset
"""
serialize = _sym_db.GetSymbol("category.ListTopicsRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.ListTopicsResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "ListTopics")
body = serialize(list_topics_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def list_datasets(self, list_datasets_request):
"""
Lists all classifications for a set of topics
"""
serialize = _sym_db.GetSymbol("category.ListDatasetsRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.ListDatasetsResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "ListDatasets")
body = serialize(list_datasets_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def get_classifications(self, get_classifications_request):
serialize = _sym_db.GetSymbol("category.GetClassificationsRequest").SerializeToString
deserialize = _sym_db.GetSymbol("category.GetClassificationsResponse").FromString
full_method = "/{}/{}".format(self.__service_name, "GetClassifications")
body = serialize(get_classifications_request)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)
def healthz(self, empty):
serialize = _sym_db.GetSymbol("category.Empty").SerializeToString
deserialize = _sym_db.GetSymbol("category.Empty").FromString
full_method = "/{}/{}".format(self.__service_name, "Healthz")
body = serialize(empty)
resp_str = self.__make_request(body=body, full_method=full_method)
return deserialize(resp_str)