def _get_object(self, handle: str) -> Any: objects = {} with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['contact'] = WHOIS.get_contact_by_handle(handle) with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['nsset'] = WHOIS.get_nsset_by_handle(handle) with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['keyset'] = WHOIS.get_keyset_by_handle(handle) with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['registrar'] = WHOIS.get_registrar_by_handle(handle) if not handle.startswith("."): with suppress(OBJECT_NOT_FOUND, UNMANAGED_ZONE, INVALID_LABEL, TOO_MANY_LABELS, idna.IDNAError): idna_handle = idna.encode(handle).decode() try: objects['domain'] = WHOIS.get_domain_by_handle(idna_handle) except OBJECT_DELETE_CANDIDATE: objects['domain'] = None if not objects: raise WebwhoisError( code="OBJECT_NOT_FOUND", title=_("Record not found"), message=self.message_with_handle_in_html( _("%s does not match any record."), handle), object_not_found=True, ) return objects
def load_registry_object(cls, context, handle): """Load domain of the handle and append it into the context.""" if handle.startswith("."): context["server_exception"] = cls.message_invalid_handle(handle) return try: idna_handle = idna.encode(handle).decode() except idna.IDNAError: context["server_exception"] = cls.message_invalid_handle( handle, "IDNAError") return try: context[cls._registry_objects_key]["domain"] = { "detail": WHOIS.get_domain_by_handle(idna_handle), "label": _("Domain"), } except OBJECT_DELETE_CANDIDATE: context['object_delete_candidate'] = True # Add fake domain into context for ResolveHandleTypeMixin. context[cls._registry_objects_key]['domain'] = None except OBJECT_NOT_FOUND: # Only handle with format of valid domain name and in managed zone raises OBJECT_NOT_FOUND. context["server_exception"] = cls.make_message_not_found(handle) context["server_exception"]["handle_is_in_zone"] = True except UNMANAGED_ZONE: context["managed_zone_list"] = WHOIS.get_managed_zone_list() context["server_exception"] = { "code": "UNMANAGED_ZONE", "title": _("Unmanaged zone"), "message": cls.message_with_handle_in_html( _("Domain %s cannot be found in the registry. You can search for domains in the these zones only:" ), handle), "unmanaged_zone": True, } except INVALID_LABEL: # Pattern for the handle is more vague than the pattern of domain name format. context["server_exception"] = cls.message_invalid_handle( handle, "INVALID_LABEL") except TOO_MANY_LABELS: # Caution! Domain name can have more than one fullstop character and it is still valid. # for example: '0.2.4.e164.arpa' # remove subdomain names: 'www.sub.domain.cz' -> 'domain.cz' domain_match = re.search(r"([^.]+\.\w+)\.?$", handle, re.IGNORECASE) assert domain_match is not None context["example_domain_name"] = domain_match.group(1) context["server_exception"] = { "code": "TOO_MANY_LABELS", "title": _("Incorrect input"), "too_many_parts_in_domain_name": True, }
def load_registry_object(cls, context, handle): """Load domain of the handle and append it into the context.""" if handle.startswith("."): raise WebwhoisError(**cls.message_invalid_handle(handle)) try: idna_handle = idna.encode(handle).decode() except idna.IDNAError: raise WebwhoisError( **cls.message_invalid_handle(handle, "IDNAError")) try: context[cls._registry_objects_key]["domain"] = { "detail": WHOIS.get_domain_by_handle(idna_handle), "label": _("Domain"), } except OBJECT_DELETE_CANDIDATE: context['object_delete_candidate'] = True # Add fake domain into context for ResolveHandleTypeMixin. context[cls._registry_objects_key]['domain'] = None except OBJECT_NOT_FOUND as error: # Only handle with format of valid domain name and in managed zone raises OBJECT_NOT_FOUND. raise WebwhoisError('OBJECT_NOT_FOUND', **cls.make_message_not_found(handle), handle_is_in_zone=True) from error except UNMANAGED_ZONE as error: context["managed_zone_list"] = deprecated_context( _get_managed_zones(), "Context variable 'managed_zone_list' is deprecated. Use 'managed_zones' context processor instead." ) message = cls.message_with_handle_in_html( _("Domain %s cannot be found in the registry. You can search for domains in the these zones only:" ), handle) raise WebwhoisError('UNMANAGED_ZONE', title=_("Unmanaged zone"), message=message, unmanaged_zone=True) from error except INVALID_LABEL: # Pattern for the handle is more vague than the pattern of domain name format. raise WebwhoisError( **cls.message_invalid_handle(handle, "INVALID_LABEL")) except TOO_MANY_LABELS as error: # Caution! Domain name can have more than one fullstop character and it is still valid. # for example: '0.2.4.e164.arpa' # remove subdomain names: 'www.sub.domain.cz' -> 'domain.cz' domain_match = re.search(r"([^.]+\.\w+)\.?$", handle, re.IGNORECASE) assert domain_match is not None context["example_domain_name"] = domain_match.group(1) raise WebwhoisError( 'TOO_MANY_LABELS', title=_("Incorrect input"), # Templates in webwhois <=1.20 didn't expect message to be `None`. message='', too_many_parts_in_domain_name=True) from error
def get_domain_registered(self, handle: str) -> Optional[datetime]: """Return domain registration datetime.""" try: idna_handle = idna.encode(handle).decode() except idna.IDNAError: return None try: domain = WHOIS.get_domain_by_handle(idna_handle) except CORBA.Exception: return None return cast(datetime, domain.registered)
def _get_object(self, handle: str) -> Domain: if handle.startswith("."): raise WebwhoisError(**self.message_invalid_handle(handle)) try: idna_handle = idna.encode(handle).decode() except idna.IDNAError: raise WebwhoisError( **self.message_invalid_handle(handle, "IDNAError")) try: return WHOIS.get_domain_by_handle(idna_handle) except OBJECT_DELETE_CANDIDATE: return Domain(handle, None, (), None, None, None, ['deleteCandidate'], None, None, None, None, None, None, None, None, None) except OBJECT_NOT_FOUND as error: # Only handle with format of valid domain name and in managed zone raises OBJECT_NOT_FOUND. raise WebwhoisError('OBJECT_NOT_FOUND', **self.make_message_not_found(handle), handle_is_in_zone=True) from error except UNMANAGED_ZONE as error: message = self.message_with_handle_in_html( _("Domain %s cannot be found in the registry. You can search for domains in the these zones only:" ), handle) raise WebwhoisError('UNMANAGED_ZONE', title=_("Unmanaged zone"), message=message, unmanaged_zone=True) from error except INVALID_LABEL as error: # Pattern for the handle is more vague than the pattern of domain name format. raise WebwhoisError(**self.message_invalid_handle( handle, "INVALID_LABEL")) from error except TOO_MANY_LABELS as error: raise WebwhoisError( 'TOO_MANY_LABELS', title=_("Incorrect input"), # Templates in webwhois <=1.20 didn't expect message to be `None`. message='', too_many_parts_in_domain_name=True) from error