Skip to content

Commit

Permalink
Warn if missing PySocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasa committed Dec 19, 2015
1 parent d49b385 commit 4f12e74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion urllib3/contrib/socks.py
Expand Up @@ -17,7 +17,20 @@
"""
from __future__ import absolute_import

import socks
try:
import socks
except ImportError:
import warnings
from urllib3.exceptions import DependencyWarning

warnings.warn((
'SOCKS support in urllib3 requires the installation of optional '
'dependencies: specifically, PySocks. For more information, see '
'https://urllib3.readthedocs.org/en/latest/contrib.html#socks-proxies'
),
DependencyWarning
)
raise

from socket import error as SocketError, timeout as SocketTimeout

Expand Down
8 changes: 8 additions & 0 deletions urllib3/exceptions.py
Expand Up @@ -180,6 +180,14 @@ class SNIMissingWarning(HTTPWarning):
pass


class DependencyWarning(HTTPWarning):
"""
Warned when an attempt is made to import a module with missing optional
dependencies.
"""
pass


class ResponseNotChunked(ProtocolError, ValueError):
"Response needs to be chunked in order to read it as chunks."
pass
Expand Down

0 comments on commit 4f12e74

Please sign in to comment.