Skip to content

Commit 0c0206f

Browse files
committed
chore: stylefixes
1 parent 893fe9f commit 0c0206f

11 files changed

Lines changed: 43 additions & 40 deletions

File tree

sentry_sdk/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ def __init__(self, dsn=None, *args, **kwargs):
3131
self._transport.start()
3232

3333
try:
34-
integrations = options['integrations']
34+
integrations = options["integrations"]
3535
except KeyError:
3636
from .integrations.logging import LoggingIntegration
37+
3738
integrations = [LoggingIntegration()]
3839

3940
for integration in integrations or ():

sentry_sdk/integrations/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ def __call__(self, client):
2222
assert self.identifier
2323
with _installer_lock:
2424
if self.identifier in _installed_integrations:
25-
print("warning: %s integration for Sentry is already "
26-
"configured. Will ignore second configuration." % self.identifier,
27-
file=sys.stderr)
25+
print(
26+
"warning: %s integration for Sentry is already "
27+
"configured. Will ignore second configuration." % self.identifier,
28+
file=sys.stderr,
29+
)
2830
return
2931

3032
self.install(client)

sentry_sdk/integrations/_wsgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,6 @@ def get_client_ip(environ):
156156
value may be forged from a client.
157157
"""
158158
try:
159-
return environ['HTTP_X_FORWARDED_FOR'].split(',')[0].strip()
159+
return environ["HTTP_X_FORWARDED_FOR"].split(",")[0].strip()
160160
except (KeyError, IndexError):
161-
return environ.get('REMOTE_ADDR')
161+
return environ.get("REMOTE_ADDR")

sentry_sdk/integrations/celery.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class CeleryIntegration(Integration):
12-
identifier = 'celery'
12+
identifier = "celery"
1313

1414
def __init__(self):
1515
pass
@@ -19,22 +19,18 @@ def install(self, client):
1919
task_postrun.connect(self._handle_task_postrun, weak=False)
2020
task_failure.connect(self._process_failure_signal, weak=False)
2121

22-
2322
def _process_failure_signal(self, sender, task_id, einfo, **kw):
24-
if hasattr(sender, "throws") and isinstance(einfo.exception,
25-
sender.throws):
23+
if hasattr(sender, "throws") and isinstance(einfo.exception, sender.throws):
2624
return
2725

2826
capture_exception(einfo.exc_info)
2927

30-
3128
def _handle_task_prerun(self, sender, task, **kw):
3229
with _internal_exceptions():
3330
get_current_hub().push_scope()
3431

3532
with configure_scope() as scope:
3633
scope.transaction = task.name
3734

38-
3935
def _handle_task_postrun(self, sender, task_id, task, **kw):
4036
get_current_hub().pop_scope_unsafe()

sentry_sdk/integrations/django.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515

1616

1717
if DJANGO_VERSION < (1, 10):
18+
1819
def is_authenticated(request_user):
1920
return request_user.is_authenticated()
21+
22+
2023
else:
24+
2125
def is_authenticated(request_user):
2226
return request_user.is_authenticated
2327

2428

2529
class DjangoIntegration(Integration):
26-
identifier = 'django'
30+
identifier = "django"
2731

2832
def __init__(self):
2933
pass
@@ -55,7 +59,7 @@ def processor(event):
5559
with _internal_exceptions():
5660
DjangoRequestExtractor(request).extract_into_event(event)
5761

58-
if 'user' not in event:
62+
if "user" not in event:
5963
with _internal_exceptions():
6064
_set_user_info(request, event)
6165

@@ -68,7 +72,6 @@ def _got_request_exception(request=None, **kwargs):
6872
capture_exception()
6973

7074

71-
7275
class DjangoRequestExtractor(RequestExtractor):
7376
@property
7477
def url(self):
@@ -99,21 +102,19 @@ def size_of_file(self, file):
99102

100103

101104
def _set_user_info(request, event):
102-
event['user'] = user_info = {
103-
'ip_address': get_client_ip(request.META),
104-
}
105+
event["user"] = user_info = {"ip_address": get_client_ip(request.META)}
105106

106107
user = getattr(request, "user", None)
107108

108109
if user is None or not is_authenticated(user):
109110
return
110111

111112
try:
112-
user_info['email'] = user.email
113+
user_info["email"] = user.email
113114
except Exception:
114115
pass
115116

116117
try:
117-
user_info['username'] = user.get_username()
118+
user_info["username"] = user.get_username()
118119
except Exception:
119120
pass

sentry_sdk/integrations/logging.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313

1414
class LoggingIntegration(Integration):
15-
identifier = 'logging'
15+
identifier = "logging"
16+
1617
def __init__(self, level=logging.INFO, event_level=None):
1718
self._handler = SentryHandler(level=level, event_level=event_level)
1819

tests/integrations/django/myapp/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def process_response(self, request, response):
6767

6868

6969
MIDDLEWARE_CLASSES = [
70-
'django.contrib.sessions.middleware.SessionMiddleware',
71-
'django.contrib.auth.middleware.AuthenticationMiddleware',
72-
"tests.integrations.django.myapp.settings.TestMiddleware"
70+
"django.contrib.sessions.middleware.SessionMiddleware",
71+
"django.contrib.auth.middleware.AuthenticationMiddleware",
72+
"tests.integrations.django.myapp.settings.TestMiddleware",
7373
]
7474

7575
if MiddlewareMixin is not object:
@@ -135,6 +135,6 @@ def process_response(self, request, response):
135135

136136
STATIC_URL = "/static/"
137137

138-
sentry_sdk.get_current_hub().bind_client(sentry_sdk.Client(integrations=[
139-
DjangoIntegration()
140-
]))
138+
sentry_sdk.get_current_hub().bind_client(
139+
sentry_sdk.Client(integrations=[DjangoIntegration()])
140+
)

tests/integrations/django/myapp/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def message(request):
2121

2222

2323
def mylogin(request):
24-
user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
25-
user.backend = 'django.contrib.auth.backends.ModelBackend'
24+
user = User.objects.create_user("john", "lennon@thebeatles.com", "johnpassword")
25+
user.backend = "django.contrib.auth.backends.ModelBackend"
2626
login(request, user)
2727
return HttpResponse("ok")

tests/integrations/django/test_basic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ def test_request_captured(client, capture_events):
6464
def test_user_captured(client, capture_events):
6565
events = capture_events()
6666
response = client.get(reverse("mylogin"))
67-
assert response.content == b'ok'
67+
assert response.content == b"ok"
6868

6969
assert not events
7070

7171
response = client.get(reverse("message"))
72-
assert response.content == b'ok'
72+
assert response.content == b"ok"
7373

7474
event, = events
7575

76-
assert event['user'] == {
77-
'email': 'lennon@thebeatles.com',
78-
'ip_address': "127.0.0.1",
79-
"username": "john"
76+
assert event["user"] == {
77+
"email": "lennon@thebeatles.com",
78+
"ip_address": "127.0.0.1",
79+
"username": "john",
8080
}

tests/integrations/flask/test_flask.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
@pytest.fixture
2121
def app(sentry_init):
22-
sentry_init(integrations=[
23-
flask_sentry.FlaskIntegration(),
24-
LoggingIntegration(event_level="ERROR")
25-
])
22+
sentry_init(
23+
integrations=[
24+
flask_sentry.FlaskIntegration(),
25+
LoggingIntegration(event_level="ERROR"),
26+
]
27+
)
2628

2729
app = Flask(__name__)
2830
app.config["TESTING"] = True

0 commit comments

Comments
 (0)