nidhal baccouri
commited on
Commit
·
674f1bf
1
Parent(s):
cc60be4
fixed imports
Browse files- deep_translator/deepl.py +2 -2
- deep_translator/google_trans.py +7 -5
- deep_translator/linguee.py +3 -3
- deep_translator/main.py +10 -10
- deep_translator/microsoft.py +2 -2
- deep_translator/mymemory.py +3 -3
- deep_translator/papago.py +2 -2
- deep_translator/parent.py +1 -1
- deep_translator/pons.py +3 -3
- deep_translator/qcri.py +3 -2
- deep_translator/yandex.py +3 -2
- poetry.lock +16 -16
deep_translator/deepl.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import requests
|
2 |
-
from
|
3 |
-
from
|
4 |
TranslationNotFound,
|
5 |
LanguageNotSupportedException,
|
6 |
AuthorizationException)
|
|
|
1 |
import requests
|
2 |
+
from constants import BASE_URLS, DEEPL_LANGUAGE_TO_CODE
|
3 |
+
from exceptions import (ServerException,
|
4 |
TranslationNotFound,
|
5 |
LanguageNotSupportedException,
|
6 |
AuthorizationException)
|
deep_translator/google_trans.py
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
google translator API
|
3 |
"""
|
4 |
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
from bs4 import BeautifulSoup
|
9 |
import requests
|
10 |
from time import sleep
|
@@ -89,8 +89,6 @@ class GoogleTranslator(BaseTranslator):
|
|
89 |
|
90 |
if self.payload_key:
|
91 |
self._url_params[self.payload_key] = text
|
92 |
-
|
93 |
-
|
94 |
|
95 |
response = requests.get(self.__base_url,
|
96 |
params=self._url_params,
|
@@ -185,3 +183,7 @@ class GoogleTranslator(BaseTranslator):
|
|
185 |
|
186 |
|
187 |
|
|
|
|
|
|
|
|
|
|
2 |
google translator API
|
3 |
"""
|
4 |
|
5 |
+
from constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
|
6 |
+
from exceptions import TooManyRequests, LanguageNotSupportedException, TranslationNotFound, NotValidPayload, RequestError
|
7 |
+
from parent import BaseTranslator
|
8 |
from bs4 import BeautifulSoup
|
9 |
import requests
|
10 |
from time import sleep
|
|
|
89 |
|
90 |
if self.payload_key:
|
91 |
self._url_params[self.payload_key] = text
|
|
|
|
|
92 |
|
93 |
response = requests.get(self.__base_url,
|
94 |
params=self._url_params,
|
|
|
183 |
|
184 |
|
185 |
|
186 |
+
if __name__ == '__main__':
|
187 |
+
translator = GoogleTranslator(source='ru', target='uk')
|
188 |
+
t = translator.translate("Я разработчик") # => "I am a developer"
|
189 |
+
print(t)
|
deep_translator/linguee.py
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
linguee translator API
|
3 |
"""
|
4 |
|
5 |
-
from
|
6 |
-
from
|
7 |
TranslationNotFound,
|
8 |
NotValidPayload,
|
9 |
ElementNotFoundInGetRequest,
|
10 |
RequestError,
|
11 |
TooManyRequests)
|
12 |
-
from
|
13 |
from bs4 import BeautifulSoup
|
14 |
import requests
|
15 |
from requests.utils import requote_uri
|
|
|
2 |
linguee translator API
|
3 |
"""
|
4 |
|
5 |
+
from constants import BASE_URLS, LINGUEE_LANGUAGES_TO_CODES, LINGUEE_CODE_TO_LANGUAGE
|
6 |
+
from exceptions import (LanguageNotSupportedException,
|
7 |
TranslationNotFound,
|
8 |
NotValidPayload,
|
9 |
ElementNotFoundInGetRequest,
|
10 |
RequestError,
|
11 |
TooManyRequests)
|
12 |
+
from parent import BaseTranslator
|
13 |
from bs4 import BeautifulSoup
|
14 |
import requests
|
15 |
from requests.utils import requote_uri
|
deep_translator/main.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
"""Console script for deep_translator."""
|
2 |
|
3 |
import click
|
4 |
-
from
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
10 |
-
from
|
11 |
-
from
|
12 |
-
from
|
13 |
|
14 |
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
15 |
@click.group()
|
@@ -121,4 +121,4 @@ def list():
|
|
121 |
return 0
|
122 |
|
123 |
if __name__ == "__main__":
|
124 |
-
cli()
|
|
|
1 |
"""Console script for deep_translator."""
|
2 |
|
3 |
import click
|
4 |
+
from google_trans import GoogleTranslator
|
5 |
+
from mymemory import MyMemoryTranslator
|
6 |
+
from deepl import DeepL
|
7 |
+
from qcri import QCRI
|
8 |
+
from linguee import LingueeTranslator
|
9 |
+
from pons import PonsTranslator
|
10 |
+
from yandex import YandexTranslator
|
11 |
+
from microsoft import MicrosoftTranslator
|
12 |
+
from papago import PapagoTranslator
|
13 |
|
14 |
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
15 |
@click.group()
|
|
|
121 |
return 0
|
122 |
|
123 |
if __name__ == "__main__":
|
124 |
+
cli()
|
deep_translator/microsoft.py
CHANGED
@@ -4,8 +4,8 @@ import requests
|
|
4 |
import logging
|
5 |
import sys
|
6 |
|
7 |
-
from
|
8 |
-
from
|
9 |
|
10 |
|
11 |
class MicrosoftTranslator:
|
|
|
4 |
import logging
|
5 |
import sys
|
6 |
|
7 |
+
from constants import BASE_URLS, MICROSOFT_CODES_TO_LANGUAGES
|
8 |
+
from exceptions import LanguageNotSupportedException, ServerException, MicrosoftAPIerror
|
9 |
|
10 |
|
11 |
class MicrosoftTranslator:
|
deep_translator/mymemory.py
CHANGED
@@ -4,13 +4,13 @@ mymemory translator API
|
|
4 |
import logging
|
5 |
import warnings
|
6 |
|
7 |
-
from
|
8 |
-
from
|
9 |
TranslationNotFound,
|
10 |
LanguageNotSupportedException,
|
11 |
RequestError,
|
12 |
TooManyRequests)
|
13 |
-
from
|
14 |
import requests
|
15 |
from time import sleep
|
16 |
|
|
|
4 |
import logging
|
5 |
import warnings
|
6 |
|
7 |
+
from constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
|
8 |
+
from exceptions import (NotValidPayload,
|
9 |
TranslationNotFound,
|
10 |
LanguageNotSupportedException,
|
11 |
RequestError,
|
12 |
TooManyRequests)
|
13 |
+
from parent import BaseTranslator
|
14 |
import requests
|
15 |
from time import sleep
|
16 |
|
deep_translator/papago.py
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
google translator API
|
3 |
"""
|
4 |
import json
|
5 |
-
from
|
6 |
-
from
|
7 |
import requests
|
8 |
import warnings
|
9 |
import logging
|
|
|
2 |
google translator API
|
3 |
"""
|
4 |
import json
|
5 |
+
from constants import BASE_URLS, PAPAGO_LANGUAGE_TO_CODE
|
6 |
+
from exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
|
7 |
import requests
|
8 |
import warnings
|
9 |
import logging
|
deep_translator/parent.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
"""parent translator class"""
|
2 |
|
3 |
-
from
|
4 |
from abc import ABC, abstractmethod
|
5 |
import string
|
6 |
class BaseTranslator(ABC):
|
|
|
1 |
"""parent translator class"""
|
2 |
|
3 |
+
from exceptions import NotValidPayload, NotValidLength, InvalidSourceOrTargetLanguage
|
4 |
from abc import ABC, abstractmethod
|
5 |
import string
|
6 |
class BaseTranslator(ABC):
|
deep_translator/pons.py
CHANGED
@@ -3,14 +3,14 @@ pons translator API
|
|
3 |
"""
|
4 |
from bs4 import BeautifulSoup
|
5 |
import requests
|
6 |
-
from
|
7 |
-
from
|
8 |
TranslationNotFound,
|
9 |
NotValidPayload,
|
10 |
ElementNotFoundInGetRequest,
|
11 |
RequestError,
|
12 |
TooManyRequests)
|
13 |
-
from
|
14 |
from requests.utils import requote_uri
|
15 |
|
16 |
|
|
|
3 |
"""
|
4 |
from bs4 import BeautifulSoup
|
5 |
import requests
|
6 |
+
from constants import BASE_URLS, PONS_LANGUAGES_TO_CODES, PONS_CODES_TO_LANGUAGES
|
7 |
+
from exceptions import (LanguageNotSupportedException,
|
8 |
TranslationNotFound,
|
9 |
NotValidPayload,
|
10 |
ElementNotFoundInGetRequest,
|
11 |
RequestError,
|
12 |
TooManyRequests)
|
13 |
+
from parent import BaseTranslator
|
14 |
from requests.utils import requote_uri
|
15 |
|
16 |
|
deep_translator/qcri.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
|
2 |
import requests
|
3 |
-
from
|
4 |
-
from
|
|
|
5 |
|
6 |
class QCRI(object):
|
7 |
"""
|
|
|
1 |
|
2 |
import requests
|
3 |
+
from constants import BASE_URLS, QCRI_LANGUAGE_TO_CODE
|
4 |
+
from exceptions import (ServerException, TranslationNotFound)
|
5 |
+
|
6 |
|
7 |
class QCRI(object):
|
8 |
"""
|
deep_translator/yandex.py
CHANGED
@@ -2,8 +2,9 @@
|
|
2 |
Yandex translator API
|
3 |
"""
|
4 |
import requests
|
5 |
-
from
|
6 |
-
from
|
|
|
7 |
|
8 |
class YandexTranslator(object):
|
9 |
"""
|
|
|
2 |
Yandex translator API
|
3 |
"""
|
4 |
import requests
|
5 |
+
from constants import BASE_URLS
|
6 |
+
from exceptions import (RequestError, ServerException, TranslationNotFound, TooManyRequests)
|
7 |
+
|
8 |
|
9 |
class YandexTranslator(object):
|
10 |
"""
|
poetry.lock
CHANGED
@@ -56,11 +56,11 @@ lxml = ["lxml"]
|
|
56 |
|
57 |
[[package]]
|
58 |
name = "bleach"
|
59 |
-
version = "
|
60 |
description = "An easy safelist-based HTML-sanitizing tool."
|
61 |
category = "dev"
|
62 |
optional = false
|
63 |
-
python-versions = ">=
|
64 |
|
65 |
[package.dependencies]
|
66 |
packaging = "*"
|
@@ -173,7 +173,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
|
173 |
|
174 |
[[package]]
|
175 |
name = "importlib-metadata"
|
176 |
-
version = "4.6.
|
177 |
description = "Read metadata from Python packages"
|
178 |
category = "main"
|
179 |
optional = false
|
@@ -224,7 +224,7 @@ i18n = ["Babel (>=2.7)"]
|
|
224 |
|
225 |
[[package]]
|
226 |
name = "keyring"
|
227 |
-
version = "23.0
|
228 |
description = "Store and access your passwords safely."
|
229 |
category = "dev"
|
230 |
optional = false
|
@@ -302,7 +302,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
|
302 |
|
303 |
[[package]]
|
304 |
name = "pygments"
|
305 |
-
version = "2.
|
306 |
description = "Pygments is a syntax highlighting package written in Python."
|
307 |
category = "dev"
|
308 |
optional = false
|
@@ -571,7 +571,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
|
|
571 |
|
572 |
[[package]]
|
573 |
name = "tqdm"
|
574 |
-
version = "4.62.
|
575 |
description = "Fast, Extensible Progress Meter"
|
576 |
category = "dev"
|
577 |
optional = false
|
@@ -673,8 +673,8 @@ beautifulsoup4 = [
|
|
673 |
{file = "beautifulsoup4-4.9.3.tar.gz", hash = "sha256:84729e322ad1d5b4d25f805bfa05b902dd96450f43842c4e99067d5e1369eb25"},
|
674 |
]
|
675 |
bleach = [
|
676 |
-
{file = "bleach-
|
677 |
-
{file = "bleach-
|
678 |
]
|
679 |
certifi = [
|
680 |
{file = "certifi-2021.5.30-py2.py3-none-any.whl", hash = "sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8"},
|
@@ -820,8 +820,8 @@ imagesize = [
|
|
820 |
{file = "imagesize-1.2.0.tar.gz", hash = "sha256:b1f6b5a4eab1f73479a50fb79fcf729514a900c341d8503d62a62dbc4127a2b1"},
|
821 |
]
|
822 |
importlib-metadata = [
|
823 |
-
{file = "importlib_metadata-4.6.
|
824 |
-
{file = "importlib_metadata-4.6.
|
825 |
]
|
826 |
iniconfig = [
|
827 |
{file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"},
|
@@ -836,8 +836,8 @@ jinja2 = [
|
|
836 |
{file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"},
|
837 |
]
|
838 |
keyring = [
|
839 |
-
{file = "keyring-23.0
|
840 |
-
{file = "keyring-23.0.
|
841 |
]
|
842 |
markupsafe = [
|
843 |
{file = "MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51"},
|
@@ -896,8 +896,8 @@ pycparser = [
|
|
896 |
{file = "pycparser-2.20.tar.gz", hash = "sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0"},
|
897 |
]
|
898 |
pygments = [
|
899 |
-
{file = "Pygments-2.
|
900 |
-
{file = "Pygments-2.
|
901 |
]
|
902 |
pyparsing = [
|
903 |
{file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"},
|
@@ -984,8 +984,8 @@ toml = [
|
|
984 |
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
|
985 |
]
|
986 |
tqdm = [
|
987 |
-
{file = "tqdm-4.62.
|
988 |
-
{file = "tqdm-4.62.
|
989 |
]
|
990 |
twine = [
|
991 |
{file = "twine-3.4.2-py3-none-any.whl", hash = "sha256:087328e9bb405e7ce18527a2dca4042a84c7918658f951110b38bc135acab218"},
|
|
|
56 |
|
57 |
[[package]]
|
58 |
name = "bleach"
|
59 |
+
version = "4.0.0"
|
60 |
description = "An easy safelist-based HTML-sanitizing tool."
|
61 |
category = "dev"
|
62 |
optional = false
|
63 |
+
python-versions = ">=3.6"
|
64 |
|
65 |
[package.dependencies]
|
66 |
packaging = "*"
|
|
|
173 |
|
174 |
[[package]]
|
175 |
name = "importlib-metadata"
|
176 |
+
version = "4.6.4"
|
177 |
description = "Read metadata from Python packages"
|
178 |
category = "main"
|
179 |
optional = false
|
|
|
224 |
|
225 |
[[package]]
|
226 |
name = "keyring"
|
227 |
+
version = "23.1.0"
|
228 |
description = "Store and access your passwords safely."
|
229 |
category = "dev"
|
230 |
optional = false
|
|
|
302 |
|
303 |
[[package]]
|
304 |
name = "pygments"
|
305 |
+
version = "2.10.0"
|
306 |
description = "Pygments is a syntax highlighting package written in Python."
|
307 |
category = "dev"
|
308 |
optional = false
|
|
|
571 |
|
572 |
[[package]]
|
573 |
name = "tqdm"
|
574 |
+
version = "4.62.2"
|
575 |
description = "Fast, Extensible Progress Meter"
|
576 |
category = "dev"
|
577 |
optional = false
|
|
|
673 |
{file = "beautifulsoup4-4.9.3.tar.gz", hash = "sha256:84729e322ad1d5b4d25f805bfa05b902dd96450f43842c4e99067d5e1369eb25"},
|
674 |
]
|
675 |
bleach = [
|
676 |
+
{file = "bleach-4.0.0-py2.py3-none-any.whl", hash = "sha256:c1685a132e6a9a38bf93752e5faab33a9517a6c0bb2f37b785e47bf253bdb51d"},
|
677 |
+
{file = "bleach-4.0.0.tar.gz", hash = "sha256:ffa9221c6ac29399cc50fcc33473366edd0cf8d5e2cbbbb63296dc327fb67cc8"},
|
678 |
]
|
679 |
certifi = [
|
680 |
{file = "certifi-2021.5.30-py2.py3-none-any.whl", hash = "sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8"},
|
|
|
820 |
{file = "imagesize-1.2.0.tar.gz", hash = "sha256:b1f6b5a4eab1f73479a50fb79fcf729514a900c341d8503d62a62dbc4127a2b1"},
|
821 |
]
|
822 |
importlib-metadata = [
|
823 |
+
{file = "importlib_metadata-4.6.4-py3-none-any.whl", hash = "sha256:ed5157fef23a4bc4594615a0dd8eba94b2bb36bf2a343fa3d8bb2fa0a62a99d5"},
|
824 |
+
{file = "importlib_metadata-4.6.4.tar.gz", hash = "sha256:7b30a78db2922d78a6f47fb30683156a14f3c6aa5cc23f77cc8967e9ab2d002f"},
|
825 |
]
|
826 |
iniconfig = [
|
827 |
{file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"},
|
|
|
836 |
{file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"},
|
837 |
]
|
838 |
keyring = [
|
839 |
+
{file = "keyring-23.1.0-py3-none-any.whl", hash = "sha256:b32397fd7e7063f8dd74a26db910c9862fc2109285fa16e3b5208bcb42a3e579"},
|
840 |
+
{file = "keyring-23.1.0.tar.gz", hash = "sha256:b7e0156667f5dcc73c1f63a518005cd18a4eb23fe77321194fefcc03748b21a4"},
|
841 |
]
|
842 |
markupsafe = [
|
843 |
{file = "MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51"},
|
|
|
896 |
{file = "pycparser-2.20.tar.gz", hash = "sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0"},
|
897 |
]
|
898 |
pygments = [
|
899 |
+
{file = "Pygments-2.10.0-py3-none-any.whl", hash = "sha256:b8e67fe6af78f492b3c4b3e2970c0624cbf08beb1e493b2c99b9fa1b67a20380"},
|
900 |
+
{file = "Pygments-2.10.0.tar.gz", hash = "sha256:f398865f7eb6874156579fdf36bc840a03cab64d1cde9e93d68f46a425ec52c6"},
|
901 |
]
|
902 |
pyparsing = [
|
903 |
{file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"},
|
|
|
984 |
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
|
985 |
]
|
986 |
tqdm = [
|
987 |
+
{file = "tqdm-4.62.2-py2.py3-none-any.whl", hash = "sha256:80aead664e6c1672c4ae20dc50e1cdc5e20eeff9b14aa23ecd426375b28be588"},
|
988 |
+
{file = "tqdm-4.62.2.tar.gz", hash = "sha256:a4d6d112e507ef98513ac119ead1159d286deab17dffedd96921412c2d236ff5"},
|
989 |
]
|
990 |
twine = [
|
991 |
{file = "twine-3.4.2-py3-none-any.whl", hash = "sha256:087328e9bb405e7ce18527a2dca4042a84c7918658f951110b38bc135acab218"},
|