From f3e810ab6d5af1499670ae359ecc9f0cabcb1fae Mon Sep 17 00:00:00 2001 From: Mostafa Date: Mon, 25 Jul 2022 14:03:27 +0430 Subject: [PATCH] Use idna for normalize host Add idna package to dependencies. Remove python 2.7 from supported python versions. --- pyproject.toml | 3 ++- url_normalize/url_normalize.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ed77161..e0ef3ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,8 +14,9 @@ version = "1.4.3" "Changelog" = "https://github.com/niksite/url-normalize#url-normalize" [tool.poetry.dependencies] -python = "~2.7 || ^3.6" +python = "^3.6" six = "*" +idna = "^3.3" [tool.poetry.dev-dependencies] bandit = [{version="*", python="^3.6"}] diff --git a/url_normalize/url_normalize.py b/url_normalize/url_normalize.py index a80dd00..b2f61a1 100644 --- a/url_normalize/url_normalize.py +++ b/url_normalize/url_normalize.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """URL normalize main module.""" import re - +import idna from .tools import deconstruct_url, force_unicode, quote, reconstruct_url, unquote DEFAULT_PORT = { @@ -104,7 +104,7 @@ def normalize_host(host, charset=DEFAULT_CHARSET): host = force_unicode(host, charset) host = host.lower() host = host.strip(".") - host = host.encode("idna").decode(charset) + host = idna.encode(host, uts46=True, transitional=True).decode(charset) return host @@ -204,7 +204,7 @@ def normalize_query(query, sort_query_params=True): def url_normalize( - url, charset=DEFAULT_CHARSET, default_scheme=DEFAULT_SCHEME, sort_query_params=True + url, charset=DEFAULT_CHARSET, default_scheme=DEFAULT_SCHEME, sort_query_params=True ): """URI normalization routine.