Permalink
Browse files

Add chronological accuracy to Shabbos detection!

  • Loading branch information...
Ben Regenspan
Ben Regenspan committed Dec 22, 2012
1 parent 3e66bd9 commit 0244c15b3aab39a180b4ddc577fe1298e628aab0
Showing with 35 additions and 9 deletions.
  1. +4 −0 README.rst
  2. +13 −0 gunicorn/config.py
  3. +13 −5 gunicorn/http/message.py
  4. +0 −4 gunicorn/util.py
  5. +5 −0 setup.py
View
@@ -53,6 +53,10 @@ that can be used for serving the various supported web frameworks: ``gunicorn``,
Commonly Used Arguments
+++++++++++++++++++++++
* ``--city=CITY`` - Specify the name of your city, or nearest population center.
It is important that this be set in order to correctly determine whether it
currently is or is not Shabbos. City must be one of those listed at
http://packages.python.org/astral/#cities
* ``-c CONFIG, --config=CONFIG`` - Specify the path to a `config file`_
* ``-b BIND, --bind=BIND`` - Specify a server socket to bind. Server sockets
can be any of ``$(HOST)``, ``$(HOST):$(PORT)``, or ``unix:$(PATH)``.
View
@@ -1055,3 +1055,16 @@ class ProxyAllowFrom(Setting):
desc = """\
Front-end's IPs from which allowed accept proxy requests (comma separate).
"""
class City(Setting):
name = "city"
section = "Server Mechanics"
cli = ["--city"]
validator = validate_string
default = "New York"
desc = """\
Name of nearby city to use for sun-up/sun-down calculations.
Must be in list of cities contained in
http://packages.python.org/astral/#astral-v0-6-2
"""
View
@@ -8,14 +8,17 @@
import socket
from errno import ENOTCONN
from astral import Astral
import pytz
from gunicorn.http.unreader import SocketUnreader
from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body
from gunicorn.http.errors import InvalidHeader, InvalidHeaderName, NoMoreData, \
InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion, \
LimitRequestLine, LimitRequestHeaders, UnkosherRequest
from gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest
from gunicorn.six import BytesIO, urlsplit, bytes_to_str
from gunicorn.util import SHABBOS, weekdayname
from gunicorn.util import weekdayname
MAX_REQUEST_LINE = 8190
MAX_HEADERS = 32768
@@ -162,10 +165,15 @@ def get_data(self, unreader, buf, stop=False):
buf.write(data)
def parse(self, unreader):
day_today = weekdayname[datetime.today().weekday()]
if day_today == SHABBOS:
raise UnkosherRequest("I don't work on Shabbos!")
now = datetime.now(pytz.utc)
day_today = weekdayname[now.weekday()]
if day_today in ('Fri', 'Sat',):
a = Astral()
city = a[self.cfg.city]
times = city.sun(date=now, local=False)
if ((day_today == 'Fri' and now > times['sunrise'])
or (day_today == 'Sat' and now < times['sunset'])):
raise UnkosherRequest("I don't work on Shabbos!")
buf = BytesIO()
self.get_data(unreader, buf, stop=True)
View
@@ -44,10 +44,6 @@
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# This is an extremely naive definition of Shabbos
# (TODO: use local sundown)
SHABBOS = 'Sat'
# Server and Date aren't technically hop-by-hop
# headers, but they are in the purview of the
# origin server which the WSGI spec says we should
View
@@ -82,6 +82,11 @@ def run(self):
tests_require = tests_require,
cmdclass = {'test': PyTest},
install_requires=[
'astral==0.6.2',
'pytz==2012h'
],
entry_points="""
[console_scripts]

0 comments on commit 0244c15

Please sign in to comment.