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


Python util.InsensitiveDict方法代码示例

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


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

示例1: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(self, tagName, attributes=None, parentNode=None,
                 filename=None, markpos=None,
                 caseInsensitive=1, preserveCase=0,
                 namespace=None):
        Node.__init__(self, parentNode)
        self.preserveCase = preserveCase or not caseInsensitive
        self.caseInsensitive = caseInsensitive
        if not preserveCase:
            tagName = tagName.lower()
        if attributes is None:
            self.attributes = {}
        else:
            self.attributes = attributes
            for k, v in self.attributes.items():
                self.attributes[k] = unescape(v)

        if caseInsensitive:
            self.attributes = InsensitiveDict(self.attributes,
                                              preserve=preserveCase)

        self.endTagName = self.nodeName = self.tagName = tagName
        self._filename = filename
        self._markpos = markpos
        self.namespace = namespace 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:microdom.py

示例2: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(
        self, tagName, attributes=None, parentNode=None, filename=None,
        markpos=None, case_insensitive=1, namespace=None
    ):
        Node.__init__(self, parentNode)
        preserve_case = not case_insensitive
        tagName = tagName if preserve_case else tagName.lower()
        unescaped = unescape_dict(attributes or {})

        if case_insensitive:
            self.attributes = InsensitiveDict(unescaped, preserve=preserve_case)
        else:
            self.attributes = unescaped

        self.preserve_case = not case_insensitive
        self.case_insensitive = case_insensitive
        self.endTagName = self.nodeName = self.tagName = tagName
        self._filename = filename
        self._markpos = markpos
        self.namespace = namespace
        self.tag_is_blockelement = tagName in self.BLOCKELEMENTS
        self.tag_is_nice_format = tagName in self.NICEFORMATS
        self.tag_is_singleton = tagName.lower() in self.SINGLETONS 
开发者ID:nerevu,项目名称:riko,代码行数:25,代码来源:microdom.py

示例3: testPreserve

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def testPreserve(self):
        InsensitiveDict=util.InsensitiveDict
        dct=InsensitiveDict({'Foo':'bar', 1:2, 'fnz':{1:2}}, preserve=1)
        self.assertEquals(dct['fnz'], {1:2})
        self.assertEquals(dct['foo'], 'bar')
        self.assertEquals(dct.copy(), dct)
        self.assertEquals(dct['foo'], dct.get('Foo'))
        assert 1 in dct and 'foo' in dct
        self.assertEquals(eval(repr(dct)), dct)
        keys=['Foo', 'fnz', 1]
        for x in keys:
            assert x in dct.keys()
            assert (x, dct[x]) in dct.items()
        self.assertEquals(len(keys), len(dct))
        del dct[1]
        del dct['foo'] 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_util.py

示例4: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(self, tagName, attributes=None, parentNode=None,
                        filename=None, markpos=None,
                        caseInsensitive=1, preserveCase=0,
                 namespace=''):
        Node.__init__(self, parentNode)
        self.preserveCase = preserveCase or not caseInsensitive
        self.caseInsensitive = caseInsensitive
        if not preserveCase:
            tagName = tagName.lower()
        if attributes is None:
            self.attributes = {}
        else:
            self.attributes = attributes
            for k, v in self.attributes.items():
                self.attributes[k] = unescape(v)

        if caseInsensitive:
            self.attributes = InsensitiveDict(self.attributes, 
                                              preserve=preserveCase)

        self.endTagName = self.nodeName = self.tagName = tagName
        self._filename = filename
        self._markpos = markpos
        self.namespace = namespace 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:26,代码来源:microdom.py

示例5: index

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def index(document, filename, chapterReference):
    entries = domhelpers.findElementsWithAttribute(document, "class", "index")
    if not entries:
        return
    i = 0;
    for entry in entries:
        i += 1
        anchor = 'index%02d' % i
        if chapterReference:
            ref = getSectionReference(entry) or chapterReference
        else:
            ref = 'link'
        indexer.addEntry(filename, anchor, entry.attributes['value'], ref)
        # does nodeName even affect anything?
        entry.nodeName = entry.tagName = entry.endTagName = 'a'
        entry.attributes = InsensitiveDict({'name': anchor}) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:tree.py

示例6: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(self, url, method=b'GET', postdata=None, headers=None,
                 agent=b"Twisted PageGetter", timeout=0, cookies=None,
                 followRedirect=True, redirectLimit=20,
                 afterFoundGet=False):
        self.followRedirect = followRedirect
        self.redirectLimit = redirectLimit
        self._redirectCount = 0
        self.timeout = timeout
        self.agent = agent
        self.afterFoundGet = afterFoundGet
        if cookies is None:
            cookies = {}
        self.cookies = cookies
        if headers is not None:
            self.headers = InsensitiveDict(headers)
        else:
            self.headers = InsensitiveDict()
        if postdata is not None:
            self.headers.setdefault(b'Content-Length',
                                    intToBytes(len(postdata)))
            # just in case a broken http/1.1 decides to keep connection alive
            self.headers.setdefault(b"connection", b"close")
        self.postdata = postdata
        self.method = method

        self.setURL(url)

        self.waiting = 1
        self._disconnectedDeferred = defer.Deferred()
        self.deferred = defer.Deferred()
        # Make sure the first callback on the result Deferred pauses the
        # callback chain until the request connection is closed.
        self.deferred.addBoth(self._waitForDisconnect)
        self.response_headers = None 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:client.py

示例7: getChild

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def getChild(self, path, request):
        """
        If this L{File}'s path refers to a directory, return a L{File}
        referring to the file named C{path} in that directory.

        If C{path} is the empty string, return a L{DirectoryLister} instead.
        """
        self.restat(reraise=False)

        if not self.isdir():
            return self.childNotFound

        if path:
            try:
                fpath = self.child(path)
            except filepath.InsecurePath:
                return self.childNotFound
        else:
            fpath = self.childSearchPreauth(*self.indexNames)
            if fpath is None:
                return self.directoryListing()

        if not fpath.exists():
            fpath = fpath.siblingExtensionSearch(*self.ignoredExts)
            if fpath is None:
                return self.childNotFound

        if platformType == "win32":
            # don't want .RPY to be different than .rpy, since that would allow
            # source disclosure.
            processor = InsensitiveDict(self.processors).get(fpath.splitext()[1])
        else:
            processor = self.processors.get(fpath.splitext()[1])
        if processor:
            return resource.IResource(processor(fpath.path, self.registry))
        return self.createSimilarFile(fpath.path)


    # methods to allow subclasses to e.g. decrypt files on the fly: 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:41,代码来源:static.py

示例8: test_preserve

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def test_preserve(self):
        """
        L{util.InsensitiveDict} preserves the case of keys if constructed with
        C{preserve=True}.
        """
        dct = util.InsensitiveDict({'Foo':'bar', 1:2, 'fnz':{1:2}}, preserve=1)
        self.assertEqual(dct['fnz'], {1:2})
        self.assertEqual(dct['foo'], 'bar')
        self.assertEqual(dct.copy(), dct)
        self.assertEqual(dct['foo'], dct.get('Foo'))
        self.assertIn(1, dct)
        self.assertIn('foo', dct)

        result = eval(repr(dct), {
            'dct': dct,
            'InsensitiveDict': util.InsensitiveDict,
            })
        self.assertEqual(result, dct)

        keys=['Foo', 'fnz', 1]
        for x in keys:
            self.assertIn(x, dct.keys())
            self.assertIn((x, dct[x]), dct.items())
        self.assertEqual(len(keys), len(dct))
        del dct[1]
        del dct['foo']
        self.assertEqual(dct.keys(), ['fnz']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:29,代码来源:test_util.py

示例9: test_noPreserve

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def test_noPreserve(self):
        """
        L{util.InsensitiveDict} does not preserves the case of keys if
        constructed with C{preserve=False}.
        """
        dct = util.InsensitiveDict({'Foo':'bar', 1:2, 'fnz':{1:2}}, preserve=0)
        keys=['foo', 'fnz', 1]
        for x in keys:
            self.assertIn(x, dct.keys())
            self.assertIn((x, dct[x]), dct.items())
        self.assertEqual(len(keys), len(dct))
        del dct[1]
        del dct['foo']
        self.assertEqual(dct.keys(), ['fnz']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_util.py

示例10: test_bytes

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def test_bytes(self):
        """
        Bytes keys are case insensitive.
        """
        d = util.InsensitiveDict(preserve=False)
        d[b"Foo"] = 1
        self.assertEqual(d[b"FOO"], 1)
        self.assertEqual(d.keys(), [b"foo"]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_util.py

示例11: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(self, url, method=b'GET', postdata=None, headers=None,
                 agent=b"Twisted PageGetter", timeout=0, cookies=None,
                 followRedirect=True, redirectLimit=20,
                 afterFoundGet=False):
        self.followRedirect = followRedirect
        self.redirectLimit = redirectLimit
        self._redirectCount = 0
        self.timeout = timeout
        self.agent = agent
        self.afterFoundGet = afterFoundGet
        if cookies is None:
            cookies = {}
        self.cookies = cookies
        if headers is not None:
            self.headers = InsensitiveDict(headers)
        else:
            self.headers = InsensitiveDict()
        if postdata is not None:
            self.headers.setdefault(b'Content-Length',
                                    intToBytes(len(postdata)))
            # just in case a broken http/1.1 decides to keep connection alive
            self.headers.setdefault(b"connection", b"close")
        self.postdata = postdata
        self.method = _ensureValidMethod(method)

        self.setURL(url)

        self.waiting = 1
        self._disconnectedDeferred = defer.Deferred()
        self.deferred = defer.Deferred()
        # Make sure the first callback on the result Deferred pauses the
        # callback chain until the request connection is closed.
        self.deferred.addBoth(self._waitForDisconnect)
        self.response_headers = None 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:36,代码来源:client.py

示例12: test_unicode

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def test_unicode(self):
        """
        Unicode keys are case insensitive.
        """
        d = util.InsensitiveDict(preserve=False)
        d[u"Foo"] = 1
        self.assertEqual(d[u"FOO"], 1)
        self.assertEqual(d.keys(), [u"foo"]) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:10,代码来源:test_util.py

示例13: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(self, url, method='GET', postdata=None, headers=None,
                 agent="Twisted PageGetter", timeout=0, cookies=None,
                 followRedirect=True, redirectLimit=20,
                 afterFoundGet=False):
        self.followRedirect = followRedirect
        self.redirectLimit = redirectLimit
        self._redirectCount = 0
        self.timeout = timeout
        self.agent = agent
        self.afterFoundGet = afterFoundGet
        if cookies is None:
            cookies = {}
        self.cookies = cookies
        if headers is not None:
            self.headers = InsensitiveDict(headers)
        else:
            self.headers = InsensitiveDict()
        if postdata is not None:
            self.headers.setdefault('Content-Length', len(postdata))
            # just in case a broken http/1.1 decides to keep connection alive
            self.headers.setdefault("connection", "close")
        self.postdata = postdata
        self.method = method

        self.setURL(url)

        self.waiting = 1
        self.deferred = defer.Deferred()
        self.response_headers = None 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:31,代码来源:client.py

示例14: testNoPreserve

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def testNoPreserve(self):
        InsensitiveDict=util.InsensitiveDict
        dct=InsensitiveDict({'Foo':'bar', 1:2, 'fnz':{1:2}}, preserve=0)
        keys=['foo', 'fnz', 1]
        for x in keys:
            assert x in dct.keys()
            assert (x, dct[x]) in dct.items()
        self.assertEquals(len(keys), len(dct))
        del dct[1]
        del dct['foo'] 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:12,代码来源:test_util.py

示例15: __init__

# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import InsensitiveDict [as 别名]
def __init__(self, url, method='GET', postdata=None, headers=None,
                 agent="Twisted PageGetter", timeout=0, cookies=None,
                 followRedirect=1):
        self.protocol.followRedirect = followRedirect
        self.timeout = timeout
        self.agent = agent

        if cookies is None:
            cookies = {}
        self.cookies = cookies
        if headers is not None:
            self.headers = InsensitiveDict(headers)
        else:
            self.headers = InsensitiveDict()
        if postdata is not None:
            self.headers.setdefault('Content-Length', len(postdata))
            # just in case a broken http/1.1 decides to keep connection alive
            self.headers.setdefault("connection", "close")
        self.postdata = postdata
        self.method = method

        self.setURL(url)

        self.waiting = 1
        self.deferred = defer.Deferred()
        self.response_headers = None 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:28,代码来源:client.py


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