Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_ssl.ThreadedEchoServer.ConnectionHandler Class Reference
Inheritance diagram for test.test_ssl.ThreadedEchoServer.ConnectionHandler:
Inheritance graph
[legend]
Collaboration diagram for test.test_ssl.ThreadedEchoServer.ConnectionHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def wrap_conn
def read
def write
def close
def run
def daemon
def daemon
def name
def name
def __repr__
def start
def join
def ident
def is_alive
def isDaemon
def setDaemon
def getName
def setName

Public Attributes

 server
 running
 sock
 addr
 sslconn
 daemon
 name
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 isAlive = is_alive

Detailed Description

A mildly complicated class, because we want it to work both
with and without the SSL wrapper around the socket connection, so
that we can test the STARTTLS functionality.

Definition at line 719 of file test_ssl.py.


Constructor & Destructor Documentation

def test.test_ssl.ThreadedEchoServer.ConnectionHandler.__init__ (   self,
  server,
  connsock,
  addr 
)

Definition at line 725 of file test_ssl.py.

00725 
00726             def __init__(self, server, connsock, addr):
00727                 self.server = server
00728                 self.running = False
00729                 self.sock = connsock
00730                 self.addr = addr
00731                 self.sock.setblocking(1)
00732                 self.sslconn = None
00733                 threading.Thread.__init__(self)
00734                 self.daemon = True

Here is the caller graph for this function:


Member Function Documentation

def threading.Thread.__repr__ (   self) [inherited]

Definition at line 659 of file threading.py.

00659 
00660     def __repr__(self):
00661         assert self._initialized, "Thread.__init__() was not called"
00662         status = "initial"
00663         if self._started.is_set():
00664             status = "started"
00665         if self._stopped:
00666             status = "stopped"
00667         if self._daemonic:
00668             status += " daemon"
00669         if self._ident is not None:
00670             status += " %s" % self._ident
00671         return "<%s(%s, %s)>" % (self.__class__.__name__, self._name, status)

Definition at line 774 of file test_ssl.py.

00774 
00775             def close(self):
00776                 if self.sslconn:
00777                     self.sslconn.close()
00778                 else:
00779                     self.sock.close()

Here is the caller graph for this function:

def threading.Thread.daemon (   self) [inherited]

Definition at line 894 of file threading.py.

00894 
00895     def daemon(self):
00896         assert self._initialized, "Thread.__init__() not called"
00897         return self._daemonic

def threading.Thread.daemon (   self,
  daemonic 
) [inherited]

Definition at line 899 of file threading.py.

00899 
00900     def daemon(self, daemonic):
00901         if not self._initialized:
00902             raise RuntimeError("Thread.__init__() not called")
00903         if self._started.is_set():
00904             raise RuntimeError("cannot set daemon status of active thread");
00905         self._daemonic = daemonic

def threading.Thread.getName (   self) [inherited]

Definition at line 912 of file threading.py.

00912 
00913     def getName(self):
00914         return self.name

def threading.Thread.ident (   self) [inherited]

Definition at line 883 of file threading.py.

00883 
00884     def ident(self):
00885         assert self._initialized, "Thread.__init__() not called"
00886         return self._ident

def threading.Thread.is_alive (   self) [inherited]

Definition at line 887 of file threading.py.

00887 
00888     def is_alive(self):
00889         assert self._initialized, "Thread.__init__() not called"
00890         return self._started.is_set() and not self._stopped

Here is the caller graph for this function:

def threading.Thread.isDaemon (   self) [inherited]

Definition at line 906 of file threading.py.

00906 
00907     def isDaemon(self):
00908         return self.daemon

def threading.Thread.join (   self,
  timeout = None 
) [inherited]

Reimplemented in threading._DummyThread.

Definition at line 838 of file threading.py.

00838 
00839     def join(self, timeout=None):
00840         if not self._initialized:
00841             raise RuntimeError("Thread.__init__() not called")
00842         if not self._started.is_set():
00843             raise RuntimeError("cannot join thread before it is started")
00844         if self is current_thread():
00845             raise RuntimeError("cannot join current thread")
00846 
00847         if __debug__:
00848             if not self._stopped:
00849                 self._note("%s.join(): waiting until thread stops", self)
00850 
00851         self._block.acquire()
00852         try:
00853             if timeout is None:
00854                 while not self._stopped:
00855                     self._block.wait()
00856                 if __debug__:
00857                     self._note("%s.join(): thread stopped", self)
00858             else:
00859                 deadline = _time() + timeout
00860                 while not self._stopped:
00861                     delay = deadline - _time()
00862                     if delay <= 0:
00863                         if __debug__:
00864                             self._note("%s.join(): timed out", self)
00865                         break
00866                     self._block.wait(delay)
00867                 else:
00868                     if __debug__:
00869                         self._note("%s.join(): thread stopped", self)
00870         finally:
00871             self._block.release()

Here is the call graph for this function:

Here is the caller graph for this function:

def threading.Thread.name (   self) [inherited]

Definition at line 873 of file threading.py.

00873 
00874     def name(self):
00875         assert self._initialized, "Thread.__init__() not called"
00876         return self._name

Here is the caller graph for this function:

def threading.Thread.name (   self,
  name 
) [inherited]

Definition at line 878 of file threading.py.

00878 
00879     def name(self, name):
00880         assert self._initialized, "Thread.__init__() not called"
00881         self._name = str(name)

Here is the caller graph for this function:

Definition at line 762 of file test_ssl.py.

00762 
00763             def read(self):
00764                 if self.sslconn:
00765                     return self.sslconn.read()
00766                 else:
00767                     return self.sock.recv(1024)

Here is the caller graph for this function:

Reimplemented from threading.Thread.

Definition at line 780 of file test_ssl.py.

00780 
00781             def run(self):
00782                 self.running = True
00783                 if not self.server.starttls_server:
00784                     if not self.wrap_conn():
00785                         return
00786                 while self.running:
00787                     try:
00788                         msg = self.read()
00789                         stripped = msg.strip()
00790                         if not stripped:
00791                             # eof, so quit this handler
00792                             self.running = False
00793                             self.close()
00794                         elif stripped == b'over':
00795                             if support.verbose and self.server.connectionchatty:
00796                                 sys.stdout.write(" server: client closed connection\n")
00797                             self.close()
00798                             return
00799                         elif (self.server.starttls_server and
00800                               stripped == b'STARTTLS'):
00801                             if support.verbose and self.server.connectionchatty:
00802                                 sys.stdout.write(" server: read STARTTLS from client, sending OK...\n")
00803                             self.write(b"OK\n")
00804                             if not self.wrap_conn():
00805                                 return
00806                         elif (self.server.starttls_server and self.sslconn
00807                               and stripped == b'ENDTLS'):
00808                             if support.verbose and self.server.connectionchatty:
00809                                 sys.stdout.write(" server: read ENDTLS from client, sending OK...\n")
00810                             self.write(b"OK\n")
00811                             self.sock = self.sslconn.unwrap()
00812                             self.sslconn = None
00813                             if support.verbose and self.server.connectionchatty:
00814                                 sys.stdout.write(" server: connection is now unencrypted...\n")
00815                         else:
00816                             if (support.verbose and
00817                                 self.server.connectionchatty):
00818                                 ctype = (self.sslconn and "encrypted") or "unencrypted"
00819                                 sys.stdout.write(" server: read %r (%s), sending back %r (%s)...\n"
00820                                                  % (msg, ctype, msg.lower(), ctype))
00821                             self.write(msg.lower())
00822                     except socket.error:
00823                         if self.server.chatty:
00824                             handle_error("Test server failure:\n")
00825                         self.close()
00826                         self.running = False
00827                         # normally, we'd just stop here, but for the test
00828                         # harness, we want to stop the server
00829                         self.server.stop()
00830 
        def __init__(self, certificate=None, ssl_version=None,

Here is the caller graph for this function:

def threading.Thread.setDaemon (   self,
  daemonic 
) [inherited]

Definition at line 909 of file threading.py.

00909 
00910     def setDaemon(self, daemonic):
00911         self.daemon = daemonic

def threading.Thread.setName (   self,
  name 
) [inherited]

Definition at line 915 of file threading.py.

00915 
00916     def setName(self, name):
00917         self.name = name
00918 
00919 # The timer class was contributed by Itamar Shtull-Trauring

def threading.Thread.start (   self) [inherited]

Reimplemented in test.test_ftplib.DummyFTPServer, test.test_poplib.DummyPOP3Server, and multiprocessing.dummy.DummyProcess.

Definition at line 672 of file threading.py.

00672 
00673     def start(self):
00674         if not self._initialized:
00675             raise RuntimeError("thread.__init__() not called")
00676 
00677         if self._started.is_set():
00678             raise RuntimeError("threads can only be started once")
00679         if __debug__:
00680             self._note("%s.start(): starting thread", self)
00681         with _active_limbo_lock:
00682             _limbo[self] = self
00683         try:
00684             _start_new_thread(self._bootstrap, ())
00685         except Exception:
00686             with _active_limbo_lock:
00687                 del _limbo[self]
00688             raise
00689         self._started.wait()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 735 of file test_ssl.py.

00735 
00736             def wrap_conn(self):
00737                 try:
00738                     self.sslconn = self.server.context.wrap_socket(
00739                         self.sock, server_side=True)
00740                 except ssl.SSLError:
00741                     # XXX Various errors can have happened here, for example
00742                     # a mismatching protocol version, an invalid certificate,
00743                     # or a low-level bug. This should be made more discriminating.
00744                     if self.server.chatty:
00745                         handle_error("\n server:  bad connection attempt from " + repr(self.addr) + ":\n")
00746                     self.running = False
00747                     self.server.stop()
00748                     self.close()
00749                     return False
00750                 else:
00751                     if self.server.context.verify_mode == ssl.CERT_REQUIRED:
00752                         cert = self.sslconn.getpeercert()
00753                         if support.verbose and self.server.chatty:
00754                             sys.stdout.write(" client cert is " + pprint.pformat(cert) + "\n")
00755                         cert_binary = self.sslconn.getpeercert(True)
00756                         if support.verbose and self.server.chatty:
00757                             sys.stdout.write(" cert binary is " + str(len(cert_binary)) + " bytes\n")
00758                     cipher = self.sslconn.cipher()
00759                     if support.verbose and self.server.chatty:
00760                         sys.stdout.write(" server: connection cipher is now " + str(cipher) + "\n")
00761                     return True

Here is the caller graph for this function:

Definition at line 768 of file test_ssl.py.

00768 
00769             def write(self, bytes):
00770                 if self.sslconn:
00771                     return self.sslconn.write(bytes)
00772                 else:
00773                     return self.sock.send(bytes)


Member Data Documentation

Definition at line 729 of file test_ssl.py.

Reimplemented from threading.Thread.

Definition at line 733 of file test_ssl.py.

threading.Thread.isAlive = is_alive [static, inherited]

Definition at line 891 of file threading.py.

threading.Thread.name [inherited]

Definition at line 916 of file threading.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 727 of file test_ssl.py.

Definition at line 726 of file test_ssl.py.

Definition at line 728 of file test_ssl.py.

Definition at line 731 of file test_ssl.py.


The documentation for this class was generated from the following file: