本文整理汇总了Python中twisted.python.util.InsensitiveDict类的典型用法代码示例。如果您正苦于以下问题:Python InsensitiveDict类的具体用法?Python InsensitiveDict怎么用?Python InsensitiveDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InsensitiveDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, url, method='GET', postdata=None, headers=None,
agent="Twisted PageGetter", timeout=0, cookies=None,
followRedirect=1, proxy=None):
self.protocol.followRedirect = followRedirect
self.timeout = timeout
self.agent = agent
self.proxy = proxy
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
示例2: __init__
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._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
示例3: __init__
def __init__(self, initial=None, case_mapping=None):
if case_mapping is None:
case_mapping = CaseMapping.by_name("rfc1459")
elif isinstance(case_mapping, basestring):
case_mapping = CaseMapping.by_name(case_mapping)
self.case_mapping = case_mapping
InsensitiveDict.__init__(self, initial, preserve=1)
示例4: RestClientFactory
class RestClientFactory(protocol.ClientFactory):
protocol = client.HTTPPageGetter
noisy = False
def __init__(self, host, port, path, data, timeout = 60):
self.log = log.getChild('ClientFactory')
self.timeout = timeout
self.agent = "RestClient"
self.headers = InsensitiveDict()
self.headers.setdefault('Content-Length', len(data))
self.headers.setdefault("connection", "close")
self.method = 'POST'
self.url = 'http://' + host + ':' + str(port) + path
self.scheme = 'http'
self.postdata = data
self.host = host
self.port = port
self.path = path
self.waiting = 1
self.deferred = defer.Deferred()
self.response_headers = None
self.cookies = {}
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.url)
def buildProtocol(self, addr):
p = protocol.ClientFactory.buildProtocol(self, addr)
if self.timeout:
timeoutCall = reactor.callLater(self.timeout, p.timeout)
self.deferred.addBoth(self._cancelTimeout, timeoutCall)
return p
def _cancelTimeout(self, result, timeoutCall):
if timeoutCall.active():
timeoutCall.cancel()
return result
def gotHeaders(self, headers):
self.response_headers = headers
def gotStatus(self, version, status):
self.version, self.status = version, status
def page(self, page):
if self.waiting:
self.waiting = 0
self.deferred.callback(page)
def noPage(self, reason):
if self.waiting:
self.waiting = 0
self.deferred.errback(reason)
def clientConnectionFailed(self, _, reason):
if self.waiting:
self.waiting = 0
self.deferred.errback(reason)
示例5: HeaderAwareHTTPClientFactory
class HeaderAwareHTTPClientFactory(client.HTTPClientFactory):
protocol = yourHTTPPageGetter
noisy = False
def __init__(self, url, method='GET', postdata=None, headers=None,
agent="Coherence PageGetter", timeout=0, cookies=None,
followRedirect=True, redirectLimit=20):
self.followRedirect = followRedirect
self.redirectLimit = redirectLimit
self._redirectCount = 0
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._disconnectedDeferred = defer.Deferred()
self.response_headers = None
def buildProtocol(self, addr):
p = protocol.ClientFactory.buildProtocol(self, addr)
p.method = self.method
p.followRedirect = self.followRedirect
if self.timeout:
timeoutCall = reactor.callLater(self.timeout, p.timeout)
self.deferred.addBoth(self._cancelTimeout, timeoutCall)
self._disconnectedDeferred = defer.Deferred()
return p
def page(self, page):
if self.waiting:
self.waiting = 0
self.deferred.callback((page, self.response_headers))
示例6: __init__
def __init__(self, factory, parent):
self.factory = factory
self.nickname = parent.nickname.encode('ascii')
self.realname = parent.realname.encode('ascii')
self.username = parent.ident.encode('ascii')
self.ns_username = parent.username
self.ns_password = parent.password
self.password = parent.server_password.encode('ascii')
self.join_channels = parent.channel_map.keys()
self.users = InsensitiveDict()
self.channels = InsensitiveDict()
self.cap_requests = set()
self.parent = parent
示例7: __init__
def __init__(self, factory, plugin):
self.factory = factory
self.nickname = plugin.nickname.encode('ascii')
self.realname = plugin.realname.encode('ascii')
self.username = plugin.username.encode('ascii')
self.ns_password = plugin.password
self.password = plugin.server_password.encode('ascii')
self.channel = plugin.channel.encode('ascii')
self.console = plugin.console
self.irc_message = plugin.irc_message
self.users = InsensitiveDict()
示例8: __init__
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
示例9: test01_proxy
def test01_proxy(self):
data = '{"type": "PacketPing"}'
headers = InsensitiveDict()
headers.setdefault('Content-Length', len(data))
headers.setdefault("connection", "close")
headers.setdefault("proxy-connection", "foo")
host = '127.0.0.1'
port = 19481
path = '/POKER_REST'
factory = pokerrestclient.PokerProxyClientFactory('POST', path, '1.1', headers, data, MockRequest(), 6, host + ':' + str(port) + path)
reactor.connectTCP(host, port, factory)
factory.deferred.addCallback(self.assertNotEquals, None)
return factory.deferred
示例10: __init__
def __init__(self, host, port, path, data, timeout = 60):
self.timeout = timeout
self.agent = "RestClient"
self.headers = InsensitiveDict()
self.headers.setdefault('Content-Length', len(data))
self.headers.setdefault("connection", "close")
self.method = 'POST'
self.url = 'http://' + host + ':' + str(port) + path
self.postdata = data
self.host = host
self.port = port
self.path = path
self.waiting = 1
self.deferred = defer.Deferred()
self.response_headers = None
self.cookies = {}
示例11: __init__
def __init__(self, factory, plugin):
self.factory = factory
self.nickname = plugin.nickname.encode('ascii')
self.realname = plugin.realname.encode('ascii')
self.username = plugin.ident.encode('ascii')
self.ns_username = plugin.username
self.ns_password = plugin.password
self.password = plugin.server_password.encode('ascii')
self.channel = plugin.channel.encode('ascii')
self.console = plugin.console
self.irc_message = plugin.irc_message
self.irc_action = plugin.irc_action
self.irc_chat_status = plugin.irc_chat_status
self.mangle_username = plugin.mangle_username
self.users = InsensitiveDict()
self.cap_requests = set()
示例12: __init__
def __init__(self, host, port, path, data, timeout=60):
self.timeout = timeout
self.agent = "RestClient"
self.headers = InsensitiveDict()
self.headers.setdefault("Content-Length", len(data))
self.headers.setdefault("connection", "close")
self.method = "POST"
self.url = "http://" + host + ":" + str(port) + path
self.scheme = "http"
self.postdata = data
self.host = host
self.port = port
self.path = path
self.waiting = 1
self.deferred = defer.Deferred()
self.response_headers = None
self.cookies = {}
self._disconnectedDeferred = defer.Deferred()
示例13: __init__
def __init__(self, headers):
self.expires = None
self.mtime = None
self.length = 0
self.start = 0
self.size = 0
self.mimeType = None
headers = InsensitiveDict(headers)
encoding = headers.get("Transfer-Encoding", None)
if encoding == 'chunked':
raise errors.FlumotionError("Chunked transfer not supported")
expires = headers.get("Expires", None)
if expires is not None:
try:
self.expires = http.stringToDatetime(expires)
except:
self.expires = 0
lastmod = headers.get("Last-Modified", None)
if lastmod is not None:
self.mtime = http.stringToDatetime(lastmod)
range = headers.get("Content-Range", None)
length = headers.get("Content-Length", None)
if range is not None:
start, end, total = http.parseContentRange(range)
self.start = start
self.length = total
if length is not None:
self.size = int(length)
else:
self.size = end - start
elif length is not None:
self.length = int(length)
self.size = int(length)
else:
raise errors.FlumotionError("Can't get length/size from headers",
headers)
ctype = headers.get("Content-Type", None)
if ctype is not None:
self.mimeType, _pdict = cgi.parse_header(ctype)
示例14: __init__
def __init__(self, dn, attributes={}):
"""
Initialize the object.
@param dn: Distinguished Name of the object, as a string.
@param attributes: Attributes of the object. A dictionary of
attribute types to list of attribute values.
"""
self._attributes=InsensitiveDict()
self.dn = distinguishedname.DistinguishedName(dn)
for k,vs in attributes.items():
if k not in self._attributes:
self._attributes[k] = []
self._attributes[k].extend(vs)
for k,vs in self._attributes.items():
self._attributes[k] = self.buildAttributeSet(k, vs)
示例15: __init__
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