Skip to content

Commit

Permalink
Packages migration to latest version. Code adjust.
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbres committed Sep 29, 2022
1 parent a094b3a commit 335a3f0
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 67 deletions.
7 changes: 3 additions & 4 deletions api/management/commands/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ class Command(BaseCommand):

def handle(self, *args, **options):
inboxes = expire_inboxes()
print 'expired %d inboxes' % inboxes
print('expired %d inboxes' % inboxes)

# expire items of remaining inboxes
items, inboxes = expire_items()
print 'expired %d items in %d active inboxes' % (items,
inboxes)
print('expired %d items in %d active inboxes' % (items, inboxes))

# we expect this command to run once per minute, so to achieve
# a 10 second interval, we'll do 6 iterations within a
Expand All @@ -21,4 +20,4 @@ def handle(self, *args, **options):
if n != 0:
time.sleep(10)
requests = expire_requests()
print 'expired %d requests' % requests
print('expired %d requests' % requests)
4 changes: 2 additions & 2 deletions api/redis_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def _get_redis(self):

@staticmethod
def _gen_id():
return ''.join(random.choice(string.letters + string.digits) for n in xrange(8))
return ''.join(random.choice(string.ascii_letters + string.digits) for n in range(8))

@staticmethod
def _validate_id(id):
for c in id:
if c not in string.letters and c not in string.digits and c not in '_-@':
if c not in string.ascii_letters and c not in string.digits and c not in '_-@':
raise InvalidId('id contains invalid character: %s' % c)

@staticmethod
Expand Down
18 changes: 9 additions & 9 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.conf.urls import url
from django.urls import re_path
from . import views

urlpatterns = [
url(r'^$', views.root, name='root'),
url(r'^create/$', views.create, name='create'),
url(r'^i/(?P<inbox_id>[^/]+)/$', views.inbox, name='inbox'),
url(r'^i/(?P<inbox_id>[^/]+)/refresh/$', views.refresh, name='refresh'),
url(r'^i/(?P<inbox_id>[^/]+)/respond/(?P<item_id>[^/]+)/$', views.respond, name='respond'),
url(r'^i/(?P<inbox_id>[^/]+)/in/', views.hit, name='hit'),
url(r'^i/(?P<inbox_id>[^/]+)/items/$', views.items, name='items'),
url(r'^i/(?P<inbox_id>[^/]+)/stream/$', views.stream, name='stream')
re_path(r'^$', views.root, name='root'),
re_path(r'^create/$', views.create, name='create'),
re_path(r'^i/(?P<inbox_id>[^/]+)/$', views.inbox, name='inbox'),
re_path(r'^i/(?P<inbox_id>[^/]+)/refresh/$', views.refresh, name='refresh'),
re_path(r'^i/(?P<inbox_id>[^/]+)/respond/(?P<item_id>[^/]+)/$', views.respond, name='respond'),
re_path(r'^i/(?P<inbox_id>[^/]+)/in/', views.hit, name='hit'),
re_path(r'^i/(?P<inbox_id>[^/]+)/items/$', views.items, name='items'),
re_path(r'^i/(?P<inbox_id>[^/]+)/stream/$', views.stream, name='stream')
]
2 changes: 1 addition & 1 deletion api/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from gripcontrol import HttpResponseFormat
from django_grip import publish
import redis_ops
from . import redis_ops

def _setting(name, default):
v = getattr(settings, name, None)
Expand Down
10 changes: 5 additions & 5 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound, HttpResponseNotAllowed
from gripcontrol import Channel, HttpResponseFormat, HttpStreamFormat
from django_grip import set_hold_longpoll, set_hold_stream, publish
import redis_ops
from . import redis_ops

def _setting(name, default):
v = getattr(settings, name, None)
Expand Down Expand Up @@ -73,7 +73,7 @@ def _req_to_item(req):
content_type = req.META.get('CONTENT_TYPE')
if content_type:
raw_headers.append(('CONTENT_TYPE', content_type))
for k, v in req.META.iteritems():
for k, v in req.META.items():
if k.startswith('HTTP_'):
raw_headers.append((k[5:], v))
# undjangoify the header names
Expand Down Expand Up @@ -130,7 +130,6 @@ def create(req):
host = req.META.get('HTTP_HOST')
if not host:
return HttpResponseBadRequest('Bad Request: No \'Host\' header\n')

inbox_id = req.POST.get('id')
if inbox_id is not None and len(inbox_id) > 64:
return HttpResponseBadRequest('Bad Request: Id length must not exceed 64\n')
Expand All @@ -140,7 +139,6 @@ def create(req):
ttl = int(ttl)
if ttl is None:
ttl = 3600

response_mode = req.POST.get('response_mode')
if not response_mode:
response_mode = 'auto'
Expand Down Expand Up @@ -268,7 +266,7 @@ def respond(req, inbox_id, item_id):

def hit(req, inbox_id):
if len(req.grip.last) > 0:
for channel, last_id in req.grip.last.iteritems():
for channel, last_id in req.grip.last.items():
break
set_hold_longpoll(req, Channel(channel, last_id))
return HttpResponse('Service Unavailable\n', status=503, content_type='text/html')
Expand Down Expand Up @@ -401,6 +399,7 @@ def items(req, inbox_id):
out['last_cursor'] = last_id
out_items = list()
for i in items:
print('4')
out_items.append(_convert_item(i, not db.request_is_pending(inbox_id, i['id'])))
out['items'] = out_items

Expand All @@ -423,6 +422,7 @@ def items(req, inbox_id):
out['last_cursor'] = last_id
out_items = list()
for i in items:
print('5')
out_items.append(_convert_item(i, not db.request_is_pending(inbox_id, i['id'])))
out['items'] = out_items
return HttpResponse(json.dumps(out) + '\n', content_type='application/json')
Expand Down
70 changes: 38 additions & 32 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
alabaster==0.7.12
Babel==2.6.0
certifi==2019.3.9
chardet==3.0.4
dj-database-url==0.3.0
asgiref==3.5.2
async-timeout==4.0.2
Babel==2.10.3
certifi==2022.9.24
charset-normalizer==2.1.1
Deprecated==1.2.13
dj-static==0.0.6
Django==1.11.23
django-dotenv==1.4.1
django-grip==2.0.1
django-hosts==3.0
docutils==0.14
gripcontrol==3.3.1
gunicorn==19.9.0
idna==2.8
imagesize==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
packaging==19.0
pkg-resources==0.0.0
pubcontrol==2.4.2
Pygments==2.3.1
PyJWT==1.7.1
pyparsing==2.3.1
pytz==2018.9
Django==4.1.1
django-dotenv==1.4.2
django-grip==3.2.0
django-hosts==5.1
docutils==0.19
gripcontrol==4.1.0
idna==3.4
imagesize==1.4.1
Jinja2==3.1.2
MarkupSafe==2.1.1
packaging==21.3
pubcontrol==3.3.0
Pygments==2.13.0
PyJWT==2.5.0
pyparsing==3.0.9
pytz==2022.2.1
redis==2.10.3
requests==2.21.0
six==1.12.0
snowballstemmer==1.2.1
Sphinx==1.8.5
sphinxcontrib-websupport==1.1.0
static3==0.6.1
typing==3.6.6
urllib3==1.24.2
Werkzeug==0.15.3
whitenoise==1.0.6
requests==2.28.1
six==1.16.0
snowballstemmer==2.2.0
Sphinx==5.2.2
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sqlparse==0.4.3
static3==0.7.0
urllib3==1.26.12
Werkzeug==2.2.2
whitenoise==6.2.0
wrapt==1.14.1
3 changes: 2 additions & 1 deletion server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'django_hosts.middleware.HostsRequestMiddleware',
'django_grip.GripMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'api.middleware.OptionsMiddleware',
Expand Down Expand Up @@ -125,7 +126,7 @@
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

LOGGING = {
'version': 1,
Expand Down
6 changes: 3 additions & 3 deletions server/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import include, url
from django.urls import include, re_path

urlpatterns = [
url(r'', include('website.urls')),
url(r'^api/', include('api.urls'))
re_path(r'', include('website.urls')),
re_path(r'^api/', include('api.urls'))
]
2 changes: 1 addition & 1 deletion server/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.conf import settings

if not settings.DEBUG:
from whitenoise.django import DjangoWhiteNoise
from whitenoise import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())
else:
from dj_static import Cling
Expand Down
2 changes: 1 addition & 1 deletion website/templates/website/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}<!DOCTYPE html>
{% load static %}<!DOCTYPE html>
<html>
<head>
<title>WebhookInbox{% block title_suffix %}{% endblock %}</title>
Expand Down
2 changes: 1 addition & 1 deletion website/templates/website/home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'website/base.html' %}
{% load staticfiles %}
{% load static %}

{% block head_extra %}
{% if not debug and ga_id %}
Expand Down
2 changes: 1 addition & 1 deletion website/templates/website/l2_base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'website/base.html' %}
{% load staticfiles %}
{% load static %}

{% block body_main %}
<div class="header header80 container fixed-height">
Expand Down
2 changes: 1 addition & 1 deletion website/templates/website/view.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'website/base.html' %}
{% load staticfiles %}
{% load static %}

{% block title_suffix %} Viewer{% endblock %}

Expand Down
10 changes: 5 additions & 5 deletions website/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf.urls import url
from django.urls import re_path
from . import views

urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^view/(?P<inbox_id>[^/]+)/$', views.view, name='view'),
url(r'^about/$', views.about, name='about'),
url(r'^contact/$', views.contact, name='contact')
re_path(r'^$', views.home, name='home'),
re_path(r'^view/(?P<inbox_id>[^/]+)/$', views.view, name='view'),
re_path(r'^about/$', views.about, name='about'),
re_path(r'^contact/$', views.contact, name='contact')
]

0 comments on commit 335a3f0

Please sign in to comment.