當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。