irc / irc /

from __future__ import absolute_import

import socket
    from importlib import import_module
except ImportError:
    # for Python 2.6 compatibility
    import_module = __import__

identity = lambda x: x

class Factory(object):
    A class for creating custom socket connections.

    To create a simple connection:

        server_address = ('localhost', 80)

    To create an SSL connection:


    To create an SSL connection with parameters to wrap_socket:

        wrapper = functools.partial(ssl.wrap_socket, ssl_cert=get_cert())

    To create an IPv6 connection:


    Note that Factory doesn't save the state of the socket itself. The
    caller must do that, as necessary. As a result, the Factory may be
    re-used to create new connections with the same settings.


    family = socket.AF_INET

    def __init__(self, bind_address=('', 0), wrapper=identity, ipv6=False):
        self.bind_address = bind_address
        self.wrapper = wrapper
        if ipv6:
   = socket.AF_INET6

    def from_legacy_params(self, localaddress='', localport=0, ssl=False,
        if localaddress or localport:
            self.bind_address = (localaddress, localport)
        if ssl:
            self.wrapper = import_module('ssl').wrap_socket
        if ipv6:
   = socket.AF_INET6

    def connect(self, server_address):
        sock = self.wrapper(socket.socket(, socket.SOCK_STREAM))
        return sock
    __call__ = connect
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.