from enum import Enum as _Enum __author__ = 'faddey' def _enum_choices(enum): return tuple( (item.value, name) for name, item in enum.__members__.items() ) Unit = _Enum( 'Unit', [ 'ml', 'kg', 'k', 'l', 'pack', ] )
# vim: set fileencoding=utf-8 from __future__ import division, print_function, unicode_literals from collections import namedtuple as _namedtuple from enum import Enum as _Enum import itertools as _itertools import sys as _sys __author__ = "Antony Lee" __version__ = "0.2" __fullname__ = "redeal v. {}".format(__version__) __copyright__ = "{}, (c) {}".format(__fullname__, __author__) Seat = _Enum("Seat", zip("NESW", range(4))) Seat.N._s, Seat.E._s, Seat.S._s, Seat.W._s = ( "North", "East", "South", "West") Seat.__str__ = lambda self: self._s Seat.__index__ = lambda self: self.value Seat.__add__ = lambda self, val: Seat((self.value + val) % len(Seat)) class Suit(_Enum): S = 0, " S", "♠" H = 1, " H", "♡" D = 2, " D", "♢" C = 3, " C", "♣" def __init__(self, value, sym, unicode_sym): self._value_ = value
async def ensure(self, *, checkpoint): if not self.started: self.started = True await self._afn(*self._args) self._done.set() elif not checkpoint and self._done.is_set(): return else: await self._done.wait() @property def done(self): return self._done.is_set() _State = _Enum("_State", ["OK", "BROKEN", "CLOSED"]) class SSLStream(Stream): r"""Encrypted communication using SSL/TLS. :class:`SSLStream` wraps an arbitrary :class:`~trio.abc.Stream`, and allows you to perform encrypted communication over it using the usual :class:`~trio.abc.Stream` interface. You pass regular data to :meth:`send_all`, then it encrypts it and sends the encrypted data on the underlying :class:`~trio.abc.Stream`; :meth:`receive_some` takes encrypted data out of the underlying :class:`~trio.abc.Stream` and decrypts it before returning it. You should read the standard library's :mod:`ssl` documentation carefully before attempting to use this class, and probably other general
self._args = args self.started = False self._done = _sync.Event() async def ensure(self, *, checkpoint): if not self.started: self.started = True await self._afn(*self._args) self._done.set() elif not checkpoint and self._done.is_set(): return else: await self._done.wait() _State = _Enum("_State", ["OK", "BROKEN", "CLOSED"]) _default_max_refill_bytes = 32 * 1024 class SSLStream(Stream): """Encrypted communication using SSL/TLS. :class:`SSLStream` wraps an arbitrary :class:`~trio.abc.Stream`, and allows you to perform encrypted communication over it using the usual :class:`~trio.abc.Stream` interface. You pass regular data to :meth:`send_all`, then it encrypts it and sends the encrypted data on the underlying :class:`~trio.abc.Stream`; :meth:`receive_some` takes encrypted data out of the underlying :class:`~trio.abc.Stream` and decrypts it before returning it.