Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def to_literal(self, value):
return f'{value.parent.namespace}.{value}'
def from_json(self, value):
return getattr(self._enum_type, value)
def from_literal(self, value):
# remove namespaces
enum_value = value.split('.')[-1]
# remove enum type
name = enum_value.split("'")[1]
return getattr(self._enum_type, name)
class Typ(Identifier):
Types = None
Kinds = Enum('Kinds', 'Primitive Complex')
def __init__(self, name, null_value, traits=TypTraits(), kind=None):
super(Typ, self).__init__(name)
self._null_value = null_value
self._kind = kind if kind is not None else Typ.Kinds.Primitive # no way how to us enum value for parameter default value
self._traits = traits
@property
def null_value(self):
return self._null_value
@property
for proprty in type_node.xpath('edm:Key/edm:PropertyRef', namespaces=config.namespaces):
etype._key.append(etype.proprty(proprty.get('Name')))
for proprty in type_node.xpath('edm:NavigationProperty', namespaces=config.namespaces):
navp = NavigationTypeProperty.from_etree(proprty)
if navp.name in etype._nav_properties:
raise KeyError('{0} already has navigation property {1}'.format(etype, navp.name))
etype._nav_properties[navp.name] = navp
return etype
class EntitySet(Identifier):
def __init__(self, name, entity_type_info, addressable, creatable, updatable, deletable, searchable, countable,
pageable, topable, req_filter, label):
super(EntitySet, self).__init__(name)
self._entity_type_info = entity_type_info
self._entity_type = None
self._addressable = addressable
self._creatable = creatable
self._updatable = updatable
self._deletable = deletable
self._searchable = searchable
self._countable = countable
self._pageable = pageable
self._topable = topable
self._req_filter = req_filter
self._label = label
def from_etree(node):
return NavigationTypeProperty(
node.get('Name'), node.get('FromRole'), node.get('ToRole'), Identifier.parse(node.get('Relationship')))
def from_etree(value_help_parameter_node):
typ = value_help_parameter_node.get('Type')
direction = SAP_VALUE_HELPER_DIRECTIONS[typ]
local_prop_name = None
list_prop_name = None
for pval in value_help_parameter_node.xpath('edm:PropertyValue', namespaces=ANNOTATION_NAMESPACES):
pv_name = pval.get('Property')
if pv_name == 'LocalDataProperty':
local_prop_name = pval.get('PropertyPath')
elif pv_name == 'ValueListProperty':
list_prop_name = pval.get('String')
return ValueHelperParameter(direction, local_prop_name, list_prop_name)
class FunctionImport(Identifier):
def __init__(self, name, return_type_info, entity_set, parameters, http_method='GET'):
super(FunctionImport, self).__init__(name)
self._entity_set_name = entity_set
self._return_type_info = return_type_info
self._return_type = None
self._parameters = parameters
self._http_method = http_method
@property
def return_type_info(self):
return self._return_type_info
@property
def return_type(self):
return self._return_type
def __init__(self, name):
super(Identifier, self).__init__()
self._name = name
return f"{self._parent.name}\'{self._name}\'"
@property
def name(self):
return self._name
@property
def value(self):
return self._value
@property
def parent(self):
return self._parent
class EnumType(Identifier):
def __init__(self, name, is_flags, underlying_type, namespace):
super(EnumType, self).__init__(name)
self._member = list()
self._underlying_type = underlying_type
self._traits = TypTraits()
self._namespace = namespace
if is_flags == 'True':
self._is_flags = True
else:
self._is_flags = False
def __str__(self):
return f"{self.__class__.__name__}({self._name})"
def __getattr__(self, item):
# pylint: disable=no-self-use
def to_literal(self, value):
if not isinstance(value, list):
raise PyODataException('Bad format: invalid list value {}'.format(value))
return [self._item_type.traits.to_literal(v) for v in value]
# pylint: disable=no-self-use
def from_json(self, value):
if not isinstance(value, list):
raise PyODataException('Bad format: invalid list value {}'.format(value))
return [self._item_type.traits.from_json(v) for v in value]
class VariableDeclaration(Identifier):
MAXIMUM_LENGTH = -1
def __init__(self, name, type_info, nullable, max_length, precision, scale):
super(VariableDeclaration, self).__init__(name)
self._type_info = type_info
self._typ = None
self._nullable = bool(nullable)
if not max_length:
self._max_length = None
elif max_length.upper() == 'MAX':
self._max_length = VariableDeclaration.MAXIMUM_LENGTH
else:
self._max_length = int(max_length)