Skip to content

Commit

Permalink
Fixed issue in code
Browse files Browse the repository at this point in the history
  • Loading branch information
sonus21 committed Oct 21, 2020
1 parent 85784e7 commit c28ec44
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
24 changes: 17 additions & 7 deletions error_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,37 @@
# :license: BSD-3-Clause
#

__version__ = '1.1.7'
__version__ = '1.1.8'
__author__ = 'Sonu Kumar'
__email__ = '[email protected]'

from error_tracker.libs.mixins import *
from error_tracker.libs.exception_formatter import *

flaskInstalled = False
try:
import flask
from error_tracker.flask import *
from error_tracker.flask.utils import configure_scope as flask_scope

flaskInstalled = True
except ImportError:
pass

if flaskInstalled:
from error_tracker.flask import *
from error_tracker.flask.utils import configure_scope as flask_scope

djangoInstalled = False
try:
import django

djangoInstalled = True
except ImportError as e:
raise e

This comment has been minimized.

Copy link
@zais

zais Oct 24, 2020

This causes django to be a hard requirement. Please update to pass.


if djangoInstalled:
from error_tracker.django import *
from error_tracker.django.apps import DjangoErrorTracker
from error_tracker.django.utils import capture_message, track_exception, configure_scope, capture_exception
except ImportError:
pass

from error_tracker.libs.exception_formatter import *

__all__ = [
# flask modules
Expand Down
2 changes: 1 addition & 1 deletion error_tracker/django/migrations/0002_auto_20201018_1311.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('django', '0001_initial'),
('error_tracker', '0001_initial'),
]

operations = [
Expand Down
39 changes: 23 additions & 16 deletions error_tracker/django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import json
from django.http import RawPostDataException
from http.cookies import SimpleCookie

from error_tracker.libs.mixins import ContextBuilderMixin, NotificationMixin, ViewPermissionMixin
from error_tracker.libs.utils import get_context_dict
Expand Down Expand Up @@ -91,6 +90,7 @@ def notify(self, request, exception,
exception.notification_sent = True
exception.save()


class DefaultDjangoViewPermission(ViewPermissionMixin):

def __call__(self, request):
Expand Down Expand Up @@ -190,6 +190,27 @@ def clean_value(x):
return x


def get_value(key, value):
try:
# Parse each key, value from headers items and Test if could be "json loaded". If not, we set the correspondant value to empty except for cookie key.
json.loads('{"%s":"%s"}' % (key, value))
except Exception as e:
if key in ["Cookie", "cookie"]:
try:
from http.cookies import SimpleCookie
try:
cookie = SimpleCookie()
cookie.load(value)
value = {k: clean_value(v) for k, v in cookie.items()}
except Exception as e:
value = ""
except ImportError:
pass
else:
value = ""
return value


def parse_headers(headers):
"""
Parse request headers to extract cookie.
Expand All @@ -198,19 +219,5 @@ def parse_headers(headers):
"""
new_headers = {}
for key, value in headers.items():
try:
# Pare each key, value from headers items and Test if could be "json loaded". If not, we set the correspondant value to empty except for cookie key.
json.loads('{"%s":"%s"}' % (key, value))
except Exception as e:
if key in ["Cookie", "cookie"]:
try:
cookie = SimpleCookie()
cookie.load(value)
value = {k: clean_value(v) for k, v in cookie.items()}
except Exception as e:
value = ""
else:
value = ""

new_headers[key] = value
new_headers[key] = get_value(key, value)
return new_headers

0 comments on commit c28ec44

Please sign in to comment.