| 1 |
#------------------------------------------------------------------------- |
| 2 |
# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 |
# Licensed under the MIT License. See License.txt in the project root for |
| 4 |
# license information. |
| 5 |
#-------------------------------------------------------------------------- |
| 6 |
|
| 7 |
# Python imports |
| 8 |
import logging |
| 9 |
import copy |
| 10 |
|
| 11 |
# C imports |
| 12 |
cimport c_amqp_definitions |
| 13 |
cimport c_amqpvalue |
| 14 |
|
| 15 |
|
| 16 |
_logger = logging.getLogger(__name__) |
| 17 |
|
| 18 |
|
| 19 |
cpdef create_error(const char* condition_value): |
| 20 |
new_error = cError() |
| 21 |
new_error.create(condition_value) |
| 22 |
return new_error |
| 23 |
|
| 24 |
cdef error_factory(c_amqp_definitions.ERROR_HANDLE error): |
| 25 |
wrapper = cError() |
| 26 |
wrapper.wrap(error) |
| 27 |
return wrapper |
| 28 |
|
| 29 |
|
| 30 |
cdef class cError(StructBase): |
| 31 |
|
| 32 |
cdef c_amqp_definitions.ERROR_HANDLE _c_value |
| 33 |
|
| 34 |
def __cinit__(self): |
| 35 |
pass |
| 36 |
|
| 37 |
def __dealloc__(self): |
| 38 |
_logger.debug("Deallocating cError") |
| 39 |
#self.destroy() |
| 40 |
|
| 41 |
cdef _create(self): |
| 42 |
if <void*>self._c_value is NULL: |
| 43 |
self._memory_error() |
| 44 |
|
| 45 |
cpdef destroy(self): |
| 46 |
if <void*>self._c_value is not NULL: |
| 47 |
_logger.debug("Destroying cError") |
| 48 |
c_amqp_definitions.error_destroy(self._c_value) |
| 49 |
self._c_value = <c_amqp_definitions.ERROR_HANDLE>NULL |
| 50 |
|
| 51 |
cdef wrap(self, c_amqp_definitions.ERROR_HANDLE value): |
| 52 |
self.destroy() |
| 53 |
self._c_value = value |
| 54 |
self._create() |
| 55 |
|
| 56 |
cdef create(self, const char* condition_value): |
| 57 |
self.destroy() |
| 58 |
self._c_value = c_amqp_definitions.error_create(condition_value) |
| 59 |
self._create() |
| 60 |
|
| 61 |
@property |
| 62 |
def condition(self): |
| 63 |
cdef const char* condition_value |
| 64 |
if c_amqp_definitions.error_get_condition(self._c_value, &condition_value) != 0: |
| 65 |
self._value_error() |
| 66 |
return condition_value |
| 67 |
|
| 68 |
@condition.setter |
| 69 |
def condition(self, const char* condition_value): |
| 70 |
if c_amqp_definitions.error_set_condition(self._c_value, condition_value) != 0: |
| 71 |
self._value_error() |
| 72 |
|
| 73 |
@property |
| 74 |
def description(self): |
| 75 |
cdef const char* description_value |
| 76 |
if c_amqp_definitions.error_get_description(self._c_value, &description_value) != 0: |
| 77 |
return None |
| 78 |
return description_value |
| 79 |
|
| 80 |
@description.setter |
| 81 |
def description(self, const char* description_value): |
| 82 |
if c_amqp_definitions.error_set_description(self._c_value, description_value) != 0: |
| 83 |
self._value_error() |
| 84 |
|
| 85 |
@property |
| 86 |
def info(self): |
| 87 |
cdef c_amqp_definitions.fields info_value |
| 88 |
if c_amqp_definitions.error_get_info(self._c_value, &info_value) != 0: |
| 89 |
return None |
| 90 |
try: |
| 91 |
info = value_factory(info_value) |
| 92 |
return copy.deepcopy(info.value) |
| 93 |
except TypeError: |
| 94 |
return None |
| 95 |
|
| 96 |
@info.setter |
| 97 |
def info(self, AMQPValue info_value): |
| 98 |
if c_amqp_definitions.error_set_info(self._c_value, <c_amqp_definitions.fields>info_value._c_value) != 0: |
| 99 |
self._value_error() |