REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 3.10 KB
Close
/opt/alt/python37/lib/python3.7/site-packages/raven/contrib/django/utils.py
Text
Base64
""" raven.contrib.django.utils ~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ from __future__ import absolute_import import os from django.conf import settings def linebreak_iter(template_source): yield 0 p = template_source.find('\n') while p >= 0: yield p + 1 p = template_source.find('\n', p + 1) yield len(template_source) + 1 def get_data_from_template(source, debug=None): def _remove_numbers(items): rv = [] for item in items: # Some debug info from django has tuples in the form (lineno, # code) instead of just the code there. if isinstance(item, (list, tuple)) and len(item) == 2: item = item[1] rv.append(item) return rv if debug is not None: lineno = debug['line'] filename = debug['name'] source_lines = [] source_lines += [''] * (debug['source_lines'][0][0]) for num, line in debug['source_lines']: source_lines.append(line) source_lines += [''] * 4 elif source: origin, (start, end) = source filename = culprit = getattr(origin, 'loadname', None) template_source = origin.reload() lineno = None upto = 0 source_lines = [] for num, next in enumerate(linebreak_iter(template_source)): if start >= upto and end <= next: lineno = num source_lines.append(template_source[upto:next]) upto = next if not source_lines or lineno is None: return {} else: raise TypeError('Source or debug needed') if filename is None: filename = '<unknown filename>' culprit = '<unknown filename>' else: culprit = filename.split('/templates/')[-1] pre_context = _remove_numbers(source_lines[max(lineno - 3, 0):lineno]) post_context = _remove_numbers(source_lines[(lineno + 1):(lineno + 4)]) context_line = _remove_numbers([source_lines[lineno]])[0] return { 'template': { 'filename': os.path.basename(filename), 'abs_path': filename, 'pre_context': pre_context, 'context_line': context_line, 'lineno': lineno, 'post_context': post_context, }, 'culprit': culprit, } def get_host(request): """ A reimplementation of Django's get_host, without the SuspiciousOperation check. """ # We try three options, in order of decreasing preference. if settings.USE_X_FORWARDED_HOST and ( 'HTTP_X_FORWARDED_HOST' in request.META): host = request.META['HTTP_X_FORWARDED_HOST'] elif 'HTTP_HOST' in request.META: host = request.META['HTTP_HOST'] else: # Reconstruct the host using the algorithm from PEP 333. host = request.META['SERVER_NAME'] server_port = str(request.META['SERVER_PORT']) if server_port != (request.is_secure() and '443' or '80'): host = '%s:%s' % (host, server_port) return host
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 6 × Files: 11
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
celery
DIR
-
drwxr-xr-x
2024-03-03 23:10:23
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
management
DIR
-
drwxr-xr-x
2024-03-03 23:10:23
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
middleware
DIR
-
drwxr-xr-x
2024-03-03 23:10:23
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
raven_compat
DIR
-
drwxr-xr-x
2024-03-03 23:10:23
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
templatetags
DIR
-
drwxr-xr-x
2024-03-03 23:10:23
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__pycache__
DIR
-
drwxr-xr-x
2024-03-03 23:10:23
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
apps.py
308 B
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
client.py
10.13 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
handlers.py
1.01 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
logging.py
466 B
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
models.py
9.19 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
resolver.py
2.84 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
serializers.py
2.12 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
urls.py
594 B
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
utils.py
3.10 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
views.py
2.92 KB
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__init__.py
315 B
lrw-r--r--
2017-10-29 17:41:19
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).