Skip to content

Commit de30a83

Browse files
django-botfelixxm
authored andcommitted
Reformatted code with Black.
1 parent b644f85 commit de30a83

File tree

5 files changed

+69
-60
lines changed

5 files changed

+69
-60
lines changed

DjangoPlugin/setup.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from setuptools import setup
22

33
setup(
4-
name='Django Plugin',
5-
version='1.1',
6-
packages=['tracdjangoplugin'],
4+
name="Django Plugin",
5+
version="1.1",
6+
packages=["tracdjangoplugin"],
77
include_package_data=True,
8-
entry_points = {
9-
'trac.plugins': ['tracdjangoplugin = tracdjangoplugin']
10-
}
8+
entry_points={"trac.plugins": ["tracdjangoplugin = tracdjangoplugin"]},
119
)

DjangoPlugin/tracdjangoplugin/__init__.py

+29-22
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ class CustomWikiModule(WikiModule):
1212
"""
1313

1414
def get_active_navigation_item(self, req):
15-
pagename = req.args.get('page')
16-
if pagename == 'Reports':
17-
return 'custom_reports'
18-
return 'wiki'
15+
pagename = req.args.get("page")
16+
if pagename == "Reports":
17+
return "custom_reports"
18+
return "wiki"
1919

2020

2121
class CustomNewTicket(Component):
2222
"""Hide certain options for the new ticket page"""
23+
2324
implements(IRequestFilter, IRequestHandler)
24-
hidden_fields = frozenset(['stage', 'needs_tests', 'needs_docs',
25-
'needs_better_patch'])
25+
hidden_fields = frozenset(
26+
["stage", "needs_tests", "needs_docs", "needs_better_patch"]
27+
)
2628

2729
def match_request(self, req):
28-
return req.path_info == '/simpleticket'
30+
return req.path_info == "/simpleticket"
2931

3032
def process_request(self, req):
3133
req.redirect(req.href.newticket())
@@ -36,26 +38,32 @@ def pre_process_request(self, req, handler):
3638
def post_process_request(self, req, template, data, content_type):
3739
if data is None:
3840
data = {}
39-
if req.path_info == '/newticket' and not data.get('preview_mode', False):
40-
simple_interface = 'TICKET_BATCH_MODIFY' not in req.perm
41-
if simple_interface and 'fields' in data:
42-
data['fields'] = [f for f in data['fields']
43-
if f['name'] not in self.hidden_fields]
44-
data['simple_interface'] = simple_interface
45-
template = 'custom_ticket.html'
41+
if req.path_info == "/newticket" and not data.get("preview_mode", False):
42+
simple_interface = "TICKET_BATCH_MODIFY" not in req.perm
43+
if simple_interface and "fields" in data:
44+
data["fields"] = [
45+
f for f in data["fields"] if f["name"] not in self.hidden_fields
46+
]
47+
data["simple_interface"] = simple_interface
48+
template = "custom_ticket.html"
4649
return template, data, content_type
4750

4851

4952
class CustomNavigationBar(Component):
5053
"""Implements some more items for the navigation bar."""
54+
5155
implements(INavigationContributor)
5256

5357
def get_active_navigation_item(self, req):
54-
return ''
58+
return ""
5559

5660
def get_navigation_items(self, req):
5761
return [
58-
('mainnav', 'custom_reports', Markup('<a href="%s">Reports</a>' % req.href.wiki('Reports'))),
62+
(
63+
"mainnav",
64+
"custom_reports",
65+
Markup('<a href="%s">Reports</a>' % req.href.wiki("Reports")),
66+
),
5967
]
6068

6169

@@ -68,14 +76,13 @@ def get_navigation_items(self, req):
6876
from genshi.builder import tag
6977

7078
class GitHubBrowserWithSVNChangesets(GitHubBrowser):
71-
72-
def _format_changeset_link(self, formatter, ns, chgset, label,
73-
fullmatch=None):
79+
def _format_changeset_link(self, formatter, ns, chgset, label, fullmatch=None):
7480
# Dead-simple version for SVN changesets
7581
if chgset.isnumeric():
76-
href = formatter.href.changeset(chgset, None, '/')
82+
href = formatter.href.changeset(chgset, None, "/")
7783
return tag.a(label, class_="changeset", href=href)
7884

7985
# Fallback to the default implemntation
80-
return (super(GitHubBrowserWithSVNChangesets,self)
81-
._format_changeset_link(formatter, ns, chgset, label, fullmatch))
86+
return super(GitHubBrowserWithSVNChangesets, self)._format_changeset_link(
87+
formatter, ns, chgset, label, fullmatch
88+
)

DjangoPlugin/tracdjangoplugin/djangoauth.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,26 @@
3838

3939

4040
class DjangoAuth:
41-
42-
login_url = getattr(settings, 'BASIC_AUTH_LOGIN_URL', '/login')
43-
message = getattr(settings, 'BASIC_AUTH_MESSAGE', "Authorization required.")
44-
message_type = getattr(settings, 'BASIC_AUTH_MESSAGE_TYPE', 'text/plain')
45-
realm = getattr(settings, 'BASIC_AUTH_REALM', "Authenticate")
41+
login_url = getattr(settings, "BASIC_AUTH_LOGIN_URL", "/login")
42+
message = getattr(settings, "BASIC_AUTH_MESSAGE", "Authorization required.")
43+
message_type = getattr(settings, "BASIC_AUTH_MESSAGE_TYPE", "text/plain")
44+
realm = getattr(settings, "BASIC_AUTH_REALM", "Authenticate")
4645

4746
def __init__(self, application):
4847
self.application = application
4948

5049
def __call__(self, environ, start_response):
51-
5250
try:
5351
if get_path_info(environ) == self.login_url:
5452
username = self.process_authorization(environ)
5553
if username is None:
56-
start_response('401 Unauthorized', [
57-
('Content-Type', self.message_type),
58-
('WWW-Authenticate', 'Basic realm="%s"' % self.realm),
59-
])
54+
start_response(
55+
"401 Unauthorized",
56+
[
57+
("Content-Type", self.message_type),
58+
("WWW-Authenticate", 'Basic realm="%s"' % self.realm),
59+
],
60+
)
6061
return [self.message]
6162
finally:
6263
close_old_connections()
@@ -66,24 +67,24 @@ def __call__(self, environ, start_response):
6667
@staticmethod
6768
def process_authorization(environ):
6869
# Don't override authentication information set by another component.
69-
remote_user = environ.get('REMOTE_USER')
70+
remote_user = environ.get("REMOTE_USER")
7071
if remote_user is not None:
7172
return
7273

73-
authorization = environ.get('HTTP_AUTHORIZATION')
74+
authorization = environ.get("HTTP_AUTHORIZATION")
7475
if authorization is None:
7576
return
7677

77-
if six.PY3: # because fuck you PEP 3333.
78-
authorization = authorization.encode('iso-8859-1').decode('utf-8')
78+
if six.PY3: # because fuck you PEP 3333.
79+
authorization = authorization.encode("iso-8859-1").decode("utf-8")
7980

80-
method, _, credentials = authorization.partition(' ')
81-
if not method.lower() == 'basic':
81+
method, _, credentials = authorization.partition(" ")
82+
if not method.lower() == "basic":
8283
return
8384

8485
try:
8586
credentials = b64decode(credentials.strip())
86-
username, _, password = credentials.partition(':')
87+
username, _, password = credentials.partition(":")
8788
except Exception:
8889
return
8990

@@ -92,9 +93,9 @@ def process_authorization(environ):
9293

9394
remote_user = username
9495

95-
if six.PY3: # because fuck you PEP 3333.
96-
remote_user = remote_user.encode('utf-8').decode('iso-8859-1')
96+
if six.PY3: # because fuck you PEP 3333.
97+
remote_user = remote_user.encode("utf-8").decode("iso-8859-1")
9798

98-
environ['REMOTE_USER'] = remote_user
99+
environ["REMOTE_USER"] = remote_user
99100

100101
return username
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import json
22
import os
33

4-
with open(os.environ.get('SECRETS_FILE')) as handle:
4+
with open(os.environ.get("SECRETS_FILE")) as handle:
55
SECRETS = json.load(handle)
66

77
DEBUG = False
88

99
DATABASES = {
10-
'default': {
11-
'ENGINE': 'django.db.backends.postgresql_psycopg2',
12-
'NAME': 'djangoproject',
13-
'USER': 'djangoproject',
14-
'HOST': SECRETS.get('db_host', ''),
15-
'PORT': SECRETS.get('db_port', 5432),
16-
'PASSWORD': SECRETS.get('db_password', ''),
10+
"default": {
11+
"ENGINE": "django.db.backends.postgresql_psycopg2",
12+
"NAME": "djangoproject",
13+
"USER": "djangoproject",
14+
"HOST": SECRETS.get("db_host", ""),
15+
"PORT": SECRETS.get("db_port", 5432),
16+
"PASSWORD": SECRETS.get("db_password", ""),
1717
},
1818
}
1919

2020
INSTALLED_APPS = [
21-
'django.contrib.auth',
22-
'django.contrib.contenttypes',
21+
"django.contrib.auth",
22+
"django.contrib.contenttypes",
2323
]
2424

2525

26-
SECRET_KEY = str(SECRETS['secret_key'])
26+
SECRET_KEY = str(SECRETS["secret_key"])
2727

2828
BASIC_AUTH_REALM = "Django's Trac"

DjangoPlugin/tracdjangoplugin/wsgi.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import os
22

33
import trac.web.main
4+
45
application = trac.web.main.dispatch_request
56

67
# Massive hack to make Trac fast, otherwise every git call tries to close ulimit -n (1e6) fds
78
# Python 3 would perform better here, but we are still on 2.7 for Trac, so leak fds for now.
89
from tracopt.versioncontrol.git import PyGIT
10+
911
PyGIT.close_fds = False
1012

1113
from .djangoauth import DjangoAuth
14+
1215
application = DjangoAuth(application)
1316

1417
trac_dsn = os.getenv("SENTRY_DSN")
1518

1619
if trac_dsn:
1720
import sentry_sdk
1821
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
22+
1923
sentry_sdk.init(
2024
dsn=trac_dsn,
21-
2225
# Set traces_sample_rate to 1.0 to capture 100%
2326
# of transactions for performance monitoring.
2427
# We recommend adjusting this value in production,

0 commit comments

Comments
 (0)