from __future__ import absolute_import, division, print_function, with_statement
+import calendar
import collections
import datetime
+import email.utils
import numbers
import re
import time
>>> format_timestamp(1359312200)
'Sun, 27 Jan 2013 18:43:20 GMT'
"""
- if isinstance(ts, (tuple, time.struct_time)):
+ if isinstance(ts, numbers.Real):
pass
+ elif isinstance(ts, (tuple, time.struct_time)):
+ ts = calendar.timegm(ts)
elif isinstance(ts, datetime.datetime):
- ts = ts.utctimetuple()
- elif isinstance(ts, numbers.Real):
- ts = time.gmtime(ts)
+ ts = calendar.timegm(ts.utctimetuple())
else:
raise TypeError("unknown timestamp type: %r" % ts)
- return time.strftime("%a, %d %b %Y %H:%M:%S GMT", ts)
+ return email.utils.formatdate(ts, usegmt=True)
# _parseparam and _parse_header are copied and modified from python2.7's cgi.py
# The original 2.7 version of this code did not correctly support some
from __future__ import absolute_import, division, print_function, with_statement
import gc
+import locale # system locale module, not tornado.locale
import logging
import operator
import textwrap
"e.g. DEBUG_STATS or DEBUG_COLLECTABLE,DEBUG_OBJECTS",
callback=lambda values: gc.set_debug(
reduce(operator.or_, (getattr(gc, v) for v in values))))
+ define('locale', type=str, default=None,
+ callback=lambda x: locale.setlocale(locale.LC_ALL, x))
def configure_ioloop():
kwargs = {}
import binascii
import datetime
+import email.utils
import logging
import os
import re
def test_date_header(self):
response = self.fetch('/')
- header_date = datetime.datetime.strptime(response.headers['Date'],
- "%a, %d %b %Y %H:%M:%S GMT")
+ header_date = datetime.datetime(
+ *email.utils.parsedate(response.headers['Date'])[:6])
self.assertTrue(header_date - datetime.datetime.utcnow() <
datetime.timedelta(seconds=2))
self._headers = httputil.HTTPHeaders({
"Server": "TornadoServer/%s" % tornado.version,
"Content-Type": "text/html; charset=UTF-8",
- "Date": httputil.format_timestamp(time.gmtime()),
+ "Date": httputil.format_timestamp(time.time()),
})
self.set_default_headers()
if (not self.request.supports_http_1_1() and
[tox]
# "-full" variants include optional dependencies, to ensure
# that things work both in a bare install and with all the extras.
-envlist = py27-full, py27-curl, py32-full, pypy, py26, py26-full, py27, py32, py32-utf8, py33, py27-opt, py32-opt, pypy-full, py27-select, py27-monotonic, py33-monotonic, py27-twisted, py27-threadedresolver, py27-twistedresolver, py27-twistedlayered, py27-caresresolver, py32-caresresolver, py27-docs
+envlist = py27-full, py27-curl, py32-full, pypy, py26, py26-full, py27, py32, py32-utf8, py33, py27-opt, py32-opt, pypy-full, py27-select, py27-monotonic, py33-monotonic, py27-twisted, py27-threadedresolver, py27-twistedresolver, py27-twistedlayered, py27-caresresolver, py32-caresresolver, py27-locale, py27-docs
[testenv]
commands = python -m tornado.test.runtests {posargs:}
twisted
commands = python -m tornado.test.runtests --resolver=tornado.platform.caresresolver.CaresResolver {posargs:}
+[testenv:py27-locale]
+basepython = python2.7
+commands = python -m tornado.test.runtests --locale=zh_TW {posargs:}
+
[testenv:pypy-full]
# This configuration works with pypy 1.9. pycurl installs ok but
# curl_httpclient doesn't work. Twisted works most of the time, but