Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get(name, element_type):
try:
return ELEMENTS[element_type][name]
except KeyError:
raise ChildNotFound(name)
def find(name, where):
"""
>>> from hl7apy.core import Segment
>>> from hl7apy import find_reference
>>> find_reference('UNKNOWN', (Segment, ), '2.6') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ChildNotFound: No child named UNKNOWN
"""
for cls in where:
try:
return {'ref': get(name, cls.__name__), 'name': name, 'cls': cls}
except ChildNotFound:
pass
raise ChildNotFound(name)
def find(name, where):
"""
>>> from hl7apy.core import Segment
>>> from hl7apy import find_reference
>>> find_reference('UNKNOWN', (Segment, ), '2.2') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ChildNotFound: No child named UNKNOWN
"""
for cls in where:
try:
return {'ref': get(name, cls.__name__), 'name': name, 'cls': cls}
except ChildNotFound:
pass
raise ChildNotFound(name)
def find(name, where):
"""
>>> from hl7apy.core import Segment
>>> from hl7apy import find_reference
>>> find_reference('UNKNOWN', (Segment, ), '2.2') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ChildNotFound: No child named UNKNOWN
"""
for cls in where:
try:
return {'ref': get(name, cls.__name__), 'name': name, 'cls': cls}
except ChildNotFound:
pass
raise ChildNotFound(name)
def find(name, where):
"""
>>> from hl7apy.core import Segment
>>> from hl7apy import find_reference
>>> find_reference('UNKNOWN', (Segment, ), '2.7') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ChildNotFound: No child named UNKNOWN
"""
for cls in where:
try:
return {'ref': get(name, cls.__name__), 'name': name, 'cls': cls}
except ChildNotFound:
pass
raise ChildNotFound(name)
def _do_traversal(self, mode, name, value=None):
try:
if mode == 'get':
return super(Field, self).__getattr__(name)
elif mode == 'set':
super(Field, self).__setattr__(name, value)
else:
super(Field, self).__delattr__(name)
except ChildNotFound as e:
component, subcomponent = self._get_traversal_children(name)
if component is None:
raise ChildNotFound(name)
if is_base_datatype(self.datatype, self.version):
if subcomponent is not None or component != 1:
raise ChildNotFound(name)
component_name = self.datatype
else:
component_name = '{0}_{1}'.format(self.datatype, component)
if subcomponent is None:
if mode == 'get':
return getattr(self, component_name)
elif mode == 'set':
setattr(self, component_name, value)
else:
delattr(self, component_name)
else:
component = getattr(self, component_name)
component_ref = self.structure_by_name[component_name]['ref']
component_datatype = component_ref[2]
subcomponent_name = '{0}_{1}'.format(component_datatype, subcomponent)
try:
def get(name, element_type):
try:
return ELEMENTS[element_type][name]
except KeyError:
raise ChildNotFound(name)
def get(name, element_type):
try:
return ELEMENTS[element_type][name]
except KeyError:
raise ChildNotFound(name)
def find(name, where):
"""
>>> from hl7apy.core import Segment
>>> from hl7apy import find_reference
>>> find_reference('UNKNOWN', (Segment, ), '2.1') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ChildNotFound: No child named UNKNOWN
"""
for cls in where:
try:
return {'ref': get(name, cls.__name__), 'name': name, 'cls': cls}
except ChildNotFound:
pass
raise ChildNotFound(name)
def get(name, element_type):
try:
return ELEMENTS[element_type][name]
except KeyError:
raise ChildNotFound(name)