Ejemplo n.º 1
0
    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,
            }
Ejemplo n.º 2
0
    def load_registry_object(cls, context, handle):
        """Load all registry objects of the handle and append it into the context."""
        ContactDetailMixin.load_registry_object(context, handle)
        NssetDetailMixin.load_registry_object(context, handle)
        KeysetDetailMixin.load_registry_object(context, handle)
        RegistrarDetailMixin.load_registry_object(context, handle)
        DomainDetailMixin.load_registry_object(context, handle)

        if not context[cls._registry_objects_key]:
            # No object was found. Create a virtual server exception to render its template.
            # TODO: This solution is hopefully temporary and should be removed very soon.
            context["server_exception"] = {
                "code":
                "OBJECT_NOT_FOUND",
                "title":
                _("Record not found"),
                "message":
                cls.message_with_handle_in_html(
                    _("%s does not match any record."), handle),
                "object_not_found":
                True,
            }
            context["managed_zone_list"] = WHOIS.get_managed_zone_list()