本文整理汇总了Python中twisted.web.http.datetimeToString方法的典型用法代码示例。如果您正苦于以下问题:Python http.datetimeToString方法的具体用法?Python http.datetimeToString怎么用?Python http.datetimeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.http
的用法示例。
在下文中一共展示了http.datetimeToString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def process(self):
"""
Process a request.
"""
# get site from channel
self.site = self.channel.site
# set various default headers
self.setHeader(b'server', version)
self.setHeader(b'date', http.datetimeToString())
# Resource Identification
self.prepath = []
self.postpath = list(map(unquote, self.path[1:].split(b'/')))
try:
resrc = self.site.getResourceFor(self)
if resource._IEncodingResource.providedBy(resrc):
encoder = resrc.getEncoder(self)
if encoder is not None:
self._encoder = encoder
self.render(resrc)
except:
self.processingFailed(failure.Failure())
示例2: test_unmodified
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_unmodified(self):
"""
If a request is made with an I{If-Modified-Since} header value with a
timestamp indicating a time after the last modification of the request
resource, a 304 response is returned along with an empty response body
and no Content-Type header if the application does not set one.
"""
for line in [b"GET / HTTP/1.1",
b"If-Modified-Since: " + http.datetimeToString(100), b""]:
self.channel.dataReceived(line + b'\r\n')
result = self.transport.getvalue()
self.assertEqual(httpCode(result), http.NOT_MODIFIED)
self.assertEqual(httpBody(result), b"")
# Since there SHOULD NOT (RFC 2616, section 10.3.5) be any
# entity-headers, the Content-Type is not set if the application does
# not explicitly set it.
self.assertEqual(httpHeader(result, b"Content-Type"), None)
示例3: process
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def process(self):
"Process a request."
# get site from channel
self.site = self.channel.site
# set various default headers
self.setHeader('server', version)
self.setHeader('date', http.datetimeToString())
self.setHeader('content-type', "text/html")
# Resource Identification
self.prepath = []
self.postpath = map(unquote, string.split(self.path[1:], '/'))
try:
resrc = self.site.getResourceFor(self)
self.render(resrc)
except:
self.processingFailed(failure.Failure())
示例4: test_modified
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_modified(self):
"""
If a request is made with an I{If-Modified-Since} header value with
a timestamp indicating a time before the last modification of the
requested resource, a 200 response is returned along with a response
body containing the resource.
"""
self._modifiedTest(modifiedSince=http.datetimeToString(1))
示例5: test_deprecatedAttributeDateTimeString
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_deprecatedAttributeDateTimeString(self):
"""
twisted.web.server.date_time_string should not be used; instead use
twisted.web.http.datetimeToString directly
"""
server.date_time_string
warnings = self.flushWarnings(
offendingFunctions=[self.test_deprecatedAttributeDateTimeString])
self.assertEqual(len(warnings), 1)
self.assertEqual(warnings[0]['category'], DeprecationWarning)
self.assertEqual(
warnings[0]['message'],
("twisted.web.server.date_time_string was deprecated in Twisted "
"12.1.0: Please use twisted.web.http.datetimeToString instead"))
示例6: testRoundtrip
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def testRoundtrip(self):
for i in range(10000):
time = random.randint(0, 2000000000)
timestr = http.datetimeToString(time)
time2 = http.stringToDatetime(timestr)
self.assertEqual(time, time2)
示例7: process
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def process(self):
"""
Process a request.
Find the addressed resource in this request's L{Site},
and call L{self.render()<Request.render()>} with it.
@see: L{Site.getResourceFor()}
"""
# get site from channel
self.site = self.channel.site
# set various default headers
self.setHeader(b'server', version)
self.setHeader(b'date', http.datetimeToString())
# Resource Identification
self.prepath = []
self.postpath = list(map(unquote, self.path[1:].split(b'/')))
# Short-circuit for requests whose path is '*'.
if self.path == b'*':
self._handleStar()
return
try:
resrc = self.site.getResourceFor(self)
if resource._IEncodingResource.providedBy(resrc):
encoder = resrc.getEncoder(self)
if encoder is not None:
self._encoder = encoder
self.render(resrc)
except:
self.processingFailed(failure.Failure())
示例8: test_modified
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_modified(self):
"""
If a request is made with an I{If-Modified-Since} header value with
a timestamp indicating a time before the last modification of the
requested resource, a 200 response is returned along with a response
body containing the resource.
"""
self._modifiedTest(http.datetimeToString(1))
示例9: test_unmodified
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_unmodified(self):
"""
If a request is made with an I{If-Modified-Since} header value with
a timestamp indicating a time after the last modification of the
request resource, a 304 response is returned along with an empty
response body.
"""
self.channel.lineReceived("If-Modified-Since: %s"
% http.datetimeToString(100))
self.channel.lineReceived('')
result = self.transport.getvalue()
self.failUnlessEqual(httpCode(result), http.NOT_MODIFIED)
self.failUnlessEqual(httpBody(result), "")
示例10: testRoundtrip
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def testRoundtrip(self):
for i in range(10000):
time = random.randint(0, 2000000000)
timestr = http.datetimeToString(time)
time2 = http.stringToDatetime(timestr)
self.assertEquals(time, time2)
示例11: test_modified
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_modified(self):
"""If-Modified-Since cache validator (positive)"""
self.channel.lineReceived("If-Modified-Since: %s"
% http.datetimeToString(1))
self.channel.lineReceived('')
result = self.transport.getvalue()
self.failUnlessEqual(httpCode(result), http.OK)
self.failUnlessEqual(httpBody(result), "correct")
示例12: test_unmodified
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def test_unmodified(self):
"""If-Modified-Since cache validator (negative)"""
self.channel.lineReceived("If-Modified-Since: %s"
% http.datetimeToString(100))
self.channel.lineReceived('')
result = self.transport.getvalue()
self.failUnlessEqual(httpCode(result), http.NOT_MODIFIED)
self.failUnlessEqual(httpBody(result), "")
示例13: datagramReceived
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def datagramReceived(self, datagram, address):
# Broadcast
try:
cmd, headers = parse_http_response(datagram)
_log.debug("ServerBase::Received %s, %s from %r" % (cmd, headers, address, ))
if cmd[0] == 'M-SEARCH' and cmd[1] == '*':
_log.debug("Ignore list %s ignore %s" % (self.ignore_list, address not in self.ignore_list))
# Only reply to our requests
if SERVICE_UUID in headers['st'] and address not in self.ignore_list:
for k, addrs in self._services.items():
for addr in addrs:
# Only tell local about local
if addr[0] == "127.0.0.1" and address[0] != "127.0.0.1":
continue
response = MS_RESP[SERVICE_UUID] % ('%s:%d' % addr, str(time.time()),
k, self._control_uri + "/node/" + self._node_id, datetimeToString())
if "cert" in self._msearches_resp[SERVICE_UUID].keys():
response += "CERTIFICATE: {}\r\n\r\n".format(self._msearches_resp[SERVICE_UUID]["cert"])
_log.debug("ServerBase::Sending response: %s" % repr(response))
delay = random.randint(0, min(5, int(headers['mx'])))
reactor.callLater(delay, self.send_it,
response, address)
elif CA_SERVICE_UUID in headers['st'] and address not in self.ignore_list\
and self._msearches_resp[CA_SERVICE_UUID]["sign"]:
for k, addrs in self._services.items():
for addr in addrs:
# Only tell local about local
if addr[0] == "127.0.0.1" and address[0] != "127.0.0.1":
continue
try:
response = MS_RESP[CA_SERVICE_UUID] % (str(addr),
str(time.time()),
self._control_uri + "/node/" + self._node_id,
datetimeToString())
except Exception as err:
_log.error("Failed to create response, err={}".format(err))
raise
_log.debug("ServerBase::Sending response: %s" % repr(response))
delay = random.randint(0, min(5, int(headers['mx'])))
reactor.callLater(delay, self.send_it,
response, address)
except:
_log.exception("Error datagram received")
示例14: datagramReceived
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import datetimeToString [as 别名]
def datagramReceived(self, datagram, address):
# Broadcast
try:
cmd, headers = parse_http_response(datagram)
_log.debug("ServerBase::Received %s, %s from %r" % (cmd, headers, address, ))
if cmd[0] == 'M-SEARCH' and cmd[1] == '*':
_log.debug("Ignore list %s ignore %s" % (self.ignore_list, address not in self.ignore_list))
# Only reply to our requests
if SERVICE_UUID in headers['st'] and address not in self.ignore_list:
for k, addrs in self._services.items():
for addr in addrs:
# Only tell local about local
if addr[0] == "127.0.0.1" and address[0] != "127.0.0.1":
continue
response = MS_RESP[SERVICE_UUID] % ('%s:%d' % addr, str(time.time()),
k, self._control_uri + "/node/" + self._node_id, datetimeToString())
if "cert" in self._msearches_resp[SERVICE_UUID].keys():
response += "CERTIFICATE: {}\r\n\r\n".format(self._msearches_resp[SERVICE_UUID]["cert"])
_log.debug("ServerBase::Sending response: %s" % repr(response))
delay = random.randint(0, min(5, int(headers['mx'])))
reactor.callLater(delay, self.send_it,
response, address)
elif CA_SERVICE_UUID in headers['st'] and address not in self.ignore_list\
and self._msearches_resp[CA_SERVICE_UUID]["sign"]:
for k, addrs in self._services.items():
for addr in addrs:
# Only tell local about local
if addr[0] == "127.0.0.1" and address[0] != "127.0.0.1":
continue
try:
response = MS_RESP[CA_SERVICE_UUID] % (str(addr),
str(time.time()),
self._control_uri + "/node/" + self._node_id,
datetimeToString())
except Exception as err:
_log.error("Failed to create response, err={}".format(err))
raise
_log.debug("ServerBase::Sending response: %s" % repr(response))
delay = random.randint(0, min(5, int(headers['mx'])))
reactor.callLater(delay, self.send_it,
response, address)
except Exception as err:
_log.exception("SSDP search received, but failed handling, err={}".format(err))