當前位置: 首頁>>代碼示例>>Python>>正文


Python socks.socksocket方法代碼示例

本文整理匯總了Python中httplib2.socks.socksocket方法的典型用法代碼示例。如果您正苦於以下問題:Python socks.socksocket方法的具體用法?Python socks.socksocket怎麽用?Python socks.socksocket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在httplib2.socks的用法示例。


在下文中一共展示了socks.socksocket方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: connect

# 需要導入模塊: from httplib2 import socks [as 別名]
# 或者: from httplib2.socks import socksocket [as 別名]
def connect(self):
        """Connect to the host and port specified in __init__."""
        # Mostly verbatim from httplib.py.
        if self.proxy_info and socks is None:
            raise ProxiesUnavailableError(
                'Proxy support missing but proxy use was requested!')
        msg = "getaddrinfo returns an empty list"
        if self.proxy_info and self.proxy_info.isgood():
            use_proxy = True
            proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass = self.proxy_info.astuple()

            host = proxy_host
            port = proxy_port
        else:
            use_proxy = False

            host = self.host
            port = self.port

        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                if use_proxy:
                    self.sock = socks.socksocket(af, socktype, proto)
                    self.sock.setproxy(proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass)
                else:
                    self.sock = socket.socket(af, socktype, proto)
                    self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                # Different from httplib: support timeouts.
                if has_timeout(self.timeout):
                    self.sock.settimeout(self.timeout)
                    # End of difference from httplib.
                if self.debuglevel > 0:
                    print "connect: (%s, %s) ************" % (self.host, self.port)
                    if use_proxy:
                        print "proxy: %s ************" % str((proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass))

                self.sock.connect((self.host, self.port) + sa[2:])
            except socket.error, msg:
                if self.debuglevel > 0:
                    print "connect fail: (%s, %s)" % (self.host, self.port)
                    if use_proxy:
                        print "proxy: %s" % str((proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass))
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:50,代碼來源:__init__.py

示例2: connect

# 需要導入模塊: from httplib2 import socks [as 別名]
# 或者: from httplib2.socks import socksocket [as 別名]
def connect(self):
        """Connect to the host and port specified in __init__."""
        # Mostly verbatim from httplib.py.
        if self.proxy_info and socks is None:
            raise ProxiesUnavailableError(
                'Proxy support missing but proxy use was requested!')
        msg = "getaddrinfo returns an empty list"
        if self.proxy_info and self.proxy_info.isgood():
            use_proxy = True
            proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass, proxy_headers = self.proxy_info.astuple()

            host = proxy_host
            port = proxy_port
        else:
            use_proxy = False

            host = self.host
            port = self.port

        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                if use_proxy:
                    self.sock = socks.socksocket(af, socktype, proto)
                    self.sock.setproxy(proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass, proxy_headers)
                else:
                    self.sock = socket.socket(af, socktype, proto)
                    self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                # Different from httplib: support timeouts.
                if has_timeout(self.timeout):
                    self.sock.settimeout(self.timeout)
                    # End of difference from httplib.
                if self.debuglevel > 0:
                    print "connect: (%s, %s) ************" % (self.host, self.port)
                    if use_proxy:
                        print "proxy: %s ************" % str((proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass, proxy_headers))

                self.sock.connect((self.host, self.port) + sa[2:])
            except socket.error, msg:
                if self.debuglevel > 0:
                    print "connect fail: (%s, %s)" % (self.host, self.port)
                    if use_proxy:
                        print "proxy: %s" % str((proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass, proxy_headers))
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break 
開發者ID:skarlekar,項目名稱:faces,代碼行數:50,代碼來源:__init__.py

示例3: connect

# 需要導入模塊: from httplib2 import socks [as 別名]
# 或者: from httplib2.socks import socksocket [as 別名]
def connect(self):
        """Connect to the host and port specified in __init__."""
        # Mostly verbatim from httplib.py.
        if self.proxy_info and socks is None:
            raise ProxiesUnavailableError(
                'Proxy support missing but proxy use was requested!')
        msg = "getaddrinfo returns an empty list"
        if self.proxy_info and self.proxy_info.isgood():
            use_proxy = True
            proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass = self.proxy_info.astuple()
        else:
            use_proxy = False
        if use_proxy and proxy_rdns:
            host = proxy_host
            port = proxy_port
        else:
            host = self.host
            port = self.port

        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                if use_proxy:
                    self.sock = socks.socksocket(af, socktype, proto)
                    self.sock.setproxy(proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass)
                else:
                    self.sock = socket.socket(af, socktype, proto)
                    self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                # Different from httplib: support timeouts.
                if has_timeout(self.timeout):
                    self.sock.settimeout(self.timeout)
                    # End of difference from httplib.
                if self.debuglevel > 0:
                    print "connect: (%s, %s) ************" % (self.host, self.port)
                    if use_proxy:
                        print "proxy: %s ************" % str((proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass))

                self.sock.connect((self.host, self.port) + sa[2:])
            except socket.error, msg:
                if self.debuglevel > 0:
                    print "connect fail: (%s, %s)" % (self.host, self.port)
                    if use_proxy:
                        print "proxy: %s" % str((proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass))
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:50,代碼來源:__init__.py


注:本文中的httplib2.socks.socksocket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。