Created
January 13, 2015 03:22
-
-
Save stevommmm/956f0204309d832e15dc to your computer and use it in GitHub Desktop.
sslablesockets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SmartServerSocket: | |
| def __init__( self, sock ): | |
| self.sock = sock | |
| # delegate methods as needed | |
| _delegate_methods = [ "fileno" ] | |
| for method in _delegate_methods: | |
| setattr( self, method, getattr( sock, method ) ) | |
| def accept( self ): | |
| (conn, addr) = self.sock.accept() | |
| if conn.recv( 1, socket.MSG_PEEK ) == "\x16": | |
| return (ssl.wrap_socket( conn, certfile='cert.pem', server_side=True ), addr) | |
| else: | |
| return (conn, addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment