def get_description(self, path: _t.Text, method: _t.Text) -> _t.Text: # pylint: disable=simplifiable-if-statement,redefined-outer-name method_name: _t.Text = getattr(self.view, 'action', method.lower()) method_obj: _t.Optional[_t.Callable] = getattr(self.view, method_name, None) method_view: _t.Optional[_t.Type[rvs.APIView]] = ( getattr(method_obj, '_nested_view', None) if method_obj else None ) if method_obj.__doc__: return method_obj.__doc__.strip() if not method_view: return super().get_description(path, method) method_view_obj = method_view() action = path.split('/')[-2] submethod = getattr(method_view, action, None) if submethod.__doc__: return str(submethod.__doc__).strip() # nocv if method == 'GET' and '{' not in path[:-1].split('/')[-1]: action = 'list' elif method == 'POST': action = 'create' elif method == 'GET': action = 'retrieve' elif method == 'PUT': action = 'update' elif method == 'PATCH': action = 'partial_update' elif method == 'DELETE': action = 'destroy' method_view_obj.action = action # type: ignore if method_view_obj.schema is None: return 'No description' # nocv return method_view_obj.schema.get_description(path, method) # type: ignore
def _validate_host(host: T.Text) -> T.Text: if host.lower() == "localhost": return host try: IPv4Address(host) return host except AddressValueError: try: IPv6Address(host) return host except AddressValueError: raise ValueError(f"'host' is invalid in configuration: {host}")
def get_action_name(master_view: MasterViewType, method: _t.Text = '') -> _t.Text: method = method.lower() if method == 'post': action_name = 'create' elif method == 'get' and not master_view.nested_detail: action_name = 'list' elif method == 'get' and master_view.nested_detail: action_name = 'retrieve' elif method == 'put': action_name = 'update' elif method == 'patch': action_name = 'partial_update' elif method == 'delete': action_name = 'destroy' else: # nocv action_name = None # type: ignore return action_name
def lookup_fhir_resource_spec( resource_type: typing.Text, cache: bool = True, fhir_release: FHIR_VERSION = FHIR_VERSION.DEFAULT, ) -> typing.Optional[FHIRStructureDefinition]: """ :arg resource_type: the resource type name (required). i.e Organization :arg cache: (default True) the flag which indicates should query fresh or serve from cache if available. :arg fhir_release: FHIR Release (version) name. i.e FHIR_VERSION.STU3, FHIR_VERSION.R4 :return FHIRStructureDefinition Example:: >>> from fhirpath.fhirspec import lookup_fhir_resource_spec >>> from zope.interface import Invalid >>> dotted_path = lookup_fhir_resource_spec('Patient') >>> 'fhir.resources.patient.Patient' == dotted_path True >>> dotted_path = lookup_fhir_resource_spec('FakeResource') >>> dotted_path is None True """ fhir_release = FHIR_VERSION.normalize(fhir_release) storage = FHIR_RESOURCE_SPEC_STORAGE.get(fhir_release.name) if storage.exists(resource_type) and cache: return storage.get(resource_type) specs = FhirSpecFactory.from_release(fhir_release.name) try: return specs.profiles[resource_type.lower()] except KeyError: logger.info( f"{resource_type} has not been found in profile specifications") return None
def get_operation_method(self, method: _t.Text) -> _t.Callable: return getattr(self.context.get('client'), method.lower())