本文整理匯總了Python中Params.json_write方法的典型用法代碼示例。如果您正苦於以下問題:Python Params.json_write方法的具體用法?Python Params.json_write怎麽用?Python Params.json_write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Params
的用法示例。
在下文中一共展示了Params.json_write方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set
# 需要導入模塊: import Params [as 別名]
# 或者: from Params import json_write [as 別名]
def set(self, path, srcrefs, headers):
assert path and srcrefs and headers, \
(path, srcrefs, headers)
assert isinstance(path, basestring) and \
isinstance(srcrefs, list) and \
isinstance(headers, dict)
mt = headers.get('Content-Type', None)
cs = None
if mt:
p = mt.find(';')
if p > -1:
match = re.search("charset=([^;]+)", mt[p:].lower())
mt = mt[:p].strip()
if match:
cs = match.group(1).strip()
ln = headers.get('Content-Language',[])
if ln: ln = ln.split(',')
srcref = headers.get('Content-Location', None)
#if srcref and srcref not in srcrefs:
# srcrefs += [srcref]
features = {}
metadata = {}
for hd in ('Content-Type', 'Content-Language', 'Content-MD5',
'Content-Location', 'Content-Length', 'Content-Encoding',
'ETag', 'Last-Modified', 'Date', 'Vary', 'TCN',
'Cache', 'Expires'):
if hd in headers:
metadata[hd] = headers[hd]
self.__be[path] = Params.json_write((srcrefs, mt, cs, ln, metadata, features))
self.__be.sync()
示例2: control_proxy
# 需要導入模塊: import Params [as 別名]
# 或者: from Params import json_write [as 別名]
def control_proxy(self, status, protocol, request):
head, body = request.recvbuf().split( '\r\n\r\n', 1 )
req = {
'args': request.headers
}
if body:
try:
req = Params.json_read(body)
except:
#print "JSON: ",request.recvbuf()
raise
# TODO: echos only
self.prepare_response(status,
Params.json_write(req), mime="application/json")
示例3: serve_descriptor
# 需要導入模塊: import Params [as 別名]
# 或者: from Params import json_write [as 別名]
def serve_descriptor(self, status, protocol, request):
q = urlparse.urlparse( request.url[3] )[4]
url = urlparse.urlparse(urllib.unquote(q[4:]))
if ':' in url[1]:
hostinfo = url[1].split(':')
hostinfo[1] = int(hostinfo[1])
else:
hostinfo = url[1], 80
cache = Resource.get_cache(hostinfo, url[2][1:])
descriptors = Resource.get_backend()
if cache.path in descriptors:
descr = descriptors[cache.path]
self.prepare_response(status,
Params.json_write(descr),
mime='application/json')
else:
self.prepare_response("404 No Data", "No data for %s %s %s %s"%request.url)