@ -27,103 +27,99 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from grpc._cython._cygrpc cimport grpc
from grpc._cython._cygrpc cimport call
from grpc._cython._cygrpc cimport server
class ConnectivityState :
class ConnectivityState :
idle = grpc . GRPC_CHANNEL_IDLE
idle = GRPC_CHANNEL_IDLE
connecting = grpc . GRPC_CHANNEL_CONNECTING
connecting = GRPC_CHANNEL_CONNECTING
ready = grpc . GRPC_CHANNEL_READY
ready = GRPC_CHANNEL_READY
transient_failure = grpc . GRPC_CHANNEL_TRANSIENT_FAILURE
transient_failure = GRPC_CHANNEL_TRANSIENT_FAILURE
fatal_failure = grpc . GRPC_CHANNEL_FATAL_FAILURE
fatal_failure = GRPC_CHANNEL_FATAL_FAILURE
class ChannelArgKey :
class ChannelArgKey :
enable_census = grpc . GRPC_ARG_ENABLE_CENSUS
enable_census = GRPC_ARG_ENABLE_CENSUS
max_concurrent_streams = grpc . GRPC_ARG_MAX_CONCURRENT_STREAMS
max_concurrent_streams = GRPC_ARG_MAX_CONCURRENT_STREAMS
max_message_length = grpc . GRPC_ARG_MAX_MESSAGE_LENGTH
max_message_length = GRPC_ARG_MAX_MESSAGE_LENGTH
http2_initial_sequence_number = grpc . GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER
http2_initial_sequence_number = GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER
default_authority = grpc . GRPC_ARG_DEFAULT_AUTHORITY
default_authority = GRPC_ARG_DEFAULT_AUTHORITY
primary_user_agent_string = grpc . GRPC_ARG_PRIMARY_USER_AGENT_STRING
primary_user_agent_string = GRPC_ARG_PRIMARY_USER_AGENT_STRING
secondary_user_agent_string = grpc . GRPC_ARG_SECONDARY_USER_AGENT_STRING
secondary_user_agent_string = GRPC_ARG_SECONDARY_USER_AGENT_STRING
ssl_target_name_override = grpc . GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
ssl_target_name_override = GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
class WriteFlag :
class WriteFlag :
buffer_hint = grpc . GRPC_WRITE_BUFFER_HINT
buffer_hint = GRPC_WRITE_BUFFER_HINT
no_compress = grpc . GRPC_WRITE_NO_COMPRESS
no_compress = GRPC_WRITE_NO_COMPRESS
class StatusCode :
class StatusCode :
ok = grpc . GRPC_STATUS_OK
ok = GRPC_STATUS_OK
cancelled = grpc . GRPC_STATUS_CANCELLED
cancelled = GRPC_STATUS_CANCELLED
unknown = grpc . GRPC_STATUS_UNKNOWN
unknown = GRPC_STATUS_UNKNOWN
invalid_argument = grpc . GRPC_STATUS_INVALID_ARGUMENT
invalid_argument = GRPC_STATUS_INVALID_ARGUMENT
deadline_exceeded = grpc . GRPC_STATUS_DEADLINE_EXCEEDED
deadline_exceeded = GRPC_STATUS_DEADLINE_EXCEEDED
not_found = grpc . GRPC_STATUS_NOT_FOUND
not_found = GRPC_STATUS_NOT_FOUND
already_exists = grpc . GRPC_STATUS_ALREADY_EXISTS
already_exists = GRPC_STATUS_ALREADY_EXISTS
permission_denied = grpc . GRPC_STATUS_PERMISSION_DENIED
permission_denied = GRPC_STATUS_PERMISSION_DENIED
unauthenticated = grpc . GRPC_STATUS_UNAUTHENTICATED
unauthenticated = GRPC_STATUS_UNAUTHENTICATED
resource_exhausted = grpc . GRPC_STATUS_RESOURCE_EXHAUSTED
resource_exhausted = GRPC_STATUS_RESOURCE_EXHAUSTED
failed_precondition = grpc . GRPC_STATUS_FAILED_PRECONDITION
failed_precondition = GRPC_STATUS_FAILED_PRECONDITION
aborted = grpc . GRPC_STATUS_ABORTED
aborted = GRPC_STATUS_ABORTED
out_of_range = grpc . GRPC_STATUS_OUT_OF_RANGE
out_of_range = GRPC_STATUS_OUT_OF_RANGE
unimplemented = grpc . GRPC_STATUS_UNIMPLEMENTED
unimplemented = GRPC_STATUS_UNIMPLEMENTED
internal = grpc . GRPC_STATUS_INTERNAL
internal = GRPC_STATUS_INTERNAL
unavailable = grpc . GRPC_STATUS_UNAVAILABLE
unavailable = GRPC_STATUS_UNAVAILABLE
data_loss = grpc . GRPC_STATUS_DATA_LOSS
data_loss = GRPC_STATUS_DATA_LOSS
class CallError :
class CallError :
ok = grpc . GRPC_CALL_OK
ok = GRPC_CALL_OK
error = grpc . GRPC_CALL_ERROR
error = GRPC_CALL_ERROR
not_on_server = grpc . GRPC_CALL_ERROR_NOT_ON_SERVER
not_on_server = GRPC_CALL_ERROR_NOT_ON_SERVER
not_on_client = grpc . GRPC_CALL_ERROR_NOT_ON_CLIENT
not_on_client = GRPC_CALL_ERROR_NOT_ON_CLIENT
already_accepted = grpc . GRPC_CALL_ERROR_ALREADY_ACCEPTED
already_accepted = GRPC_CALL_ERROR_ALREADY_ACCEPTED
already_invoked = grpc . GRPC_CALL_ERROR_ALREADY_INVOKED
already_invoked = GRPC_CALL_ERROR_ALREADY_INVOKED
not_invoked = grpc . GRPC_CALL_ERROR_NOT_INVOKED
not_invoked = GRPC_CALL_ERROR_NOT_INVOKED
already_finished = grpc . GRPC_CALL_ERROR_ALREADY_FINISHED
already_finished = GRPC_CALL_ERROR_ALREADY_FINISHED
too_many_operations = grpc . GRPC_CALL_ERROR_TOO_MANY_OPERATIONS
too_many_operations = GRPC_CALL_ERROR_TOO_MANY_OPERATIONS
invalid_flags = grpc . GRPC_CALL_ERROR_INVALID_FLAGS
invalid_flags = GRPC_CALL_ERROR_INVALID_FLAGS
invalid_metadata = grpc . GRPC_CALL_ERROR_INVALID_METADATA
invalid_metadata = GRPC_CALL_ERROR_INVALID_METADATA
class CompletionType :
class CompletionType :
queue_shutdown = grpc . GRPC_QUEUE_SHUTDOWN
queue_shutdown = GRPC_QUEUE_SHUTDOWN
queue_timeout = grpc . GRPC_QUEUE_TIMEOUT
queue_timeout = GRPC_QUEUE_TIMEOUT
operation_complete = grpc . GRPC_OP_COMPLETE
operation_complete = GRPC_OP_COMPLETE
class OperationType :
class OperationType :
send_initial_metadata = grpc . GRPC_OP_SEND_INITIAL_METADATA
send_initial_metadata = GRPC_OP_SEND_INITIAL_METADATA
send_message = grpc . GRPC_OP_SEND_MESSAGE
send_message = GRPC_OP_SEND_MESSAGE
send_close_from_client = grpc . GRPC_OP_SEND_CLOSE_FROM_CLIENT
send_close_from_client = GRPC_OP_SEND_CLOSE_FROM_CLIENT
send_status_from_server = grpc . GRPC_OP_SEND_STATUS_FROM_SERVER
send_status_from_server = GRPC_OP_SEND_STATUS_FROM_SERVER
receive_initial_metadata = grpc . GRPC_OP_RECV_INITIAL_METADATA
receive_initial_metadata = GRPC_OP_RECV_INITIAL_METADATA
receive_message = grpc . GRPC_OP_RECV_MESSAGE
receive_message = GRPC_OP_RECV_MESSAGE
receive_status_on_client = grpc . GRPC_OP_RECV_STATUS_ON_CLIENT
receive_status_on_client = GRPC_OP_RECV_STATUS_ON_CLIENT
receive_close_on_server = grpc . GRPC_OP_RECV_CLOSE_ON_SERVER
receive_close_on_server = GRPC_OP_RECV_CLOSE_ON_SERVER
cdef class Timespec :
cdef class Timespec :
def __cinit__ ( self , time ) :
def __cinit__ ( self , time ) :
if time is None :
if time is None :
self . c_time = grpc . g pr_now ( grpc . GPR_CLOCK_REALTIME )
self . c_time = gpr_now ( GPR_CLOCK_REALTIME )
return
return
if isinstance ( time , int ) :
if isinstance ( time , int ) :
time = float ( time )
time = float ( time )
if isinstance ( time , float ) :
if isinstance ( time , float ) :
if time == float ( " +inf " ) :
if time == float ( " +inf " ) :
self . c_time = grpc . g pr_inf_future ( grpc . GPR_CLOCK_REALTIME )
self . c_time = gpr_inf_future ( GPR_CLOCK_REALTIME )
elif time == float ( " -inf " ) :
elif time == float ( " -inf " ) :
self . c_time = grpc . g pr_inf_past ( grpc . GPR_CLOCK_REALTIME )
self . c_time = gpr_inf_past ( GPR_CLOCK_REALTIME )
else :
else :
self . c_time . seconds = time
self . c_time . seconds = time
self . c_time . nanoseconds = ( time - float ( self . c_time . seconds ) ) * 1e9
self . c_time . nanoseconds = ( time - float ( self . c_time . seconds ) ) * 1e9
self . c_time . clock_type = grpc . GPR_CLOCK_REALTIME
self . c_time . clock_type = GPR_CLOCK_REALTIME
elif isinstance ( time , Timespec ) :
elif isinstance ( time , Timespec ) :
self . c_time = ( < Timespec > time ) . c_time
self . c_time = ( < Timespec > time ) . c_time
else :
else :
@ -135,19 +131,19 @@ cdef class Timespec:
# TODO(atash) ensure that everywhere a Timespec is created that it's
# TODO(atash) ensure that everywhere a Timespec is created that it's
# converted to GPR_CLOCK_REALTIME then and not every time someone wants to
# converted to GPR_CLOCK_REALTIME then and not every time someone wants to
# read values off in Python.
# read values off in Python.
cdef grpc .g pr_timespec real_time = (
cdef gpr_timespec real_time = (
grpc . g pr_convert_clock_type ( self . c_time , grpc . GPR_CLOCK_REALTIME ) )
gpr_convert_clock_type ( self . c_time , GPR_CLOCK_REALTIME ) )
return real_time . seconds
return real_time . seconds
@property
@property
def nanoseconds ( self ) :
def nanoseconds ( self ) :
cdef grpc .g pr_timespec real_time = (
cdef gpr_timespec real_time = (
grpc . g pr_convert_clock_type ( self . c_time , grpc . GPR_CLOCK_REALTIME ) )
gpr_convert_clock_type ( self . c_time , GPR_CLOCK_REALTIME ) )
return real_time . nanoseconds
return real_time . nanoseconds
def __float__ ( self ) :
def __float__ ( self ) :
cdef grpc .g pr_timespec real_time = (
cdef gpr_timespec real_time = (
grpc . g pr_convert_clock_type ( self . c_time , grpc . GPR_CLOCK_REALTIME ) )
gpr_convert_clock_type ( self . c_time , GPR_CLOCK_REALTIME ) )
return < double > real_time . seconds + < double > real_time . nanoseconds / 1e9
return < double > real_time . seconds + < double > real_time . nanoseconds / 1e9
infinite_future = Timespec ( float ( " +inf " ) )
infinite_future = Timespec ( float ( " +inf " ) )
@ -157,10 +153,10 @@ cdef class Timespec:
cdef class CallDetails :
cdef class CallDetails :
def __cinit__ ( self ) :
def __cinit__ ( self ) :
grpc . grpc _call_details_init( & self . c_details )
grpc_call_details_init ( & self . c_details )
def __dealloc__ ( self ) :
def __dealloc__ ( self ) :
grpc . grpc _call_details_destroy( & self . c_details )
grpc_call_details_destroy ( & self . c_details )
@property
@property
def method ( self ) :
def method ( self ) :
@ -192,8 +188,8 @@ cdef class OperationTag:
cdef class Event :
cdef class Event :
def __cinit__ ( self , grpc . grpc _completion_type type , bint success ,
def __cinit__ ( self , grpc_completion_type type , bint success ,
object tag , call . Call operation_call ,
object tag , Call operation_call ,
CallDetails request_call_details ,
CallDetails request_call_details ,
Metadata request_metadata ,
Metadata request_metadata ,
bint is_new_request ,
bint is_new_request ,
@ -228,31 +224,31 @@ cdef class ByteBuffer:
" ByteBuffer, not {} " . format ( type ( data ) ) )
" ByteBuffer, not {} " . format ( type ( data ) ) )
cdef char *c_data = data
cdef char *c_data = data
data_slice = grpc . g pr_slice_from_copied_buffer ( c_data , len ( data ) )
data_slice = gpr_slice_from_copied_buffer ( c_data , len ( data ) )
self . c_byte_buffer = grpc . grpc _raw_byte_buffer_create(
self . c_byte_buffer = grpc_raw_byte_buffer_create (
& data_slice , 1 )
& data_slice , 1 )
grpc . g pr_slice_unref ( data_slice )
gpr_slice_unref ( data_slice )
def bytes ( self ) :
def bytes ( self ) :
cdef grpc .grpc _byte_buffer_reader reader
cdef grpc_byte_buffer_reader reader
cdef grpc .g pr_slice data_slice
cdef gpr_slice data_slice
cdef size_t data_slice_length
cdef size_t data_slice_length
cdef void *data_slice_pointer
cdef void *data_slice_pointer
if self . c_byte_buffer != NULL :
if self . c_byte_buffer != NULL :
grpc . grpc _byte_buffer_reader_init( & reader , self . c_byte_buffer )
grpc_byte_buffer_reader_init ( & reader , self . c_byte_buffer )
result = b " "
result = b " "
while grpc . grpc _byte_buffer_reader_next( & reader , & data_slice ) :
while grpc_byte_buffer_reader_next ( & reader , & data_slice ) :
data_slice_pointer = grpc . g pr_slice_start_ptr ( data_slice )
data_slice_pointer = gpr_slice_start_ptr ( data_slice )
data_slice_length = grpc . g pr_slice_length ( data_slice )
data_slice_length = gpr_slice_length ( data_slice )
result + = ( < char * > data_slice_pointer ) [ : data_slice_length ]
result + = ( < char * > data_slice_pointer ) [ : data_slice_length ]
grpc . grpc _byte_buffer_reader_destroy( & reader )
grpc_byte_buffer_reader_destroy ( & reader )
return result
return result
else :
else :
return None
return None
def __len__ ( self ) :
def __len__ ( self ) :
if self . c_byte_buffer != NULL :
if self . c_byte_buffer != NULL :
return grpc . grpc _byte_buffer_length( self . c_byte_buffer )
return grpc_byte_buffer_length ( self . c_byte_buffer )
else :
else :
return 0
return 0
@ -261,7 +257,7 @@ cdef class ByteBuffer:
def __dealloc__ ( self ) :
def __dealloc__ ( self ) :
if self . c_byte_buffer != NULL :
if self . c_byte_buffer != NULL :
grpc . grpc _byte_buffer_destroy( self . c_byte_buffer )
grpc_byte_buffer_destroy ( self . c_byte_buffer )
cdef class SslPemKeyCertPair :
cdef class SslPemKeyCertPair :
@ -295,15 +291,15 @@ cdef class ChannelArg:
raise TypeError ( " expected key to be of type str or bytes " )
raise TypeError ( " expected key to be of type str or bytes " )
if isinstance ( value , bytes ) :
if isinstance ( value , bytes ) :
self . value = value
self . value = value
self . c_arg . type = grpc . GRPC_ARG_STRING
self . c_arg . type = GRPC_ARG_STRING
self . c_arg . value . string = self . value
self . c_arg . value . string = self . value
elif isinstance ( value , basestring ) :
elif isinstance ( value , basestring ) :
self . value = value . encode ( )
self . value = value . encode ( )
self . c_arg . type = grpc . GRPC_ARG_STRING
self . c_arg . type = GRPC_ARG_STRING
self . c_arg . value . string = self . value
self . c_arg . value . string = self . value
elif isinstance ( value , int ) :
elif isinstance ( value , int ) :
self . value = int ( value )
self . value = int ( value )
self . c_arg . type = grpc . GRPC_ARG_INTEGER
self . c_arg . type = GRPC_ARG_INTEGER
self . c_arg . value . integer = self . value
self . c_arg . value . integer = self . value
else :
else :
raise TypeError ( " expected value to be of type str or bytes or int " )
raise TypeError ( " expected value to be of type str or bytes or int " )
@ -318,14 +314,14 @@ cdef class ChannelArgs:
if not isinstance ( arg , ChannelArg ) :
if not isinstance ( arg , ChannelArg ) :
raise TypeError ( " expected list of ChannelArg " )
raise TypeError ( " expected list of ChannelArg " )
self . c_args . arguments_length = len ( self . args )
self . c_args . arguments_length = len ( self . args )
self . c_args . arguments = < grpc . grpc _arg * > grpc . gpr_malloc (
self . c_args . arguments = < grpc_arg * > gpr_malloc (
self . c_args . arguments_length * sizeof ( grpc . grpc _arg)
self . c_args . arguments_length * sizeof ( grpc_arg )
)
)
for i in range ( self . c_args . arguments_length ) :
for i in range ( self . c_args . arguments_length ) :
self . c_args . arguments [ i ] = ( < ChannelArg > self . args [ i ] ) . c_arg
self . c_args . arguments [ i ] = ( < ChannelArg > self . args [ i ] ) . c_arg
def __dealloc__ ( self ) :
def __dealloc__ ( self ) :
grpc . g pr_free ( self . c_args . arguments )
gpr_free ( self . c_args . arguments )
def __len__ ( self ) :
def __len__ ( self ) :
# self.args is never stale; it's only updated from this file
# self.args is never stale; it's only updated from this file
@ -406,11 +402,11 @@ cdef class Metadata:
for metadatum in metadata :
for metadatum in metadata :
if not isinstance ( metadatum , Metadatum ) :
if not isinstance ( metadatum , Metadatum ) :
raise TypeError ( " expected list of Metadatum " )
raise TypeError ( " expected list of Metadatum " )
grpc . grpc _metadata_array_init( & self . c_metadata_array )
grpc_metadata_array_init ( & self . c_metadata_array )
self . c_metadata_array . count = len ( self . metadata )
self . c_metadata_array . count = len ( self . metadata )
self . c_metadata_array . capacity = len ( self . metadata )
self . c_metadata_array . capacity = len ( self . metadata )
self . c_metadata_array . metadata = < grpc . grpc _metadata * > grpc . gpr_malloc (
self . c_metadata_array . metadata = < grpc_metadata * > gpr_malloc (
self . c_metadata_array . count * sizeof ( grpc . grpc _metadata)
self . c_metadata_array . count * sizeof ( grpc_metadata )
)
)
for i in range ( self . c_metadata_array . count ) :
for i in range ( self . c_metadata_array . count ) :
self . c_metadata_array . metadata [ i ] = (
self . c_metadata_array . metadata [ i ] = (
@ -420,7 +416,7 @@ cdef class Metadata:
# this frees the allocated memory for the grpc_metadata_array (although
# this frees the allocated memory for the grpc_metadata_array (although
# it'd be nice if that were documented somewhere...) TODO(atash): document
# it'd be nice if that were documented somewhere...) TODO(atash): document
# this in the C core
# this in the C core
grpc . grpc _metadata_array_destroy( & self . c_metadata_array )
grpc_metadata_array_destroy ( & self . c_metadata_array )
def __len__ ( self ) :
def __len__ ( self ) :
return self . c_metadata_array . count
return self . c_metadata_array . count
@ -449,49 +445,49 @@ cdef class Operation:
@property
@property
def has_status ( self ) :
def has_status ( self ) :
return self . c_op . type == grpc . GRPC_OP_RECV_STATUS_ON_CLIENT
return self . c_op . type == GRPC_OP_RECV_STATUS_ON_CLIENT
@property
@property
def received_message ( self ) :
def received_message ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_MESSAGE :
if self . c_op . type != GRPC_OP_RECV_MESSAGE :
raise TypeError ( " self must be an operation receiving a message " )
raise TypeError ( " self must be an operation receiving a message " )
return self . _received_message
return self . _received_message
@property
@property
def received_message_or_none ( self ) :
def received_message_or_none ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_MESSAGE :
if self . c_op . type != GRPC_OP_RECV_MESSAGE :
return None
return None
return self . _received_message
return self . _received_message
@property
@property
def received_metadata ( self ) :
def received_metadata ( self ) :
if ( self . c_op . type != grpc . GRPC_OP_RECV_INITIAL_METADATA and
if ( self . c_op . type != GRPC_OP_RECV_INITIAL_METADATA and
self . c_op . type != grpc . GRPC_OP_RECV_STATUS_ON_CLIENT ) :
self . c_op . type != GRPC_OP_RECV_STATUS_ON_CLIENT ) :
raise TypeError ( " self must be an operation receiving metadata " )
raise TypeError ( " self must be an operation receiving metadata " )
return self . _received_metadata
return self . _received_metadata
@property
@property
def received_metadata_or_none ( self ) :
def received_metadata_or_none ( self ) :
if ( self . c_op . type != grpc . GRPC_OP_RECV_INITIAL_METADATA and
if ( self . c_op . type != GRPC_OP_RECV_INITIAL_METADATA and
self . c_op . type != grpc . GRPC_OP_RECV_STATUS_ON_CLIENT ) :
self . c_op . type != GRPC_OP_RECV_STATUS_ON_CLIENT ) :
return None
return None
return self . _received_metadata
return self . _received_metadata
@property
@property
def received_status_code ( self ) :
def received_status_code ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_STATUS_ON_CLIENT :
if self . c_op . type != GRPC_OP_RECV_STATUS_ON_CLIENT :
raise TypeError ( " self must be an operation receiving a status code " )
raise TypeError ( " self must be an operation receiving a status code " )
return self . _received_status_code
return self . _received_status_code
@property
@property
def received_status_code_or_none ( self ) :
def received_status_code_or_none ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_STATUS_ON_CLIENT :
if self . c_op . type != GRPC_OP_RECV_STATUS_ON_CLIENT :
return None
return None
return self . _received_status_code
return self . _received_status_code
@property
@property
def received_status_details ( self ) :
def received_status_details ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_STATUS_ON_CLIENT :
if self . c_op . type != GRPC_OP_RECV_STATUS_ON_CLIENT :
raise TypeError ( " self must be an operation receiving status details " )
raise TypeError ( " self must be an operation receiving status details " )
if self . _received_status_details :
if self . _received_status_details :
return self . _received_status_details
return self . _received_status_details
@ -500,7 +496,7 @@ cdef class Operation:
@property
@property
def received_status_details_or_none ( self ) :
def received_status_details_or_none ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_STATUS_ON_CLIENT :
if self . c_op . type != GRPC_OP_RECV_STATUS_ON_CLIENT :
return None
return None
if self . _received_status_details :
if self . _received_status_details :
return self . _received_status_details
return self . _received_status_details
@ -509,14 +505,14 @@ cdef class Operation:
@property
@property
def received_cancelled ( self ) :
def received_cancelled ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_CLOSE_ON_SERVER :
if self . c_op . type != GRPC_OP_RECV_CLOSE_ON_SERVER :
raise TypeError ( " self must be an operation receiving cancellation "
raise TypeError ( " self must be an operation receiving cancellation "
" information " )
" information " )
return False if self . _received_cancelled == 0 else True
return False if self . _received_cancelled == 0 else True
@property
@property
def received_cancelled_or_none ( self ) :
def received_cancelled_or_none ( self ) :
if self . c_op . type != grpc . GRPC_OP_RECV_CLOSE_ON_SERVER :
if self . c_op . type != GRPC_OP_RECV_CLOSE_ON_SERVER :
return None
return None
return False if self . _received_cancelled == 0 else True
return False if self . _received_cancelled == 0 else True
@ -524,12 +520,12 @@ cdef class Operation:
# We *almost* don't need to do anything; most of the objects are handled by
# We *almost* don't need to do anything; most of the objects are handled by
# Python. The remaining one(s) are primitive fields filled in by GRPC core.
# Python. The remaining one(s) are primitive fields filled in by GRPC core.
# This means that we need to clean up after receive_status_on_client.
# This means that we need to clean up after receive_status_on_client.
if self . c_op . type == grpc . GRPC_OP_RECV_STATUS_ON_CLIENT :
if self . c_op . type == GRPC_OP_RECV_STATUS_ON_CLIENT :
grpc . g pr_free ( self . _received_status_details )
gpr_free ( self . _received_status_details )
def operation_send_initial_metadata ( Metadata metadata ) :
def operation_send_initial_metadata ( Metadata metadata ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_SEND_INITIAL_METADATA
op . c_op . type = GRPC_OP_SEND_INITIAL_METADATA
op . c_op . data . send_initial_metadata . count = metadata . c_metadata_array . count
op . c_op . data . send_initial_metadata . count = metadata . c_metadata_array . count
op . c_op . data . send_initial_metadata . metadata = (
op . c_op . data . send_initial_metadata . metadata = (
metadata . c_metadata_array . metadata )
metadata . c_metadata_array . metadata )
@ -539,7 +535,7 @@ def operation_send_initial_metadata(Metadata metadata):
def operation_send_message ( data ) :
def operation_send_message ( data ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_SEND_MESSAGE
op . c_op . type = GRPC_OP_SEND_MESSAGE
byte_buffer = ByteBuffer ( data )
byte_buffer = ByteBuffer ( data )
op . c_op . data . send_message = byte_buffer . c_byte_buffer
op . c_op . data . send_message = byte_buffer . c_byte_buffer
op . references . append ( byte_buffer )
op . references . append ( byte_buffer )
@ -548,12 +544,12 @@ def operation_send_message(data):
def operation_send_close_from_client ( ) :
def operation_send_close_from_client ( ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_SEND_CLOSE_FROM_CLIENT
op . c_op . type = GRPC_OP_SEND_CLOSE_FROM_CLIENT
op . is_valid = True
op . is_valid = True
return op
return op
def operation_send_status_from_server (
def operation_send_status_from_server (
Metadata metadata , grpc . grpc _status_code code , details ) :
Metadata metadata , grpc_status_code code , details ) :
if isinstance ( details , bytes ) :
if isinstance ( details , bytes ) :
pass
pass
elif isinstance ( details , basestring ) :
elif isinstance ( details , basestring ) :
@ -561,7 +557,7 @@ def operation_send_status_from_server(
else :
else :
raise TypeError ( " expected a str or bytes object for details " )
raise TypeError ( " expected a str or bytes object for details " )
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_SEND_STATUS_FROM_SERVER
op . c_op . type = GRPC_OP_SEND_STATUS_FROM_SERVER
op . c_op . data . send_status_from_server . trailing_metadata_count = (
op . c_op . data . send_status_from_server . trailing_metadata_count = (
metadata . c_metadata_array . count )
metadata . c_metadata_array . count )
op . c_op . data . send_status_from_server . trailing_metadata = (
op . c_op . data . send_status_from_server . trailing_metadata = (
@ -575,7 +571,7 @@ def operation_send_status_from_server(
def operation_receive_initial_metadata ( ) :
def operation_receive_initial_metadata ( ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_RECV_INITIAL_METADATA
op . c_op . type = GRPC_OP_RECV_INITIAL_METADATA
op . _received_metadata = Metadata ( [ ] )
op . _received_metadata = Metadata ( [ ] )
op . c_op . data . receive_initial_metadata = (
op . c_op . data . receive_initial_metadata = (
& op . _received_metadata . c_metadata_array )
& op . _received_metadata . c_metadata_array )
@ -584,7 +580,7 @@ def operation_receive_initial_metadata():
def operation_receive_message ( ) :
def operation_receive_message ( ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_RECV_MESSAGE
op . c_op . type = GRPC_OP_RECV_MESSAGE
op . _received_message = ByteBuffer ( None )
op . _received_message = ByteBuffer ( None )
# n.b. the c_op.data.receive_message field needs to be deleted by us,
# n.b. the c_op.data.receive_message field needs to be deleted by us,
# anyway, so we just let that be handled by the ByteBuffer() we allocated
# anyway, so we just let that be handled by the ByteBuffer() we allocated
@ -595,7 +591,7 @@ def operation_receive_message():
def operation_receive_status_on_client ( ) :
def operation_receive_status_on_client ( ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_RECV_STATUS_ON_CLIENT
op . c_op . type = GRPC_OP_RECV_STATUS_ON_CLIENT
op . _received_metadata = Metadata ( [ ] )
op . _received_metadata = Metadata ( [ ] )
op . c_op . data . receive_status_on_client . trailing_metadata = (
op . c_op . data . receive_status_on_client . trailing_metadata = (
& op . _received_metadata . c_metadata_array )
& op . _received_metadata . c_metadata_array )
@ -610,7 +606,7 @@ def operation_receive_status_on_client():
def operation_receive_close_on_server ( ) :
def operation_receive_close_on_server ( ) :
cdef Operation op = Operation ( )
cdef Operation op = Operation ( )
op . c_op . type = grpc . GRPC_OP_RECV_CLOSE_ON_SERVER
op . c_op . type = GRPC_OP_RECV_CLOSE_ON_SERVER
op . c_op . data . receive_close_on_server . cancelled = & op . _received_cancelled
op . c_op . data . receive_close_on_server . cancelled = & op . _received_cancelled
op . is_valid = True
op . is_valid = True
return op
return op
@ -647,8 +643,8 @@ cdef class Operations:
if not isinstance ( operation , Operation ) :
if not isinstance ( operation , Operation ) :
raise TypeError ( " expected operations to be iterable of Operation " )
raise TypeError ( " expected operations to be iterable of Operation " )
self . c_nops = len ( self . operations )
self . c_nops = len ( self . operations )
self . c_ops = < grpc . grpc _op * > grpc . gpr_malloc (
self . c_ops = < grpc_op * > gpr_malloc (
sizeof ( grpc . grpc _op) * self . c_nops )
sizeof ( grpc_op ) * self . c_nops )
for i in range ( self . c_nops ) :
for i in range ( self . c_nops ) :
self . c_ops [ i ] = ( < Operation > ( self . operations [ i ] ) ) . c_op
self . c_ops [ i ] = ( < Operation > ( self . operations [ i ] ) ) . c_op
@ -660,7 +656,7 @@ cdef class Operations:
return self . operations [ i ]
return self . operations [ i ]
def __dealloc__ ( self ) :
def __dealloc__ ( self ) :
grpc . g pr_free ( self . c_ops )
gpr_free ( self . c_ops )
def __iter__ ( self ) :
def __iter__ ( self ) :
return _OperationsIterator ( self )
return _OperationsIterator ( self )