Skip to content

Commit ff897ce

Browse files
committed
Avoid confusion with user's urllib3 by renaming vendored urllib3
1 parent 23b37c9 commit ff897ce

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "telegram/vendor/urllib3"]
2-
path = telegram/vendor/urllib3
2+
path = telegram/vendor/ptb_urllib3
33
url = https://github.com/python-telegram-bot/urllib3.git
44
branch = ptb

telegram/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import sys
2323
import os
2424

25-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'vendor', 'urllib3'))
26-
2725
from .base import TelegramObject
2826
from .user import User
2927
from .chat import Chat

telegram/utils/request.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@
2020
import os
2121
import socket
2222
import logging
23+
import warnings
2324

2425
try:
2526
import ujson as json
2627
except ImportError:
2728
import json
2829

2930
import certifi
30-
import urllib3
31-
import urllib3.contrib.appengine
32-
from urllib3.connection import HTTPConnection
33-
from urllib3.util.timeout import Timeout
31+
try:
32+
import telegram.vendor.ptb_urllib3.urllib3 as urllib3
33+
import telegram.vendor.ptb_urllib3.urllib3.contrib.appengine as appengine
34+
from telegram.vendor.ptb_urllib3.urllib3.connection import HTTPConnection
35+
from telegram.vendor.ptb_urllib3.urllib3.util.timeout import Timeout
36+
except ImportError:
37+
warnings.warn("python-telegram-bot wasn't properly installed. Please refer to README.rst on "
38+
"how to properly install.")
39+
raise
3440

3541
from telegram import (InputFile, TelegramError)
3642
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
@@ -90,16 +96,16 @@ def __init__(self,
9096
proxy_url = os.environ.get('HTTPS_PROXY') or os.environ.get('https_proxy')
9197

9298
if not proxy_url:
93-
if urllib3.contrib.appengine.is_appengine_sandbox():
99+
if appengine.is_appengine_sandbox():
94100
# Use URLFetch service if running in App Engine
95-
mgr = urllib3.contrib.appengine.AppEngineManager()
101+
mgr = appengine.AppEngineManager()
96102
else:
97103
mgr = urllib3.PoolManager(**kwargs)
98104
else:
99105
kwargs.update(urllib3_proxy_kwargs)
100106
if proxy_url.startswith('socks'):
101107
try:
102-
from urllib3.contrib.socks import SOCKSProxyManager
108+
from telegram.vendor.ptb_urllib3.urllib3.contrib.socks import SOCKSProxyManager
103109
except ImportError:
104110
raise RuntimeError('PySocks is missing')
105111
mgr = SOCKSProxyManager(proxy_url, **kwargs)

telegram/vendor/__init__.py

Whitespace-only changes.

telegram/vendor/ptb_urllib3

Submodule ptb_urllib3 added at 60cec0d

telegram/vendor/urllib3

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)