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


Python entitydefs.keys方法代码示例

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


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

示例1: lookslikehtml

# 需要导入模块: from htmlentitydefs import entitydefs [as 别名]
# 或者: from htmlentitydefs.entitydefs import keys [as 别名]
def lookslikehtml(self, s):
        if self.version.startswith('atom'): return
        if self.contentparams.get('type','text/html') != 'text/plain': return

        # must have a close tag or a entity reference to qualify
        if not (re.search(r'</(\w+)>',s) or re.search("&#?\w+;",s)): return

        # all tags must be in a restricted subset of valid HTML tags
        if filter(lambda t: t.lower() not in _HTMLSanitizer.acceptable_elements,
            re.findall(r'</?(\w+)',s)): return

        # all entities must have been defined as valid HTML entities
        from htmlentitydefs import entitydefs
        if filter(lambda e: e not in entitydefs.keys(),
            re.findall(r'&(\w+);',s)): return

        return 1 
开发者ID:thispc,项目名称:download-manager,代码行数:19,代码来源:feedparser.py

示例2: lookslikehtml

# 需要导入模块: from htmlentitydefs import entitydefs [as 别名]
# 或者: from htmlentitydefs.entitydefs import keys [as 别名]
def lookslikehtml(s):
        # must have a close tag or an entity reference to qualify
        if not (re.search(r'</(\w+)>',s) or re.search("&#?\w+;",s)):
            return

        # all tags must be in a restricted subset of valid HTML tags
        if filter(lambda t: t.lower() not in _HTMLSanitizer.acceptable_elements,
            re.findall(r'</?(\w+)',s)):
            return

        # all entities must have been defined as valid HTML entities
        if filter(lambda e: e not in entitydefs.keys(), re.findall(r'&(\w+);', s)):
            return

        return 1 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:17,代码来源:feedparser.py

示例3: __setitem__

# 需要导入模块: from htmlentitydefs import entitydefs [as 别名]
# 或者: from htmlentitydefs.entitydefs import keys [as 别名]
def __setitem__(self, key, value):
        for k in self.keymap.keys():
            if key == k:
                key = self.keymap[k]
                if type(key) == types.ListType:
                    key = key[0]
        return UserDict.__setitem__(self, key, value) 
开发者ID:thispc,项目名称:download-manager,代码行数:9,代码来源:feedparser.py

示例4: handle_entityref

# 需要导入模块: from htmlentitydefs import entitydefs [as 别名]
# 或者: from htmlentitydefs.entitydefs import keys [as 别名]
def handle_entityref(self, ref):
        # called for each entity reference, e.g. for '&copy;', ref will be 'copy'
        if not self.elementstack: return
        if _debug: sys.stderr.write('entering handle_entityref with %s\n' % ref)
        if ref in ('lt', 'gt', 'quot', 'amp', 'apos'):
            text = '&%s;' % ref
        elif ref in self.entities.keys():
            text = self.entities[ref]
            if text.startswith('&#') and text.endswith(';'):
                return self.handle_entityref(text)
        else:
            try: name2codepoint[ref]
            except KeyError: text = '&%s;' % ref
            else: text = unichr(name2codepoint[ref]).encode('utf-8')
        self.elementstack[-1][2].append(text) 
开发者ID:thispc,项目名称:download-manager,代码行数:17,代码来源:feedparser.py

示例5: handle_charref

# 需要导入模块: from htmlentitydefs import entitydefs [as 别名]
# 或者: from htmlentitydefs.entitydefs import keys [as 别名]
def handle_charref(self, ref):
        # called for each character reference, e.g. for '&#160;', ref will be '160'
        # Reconstruct the original character reference.
        if ref.startswith('x'):
            value = unichr(int(ref[1:],16))
        else:
            value = unichr(int(ref))

        if value in _cp1252.keys():
            self.pieces.append('&#%s;' % hex(ord(_cp1252[value]))[1:])
        else:
            self.pieces.append('&#%(ref)s;' % locals()) 
开发者ID:thispc,项目名称:download-manager,代码行数:14,代码来源:feedparser.py

示例6: _writer

# 需要导入模块: from htmlentitydefs import entitydefs [as 别名]
# 或者: from htmlentitydefs.entitydefs import keys [as 别名]
def _writer(self, stream, node, prefix):
        if not node: return
        if hasattr(node, 'keys'):
            keys = node.keys()
            keys.sort()
            for k in keys:
                if k in ('description', 'link'): continue
                if node.has_key(k + '_detail'): continue
                if node.has_key(k + '_parsed'): continue
                self._writer(stream, node[k], prefix + k + '.')
        elif type(node) == types.ListType:
            index = 0
            for n in node:
                self._writer(stream, n, prefix[:-1] + '[' + str(index) + '].')
                index += 1
        else:
            try:
                s = str(node).encode('utf-8')
                s = s.replace('\\', '\\\\')
                s = s.replace('\r', '')
                s = s.replace('\n', r'\n')
                stream.write(prefix[:-1])
                stream.write('=')
                stream.write(s)
                stream.write('\n')
            except:
                pass 
开发者ID:thispc,项目名称:download-manager,代码行数:29,代码来源:feedparser.py


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