本文整理汇总了Python中x84.bbs.session.getsession函数的典型用法代码示例。如果您正苦于以下问题:Python getsession函数的具体用法?Python getsession怎么用?Python getsession使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getsession函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, cmd='/bin/uname', args=(), env=None, cp437=False):
"""
Class initializer.
:param str cmd: full path of command to execute.
:param tuple args: command arguments as tuple.
:param bool cp437: When true, forces decoding of external program as
codepage 437. This is the most common encoding used
by DOS doors.
:param dict env: Environment variables to extend to the sub-process.
You should more than likely specify values for TERM,
PATH, HOME, and LANG.
"""
self._session, self._term = getsession(), getterminal()
self.cmd = cmd
if isinstance(args, tuple):
self.args = (self.cmd,) + args
elif isinstance(args, list):
self.args = [self.cmd, ] + args
else:
raise ValueError('args must be tuple or list')
self.log = logging.getLogger(__name__)
self.env = (env or {}).copy()
self.env.update(
{'LANG': env.get('LANG', 'en_US.UTF-8'),
'TERM': env.get('TERM', self._term.kind),
'PATH': env.get('PATH', get_ini('door', 'path')),
'HOME': env.get('HOME', os.getenv('HOME')),
'LINES': str(self._term.height),
'COLUMNS': str(self._term.width),
})
self.cp437 = cp437
self._utf8_decoder = codecs.getincrementaldecoder('utf8')()
示例2: echo
def echo(ucs):
"""
Display unicode terminal sequence.
"""
session = getsession()
if not isinstance(ucs, unicode):
warnings.warn('non-unicode: %r' % (ucs,), UnicodeWarning, 2)
return session.write(ucs.decode('iso8859-1'))
return session.write(ucs)
示例3: _decode
def _decode(what):
# pylint: disable=C0111
# Missing function docstring (col 8)
session = getsession()
if session.encoding == 'utf8':
return what.decode(encoding)
elif session.encoding == 'cp437':
return what.decode('cp437')
else:
return what
示例4: read
def read(self):
"""
Reads input until ESCAPE key is pressed (Blocking). Returns None.
"""
from x84.bbs.session import getsession
from x84.bbs.output import echo
session = getsession()
self._quit = False
echo(self.refresh())
while not self.quit:
echo(self.process_keystroke(session.read_event('input')))
示例5: __init__
def __init__(self, schema, table='unnamed', use_session=True):
"""
Arguments:
schema: database key, to become basename of .sqlite3 files.
"""
from x84.bbs.session import getsession
self.log = logging.getLogger(__name__)
self.schema = schema
self.table = table
self._tap_db = should_tapdb()
self.session = use_session and getsession()
示例6: __init__
def __init__(self, recipient=None, subject=u'', body=u''):
from x84.bbs.session import getsession
self._ctime = datetime.datetime.now()
self._stime = None
self.author = getsession().handle
self.recipient = recipient
self.subject = subject
self.body = body
self.tags = set()
# reply-to tracking
self.children = set()
self.parent = None
示例7: send_modem
def send_modem(stream, protocol='xmodem1k', retry=16, timeout=30,
callback=None):
"""
Send a file using 'xmodem1k' or 'xmodem' protocol.
Currently, these are the only protocols supported. Returns ``True`` upon
successful transmission, otherwise ``False``.
:param stream: The file-like stream object to send data from.
:param int retry: The maximum number of times to try to resend a failed
packet before failing.
:param int timeout: seconds to elapse for response before failing.
:param callable callback: Reference to a callback function that has the
following signature. This is useful for getting
status updates while a transfer is underway::
def callback(total_count, success_count, error_count)
"""
# get protocol implementation class
supported_protocols = ('xmodem', 'xmodem1k')
assert protocol in supported_protocols, (protocol, supported_protocols)
Modem = {
'xmodem': xmodem.XMODEM,
'xmodem1k': xmodem.XMODEM1k,
}[protocol]
# the session's 'input' event buffer is used for receiving
# transmissions. It arrives in raw bytes, and session.write
# is used, sending "unicode" data as encoding iso8859-1.
session = getsession()
def getc(size, timeout=10):
""" Callback function for (X)Modem interface. """
val = b''
while len(val) < size:
next_val = session.read_event('input', timeout=timeout)
if next_val is None:
break
val += next_val
if len(val) > size:
session.buffer_input(val[size:])
return val[:size] or None
def putc(data, timeout=10):
# pylint: disable=W0613
# Unused argument 'timeout'
""" Callback function for (X)Modem interface. """
session.write(data.decode('iso8859-1'), 'iso8859-1')
modem = Modem(getc, putc)
return modem.send(stream=stream, retry=retry, timeout=timeout,
quiet=True, callback=callback)
示例8: init_theme
def init_theme(self):
"""
This initializer sets glyphs and colors appropriate for a "theme",
override this method to create a common color and graphic set.
"""
session = getsession()
term = getterminal()
self.colors['normal'] = term.normal
if term.number_of_colors != 0:
self.colors['border'] = term.cyan
# start with default 'ascii'
self.glyphs = GLYPHSETS['ascii'].copy()
# PC-DOS 'thin' on smart terminals
if session.env.get('TERM') != 'unknown':
self.glyphs = GLYPHSETS['thin'].copy()
示例9: __init__
def __init__(self, recipient=None, subject=u'', body=u''):
self.author = None
session = getsession()
if session:
self.author = session.user.handle
self._ctime = datetime.datetime.now()
self._stime = None
self.recipient = recipient
self.subject = subject
self.body = body
self.tags = set()
self.children = set()
self.parent = None
self.idx = None
示例10: __init__
def __init__(self, recipient=None, subject=u'', body=u''):
from x84.bbs.session import getsession
self.author = None
session = getsession()
if session:
self.author = session.handle
# msg attributes (todo: create method ..)
self._ctime = datetime.datetime.now()
self._stime = None
self.recipient = recipient
self.subject = subject
self.body = body
self.tags = set()
self.children = set()
self.parent = None
示例11: read
def read(self):
"""
Reads input until the ENTER or ESCAPE key is pressed (Blocking).
Allows backspacing. Returns unicode text, or None when cancelled.
"""
from x84.bbs.session import getsession
from x84.bbs.output import echo
session = getsession()
self._selected = False
self._quit = False
echo(self.refresh())
while not (self.selected or self.quit):
echo(self.process_keystroke(session.read_event('input')) or u'')
if self.quit:
return None
return self.selection
示例12: __init__
def __init__(self, schema, table='unnamed', use_session=True):
"""
Class constructor.
:param str scheme: database key, becomes basename of .sqlite3 file.
:param str table: optional database table.
:param bool use_session: Whether iterable returns should be sent over
an IPC pipe (client is a
:class:`x84.bbs.session.Session` instance),
or returned directly (such as used by the main
thread engine components.)
"""
self.log = logging.getLogger(__name__)
self.schema = schema
self.table = table
self._tap_db = get_ini('session', 'tab_db', getter='getboolean')
self.session = use_session and getsession()
示例13: read
def read(self):
"""
Reads input until the ENTER or ESCAPE key is pressed (Blocking).
Allows backspacing. Returns unicode text, or None when cancelled.
"""
from x84.bbs.session import getsession
from x84.bbs.output import echo
session = getsession()
echo(self.refresh())
self._quit = False
self._carriage_returned = False
while not (self.quit or self.carriage_returned):
inp = session.read_event("input")
echo(self.process_keystroke(inp))
if not self.quit:
return self.content
return None
示例14: emit
def emit(self, record):
""" Emit log record via IPC output queue. """
try:
e_inf = record.exc_info
if e_inf:
# a strange side-effect,
# sets record.exc_text
dummy = self.format(record) # NOQA
record.exc_info = None
record.handle = None
session = getsession()
if session:
record.handle = session.handle
self.oqueue.send(('logger', record))
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
self.handleError(record)
示例15: __init__
def __init__(self, cmd='/bin/uname', args=(), env_lang='en_US.UTF-8',
env_term=None, env_path=None, env_home=None, cp437=False,
env=None):
"""
Class constructor.
:param str cmd: full path of command to execute.
:param tuple args: command arguments as tuple.
:param str env_lang: exported as environment variable ``LANG``.
:param str env_term: exported as environment variable ``TERM``. When
unspecified, it is determined by the same
TERM value the original ``blessed.Terminal``
instance is used.
:param str env_path: exported as environment variable ``PATH``.
When None (default), the .ini ``env_path``
value of section ``[door]`` is
:param str env_home: exported as environment variable ``HOME``.
When env_home is ``None``, the environment
value of the main process is used.
:param bool cp437: When true, forces decoding of external program as
codepage 437. This is the most common encoding used
by DOS doors.
:param dict env: Additional environment variables to extend to the
sub-process.
"""
self._session, self._term = getsession(), getterminal()
self.cmd = cmd
if isinstance(args, tuple):
self.args = (self.cmd,) + args
elif isinstance(args, list):
self.args = [self.cmd, ] + args
else:
raise ValueError('args must be tuple or list')
self.env_lang = env_lang
self.env_term = env_term or self._term.kind
self.env_path = env_path or get_ini('door', 'path')
self.env_home = env_home or os.getenv('HOME')
self.env = env or {}
self.cp437 = cp437
self._utf8_decoder = codecs.getincrementaldecoder('utf8')()