本文整理汇总了Python中twisted.web.template.flattenString函数的典型用法代码示例。如果您正苦于以下问题:Python flattenString函数的具体用法?Python flattenString怎么用?Python flattenString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flattenString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle_windows_windows_pub_POST2
def handle_windows_windows_pub_POST2(request):
cors(request, methods=["GET", "PUT", "OPTIONS"])
request.setHeader("Allow", "GET, PUT, OPTIONS")
json_data = json.loads(request.content.getvalue())
logging.debug(json_data)
logging.debug(request.requestHeaders)
accept_type = request.requestHeaders.getRawHeaders("Accept")[0]
lastrowid = SubscriberDB.insertClient(json_data["uri"], json_data["method"], json_data["accept"], "1")
if not None:
if accept_type == "application/json":
request.setHeader("Content-Type", "application/json; charset=UTF-8")
request.setResponseCode(200)
return str(
'{"id":"%s", "uri":"%s", "method":"%s", "accept":"%s"}'
% (lastrowid, json_data["uri"], json_data["method"], json_data["accept"])
)
elif accept_type == "application/xml":
request.setHeader("Content-Type", "application/xml; charset=UTF-8")
request.setResponseCode(200)
return str(
"<client><id>%s</id><uri>%s</uri><method>%s</method><accept>%s</accept></client>"
% (lastrowid, json_data["uri"], json_data["method"], json_data["accept"])
)
else:
request.write("<!DOCTYPE html>\n")
flattenString(
request, ClientElement(lastrowid, json_data["uri"], json_data["method"], json_data["accept"], "")
).addCallback(request.write)
request.finish()
开发者ID:aruppen,项目名称:xwot-devices,代码行数:29,代码来源:HandlePublisher.py
示例2: handle_windows_windows_pub_clientid_DELETE
def handle_windows_windows_pub_clientid_DELETE(request, clientid):
cors(request, methods=["GET", "PUT", "OPTIONS"])
request.setHeader("Allow", "GET, PUT, OPTIONS")
logging.debug(request.requestHeaders)
accept_type = request.requestHeaders.getRawHeaders("Accept")[0].split()[0]
client = SubscriberDB.getClient(clientid)
SubscriberDB.deleteQuery(clientid)
if not None:
if "application/json" in accept_type:
request.setHeader("Content-Type", "application/json; charset=UTF-8")
request.setResponseCode(200)
return str(
'{"id":"%s", "uri":"%s", "method":"%s", "accept":"%s"}' % (client[0], client[1], client[2], client[3])
)
elif "application/xml" in accept_type:
request.setHeader("Content-Type", "application/xml; charset=UTF-8")
request.setResponseCode(200)
return str(
"<client><id>%s</id><uri>%s</uri><method>%s</method><accept>%s</accept></client>"
% (client[0], client[1], client[2], client[3])
)
else:
request.write("<!DOCTYPE html>\n")
flattenString(request, ClientElement(client[0], client[1], client[2], client[3])).addCallback(request.write)
request.finish()
开发者ID:aruppen,项目名称:xwot-devices,代码行数:25,代码来源:TemperaturePublisherClient.py
示例3: cbResponse
def cbResponse(self, response):
self.proxy_response = response
if 600 <= int(response.code) <= 699:
self.setResponseCode(500)
self.var['errorcode'] = int(response.code) - 600
if self.var['errorcode'] in SOCKS_errors:
return flattenString(self, templates[SOCKS_errors[self.var['errorcode']]]).addCallback(self.contentFinish)
else:
return flattenString(self, templates[SOCKS_errors[0x00]]).addCallback(self.contentFinish)
self.setResponseCode(response.code)
self.processResponseHeaders(response.headers)
if response.length is not 0:
finished = defer.Deferred()
if self.obj.html:
response.deliverBody(BodyStreamer(self.handleFixPart, finished))
finished.addCallback(self.handleFixEnd)
else:
response.deliverBody(BodyStreamer(self.handleForwardPart, finished))
finished.addCallback(self.handleForwardEnd)
return finished
else:
self.contentFinish('')
return defer.succeed
开发者ID:Acidburn0zzz,项目名称:Tor2web-3.0,代码行数:27,代码来源:t2w.py
示例4: test_templateLoaderWithAttributes
def test_templateLoaderWithAttributes(self):
"""
L{StringFormatTemplateLoader.load} will convert a template with
C{%(x)s}-format slots inside attributes into t:attr elements containing
t:slot slots.
"""
class StubElement(Element):
loader = StringFormatTemplateLoader(
lambda: StringIO(
'<test><alpha beta="before %(slot1)s after">inner</alpha>'
'%(other)s</test>'
),
"testRenderHere"
)
@renderer
def testRenderHere(self, request, tag):
return tag.fillSlots(slot1="hello",
other="world")
result = []
flattenString(None, StubElement()).addCallback(result.append)
self.assertEquals(
result,
[
'<test><alpha beta="before hello after">'
'inner</alpha>world</test>'
]
)
开发者ID:eventable,项目名称:CalendarServer,代码行数:28,代码来源:test_outbound.py
示例5: handle_windows_windows_pub_GET2
def handle_windows_windows_pub_GET2(request):
cors(request, methods=["GET", "PUT", "OPTIONS"])
request.setHeader("Allow", "GET, PUT, OPTIONS")
dbclient = SubscriberDB.getAllClients("1")
logging.debug(request.requestHeaders)
accept_type = request.requestHeaders.getRawHeaders("Accept")[0]
clients = ""
if not None:
if accept_type == "application/json":
request.setHeader("Content-Type", "application/json; charset=UTF-8")
request.setResponseCode(200)
for cl in dbclient:
clients += str('{"id":"%s", "uri":"%s", "method":"%s", "accept":"%s"}, ' % (cl[0], cl[1], cl[2], cl[3]))
return str('{"clients": {"client":[%s]}}' % (clients[:-2]))
elif accept_type == "application/xml":
request.setHeader("Content-Type", "application/xml; charset=UTF-8")
request.setResponseCode(200)
for cl in dbclient:
clients += str(
"<client><id>%s</id><uri>%s</uri><method>%s</method><accept>%s</accept></client> "
% (cl[0], cl[1], cl[2], cl[3])
)
return str("<clients>%s</clients>" % (clients))
else:
request.write("<!DOCTYPE html>\n")
flattenString(request, ClientsElement(dbclient)).addCallback(request.write)
request.finish()
开发者ID:aruppen,项目名称:xwot-devices,代码行数:27,代码来源:HandlePublisher.py
示例6: test_stringFormatTemplateLoader
def test_stringFormatTemplateLoader(self):
"""
L{StringFormatTemplateLoader.load} will convert a template with
C{%(x)s}-format slots by converting it to a template with C{<t:slot
name="x" />} slots, and a renderer on the document element named
according to the constructor argument.
"""
class StubElement(Element):
loader = StringFormatTemplateLoader(
lambda: StringIO(
"<test><alpha>%(slot1)s</alpha>%(other)s</test>"
),
"testRenderHere"
)
@renderer
def testRenderHere(self, request, tag):
return tag.fillSlots(slot1="hello",
other="world")
result = []
flattenString(None, StubElement()).addCallback(result.append)
self.assertEquals(
list(result),
["<test><alpha>hello</alpha>world</test>"]
)
开发者ID:eventable,项目名称:CalendarServer,代码行数:25,代码来源:test_outbound.py
示例7: test_templateLoaderTagSoup
def test_templateLoaderTagSoup(self):
"""
L{StringFormatTemplateLoader.load} will convert a template with
C{%(x)s}-format slots into t:slot slots, and render a well-formed output
document, even if the input is malformed (i.e. missing necessary closing
tags).
"""
class StubElement(Element):
loader = StringFormatTemplateLoader(
lambda : StringIO(
'<test><alpha beta="before %(slot1)s after">inner</alpha>'
'%(other)s'
),
"testRenderHere"
)
@renderer
def testRenderHere(self, request, tag):
return tag.fillSlots(slot1="hello",
other="world")
result = []
flattenString(None, StubElement()).addCallback(result.append)
self.assertEquals(result,
['<test><alpha beta="before hello after">'
'inner</alpha>world</test>'])
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:25,代码来源:test_outbound.py
示例8: render_DELETE
def render_DELETE(self, request):
"""Handles DELETE request"""
# TODO implement this
logging.debug(request.requestHeaders)
accept_type = request.requestHeaders.getRawHeaders("Accept")[0]
client = self.__getClient()
self.__deleteQuery()
logging.debug(request.requestHeaders)
accept_type = request.requestHeaders.getRawHeaders("Accept")[0]
client = self.__getClient()
request.setHeader('Access-Control-Allow-Origin', '*')
request.setHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE')
request.setHeader('Access-Control-Allow-Headers', 'x-prototype-version,x-requested-with')
request.setHeader('Access-Control-Max-Age', 2520) # 42 hours
if not None:
if accept_type == "application/json":
request.setHeader("Content-Type", "application/json; charset=UTF-8")
request.setResponseCode(200)
return str('{"id":"%s", "uri":"%s", "method":"%s", "accept":"%s"}' % (client[0], client[1], client[2], client[3]))
elif accept_type == "application/xml":
request.setHeader("Content-Type", "application/xml; charset=UTF-8")
request.setResponseCode(200)
return str('<client><id>%s</id><uri>%s</uri><method>%s</method><accept>%s</accept></client>' % (client[0], client[1], client[2], client[3]))
else:
request.write("<!DOCTYPE html>\n")
flattenString(request, ClientElement(client[0], client[1], client[2], client[3], '')).addCallback(
request.write)
request.finish()
return NOT_DONE_YET
开发者ID:aruppen,项目名称:xwotModelCompiler,代码行数:29,代码来源:publisher_client_skeleton.py
示例9: render_GET
def render_GET(self, request):
def _renderDone(html):
request.write(html)
request.finish()
flattenString(None, SearchElement()).addCallback(_renderDone)
return NOT_DONE_YET
开发者ID:ddormer,项目名称:Querryl,代码行数:7,代码来源:resources.py
示例10: render
def render(self, request):
if request.args:
self.headers = request.getAllHeaders()
img = cgi.FieldStorage(
fp=request.content,
headers=self.headers,
environ={'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': self.headers['content-type'], }
)
out = open(img["upl_file"].filename, 'wb')
out.write(img["upl_file"].value)
out.close()
#print img["upl_file"].name, img["upl_file"].filename, img["upl_file"].type
request.write("<!DOCTYPE html>\n")
request.write("<!DOCTYPE html>\n")
request.write("<html>\n")
request.write("<head>\n")
request.write("<meta charset=\"utf-8\">\n")
request.write("<title></title>\n")
request.write("<meta name=\"description\" content=\"\">\n")
request.write("</head>\n")
request.write("<body>\n")
flattenString(request, element.FileUpload()).addCallback(request.write)
request.write("</body>\n")
request.write("</html>\n")
request.finish()
return NOT_DONE_YET
开发者ID:frontierventures,项目名称:upload_file,代码行数:27,代码来源:server.py
示例11: flattenToFile
def flattenToFile(fobj, page):
fobj.write(DOCTYPE)
err = []
def e(r):
err.append(r.value)
flattenString(None, page).addCallback(fobj.write).addErrback(e)
if err:
raise err[0]
开发者ID:chevah,项目名称:pydoctor,代码行数:8,代码来源:writer.py
示例12: handleError
def handleError(self, failure):
if type(failure.value) is SOCKSError:
self.setResponseCode(404)
self.var['errorcode'] = failure.value.code
if failure.value.code in SOCKS_errors:
return flattenString(self, templates[SOCKS_errors[failure.value.code]]).addCallback(self.contentFinish)
else:
return flattenString(self, templates[SOCKS_errors[0x00]]).addCallback(self.contentFinish)
else:
self.sendError()
开发者ID:Acidburn0zzz,项目名称:Tor2web-3.0,代码行数:10,代码来源:t2w.py
示例13: test_commentEscaping
def test_commentEscaping(self):
"""
The data in a L{Comment} is escaped and mangled in the flattened output
so that the result is a legal SGML and XML comment.
SGML comment syntax is complicated and hard to use. This rule is more
restrictive, and more compatible:
Comments start with <!-- and end with --> and never contain -- or >.
Also by XML syntax, a comment may not end with '-'.
@see: U{http://www.w3.org/TR/REC-xml/#sec-comments}
"""
def verifyComment(c):
self.assertTrue(c.startswith("<!--"), "%r does not start with the comment prefix" % (c,))
self.assertTrue(c.endswith("-->"), "%r does not end with the comment suffix" % (c,))
# If it is shorter than 7, then the prefix and suffix overlap
# illegally.
self.assertTrue(len(c) >= 7, "%r is too short to be a legal comment" % (c,))
content = c[4:-3]
self.assertNotIn("--", content)
self.assertNotIn(">", content)
if content:
self.assertNotEqual(content[-1], "-")
results = []
for c in ["", "foo---bar", "foo---bar-", "foo>bar", "foo-->bar", "----------------"]:
d = flattenString(None, Comment(c))
d.addCallback(verifyComment)
results.append(d)
return gatherResults(results)
开发者ID:vmarkovtsev,项目名称:twisted,代码行数:33,代码来源:test_flatten.py
示例14: test_render
def test_render(self):
'''Rendering IFrameElement produces the HTML SockJS requires.'''
renderDeferred = template.flattenString(
None, R.IFrameElement(SOCKJS_URL_BYTES))
renderDeferred.addCallback(self.assertEqual, STATIC_IFRAME)
return renderDeferred
开发者ID:hhco,项目名称:txdarn,代码行数:7,代码来源:test_resources.py
示例15: test_sourceFragmentElement
def test_sourceFragmentElement(self):
"""
L{_SourceFragmentElement} renders source lines at and around the line
number indicated by a frame object.
"""
element = _SourceFragmentElement(
TagLoader(tags.div(
tags.span(render="lineNumber"),
tags.span(render="sourceLine"),
render="sourceLines")),
self.frame)
source = [
u' \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}message = '
u'"This is a problem"',
u' \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}raise Exception(message)',
u'# Figure out the line number from which the exception will be '
u'raised.',
]
d = flattenString(None, element)
d.addCallback(
self.assertEqual,
''.join([
'<div class="snippet%sLine"><span>%d</span><span>%s</span>'
'</div>' % (
["", "Highlight"][lineNumber == 1],
self.base + lineNumber,
(u" \N{NO-BREAK SPACE}" * 4 + sourceLine).encode(
'utf-8'))
for (lineNumber, sourceLine)
in enumerate(source)]))
return d
开发者ID:ali-hallaji,项目名称:twisted,代码行数:33,代码来源:test_util.py
示例16: render_GET
def render_GET(self, request):
d = flattenString(request, BravoElement(self.services))
def complete_request(html):
request.write(html)
request.finish()
d.addCallback(complete_request)
return NOT_DONE_YET
开发者ID:matejcik,项目名称:bravo,代码行数:7,代码来源:web.py
示例17: render_POST
def render_POST(self, request):
tweet = request.args["tweet"][0]
c.execute("insert into tweets values(?)", (tweet,))
conn.commit()
print request.args
return flattenString(request, IndexElement()).result
开发者ID:quoterman,项目名称:BarsLabPython,代码行数:7,代码来源:controller.py
示例18: render_GET
def render_GET(self, request):
d = flattenString(request, AutomatonStatsElement())
def complete_request(html):
request.write(html)
request.finish()
d.addCallback(complete_request)
return NOT_DONE_YET
开发者ID:EntityReborn,项目名称:bravo,代码行数:7,代码来源:web.py
示例19: render
def render(self, request):
request.write("<!DOCTYPE html>\n")
request.write("<!DOCTYPE html>\n")
request.write("<html>\n")
request.write("<head>\n")
request.write("<meta charset=\"utf-8\">\n")
request.write("<title></title>\n")
request.write("<meta name=\"description\" content=\"\">\n")
request.write("</head>\n")
request.write("<body>\n")
print request.args
#flattenString(request, ExampleElement()).addCallback(request.write)
flattenString(request, element.FileUpload()).addCallback(request.write)
request.write("</body>\n")
request.write("</html>\n")
request.finish()
return NOT_DONE_YET
开发者ID:frontierventures,项目名称:upload_client,代码行数:17,代码来源:server.py
示例20: render_GET
def render_GET(self, request):
"""
Renders self.element
"""
request.write('<!DOCTYPE html>\n')
d = flattenString(request, self.element_from_request(request))
d.addCallback(self._finish_request, request)
return NOT_DONE_YET
开发者ID:racker,项目名称:slogger,代码行数:8,代码来源:view.py
注:本文中的twisted.web.template.flattenString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论