python类IDNAError()的实例源码

name.py 文件源码 项目:Infrax-as-Code-1000-webservers-in-40-minutes 作者: ezeeetm 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def encode(self, label):
        if label == '':
            return b''
        if self.allow_pure_ascii and self.is_all_ascii(label):
            return label.encode('ascii')
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, self.transitional)
            return idna.alabel(label)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
name.py 文件源码 项目:Infrax-as-Code-1000-webservers-in-40-minutes 作者: ezeeetm 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def decode(self, label):
        if not self.strict_decode:
            return super(IDNA2008Codec, self).decode(label)
        if label == b'':
            return u''
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, False)
            return _escapify(idna.ulabel(label), True)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
models.py 文件源码 项目:drupebox 作者: duncanhawthorne 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:ServerlessCrawler-VancouverRealState 作者: MarcelloLins 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:ServerlessCrawler-VancouverRealState 作者: MarcelloLins 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:ServerlessCrawler-VancouverRealState 作者: MarcelloLins 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:plugin.video.unofficial9anime 作者: Prometheusx-git 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
wat_extract_links.py 文件源码 项目:cc-pyspark 作者: commoncrawl 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_surt_host(url):
        try:
            host = urlparse(url).hostname
        except:
            # self.get_logger().debug("Failed to parse URL {}: {}".format(url, e))
            return None
        if host is None or ExtractHostLinksJob.ip_pattern.match(host):
            return None
        host = host.strip().lower()
        if len(host) < 1 or len(host) > 253:
            return None
        parts = host.split('.')
        if parts[-1] == '':
            # trailing dot is allowed, strip it
            parts = parts[0:-1]
        if parts[0] == 'www' and len(parts) > 1:
            # strip leading 'www' to reduce number of "duplicate" hosts
            parts = parts[1:]
        for i in range(0, len(parts)):
            part = parts[i]
            if not ExtractHostLinksJob.host_part_pattern.match(part):
                try:
                    idn = idna.encode(part).decode('ascii')
                except (idna.IDNAError, UnicodeDecodeError, IndexError,
                        UnicodeEncodeError, Exception):
                    # self.get_logger().debug("Invalid host name: {}".format(url))
                    return None

                if ExtractHostLinksJob.host_part_pattern.match(idn):
                    parts[i] = idn
                else:
                    # self.get_logger().debug("Invalid host name: {}".format(url))
                    return None
        parts.reverse()
        return '.'.join(parts)
models.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
main.py 文件源码 项目:ens.py 作者: carver 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def nameprep(name):
        if not name:
            return name
        try:
            return idna.decode(name, uts46=True, std3_rules=True)
        except idna.IDNAError as exc:
            raise InvalidName("%s is an invalid name, because %s" % (name, exc)) from exc
models.py 文件源码 项目:s3-misuse-shoutings 作者: davidporter-id-au 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:core 作者: getavalon 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:plugin.program.indigo 作者: tvaddonsco 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:gardenbot 作者: GoestaO 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
models.py 文件源码 项目:cognitive-911-bot 作者: roeje 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
name.py 文件源码 项目:minihydra 作者: VillanCh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def encode(self, label):
        if label == '':
            return b''
        if self.allow_pure_ascii and self.is_all_ascii(label):
            return label.encode('ascii')
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, self.transitional)
            return idna.alabel(label)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
name.py 文件源码 项目:minihydra 作者: VillanCh 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def decode(self, label):
        if not self.strict_decode:
            return super(IDNA2008Codec, self).decode(label)
        if label == b'':
            return u''
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, False)
            return _escapify(idna.ulabel(label), True)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
models.py 文件源码 项目:Livewire-Simple-Delegation-Switcher 作者: anthonyeden 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
name.py 文件源码 项目:deb-python-eventlet 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def encode(self, label):
        if label == '':
            return b''
        if self.allow_pure_ascii and self.is_all_ascii(label):
            return label.encode('ascii')
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, self.transitional)
            return idna.alabel(label)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
name.py 文件源码 项目:deb-python-eventlet 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def decode(self, label):
        if label == b'':
            return u''
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, False)
            return _escapify(idna.ulabel(label), True)
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)


问题


面经


文章

微信
公众号

扫码关注公众号