Skip to content

Commit

Permalink
autopep and bugs to make PTSL_VERSION 3 work
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Apr 11, 2024
1 parent c530462 commit c156d06
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 61 deletions.
93 changes: 47 additions & 46 deletions ptsl/PTSL_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def __init__(self, channel):
channel: A grpc.Channel.
"""
self.SendGrpcRequest = channel.unary_unary(
'/ptsl.PTSL/SendGrpcRequest',
request_serializer=PTSL__pb2.Request.SerializeToString,
response_deserializer=PTSL__pb2.Response.FromString,
)
'/ptsl.PTSL/SendGrpcRequest',
request_serializer=PTSL__pb2.Request.SerializeToString,
response_deserializer=PTSL__pb2.Response.FromString,
)
self.SendGrpcStreamingRequest = channel.unary_stream(
'/ptsl.PTSL/SendGrpcStreamingRequest',
request_serializer=PTSL__pb2.Request.SerializeToString,
response_deserializer=PTSL__pb2.Response.FromString,
)
'/ptsl.PTSL/SendGrpcStreamingRequest',
request_serializer=PTSL__pb2.Request.SerializeToString,
response_deserializer=PTSL__pb2.Response.FromString,
)


class PTSLServicer(object):
Expand All @@ -52,58 +52,59 @@ def SendGrpcStreamingRequest(self, request, context):

def add_PTSLServicer_to_server(servicer, server):
rpc_method_handlers = {
'SendGrpcRequest': grpc.unary_unary_rpc_method_handler(
servicer.SendGrpcRequest,
request_deserializer=PTSL__pb2.Request.FromString,
response_serializer=PTSL__pb2.Response.SerializeToString,
),
'SendGrpcStreamingRequest': grpc.unary_stream_rpc_method_handler(
servicer.SendGrpcStreamingRequest,
request_deserializer=PTSL__pb2.Request.FromString,
response_serializer=PTSL__pb2.Response.SerializeToString,
),
'SendGrpcRequest': grpc.unary_unary_rpc_method_handler(
servicer.SendGrpcRequest,
request_deserializer=PTSL__pb2.Request.FromString,
response_serializer=PTSL__pb2.Response.SerializeToString,
),
'SendGrpcStreamingRequest': grpc.unary_stream_rpc_method_handler(
servicer.SendGrpcStreamingRequest,
request_deserializer=PTSL__pb2.Request.FromString,
response_serializer=PTSL__pb2.Response.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'ptsl.PTSL', rpc_method_handlers)
'ptsl.PTSL', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))


# This class is part of an EXPERIMENTAL API.


class PTSL(object):
"""*
Service for handling different types of ProTools commands using PTSL Client.
"""

@staticmethod
def SendGrpcRequest(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/ptsl.PTSL/SendGrpcRequest',
PTSL__pb2.Request.SerializeToString,
PTSL__pb2.Response.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
PTSL__pb2.Request.SerializeToString,
PTSL__pb2.Response.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def SendGrpcStreamingRequest(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_stream(request, target, '/ptsl.PTSL/SendGrpcStreamingRequest',
PTSL__pb2.Request.SerializeToString,
PTSL__pb2.Response.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
PTSL__pb2.Request.SerializeToString,
PTSL__pb2.Response.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
10 changes: 5 additions & 5 deletions ptsl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ def run(self, operation: Operation) -> None:
operation.status = response.header.status

if response.header.status == pt.Failed:
cleaned_response_error_json = response.response_error_json
#self._response_error_json_cleanup(
#response.response_error_json)
command_error = json_format.Parse(cleaned_response_error_json,
cleaned_response_error_json = response.response_error_json
# self._response_error_json_cleanup(
# response.response_error_json)
command_errors = json_format.Parse(cleaned_response_error_json,
pt.ResponseError())
raise CommandError(command_error.errors)
raise CommandError(command_errors.errors)

elif response.header.status == pt.Completed:
self._handle_completed_response(operation, response)
Expand Down
6 changes: 3 additions & 3 deletions ptsl/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def is_warning(self) -> bool:
"""
`True` if command error message is marked as a warning.
"""
return self.error_response[0].is_warning
return self.error_responses[0].is_warning

@property
def error_type(self) -> CommandErrorType:
"""
:class:`ptsl.PTSL_pb2.CommandErrorType` enumeration value.
"""
return self.error_response[0].command_error_type
return self.error_responses[0].command_error_type

@property
def error_name(self) -> Optional[str]:
Expand All @@ -51,4 +51,4 @@ def message(self) -> str:
"""
Error message as returned by the client.
"""
return self.error_response[0].command_error_message
return self.error_responses[0].command_error_message
15 changes: 8 additions & 7 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def assert_get_track_list_called(self):
def message_to_json(self, message):
return json_format.MessageToJson(
message,
including_default_value_fields=True,
preserving_proto_field_name=True)

def SendGrpcRequest(
Expand Down Expand Up @@ -83,18 +82,20 @@ def SendGrpcRequest(
elif request.header.command == pt.Copy:
status = pt.Failed
error_body_json = self.message_to_json(
pt.CommandError(
pt.ResponseError(errors=[pt.CommandError(
command_error_type=pt.PT_UnknownError,
command_error_message="Test error response",
is_warning=False)
)
]))
elif request.header.command == pt.Paste:
status = pt.Failed
error_body_json = """
{
"command_error_type": "PT_CopyOptionCopy",
"command_error_message": "Test error message",
"is_warning": true
{
"errors": [ {
"command_error_type": "PT_CopyOptionCopy",
"command_error_message": "Test error message",
"is_warning": true
} ]
}
"""

Expand Down

0 comments on commit c156d06

Please sign in to comment.