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


Python Utils.xml_to_unicode方法代码示例

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


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

示例1: _handleForm

# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import xml_to_unicode [as 别名]
 def _handleForm(self, mlist, category, subcat, cgidata, doc):
     # TK: If there is no hdrfilter_* in cgidata, we should not touch
     # the header filter rules.
     if not cgidata.has_key('hdrfilter_rebox_01'):
         return
     # First deal with
     rules = []
     # We start i at 1 and keep going until we no longer find items keyed
     # with the marked tags.
     i = 1
     downi = None
     while True:
         deltag    = 'hdrfilter_delete_%02d' % i
         reboxtag  = 'hdrfilter_rebox_%02d' % i
         actiontag = 'hdrfilter_action_%02d' % i
         wheretag  = 'hdrfilter_where_%02d' % i
         addtag    = 'hdrfilter_add_%02d' % i
         newtag    = 'hdrfilter_new_%02d' % i
         uptag     = 'hdrfilter_up_%02d' % i
         downtag   = 'hdrfilter_down_%02d' % i
         i += 1
         # Was this a delete?  If so, we can just ignore this entry
         if cgidata.has_key(deltag):
             continue
         # Get the data for the current box
         pattern = cgidata.getvalue(reboxtag)
         try:
             action  = int(cgidata.getvalue(actiontag))
             # We'll get a TypeError when the actiontag is missing and the
             # .getvalue() call returns None.
         except (ValueError, TypeError):
             action = mm_cfg.DEFER
         if pattern is None:
             # We came to the end of the boxes
             break
         if cgidata.has_key(newtag) and not pattern:
             # This new entry is incomplete.
             if i == 2:
                 # OK it is the first.
                 continue
             doc.addError(_("""Header filter rules require a pattern.
             Incomplete filter rules will be ignored."""))
             continue
         # Make sure the pattern was a legal regular expression.
         # Convert it to unicode if necessary.
         mo = re.match('.*charset=([-_a-z0-9]+)',
                       os.environ.get('CONTENT_TYPE', ''),
                       re.IGNORECASE
                      )
         if mo:
             cset = mo.group(1)
         else:
             cset = Utils.GetCharSet(mlist.preferred_language)
         try:
             upattern = Utils.xml_to_unicode(pattern, cset)
             re.compile(upattern)
             pattern = upattern
         except (re.error, TypeError):
             safepattern = Utils.websafe(pattern)
             doc.addError(_("""The header filter rule pattern
             '%(safepattern)s' is not a legal regular expression.  This
             rule will be ignored."""))
             continue
         # Was this an add item?
         if cgidata.has_key(addtag):
             # Where should the new one be added?
             where = cgidata.getvalue(wheretag)
             if where == 'before':
                 # Add a new empty rule box before the current one
                 rules.append(('', mm_cfg.DEFER, True))
                 rules.append((pattern, action, False))
                 # Default is to add it after...
             else:
                 rules.append((pattern, action, False))
                 rules.append(('', mm_cfg.DEFER, True))
         # Was this an up movement?
         elif cgidata.has_key(uptag):
             # As long as this one isn't the first rule, move it up
             if rules:
                 rules.insert(-1, (pattern, action, False))
             else:
                 rules.append((pattern, action, False))
         # Was this the down movement?
         elif cgidata.has_key(downtag):
             downi = i - 2
             rules.append((pattern, action, False))
         # Otherwise, just retain this one in the list
         else:
             rules.append((pattern, action, False))
     # Move any down button filter rule
     if downi is not None:
         rule = rules[downi]
         del rules[downi]
         rules.insert(downi+1, rule)
     mlist.header_filter_rules = rules
开发者ID:fumiyas,项目名称:mailman-ja-utf8-debian,代码行数:97,代码来源:Privacy.py


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