本文整理汇总了Python中twisted.web.http.datetimeToString函数的典型用法代码示例。如果您正苦于以下问题:Python datetimeToString函数的具体用法?Python datetimeToString怎么用?Python datetimeToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了datetimeToString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setCachingHeadersOnRequest
def setCachingHeadersOnRequest(request, cacheOptions, getTime=time.time):
cacheTime = cacheOptions.cacheTime
setRawHeaders = request.responseHeaders.setRawHeaders
timeNow = getTime()
# Even though twisted.web sets a Date header, set one ourselves to
# make sure that Date + cacheTime == Expires.
setRawHeaders('date', [datetimeToString(timeNow)])
if cacheTime != 0:
isSecure = request.isSecure()
if isSecure and cacheOptions.httpsCachePublic:
privacy = 'public'
elif not isSecure and cacheOptions.httpCachePublic:
privacy = 'public'
else:
privacy = 'private'
setRawHeaders('expires',
[datetimeToString(timeNow + cacheOptions.cacheTime)])
setRawHeaders('cache-control',
['max-age=%d, %s' % (cacheOptions.cacheTime, privacy)])
else:
setRawHeaders('expires', ['-1'])
setRawHeaders('cache-control', ['max-age=0, private'])
开发者ID:ludios,项目名称:Webmagic,代码行数:25,代码来源:untwist.py
示例2: render_start
def render_start(self, request, method):
ip = request.getClientIP()
self.log('RTSPResource.render_start(): client from %s requests %s' % (
ip, method))
self.log('RTSPResource.render_start(): uri %r' % request.path)
self.render_startCSeqDate(request, method)
request.setHeader('Server', SERVER_STRING)
request.delHeader('Content-Type')
# tests for 3gpp
request.setHeader('Last-Modified', http.datetimeToString())
request.setHeader('Cache-Control', 'must-revalidate')
#request.setHeader('x-Accept-Retransmit', 'our-revalidate')
#request.setHeader('x-Accept-Dynamic-Rate', '1')
#request.setHeader('Content-Base', 'rtsp://core.fluendo.com/test.3gpp')
#request.setHeader('Via', 'RTSP/1.0 288f9c2a')
# hacks for Real
if 'Real' in request.received_headers.get('user-agent', ''):
self.debug('Detected Real client, sending specific headers')
# request.setHeader('Public', 'OPTIONS, DESCRIBE, ANNOUNCE, PLAY,
# SETUP, GET_PARAMETER, SET_PARAMETER, TEARDOWN')
# Public seems to be the same as allowed-methods, and real clients
# seem to respect SET_PARAMETER not listed here
request.setHeader(
'Public',
'OPTIONS, DESCRIBE, ANNOUNCE, PLAY, SETUP, TEARDOWN')
# without a RealChallenge1, clients don't even go past OPTIONS
request.setHeader('RealChallenge1',
'28d49444034696e1d523f2819b8dcf4c')
开发者ID:flyapen,项目名称:UgFlu,代码行数:31,代码来源:rtsp.py
示例3: process
def process(self):
"Process a request."
# get site from channel
self.site = self.channel.site
# set various default headers
self.setHeader('server', SERVER_ID)
self.setHeader('date', http.datetimeToString())
self.setHeader('content-type', "text/html")
# Resource Identification
self.prepath = []
self.postpath = map(unquote, self.path[1:].split('/'))
try:
def deferred_rendering(r):
self.render(r)
resrc = self.site.getResourceFor(self)
if isinstance(resrc, defer.Deferred):
resrc.addCallback(deferred_rendering)
resrc.addErrback(self.processingFailed)
else:
self.render(resrc)
except:
self.processingFailed(failure.Failure())
开发者ID:AndyThirtover,项目名称:wb_gateway,代码行数:26,代码来源:utils.py
示例4: datagramReceived
def datagramReceived(self, datagram, address):
# Broadcast
try:
cmd, headers = parse_http_response(datagram)
_log.debug("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 % ('%s:%d' % addr, str(time.time()),
k, datetimeToString())
_log.debug("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")
开发者ID:Tim-SHOOSAN,项目名称:calvin-base,代码行数:26,代码来源:service_discovery_ssdp.py
示例5: _cb_render_GET
def _cb_render_GET(self, chunk, request):
# If the request finished already, then don't even bother preparing
# the image.
if request._disconnected:
return
request.setHeader('content-type', 'image/png')
i = Image.new("RGB", (16, 16))
pbo = i.load()
for x, z in product(xrange(16), repeat=2):
y = chunk.height_at(x, z)
block = chunk.blocks[x, z, y]
if block in block_colors:
color = block_colors[block]
if isinstance(color, tuple):
# Switch colors depending on height.
color = color[y / 5 % len(color)]
else:
color = default_color
pbo[x, z] = names_to_colors[color]
data = StringIO()
i.save(data, "PNG")
# cache image for 5 minutes
request.setHeader("Cache-Control", "public, max-age=360")
request.setHeader("Expires", datetimeToString(time.time() + 360))
request.write(data.getvalue())
request.finish()
开发者ID:gwylim,项目名称:bravo,代码行数:28,代码来源:web.py
示例6: process
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())
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:25,代码来源:server.py
示例7: datagramReceived
def datagramReceived(self, datagram, address):
# Broadcast
try:
cmd, headers = parse_http_response(datagram)
_log.debug("Received %s, %s from %r" % (cmd, headers, address, ))
if cmd[0] == 'M-SEARCH' and cmd[1] == '*':
# Only reply to our requests
if SERVICE_UUID in headers['st']:
for k, v in self._services.items():
addr = v
# Ignore 0.0.0.0, use the ip we where contacted on
if addr[0] == "0.0.0.0":
addr = (address[0], addr[1])
response = MS_RESP % ('%s:%d' % addr, str(time.time()),
k, datetimeToString())
delay = random.randint(0, min(5, int(headers['mx'])))
reactor.callLater(delay, self.send_it,
response, address)
except:
_log.exception("Error datagram received")
开发者ID:MalmoUniversity-DA366A,项目名称:calvin-base,代码行数:25,代码来源:service_discovery_ssdp.py
示例8: process
def process(self):
"Process a request."
# get site from channel
self.site = self.channel.site
# set various default headers
self.setHeader('server', SERVER_ID)
self.setHeader('date', http.datetimeToString())
self.setHeader('content-type', "text/html")
# Resource Identification
url = self.path
#remove trailing "/", if ever
url = url.rstrip('/')
_scheme, _netloc, path, _query, _fragment = urlsplit(url)
self.prepath = []
if path == "":
self.postpath = []
else:
self.postpath = map(unquote, path[1:].split('/'))
try:
def deferred_rendering(r):
self.render(r)
resrc = self.site.getResourceFor(self)
if resrc is None:
self.setResponseCode(http.NOT_FOUND, "Error: No resource for path %s" % path)
self.finish()
elif isinstance(resrc, defer.Deferred):
resrc.addCallback(deferred_rendering)
resrc.addErrback(self.processingFailed)
else:
self.render(resrc)
except:
self.processingFailed(failure.Failure())
开发者ID:DBrianKimmel,项目名称:coherence,代码行数:32,代码来源:utils.py
示例9: test_unmodified
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), "")
开发者ID:mrader11,项目名称:vodafone-mobile-connect,代码行数:7,代码来源:test_web.py
示例10: test_modified
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")
开发者ID:mrader11,项目名称:vodafone-mobile-connect,代码行数:7,代码来源:test_web.py
示例11: createSession
def createSession(self, ctx, segments):
"""Create a new session for this request, and redirect back to the path
given by segments."""
request = inevow.IRequest(ctx)
newCookie = _sessionCookie()
if self.useCookies:
if self.secureCookies and request.isSecure():
secure = True
else:
secure = False
if self.persistentCookies and self.sessionLifetime:
expires = http.datetimeToString(time.time() + self.sessionLifetime)
else:
expires = None
request.addCookie(self.cookieKey, newCookie,
path="/%s" % '/'.join(request.prepath),
secure=secure, expires=expires)
sz = self.sessions[newCookie] = self.sessionFactory(self, newCookie)
sz.args = request.args
sz.fields = getattr(request, 'fields', {})
sz.content = request.content
sz.method = request.method
sz.received_headers = request.received_headers
sz.checkExpired()
return urlToChild(ctx, SESSION_KEY+newCookie, *segments)
开发者ID:comfuture,项目名称:numbler,代码行数:27,代码来源:guard.py
示例12: renderHTTP
def renderHTTP(self, ctx):
"""
Checks the file modification time from the client against the
modification time on the server. Also checks the file cache to
see if it needs to be refreshed.
"""
request = inevow.IRequest(ctx)
self._check_cache()
temp_date = request.getHeader("If-Modified-Since")
if temp_date:
parsed_date = parsedate_tz(temp_date)
if parsed_date:
client_time = mktime_tz(parsed_date)
else:
client_time = 0
else:
client_time = 0
##
## Check to see if the file has been modified since the client's mtime
##
request.setHeader('content-type', "text/javascript; charset=UTF-8")
if self.mtime > client_time:
## New version available.
request.setLastModified(self.mtime)
stamp = datetime.now() + timedelta(365)
request.setHeader('expires', datetimeToString(mktime(stamp.timetuple())))
request.setHeader('content-length', str(len(self.data)))
request.setHeader('content-type', "text/javascript; charset=UTF-8")
return self.data
else:
request.setResponseCode(http.NOT_MODIFIED)
return "OK"
开发者ID:kkszysiu,项目名称:zoto-server,代码行数:32,代码来源:__init__.py
示例13: _setRequestHeaders
def _setRequestHeaders(self, request):
content = self.streamer.get_content_type()
request.setHeader('Server', HTTP_SERVER)
request.setHeader('Date', http.datetimeToString())
request.setHeader('Connection', 'close')
request.setHeader('Cache-Control', 'no-cache')
request.setHeader('Cache-Control', 'private')
request.setHeader('Content-type', content)
开发者ID:offlinehacker,项目名称:flumotion,代码行数:8,代码来源:resources.py
示例14: test_modified
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))
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:8,代码来源:test_web.py
示例15: __init__
def __init__(self):
self.data = [
'HTTP/1.1 101 FYI I am not a webserver\r\n',
'Server: MambaWebSocketWrapper/1.0\r\n',
'Date: {}\r\n'.format(datetimeToString()),
'Upgrade: WebSocket\r\n',
'Connection: Upgrade\r\n'
]
开发者ID:PyMamba,项目名称:mamba-framework,代码行数:8,代码来源:websocket.py
示例16: _setRequestHeaders
def _setRequestHeaders(self, request, content=None, allow_cache=False):
content = content or self.streamer.get_content_type()
request.setHeader('Server', self.HTTP_SERVER)
request.setHeader('Date', http.datetimeToString())
if not allow_cache:
request.setHeader('Cache-Control', 'no-cache')
request.setHeader('Cache-Control', 'private')
request.setHeader('Content-type', content)
开发者ID:ApsOps,项目名称:flumotion-orig,代码行数:8,代码来源:resources.py
示例17: rememberEmail
def rememberEmail(ctx, address):
remembered = IEmailAddress(ctx)
if remembered != address:
request = inevow.IRequest(ctx)
expires = http.datetimeToString(time.time() + 60*60*24*365)
request.addCookie(COOKIE_KEY, address,
path="/", #TODO path="/%s" % '/'.join(request.prepath),
##TODO secure=False,
expires=expires)
开发者ID:tv42,项目名称:eocmanage,代码行数:9,代码来源:common.py
示例18: processWebSocket
def processWebSocket(self):
"""
Process a specific web socket request.
"""
self.site = self.channel.site
self.setHeader('server', version)
self.setHeader('date', datetimeToString())
self.prepath = []
self.postpath = map(unquote, self.path[1:].split('/'))
self.renderWebSocket()
开发者ID:popazerty,项目名称:beyonwiz-4.1,代码行数:10,代码来源:websocket.py
示例19: renderHTTP
def renderHTTP(self, ctx):
request = inevow.IRequest(ctx)
request.setHeader("content-type", self.type)
request.setHeader("content-length", str(len(self.data)))
if self.expires is not None:
request.setHeader("expires",
http.datetimeToString(self.time() + self.expires))
if request.method == "HEAD":
return ''
return self.data
开发者ID:twisted,项目名称:nevow,代码行数:10,代码来源:static.py
示例20: render_startCSeqDate
def render_startCSeqDate(self, request, method):
"""
Set CSeq and Date on response to given request.
This should be done even for errors.
"""
cseq = request.getHeader('CSeq')
if cseq == None:
cseq = 0
request.setHeader('CSeq', cseq)
request.setHeader('Date', http.datetimeToString())
开发者ID:popazerty,项目名称:beyonwiz-4.1,代码行数:10,代码来源:rtsp.py
注:本文中的twisted.web.http.datetimeToString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论