contextlib.contextmanager()

@contextlib.contextmanager This function is a decorator that can be used to define a factory function for with statement context managers, without needing to create a class or separate __enter__() and __exit__() methods. A simple example (this is not recommended as a real way of generating HTML!): from contextlib import contextmanager @contextmanager def tag(name): print("<%s>" % name) yield print("</%s>" % name) >>> with tag("h1"): ... print("foo") ...

contextlib.ContextDecorator

class contextlib.ContextDecorator A base class that enables a context manager to also be used as a decorator. Context managers inheriting from ContextDecorator have to implement __enter__ and __exit__ as normal. __exit__ retains its optional exception handling even when used as a decorator. ContextDecorator is used by contextmanager(), so you get this functionality automatically. Example of ContextDecorator: from contextlib import ContextDecorator class mycontext(ContextDecorator): def

contextlib.closing()

contextlib.closing(thing) Return a context manager that closes thing upon completion of the block. This is basically equivalent to: from contextlib import contextmanager @contextmanager def closing(thing): try: yield thing finally: thing.close() And lets you write code like this: from contextlib import closing from urllib.request import urlopen with closing(urlopen('http://www.python.org')) as page: for line in page: print(line) without needing to expl

container.__iter__()

container.__iter__() Return an iterator object. The object is required to support the iterator protocol described below. If a container supports different types of iteration, additional methods can be provided to specifically request iterators for those iteration types. (An example of an object supporting multiple forms of iteration would be a tree structure which supports both breadth-first and depth-first traversal.) This method corresponds to the tp_iter slot of the type structure for Pyt

ConnectionResetError

exception ConnectionResetError A subclass of ConnectionError, raised when a connection is reset by the peer. Corresponds to errno ECONNRESET.

ConnectionRefusedError

exception ConnectionRefusedError A subclass of ConnectionError, raised when a connection attempt is refused by the peer. Corresponds to errno ECONNREFUSED.

ConnectionError

exception ConnectionError A base class for connection-related issues. Subclasses are BrokenPipeError, ConnectionAbortedError, ConnectionRefusedError and ConnectionResetError.

ConnectionAbortedError

exception ConnectionAbortedError A subclass of ConnectionError, raised when a connection attempt is aborted by the peer. Corresponds to errno ECONNABORTED.

configparser.SECTCRE

configparser.SECTCRE A compiled regular expression used to parse section headers. The default matches [section] to the name "section". Whitespace is considered part of the section name, thus [  larch  ] will be read as a section of name "  larch  ". Override this attribute if that’s unsuitable. For example: >>> config = """ ... [Section 1] ... option = value ... ... [ Section 2 ] ... another = val ... """ >>> typical = ConfigParser() >>> typical.read_string(confi

configparser.RawConfigParser.set()

set(section, option, value) If the given section exists, set the given option to the specified value; otherwise raise NoSectionError. While it is possible to use RawConfigParser (or ConfigParser with raw parameters set to true) for internal storage of non-string values, full functionality (including interpolation and output to files) can only be achieved using string values. This method lets users assign non-string values to keys internally. This behaviour is unsupported and will cause error