Anonymous avatar Anonymous committed 4fe8f1b

Code simplification.
- generic forwarder written for socket and OpenSSL.SSL objects.
In OpenSSL.__init__ instead of overwriting methods on the object level
with GreenSSLConnection methods, these methods are deleted. After that regular class methods are visible.
Backdor forwarder changed to look simmilar to socket forwarder.

Comments (0)

Files changed (4)

eventlet/backdoor.py

 import eventlet
 from eventlet import hubs
 from eventlet.support import greenlets, get_errno
-#FIXME no testcases for bckdor module
 
 try:
     sys.ps1
 class FileProxy(object):
     def __init__(self, f):
         self.f = f
-        def writeflush(*a, **kw):
-            f.write(*a, **kw)
-            f.flush()
-        self.fixups = {
-            'softspace': 0,
-            'isatty': lambda: True,
-            'flush': lambda: None,
-            'write': writeflush,
-            'readline': lambda *a: f.readline(*a).replace('\r\n', '\n'),
-        }
+
+    def isatty(self): 
+        return True
+
+    def flush(self): 
+        pass
+
+    def write(self, *a, **kw):
+        self.f.write(*a, **kw)
+        self.f.flush()
+
+    def readline(self, *a):
+        return self.f.readline(*a).replace('\r\n', '\n')
 
     def __getattr__(self, attr):
-        fixups = object.__getattribute__(self, 'fixups')
-        if attr in fixups:
-            return fixups[attr]
-        f = object.__getattribute__(self, 'f')
-        return getattr(f, attr)
+        return getattr(self.f, attr)
+
 
 # @@tavis: the `locals` args below mask the built-in function.  Should
 # be renamed.

eventlet/green/OpenSSL/SSL.py

             # this is used in the inherited accept() method
             fd = ctx
         super(ConnectionType, self).__init__(fd)
-        self.sock = self
         
-    def close(self):
-        super(GreenConnection, self).close()
-    
     def do_handshake(self):
         """ Perform an SSL handshake (usually called after renegotiate or one of 
         set_accept_state or set_accept_state). This can raise the same exceptions as 
     def dup(self):
         raise NotImplementedError("Dup not supported on SSL sockets")
         
-    def get_app_data(self, *args, **kw):
-        fn = self.get_app_data = self.fd.get_app_data
-        return fn(*args, **kw)
-
-    def set_app_data(self, *args, **kw):
-        fn = self.set_app_data = self.fd.set_app_data
-        return fn(*args, **kw)        
-    
-    def get_cipher_list(self, *args, **kw):
-        fn = self.get_cipher_list = self.fd.get_cipher_list
-        return fn(*args, **kw)
-        
-    def get_context(self, *args, **kw):
-        fn = self.get_context = self.fd.get_context
-        return fn(*args, **kw)
-    
-    def get_peer_certificate(self, *args, **kw):
-        fn = self.get_peer_certificate = self.fd.get_peer_certificate
-        return fn(*args, **kw)
-        
     def makefile(self, mode='r', bufsize=-1):
         raise NotImplementedError("Makefile not supported on SSL sockets")  
         
-    def pending(self, *args, **kw):
-        fn = self.pending = self.fd.pending
-        return fn(*args, **kw)      
-
     def read(self, size):
         """Works like a blocking call to SSL_read(), whose behavior is 
         described here:  http://www.openssl.org/docs/ssl/SSL_read.html"""
             
     recv = read
     
-    def renegotiate(self, *args, **kw):
-        fn = self.renegotiate = self.fd.renegotiate
-        return fn(*args, **kw)  
-
     def write(self, data):
         """Works like a blocking call to SSL_write(), whose behavior is 
         described here:  http://www.openssl.org/docs/ssl/SSL_write.html"""
         while tail < len(data):
             tail += self.send(data[tail:])
             
-    def set_accept_state(self, *args, **kw):
-        fn = self.set_accept_state = self.fd.set_accept_state
-        return fn(*args, **kw)
-
-    def set_connect_state(self, *args, **kw):
-        fn = self.set_connect_state = self.fd.set_connect_state
-        return fn(*args, **kw)
-        
     def shutdown(self):
         if self.act_non_blocking:
             return self.fd.shutdown()
                            timeout=self.gettimeout(), 
                            timeout_exc=socket.timeout)
 
-
-    def get_shutdown(self, *args, **kw):
-        fn = self.get_shutdown = self.fd.get_shutdown
-        return fn(*args, **kw)
-        
-    def set_shutdown(self, *args, **kw):
-        fn = self.set_shutdown = self.fd.set_shutdown
-        return fn(*args, **kw)
-
-    def sock_shutdown(self, *args, **kw):
-        fn = self.sock_shutdown = self.fd.sock_shutdown
-        return fn(*args, **kw)
-        
-    def state_string(self, *args, **kw):
-        fn = self.state_string = self.fd.state_string
-        return fn(*args, **kw)
-    
-    def want_read(self, *args, **kw):
-        fn = self.want_read = self.fd.want_read
-        return fn(*args, **kw)
-
-    def want_write(self, *args, **kw):
-        fn = self.want_write = self.fd.want_write
-        return fn(*args, **kw)
-
 Connection = ConnectionType = GreenConnection
 
 del greenio

eventlet/green/ssl.py

         self.act_non_blocking = sock.act_non_blocking
         self._timeout = sock.gettimeout()
         super(GreenSSLSocket, self).__init__(sock.fd, *args, **kw)
-        del sock
-        
-        # the superclass initializer trashes the methods so...
-        self.send = lambda data, flags=0: GreenSSLSocket.send(self, data, flags)
-        self.sendto = lambda data, addr, flags=0: GreenSSLSocket.sendto(self, data, addr, flags)
-        self.recv = lambda buflen=1024, flags=0: GreenSSLSocket.recv(self, buflen, flags)
-        self.recvfrom = lambda addr, buflen=1024, flags=0: GreenSSLSocket.recvfrom(self, addr, buflen, flags)
-        self.recv_into = lambda buffer, nbytes=None, flags=0: GreenSSLSocket.recv_into(self, buffer, nbytes, flags)
-        self.recvfrom_into = lambda buffer, nbytes=None, flags=0: GreenSSLSocket.recvfrom_into(self, buffer, nbytes, flags)
-        
+       
+        # the superclass initializer trashes the methods so... 
+        for fn in orig_socket._delegate_methods:
+            delattr(self, fn)
+       
     def settimeout(self, timeout):
         self._timeout = timeout
         

eventlet/greenio.py

         
         set_nonblocking(fd)
         self.fd = fd
-        self.closed = False
         # when client calls setblocking(0) or settimeout(0) the socket must
         # act non-blocking
         self.act_non_blocking = False
     def _sock(self):
         return self
 
-    @property
-    def family(self):
-        return self.fd.family
-
-    @property
-    def type(self):
-        return self.fd.type
-
-    @property
-    def proto(self):
-        return self.fd.proto
-
-    #forward unknown requests to fd
-    #i.e _io_refs and _decref_socketios in 3.x
-    def __getattr__(self, value):
-        return getattr(self.fd, value)
+    #forward unknown attibutes to fd
+    # cache the value for future use.
+    # I do not see any simple attribute which could be changed
+    # so caching everything in self is fine,
+    # If we find such attributes - only attributes having __get__ might be cahed.
+    # For now - I do not want to complicate it.
+    def __getattr__(self, name):
+        attr = getattr(self.fd, name)
+        setattr(self, name, attr)
+        return attr
 
     def accept(self):
         if self.act_non_blocking:
             trampoline(fd, read=True, timeout=self.gettimeout(),
                            timeout_exc=socket.timeout("timed out"))
 
-    def bind(self, *args, **kw):
-        fn = self.bind = self.fd.bind
-        return fn(*args, **kw)
-
-    def close(self, *args, **kw):
-        if self.closed:
-            return
-        self.closed = True
-        res = self.fd.close()
-        return res
-
     def connect(self, address):
         if self.act_non_blocking:
             return self.fd.connect(address)
         newsock.settimeout(self.gettimeout())
         return newsock
 
-    def fileno(self, *args, **kw):
-        fn = self.fileno = self.fd.fileno
-        return fn(*args, **kw)
-
-    def getpeername(self, *args, **kw):
-        fn = self.getpeername = self.fd.getpeername
-        return fn(*args, **kw)
-
-    def getsockname(self, *args, **kw):
-        fn = self.getsockname = self.fd.getsockname
-        return fn(*args, **kw)
-
-    def getsockopt(self, *args, **kw):
-        fn = self.getsockopt = self.fd.getsockopt
-        return fn(*args, **kw)
-
-    def listen(self, *args, **kw):
-        fn = self.listen = self.fd.listen
-        return fn(*args, **kw)
-
     def makefile(self, *args, **kw):
         return _fileobject(self.dup(), *args, **kw)
 
             self.act_non_blocking = True
             self._timeout = 0.0
 
-    def setsockopt(self, *args, **kw):
-        fn = self.setsockopt = self.fd.setsockopt
-        return fn(*args, **kw)
-
-    def shutdown(self, *args, **kw):
-        fn = self.shutdown = self.fd.shutdown
-        return fn(*args, **kw)
-
     def settimeout(self, howlong):
         if howlong is None or howlong == _GLOBAL_DEFAULT_TIMEOUT:
             self.setblocking(True)
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 ProjectModifiedEvent.java.
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.