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


Python Utils.open_ex方法代码示例

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


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

示例1: Enqueue

# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import open_ex [as 别名]
    def Enqueue(self, mlist, newdata={}, **kws):
        """Enqueue a message for redelivery by the qrunner cronjob.

        For each enqueued message, a .msg and a .db file is written.  The .msg
        contains the plain text of the message (TBD: should this be called
        .txt?).  The .db contains a marshaled dictionary of message metadata.
        The base name of the file is the SHA hexdigest of some unique data,
        currently the message text + the list's name + the current time.

        The message metadata is a dictionary calculated as follows:

        - If the message was previously queued, it is now being requeued and
          the metadata dictionary is initialized from the existing .db file.
          Otherwise the metadata is initialized to a dictionary containing the
          listname and a scheme version number.

        - If the argument `newdata' was given, the metadata dictionary
          initialized above is .update()'d with newdata (which must conform to
          the mapping interface).

        - If additional keyword arguments are given, they are .update()'d into
          the metadata dictionary.

        mlist is the mailing list that delivery is to be attempted for.

        """
        # Calculate a unique name for the queue file
        text = repr(self)
        if self.__filebase is None:
            hashfood = text + mlist.internal_name() + `time.time()`
            self.__filebase = sha.new(hashfood).hexdigest()
        msgfile = os.path.join(mm_cfg.QUEUE_DIR, self.__filebase + '.msg')
        dbfile = os.path.join(mm_cfg.QUEUE_DIR, self.__filebase + '.db')
        # Initialize the information about this message delivery.  It's
        # possible a delivery attempt has been previously tried on this
        # message, in which case, we'll just update the data.
        try:
            dbfp = open(dbfile)
            msgdata = marshal.load(dbfp)
            dbfp.close()
            existsp = 1
        except (EOFError, ValueError, TypeError, IOError):
            msgdata = {'listname' : mlist.internal_name(),
                       'version'  : mm_cfg.QFILE_SCHEMA_VERSION,
                       'filebase' : self.__filebase,
                       }
            existsp = 0
        # Merge in the additional msgdata
        msgdata.update(newdata)
        msgdata.update(kws)
        # Get rid of volatile entries, which have the convention of starting
        # with an underscore (TBD: should we use v_ as a naming convention?).
        # Need the _dirty flag for later though.
        dirty = msgdata.get('_dirty')
        for k in msgdata.keys():
            if k[0] == '_':
                del msgdata[k]
        # Write the data file
        dbfp = Utils.open_ex(dbfile, 'w')
        marshal.dump(msgdata, dbfp)
        dbfp.close()
        # If it doesn't already exist, or if the text of the message has
        # changed, write the message file to disk, but do it atomically so as
        # not to hit a race condition with the qrunner.
        if not existsp or dirty:
            tmpfile = msgfile + '.tmp'
            msgfp = Utils.open_ex(tmpfile, 'w')
            msgfp.write(text)
            msgfp.close()
            os.rename(tmpfile, msgfile)
开发者ID:OS2World,项目名称:APP-SERVER-MailMan,代码行数:72,代码来源:Message.py


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