当前位置: 首页>>代码示例>>Python>>正文


Python EncryptingStreamer.write方法代码示例

本文整理汇总了Python中mailpile.crypto.streamer.EncryptingStreamer.write方法的典型用法代码示例。如果您正苦于以下问题:Python EncryptingStreamer.write方法的具体用法?Python EncryptingStreamer.write怎么用?Python EncryptingStreamer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mailpile.crypto.streamer.EncryptingStreamer的用法示例。


在下文中一共展示了EncryptingStreamer.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from mailpile.crypto.streamer import EncryptingStreamer [as 别名]
# 或者: from mailpile.crypto.streamer.EncryptingStreamer import write [as 别名]
 def save(self, filename=None, gpg_recipient=None, encryption_key=None):
     filename = filename or self.filename
     if filename:
         gpg_recipient = gpg_recipient or self.gpg_recipient()
         encryption_key = encryption_key or self.encryption_key()
         if encryption_key:
             from mailpile.crypto.streamer import EncryptingStreamer
             es = EncryptingStreamer(encryption_key,
                                     dir=os.path.dirname(filename))
             es.write(self.as_vCard())
             es.save(filename)
         else:
             fd = gpg_open(filename, gpg_recipient, 'wb')
             fd.write(self.as_vCard())
             fd.close()
         return self
     else:
         raise ValueError('Save to what file?')
开发者ID:CodJonz,项目名称:Mailpile,代码行数:20,代码来源:vcard.py

示例2: EventLog

# 需要导入模块: from mailpile.crypto.streamer import EncryptingStreamer [as 别名]
# 或者: from mailpile.crypto.streamer.EncryptingStreamer import write [as 别名]
class EventLog(object):
    """
    This is the Mailpile Event Log.

    The log is written encrypted to disk on an ongoing basis (rotated
    every N lines), but entries are kept in RAM as well. The event log
    allows for recording of incomplete events, to help different parts
    of the app "remember" tasks which have yet to complete or may need
    to be retried.
    """

    def __init__(self, logdir, encryption_key_func, rollover=10240):
        self.logdir = logdir
        self.encryption_key_func = encryption_key_func
        self.rollover = rollover

        self.events = {}

        # Internals...
        self._lock = threading.Lock()
        self._log_fd = None

    def _save_filename(self):
        return os.path.join(self.logdir, self._log_start_id)

    def _open_log(self):
        if self._log_fd:
            self._log_fd.close()

        if not os.path.exists(self.logdir):
            os.mkdir(self.logdir)

        self._log_start_id = NewEventId()
        enc_key = self.encryption_key_func()
        if enc_key:
            self._log_fd = EncryptingStreamer(enc_key, dir=self.logdir)
            self._log_fd.save(self._save_filename(), finish=False)
        else:
            self._log_fd = open(self._save_filename(), 'w', 0)

        # Write any incomplete events to the new file
        for e in self.incomplete():
            self._log_fd.write('%s\n' % e)

        # We're starting over, incomplete events don't count
        self._logged = 0

    def _maybe_rotate_log(self):
        if self._logged > self.rollover:
            self._log_fd.close()
            kept_events = {}
            for e in self.incomplete():
                kept_events[e.event_id] = e
            self.events = kept_events
            self.open_log()

    def _match(self, event, filters):
        return True

    def incomplete(self, **filters):
        """Return all the incomplete events, in order."""
        for ek in sorted(self.events.keys()):
            e = self.events.get(ek, None)
            if (e is not None and
                    e.state != Event.COMPLETE and
                    self._match(e, filters)):
                yield e

    def since(self, ts, **filters):
        """Return all events since a given time, in order."""
        for ek in sorted(self.events.keys()):
            e = self.events.get(ek, None)
            if (e is not None and
                    e.ts >= ts and
                    self._match(e, filters)):
                yield e

    def log_event(self, event):
        """Log an Event object."""
        self._lock.acquire()
        try:
            if not self._log_fd:
                self._open_log()
            self._log_fd.write('%s\n' % event)
            self.events[event.event_id] = event
            self._logged += 1
            self._maybe_rotate_log()
        finally:
            self._lock.release()
        return event

    def log(self, *args, **kwargs):
        """Log a new event."""
        return self.log_event(Event(*args, **kwargs))

    def close(self):
        self._lock.acquire()
        try:
            self._log_fd.close()
            self._log_fd = None
#.........这里部分代码省略.........
开发者ID:Ivoz,项目名称:Mailpile,代码行数:103,代码来源:eventlog.py

示例3: EventLog

# 需要导入模块: from mailpile.crypto.streamer import EncryptingStreamer [as 别名]
# 或者: from mailpile.crypto.streamer.EncryptingStreamer import write [as 别名]
class EventLog(object):
    """
    This is the Mailpile Event Log.

    The log is written encrypted to disk on an ongoing basis (rotated
    every N lines), but entries are kept in RAM as well. The event log
    allows for recording of incomplete events, to help different parts
    of the app "remember" tasks which have yet to complete or may need
    to be retried.
    """
    KEEP_LOGS = 2

    def __init__(self, logdir, encryption_key_func, rollover=10240):
        self.logdir = logdir
        self.encryption_key_func = encryption_key_func
        self.rollover = rollover

        self._events = {}

        # Internals...
        self._waiter = threading.Condition()
        self._lock = threading.Lock()
        self._log_fd = None

    def _notify_waiters(self):
        self._waiter.acquire()
        self._waiter.notifyAll()
        self._waiter.release()

    def wait(self, timeout=None):
        self._waiter.acquire()
        self._waiter.wait(timeout)
        self._waiter.release()

    def _save_filename(self):
        return os.path.join(self.logdir, self._log_start_id)

    def _open_log(self):
        if self._log_fd:
            self._log_fd.close()

        if not os.path.exists(self.logdir):
            os.mkdir(self.logdir)

        self._log_start_id = NewEventId()
        enc_key = self.encryption_key_func()
        if enc_key:
            self._log_fd = EncryptingStreamer(enc_key, dir=self.logdir)
            self._log_fd.save(self._save_filename(), finish=False)
        else:
            self._log_fd = open(self._save_filename(), 'w', 0)

        # Write any incomplete events to the new file
        for e in self.incomplete():
            self._log_fd.write('%s\n' % e)

        # We're starting over, incomplete events don't count
        self._logged = 0

    def _maybe_rotate_log(self):
        if self._logged > self.rollover:
            self._log_fd.close()
            kept_events = {}
            for e in self.incomplete():
                kept_events[e.event_id] = e
            self._events = kept_events
            self._open_log()
            self.purge_old_logfiles()

    def _list_logfiles(self):
        return sorted([l for l in os.listdir(self.logdir)
                       if not l.startswith('.')])

    def _save_events(self, events):
        if not self._log_fd:
            self._open_log()
        events.sort(key=lambda ev: ev.ts)
        for event in events:
            self._log_fd.write('%s\n' % event)
            self._events[event.event_id] = event

    def _load_logfile(self, lfn):
        enc_key = self.encryption_key_func()
        with open(os.path.join(self.logdir, lfn)) as fd:
            if enc_key:
                lines = fd.read()
            else:
                with DecryptingStreamer(enc_key, fd) as streamer:
                    lines = streamer.read()
            if lines:
                for line in lines.splitlines():
                    event = Event.Parse(line)
                    self._events[event.event_id] = event

    def _match(self, event, filters):
        for kw, rule in filters.iteritems():
            if kw.endswith('!'):
                truth, okw, kw = False, kw, kw[:-1]
            else:
                truth, okw = True, kw
#.........这里部分代码省略.........
开发者ID:Bangsalina,项目名称:Mailpile,代码行数:103,代码来源:eventlog.py

示例4: EventLog

# 需要导入模块: from mailpile.crypto.streamer import EncryptingStreamer [as 别名]
# 或者: from mailpile.crypto.streamer.EncryptingStreamer import write [as 别名]
class EventLog(object):
    """
    This is the Mailpile Event Log.

    The log is written encrypted to disk on an ongoing basis (rotated
    every N lines), but entries are kept in RAM as well. The event log
    allows for recording of incomplete events, to help different parts
    of the app "remember" tasks which have yet to complete or may need
    to be retried.
    """
    KEEP_LOGS = 2

    def __init__(self, logdir, decryption_key_func, encryption_key_func,
                 rollover=1024):
        self.logdir = logdir
        self.decryption_key_func = decryption_key_func or (lambda: None)
        self.encryption_key_func = encryption_key_func or (lambda: None)
        self.rollover = rollover

        self._events = {}

        # Internals...
        self._watching_uis = []
        self._waiter = threading.Condition(EventRLock())
        self._lock = EventLock()
        self._log_fd = None

    def _notify_waiters(self):
        with self._waiter:
            self._waiter.notifyAll()

    def wait(self, timeout=None):
        with self._waiter:
            self._waiter.wait(timeout)

    def _save_filename(self):
        return os.path.join(self.logdir, self._log_start_id)

    def _open_log(self):
        if self._log_fd:
            self._log_fd.close()

        if not os.path.exists(self.logdir):
            os.mkdir(self.logdir)

        self._log_start_id = NewEventId()
        enc_key = self.encryption_key_func()
        if enc_key:
            self._log_fd = EncryptingStreamer(enc_key,
                                              dir=self.logdir,
                                              name='EventLog/ES',
                                              long_running=True)
            self._log_fd.save(self._save_filename(), finish=False)
        else:
            self._log_fd = open(self._save_filename(), 'wb', 0)

        # Write any incomplete events to the new file
        for e in self.incomplete():
            self._log_fd.write('%s\n' % e)

        # We're starting over, incomplete events don't count
        self._logged = 0

    def _maybe_rotate_log(self):
        if self._logged > self.rollover:
            self._log_fd.close()
            kept_events = {}
            for e in self.incomplete():
                kept_events[e.event_id] = e
            self._events = kept_events
            self._open_log()
            self.purge_old_logfiles()

    def _list_logfiles(self):
        return sorted([l for l in os.listdir(self.logdir)
                       if not l.startswith('.')])

    def _save_events(self, events, recursed=False):
        if not self._log_fd:
            self._open_log()
        events.sort(key=lambda ev: ev.ts)
        try:
            for event in events:
                self._log_fd.write('%s\n' % event)
                self._events[event.event_id] = event
        except IOError:
            if recursed:
                raise
            else:
                self._unlocked_close()
                return self._save_events(events, recursed=True)

    def _load_logfile(self, lfn):
        enc_key = self.decryption_key_func()
        with open(os.path.join(self.logdir, lfn)) as fd:
            if enc_key:
                with DecryptingStreamer(fd, mep_key=enc_key,
                                        name='EventLog/DS') as streamer:
                    lines = streamer.read()
                    streamer.verify(_raise=IOError)
#.........这里部分代码省略.........
开发者ID:4myPAL,项目名称:Mailpile,代码行数:103,代码来源:eventlog.py

示例5: EventLog

# 需要导入模块: from mailpile.crypto.streamer import EncryptingStreamer [as 别名]
# 或者: from mailpile.crypto.streamer.EncryptingStreamer import write [as 别名]
class EventLog(object):
    """
    This is the Mailpile Event Log.

    The log is written encrypted to disk on an ongoing basis (rotated
    every N lines), but entries are kept in RAM as well. The event log
    allows for recording of incomplete events, to help different parts
    of the app "remember" tasks which have yet to complete or may need
    to be retried.
    """
    KEEP_LOGS = 2

    def __init__(self, logdir, encryption_key_func, rollover=10240):
        self.logdir = logdir
        self.encryption_key_func = encryption_key_func
        self.rollover = rollover

        self.events = {}

        # Internals...
        self._lock = threading.Lock()
        self._log_fd = None

    def _save_filename(self):
        return os.path.join(self.logdir, self._log_start_id)

    def _open_log(self):
        if self._log_fd:
            self._log_fd.close()

        if not os.path.exists(self.logdir):
            os.mkdir(self.logdir)

        self._log_start_id = NewEventId()
        enc_key = self.encryption_key_func()
        if enc_key:
            self._log_fd = EncryptingStreamer(enc_key, dir=self.logdir)
            self._log_fd.save(self._save_filename(), finish=False)
        else:
            self._log_fd = open(self._save_filename(), 'w', 0)

        # Write any incomplete events to the new file
        for e in self.incomplete():
            self._log_fd.write('%s\n' % e)

        # We're starting over, incomplete events don't count
        self._logged = 0

    def _maybe_rotate_log(self):
        if self._logged > self.rollover:
            self._log_fd.close()
            kept_events = {}
            for e in self.incomplete():
                kept_events[e.event_id] = e
            self.events = kept_events
            self._open_log()
            self.purge_old_logfiles()

    def _match(self, event, filters):
        return True

    def _list_logfiles(self):
        return sorted([l for l in os.listdir(self.logdir)
                       if not l.startswith('.')])

    def _save_events(self, events):
        if not self._log_fd:
            self._open_log()
        events.sort(key=lambda ev: ev.ts)
        for event in events:
            self._log_fd.write('%s\n' % event)
            self.events[event.event_id] = event

    def _load_logfile(self, lfn):
        enc_key = self.encryption_key_func()
        with open(os.path.join(self.logdir, lfn)) as fd:
            if enc_key:
                lines = fd.read()
            else:
                with DecryptingStreamer(enc_key, fd) as streamer:
                    lines = fd.read()
            if lines:
                for line in lines.splitlines():
                    event = Event.Parse(line)
                    if Event.COMPLETE in event.flags:
                        if event.event_id in self.events:
                            del self.events[event.event_id]
                    else:
                        self.events[event.event_id] = event
        self._save_events(self.events.values())

    def incomplete(self, **filters):
        """Return all the incomplete events, in order."""
        for ek in sorted(self.events.keys()):
            e = self.events.get(ek, None)
            if (e is not None and
                    Event.COMPLETE not in e.flags and
                    self._match(e, filters)):
                yield e

#.........这里部分代码省略.........
开发者ID:maxking,项目名称:Mailpile,代码行数:103,代码来源:eventlog.py


注:本文中的mailpile.crypto.streamer.EncryptingStreamer.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。