[Python-modules-commits] [python-socksipy] 01/03: Import python-socksipy_1.6.4.orig.tar.gz
Wolfgang Borgert
debacle at moszumanska.debian.org
Wed Dec 7 23:38:07 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-socksipy.
commit 266439c01a8873543bd63d7b96878614b4a51e8f
Author: W. Martin Borgert <debacle at debian.org>
Date: Wed Dec 7 23:24:37 2016 +0000
Import python-socksipy_1.6.4.orig.tar.gz
---
.gitignore | 26 +++++++++++++
MANIFEST.in | 2 +
PKG-INFO | 11 ------
setup.py | 2 +-
socks.py | 56 +++++++++++++++++++++------
test/mocks.conf | 104 ---------------------------------------------------
test/socks4server.py | 2 +-
test/test.sh | 2 +-
8 files changed, 76 insertions(+), 129 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..72459dc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,26 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+setup.cfg
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..f170155
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include README.md LICENSE
+recursive-include test *
diff --git a/PKG-INFO b/PKG-INFO
deleted file mode 100644
index e70e6ad..0000000
--- a/PKG-INFO
+++ /dev/null
@@ -1,11 +0,0 @@
-Metadata-Version: 1.0
-Name: PySocks
-Version: 1.5.7
-Summary: A Python SOCKS client module. See https://github.com/Anorov/PySocks for more information.
-Home-page: https://github.com/Anorov/PySocks
-Author: Anorov
-Author-email: anorov.vorona at gmail.com
-License: BSD
-Description: UNKNOWN
-Keywords: socks,proxy
-Platform: UNKNOWN
diff --git a/setup.py b/setup.py
index fb3ef0a..bbbe2f9 100755
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from distutils.core import setup
-VERSION = "1.5.7"
+VERSION = "1.6.4"
setup(
name = "PySocks",
diff --git a/socks.py b/socks.py
index 1858d86..4710779 100644
--- a/socks.py
+++ b/socks.py
@@ -1,6 +1,6 @@
"""
SocksiPy - Python SOCKS module.
-Version 1.5.7
+Version 1.6.4
Copyright 2006 Dan-Haim. All rights reserved.
@@ -52,16 +52,25 @@ Modifications made by Anorov (https://github.com/Anorov)
-Various small bug fixes
"""
-__version__ = "1.5.7"
+__version__ = "1.6.4"
import socket
import struct
from errno import EOPNOTSUPP, EINVAL, EAGAIN
from io import BytesIO
from os import SEEK_CUR
+import os
+import sys
from collections import Callable
from base64 import b64encode
+
+if os.name == "nt" and sys.version_info < (3, 0):
+ try:
+ import win_inet_pton
+ except ImportError:
+ raise ImportError("To run PySocks on Windows you must install win_inet_pton")
+
PROXY_TYPE_SOCKS4 = SOCKS4 = 1
PROXY_TYPE_SOCKS5 = SOCKS5 = 2
PROXY_TYPE_HTTP = HTTP = 3
@@ -179,29 +188,29 @@ def create_connection(dest_pair, proxy_type=None, proxy_addr=None,
try:
sock = socksocket(family, socket_type, proto)
- if socket_options is not None:
+ if socket_options:
for opt in socket_options:
sock.setsockopt(*opt)
if isinstance(timeout, (int, float)):
sock.settimeout(timeout)
- if proxy_type is not None:
+ if proxy_type:
sock.set_proxy(proxy_type, proxy_addr, proxy_port, proxy_rdns,
proxy_username, proxy_password)
- if source_address is not None:
+ if source_address:
sock.bind(source_address)
sock.connect((remote_host, remote_port))
return sock
- except socket.error as e:
+ except (socket.error, ProxyConnectionError) as e:
err = e
- if sock is not None:
+ if sock:
sock.close()
sock = None
- if err is not None:
+ if err:
raise err
raise socket.error("gai returned empty list.")
@@ -258,6 +267,8 @@ class socksocket(_BaseSocket):
self.proxy_sockname = None
self.proxy_peername = None
+ self._timeout = None
+
def _readall(self, file, count):
"""
Receive EXACTLY the number of bytes requested from the file object.
@@ -271,6 +282,24 @@ class socksocket(_BaseSocket):
data += d
return data
+ def settimeout(self, timeout):
+ self._timeout = timeout
+ try:
+ # test if we're connected, if so apply timeout
+ peer = self.get_proxy_peername()
+ _BaseSocket.settimeout(self, self._timeout)
+ except socket.error:
+ pass
+
+ def gettimeout(self):
+ return self._timeout
+
+ def setblocking(self, v):
+ if v:
+ self.settimeout(None)
+ else:
+ self.settimeout(0.0)
+
def set_proxy(self, proxy_type=None, addr=None, port=None, rdns=True, username=None, password=None):
"""set_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]])
Sets the proxy to be used.
@@ -329,6 +358,7 @@ class socksocket(_BaseSocket):
host, _ = proxy
_, port = relay
_BaseSocket.connect(self, (host, port))
+ _BaseSocket.settimeout(self, self._timeout)
self.proxy_sockname = ("0.0.0.0", 0) # Unknown
def sendto(self, bytes, *args, **kwargs):
@@ -362,8 +392,8 @@ class socksocket(_BaseSocket):
if not self._proxyconn:
self.bind(("", 0))
- buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
- buf.seek(+2, SEEK_CUR)
+ buf = BytesIO(_BaseSocket.recv(self, bufsize + 1024, flags))
+ buf.seek(2, SEEK_CUR)
frag = buf.read(1)
if ord(frag):
raise NotImplementedError("Received UDP packet fragment")
@@ -374,7 +404,7 @@ class socksocket(_BaseSocket):
if fromhost != peerhost or peerport not in (0, fromport):
raise socket.error(EAGAIN, "Packet filtered")
- return (buf.read(), (fromhost, fromport))
+ return (buf.read(bufsize), (fromhost, fromport))
def recv(self, *pos, **kw):
bytes, _ = self.recvfrom(*pos, **kw)
@@ -495,6 +525,8 @@ class socksocket(_BaseSocket):
# Get the bound address/port
bnd = self._read_SOCKS5_address(reader)
+
+ _BaseSocket.settimeout(self, self._timeout)
return (resolved, bnd)
finally:
reader.close()
@@ -719,6 +751,7 @@ class socksocket(_BaseSocket):
if proxy_type is None:
# Treat like regular socket object
self.proxy_peername = dest_pair
+ _BaseSocket.settimeout(self, self._timeout)
_BaseSocket.connect(self, (dest_addr, dest_port))
return
@@ -745,6 +778,7 @@ class socksocket(_BaseSocket):
# Calls negotiate_{SOCKS4, SOCKS5, HTTP}
negotiate = self._proxy_negotiators[proxy_type]
negotiate(self, dest_addr, dest_port)
+ _BaseSocket.settimeout(self, self._timeout)
except socket.error as error:
# Wrap socket errors
self.close()
diff --git a/test/mocks.conf b/test/mocks.conf
deleted file mode 100644
index ab5ef59..0000000
--- a/test/mocks.conf
+++ /dev/null
@@ -1,104 +0,0 @@
-#################################################
-# #
-# Sample configuration file for MOCKS 0.0.2 #
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
-# #
-# I recommend reading the examples in this file #
-# and then extending it to suite your needs. #
-# #
-#################################################
-
-
-
-#########################
-#
-# General daemon config
-# ~~~~~~~~~~~~~~~~~~~~~
-#
-#########################
-
-PORT = 1081 # Port MOCKS is to listen to
-MOCKS_ADDR = 127.0.0.1 # IP adress MOCKS is to bind to
-LOG_FILE = mocks.log # MOCKS log file
-PID_FILE = mocks.pid # File holding MOCKS's process ID
-BUFFER_SIZE = 65536 # Traffic buffer size in bytes
-BACKLOG = 5 # Backlog for listen()
-NEGOTIATION_TIMEOUT = 5
-CONNECTION_IDLE_TIMEOUT = 300
-BIND_TIMEOUT = 30
-SHUTDOWN_TIMEOUT = 3
-MAX_CONNECTIONS = 50
-
-
-
-##########################################################################
-#
-# Client filter config
-# ~~~~~~~~~~~~~~~~~~~~
-#
-# Client filtering means sorting out which clients are allowed
-# connection and which are not. This is basically done like this:
-# MOCKS has a default behaviour regarding filtering client
-# connections. This behaviour is called the 'policy' and can either
-# be to ALLOW or to DENY the connection. After setting the policy
-# you can specify a list of exceptions. The action MOCKS takes
-# for a client matching any of these exceptions is the opposite
-# of the policy (that is, if the policy is set to ALLOW the exceptions
-# are denied and if the policy is set to DENY the exceptions are allowed).
-# An exception is specified in the form ip_address/mask, where mask
-# is optional and is an integer ranging from 0 to 32 identifying the
-# number of common heading bits that ip_address and the client's IP
-# address must have in order to yield a match. If mask is missing,
-# 32 will be assumed. For instance, 192.168.1.0/24 will match any IP
-# ranging from 192.168.1.1 to 192.168.1.255.
-#
-# Let's take two examples, one for each type of policy. Let's say we
-# only want to allow IPs 10.12.0.0 through 10.12.255.255, 172.23.2.5 and
-# 192.168.52.26 to use MOCKS. What we have to to is this:
-#
-# FILTER_POLICY = DENY
-# FILTER_EXCEPTION = 10.12.0.0/16
-# FILTER_EXCEPTION = 172.23.2.5 # implied /32
-# FILTER_EXCEPTION = 192.168.52.26 # implied /32
-#
-# Now, let's say this is a public proxy server, but for some reason
-# you don't want to let any IP ranging from 192.168.1.1 to 192.168.1.255
-# and neither 10.2.5.13 to connect to it:
-#
-# FILTER_POLICY = ALLOW
-# FILTER_EXCEPTION = 192.168.1.0/24
-# FILTER_EXCEPTION = 10.2.5.13
-#
-###########################################################################
-
-FILTER_POLICY = ALLOW
-
-
-
-#############################################################################
-#
-# Upstream proxy config
-# ~~~~~~~~~~~~~~~~~~~~~
-#
-# You can choose to further relay traffic through another proxy server.
-# MOCKS supports upstream HTTP CONNECT, SOCKS4 and SOCKS5 proxies. You
-# must specify the proxy type (one of HTTPCONNECT, SOCKS4 or SOCKS5), the
-# proxy address and the proxy port. Optionally you can specify an user
-# name and a password used to authenicate to the upstream proxy. This is
-# pretty straight forward, so let's just take an example. Let's say you
-# want to use the HTTP CONNECT server at httpconnectproxy.com, on port 3128,
-# using the username 'foo' and the password 'bar'. You do it like this:
-#
-# UP_PROXY_TYPE = HTTPCONNECT
-# UP_PROXY_ADDR = httpconnectproxy.com
-# UP_PROXY_PORT = 3128
-# UP_PROXY_USER = foo # These two can be missing if you
-# UP_PROXY_PASSWD = bar # are not required to authenticate
-#
-#############################################################################
-
-# UP_PROXY_TYPE = HTTPCONNECT
-# UP_PROXY_ADDR = 192.168.1.12
-# UP_PROXY_PORT = 3128
-
-
diff --git a/test/socks4server.py b/test/socks4server.py
index 05a54b9..15cd5f3 100755
--- a/test/socks4server.py
+++ b/test/socks4server.py
@@ -10,5 +10,5 @@ def run_proxy():
reactor.stop()
if __name__ == "__main__":
- print "Running SOCKS4 proxy server"
+ print("Running SOCKS4 proxy server")
run_proxy()
diff --git a/test/test.sh b/test/test.sh
index 18479b9..0871f34 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -5,7 +5,7 @@ type python2 >/dev/null 2>&1 || alias python2='python'
echo "Starting proxy servers..."
python2 socks4server.py > /dev/null &
python2 httpproxy.py > /dev/null &
-./mocks start
+echo "Ensure a SOCKS5 server is listening"
sleep 2
echo "Python 2.6 tests"
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-socksipy.git
More information about the Python-modules-commits
mailing list