repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
loguru | tests/exceptions/source/others/repeated_lines.py | .py | from loguru import logger
import sys
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=True, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=True)
logger.add(sys.std... | 24 | 670 |
loguru | tests/exceptions/source/others/catch_message.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="{message}", diagnose=False, backtrace=False, colorize=False)
def a():
1 / 0
with logger.catch(message="An error occurred (1):"):
a()
a = logger.catch(message="An error occurred (2):")(a)
a()
| 18 | 290 |
loguru | tests/exceptions/source/others/catch_as_function.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
def a():
1 / 0
a = logger.catch()(a)
a()
| 15 | 187 |
loguru | tests/exceptions/source/others/assertionerror_without_traceback.py | .py | import sys
from loguru import logger
def test(diagnose, backtrace):
logger.remove()
logger.add(sys.stderr, format="", diagnose=diagnose, backtrace=backtrace, colorize=True)
try:
assert False
except AssertionError:
type_, value, _ = sys.exc_info()
logger.opt(exception=(type_, ... | 21 | 418 |
loguru | tests/exceptions/source/others/catch_as_decorator_without_parentheses.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
@logger.catch
def c(a, b=0):
a / b
c(2)
| 15 | 186 |
loguru | tests/exceptions/source/others/catch_as_decorator_with_parentheses.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
@logger.catch()
def c(a, b):
a / b
c(5, b=0)
| 15 | 191 |
loguru | tests/exceptions/source/others/sys_tracebacklimit_unset.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=True, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=True, colorize=False)
logger.add(sys.std... | 61 | 714 |
loguru | tests/exceptions/source/others/level_name.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(
sys.stderr, format="{level.name} | {level.no}", diagnose=False, backtrace=False, colorize=False
)
def a():
with logger.catch(level="DEBUG"):
1 / 0
a()
| 17 | 238 |
loguru | tests/exceptions/source/others/level_number.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(
sys.stderr, format="{level.name} | {level.no}", diagnose=False, backtrace=False, colorize=False
)
def a():
with logger.catch(level=13):
1 / 0
a()
| 17 | 233 |
loguru | tests/exceptions/source/others/handler_formatting_with_context_manager.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(
sys.stderr,
format="{name} {file.name} {function} {line}",
diagnose=False,
backtrace=False,
colorize=False,
)
def a():
with logger.catch():
1 / 0
a()
| 21 | 253 |
loguru | tests/exceptions/source/others/sys_tracebacklimit_negative.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=True, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=True, colorize=False)
logger.add(sys.std... | 58 | 674 |
loguru | tests/exceptions/source/others/recursion_error.py | .py | from loguru import logger
import sys
sys.setrecursionlimit(1000)
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=True, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colo... | 22 | 518 |
loguru | tests/exceptions/source/others/exception_in_property.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=True, backtrace=True, colorize=False)
class A:
@property
def value(self):
try:
1 / 0
except:
logger.opt(exception=True).debug("test")
return None
else:
... | 23 | 373 |
loguru | tests/exceptions/source/others/zerodivisionerror_without_traceback.py | .py | import sys
from loguru import logger
def test(diagnose, backtrace):
logger.remove()
logger.add(sys.stderr, format="", diagnose=diagnose, backtrace=backtrace, colorize=True)
try:
1 / 0
except ZeroDivisionError:
type_, value, _ = sys.exc_info()
logger.opt(exception=(type_, valu... | 21 | 414 |
loguru | tests/exceptions/source/others/sys_tracebacklimit_none.py | .py | import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", diagnose=False, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=True, backtrace=False, colorize=False)
logger.add(sys.stderr, format="", diagnose=False, backtrace=True, colorize=False)
logger.add(sys.std... | 58 | 676 |
loguru | loguru/_contextvars.py | .py | import sys
def load_contextvar_class():
if sys.version_info >= (3, 7):
from contextvars import ContextVar
elif sys.version_info >= (3, 5, 3):
from aiocontextvars import ContextVar
else:
from contextvars import ContextVar
return ContextVar
ContextVar = load_contextvar_class()... | 16 | 321 |
loguru | loguru/_error_interceptor.py | .py | import sys
import traceback
class ErrorInterceptor:
def __init__(self, should_catch, handler_id):
self._should_catch = should_catch
self._handler_id = handler_id
def should_catch(self):
return self._should_catch
def print(self, record=None, *, exception=None):
if not sys.... | 35 | 1,107 |
loguru | loguru/_ctime_functions.py | .py | import os
def load_ctime_functions():
if os.name == "nt":
import win32_setctime
def get_ctime_windows(filepath):
return os.stat(filepath).st_ctime
def set_ctime_windows(filepath, timestamp):
if not win32_setctime.SUPPORTED:
return
try:... | 58 | 1,527 |
loguru | loguru/_get_frame.py | .py | import sys
from sys import exc_info
def get_frame_fallback(n):
try:
raise Exception
except Exception:
frame = exc_info()[2].tb_frame.f_back
for _ in range(n):
frame = frame.f_back
return frame
def load_get_frame_function():
if hasattr(sys, "_getframe"):
... | 24 | 458 |
loguru | loguru/_colorizer.py | .py | import re
from contextlib import contextmanager
from string import Formatter
@contextmanager
def try_formatting(*exceptions):
try:
yield
except exceptions as e:
raise ValueError(
"The logging message could not be formatted with the provided arguments.\n"
"Common causes ... | 513 | 16,264 |
loguru | loguru/_logger.py | .py | """Core logging functionalities of the `Loguru` library.
.. References and links rendered by Sphinx are kept here as "module documentation" so that they can
be used in the ``Logger`` docstrings but do not pollute ``help(logger)`` output.
.. |Logger| replace:: :class:`~Logger`
.. |add| replace:: :meth:`~Logger.add(... | 2,275 | 103,485 |
loguru | loguru/_simple_sinks.py | .py | import inspect
import logging
import weakref
from ._asyncio_loop import get_running_loop, get_task_loop
class StreamSink:
"""A sink that writes log messages to a stream object.
Parameters
----------
stream
A stream object that supports write operations.
"""
def __init__(self, stream... | 242 | 6,758 |
loguru | loguru/__init__.py | .py | """
The Loguru library provides a pre-instanced logger to facilitate dealing with logging in Python.
Just ``from loguru import logger``.
"""
import atexit as _atexit
import sys as _sys
from . import _defaults
from ._logger import Core as _Core
from ._logger import Logger as _Logger
__version__ = "0.7.3"
__all__ = ... | 35 | 627 |
loguru | loguru/_defaults.py | .py | from os import environ
def env(key, type_, default=None):
if key not in environ:
return default
val = environ[key]
if type_ is str:
return val
if type_ is bool:
if val.lower() in ["1", "true", "yes", "y", "ok", "on"]:
return True
if val.lower() in ["0", "f... | 76 | 3,009 |
loguru | loguru/_filters.py | .py | def filter_none(record):
return record["name"] is not None
def filter_by_name(record, parent, length):
name = record["name"]
if name is None:
return False
return (name + ".")[:length] == parent
def filter_by_level(record, level_per_module):
name = record["name"]
while True:
... | 25 | 618 |
loguru | loguru/_datetime.py | .py | import re
from calendar import day_abbr, day_name, month_abbr, month_name
from datetime import datetime as datetime_
from datetime import timedelta, timezone
from functools import lru_cache, partial
from time import localtime, strftime
tokens = r"H{1,2}|h{1,2}|m{1,2}|s{1,2}|S+|YYYY|YY|M{1,4}|D{1,4}|Z{1,2}|zz|A|X|x|E|Q... | 180 | 6,136 |
loguru | loguru/_handler.py | .py | import functools
import json
import multiprocessing
import os
import threading
from contextlib import contextmanager
from threading import Thread
from ._colorizer import Colorizer
from ._locks_machinery import create_handler_lock
def prepare_colored_format(format_, ansi_level):
colored = Colorizer.prepare_format... | 358 | 13,540 |
loguru | loguru/_file_sink.py | .py | import datetime
import decimal
import glob
import numbers
import os
import shutil
import string
from functools import partial
from stat import ST_DEV, ST_INO
from . import _string_parsers as string_parsers
from ._ctime_functions import get_ctime, set_ctime
from ._datetime import aware_now
def generate_rename_path(ro... | 443 | 14,951 |
loguru | loguru/_recattrs.py | .py | import pickle
from collections import namedtuple
class RecordLevel:
"""A class representing the logging level record with name, number and icon.
Attributes
----------
icon : str
The icon representing the log level
name : str
The name of the log level
no : int
The numer... | 294 | 7,333 |
loguru | loguru/_asyncio_loop.py | .py | import asyncio
import sys
def load_loop_functions():
if sys.version_info >= (3, 7):
def get_task_loop(task):
return task.get_loop()
get_running_loop = asyncio.get_running_loop
else:
def get_task_loop(task):
return task._loop
def get_running_loop():
... | 28 | 597 |
loguru | loguru/_string_parsers.py | .py | import datetime
import re
from typing import Optional, Tuple
class Frequencies:
"""Provide static methods to compute the next occurrence of various time frequencies.
Includes hourly, daily, weekly, monthly, and yearly frequencies
based on a given datetime object.
"""
@staticmethod
def hourly... | 361 | 9,326 |
loguru | loguru/_colorama.py | .py | import builtins
import os
import sys
def should_colorize(stream):
if stream is None:
return False
is_standard_stream = stream is sys.stdout or stream is sys.stderr
is_original_standard_stream = stream is sys.__stdout__ or stream is sys.__stderr__
if is_standard_stream or is_original_standard... | 84 | 2,374 |
loguru | loguru/_better_exceptions.py | .py | import builtins
import inspect
import io
import keyword
import linecache
import os
import re
import sys
import sysconfig
import tokenize
import traceback
if sys.version_info >= (3, 11):
def is_exception_group(exc):
return isinstance(exc, ExceptionGroup)
else:
try:
from exceptiongroup import E... | 586 | 21,974 |
loguru | loguru/_locks_machinery.py | .py | import os
import threading
import weakref
if not hasattr(os, "register_at_fork"):
def create_logger_lock():
return threading.Lock()
def create_handler_lock():
return threading.Lock()
else:
# While forking, we need to sanitize all locks to make sure the child process doesn't run into
... | 51 | 1,307 |
structlog | show_off.py | .py | """
Show how console logging looks like.
This is used for the screenshot in the readme and
<https://www.structlog.org/en/stable/development.html>.
"""
from dataclasses import dataclass
import structlog
@dataclass
class SomeClass:
x: int
y: str
structlog.stdlib.recreate_defaults() # so we have logger nam... | 50 | 1,093 |
structlog | docs/conf.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import os
from importlib import metadata
# Set canonical URL from the Read the Docs Domain... | 164 | 4,533 |
structlog | tests/test_native.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import logging
import pickle
import pytest
from structlog import make_filtering_bound_logge... | 383 | 11,043 |
structlog | tests/test_generic.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import pickle
import pytest
import time_machine
from structlog._config import _CONFIG
from ... | 66 | 1,676 |
structlog | tests/test_frames.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import sys
import pytest
from structlog._frames import (
_find_first_app_frame_and_name... | 188 | 5,619 |
structlog | tests/test_testing.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import pytest
import structlog
from structlog import contextvars, get_config, get_logger, t... | 228 | 6,584 |
structlog | tests/test_config.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import abc
import pickle
import warnings
from unittest.mock import call
import pytest
impo... | 469 | 13,276 |
structlog | tests/test_twisted.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import json
import pytest
from structlog import ReturnLogger
from structlog._config import ... | 361 | 10,277 |
structlog | tests/test_threadlocal.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import inspect
import threading
import pytest
import structlog
from structlog import get_l... | 506 | 13,821 |
structlog | tests/test_tracebacks.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from __future__ import annotations
import asyncio
import inspect
import json
import sys
fro... | 1,192 | 33,192 |
structlog | tests/additional_frame.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Helper function for testing the deduction of stdlib logger names.
Since the logger facto... | 16 | 488 |
structlog | tests/test_base.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import pytest
from structlog import get_context
from structlog._base import BoundLoggerBase
... | 244 | 7,276 |
structlog | tests/test_contextvars.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import asyncio
import inspect
import secrets
import pytest
import structlog
from structlog... | 305 | 9,087 |
structlog | tests/test_dev.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import pickle
import sys
from io import StringIO
from unittest import mock
import pytest
i... | 1,230 | 35,524 |
structlog | tests/helpers.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Shared test utilities.
"""
from unittest.mock import Mock, seal
from structlog._log_lev... | 47 | 975 |
structlog | tests/test_packaging.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from importlib import metadata
import pytest
import structlog
class TestLegacyMetadataHac... | 50 | 1,499 |
structlog | tests/test_output.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import copy
import gc
import pickle
from io import BytesIO, StringIO
import pytest
from st... | 443 | 12,216 |
structlog | tests/test_utils.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import multiprocessing
import sys
import pytest
from structlog._utils import get_processnam... | 72 | 2,170 |
structlog | tests/test_stdlib.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from __future__ import annotations
import json
import logging
import logging.config
import o... | 1,694 | 50,739 |
structlog | tests/conftest.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import logging
from io import StringIO
import pytest
import structlog
from structlog._log... | 77 | 1,531 |
structlog | tests/processors/test_renderers.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from __future__ import annotations
import datetime
import json
import pickle
import pytest
... | 627 | 18,374 |
structlog | tests/processors/test_processors.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from __future__ import annotations
import functools
import inspect
import itertools
import j... | 767 | 23,777 |
structlog | bench/test_benchmarks.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Benchmark structlog using CodSpeed.
"""
from __future__ import annotations
import loggi... | 200 | 4,926 |
structlog | typing_tests/api.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Make sure our configuration examples actually pass the type checker.
"""
from __future__... | 415 | 12,392 |
structlog | src/structlog/twisted.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Processors and tools specific to the `Twisted <https://twisted.org/>`_
networking engine.... | 333 | 10,135 |
structlog | src/structlog/types.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Deprecated name for :mod:`structlog.typing`.
.. versionadded:: 20.2.0
.. deprecated:: 22... | 39 | 764 |
structlog | src/structlog/_greenlets.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
greenlet-specific code that pretends to be a `threading.local`.
Fails to import if not r... | 45 | 1,206 |
structlog | src/structlog/_utils.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Generic utilities.
"""
from __future__ import annotations
import sys
from contextlib i... | 31 | 933 |
structlog | src/structlog/exceptions.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Exceptions factored out to avoid import loops.
"""
from __future__ import annotations
... | 36 | 899 |
structlog | src/structlog/_base.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Logger wrapper and helper class.
"""
from __future__ import annotations
import sys
fro... | 246 | 7,362 |
structlog | src/structlog/_config.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Global state department. Don't reload this module or everything breaks.
"""
from __futu... | 440 | 14,011 |
structlog | src/structlog/__init__.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from __future__ import annotations
from structlog import (
contextvars,
dev,
pr... | 129 | 2,911 |
structlog | src/structlog/stdlib.py | .py | # This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Processors and helpers specific to the :mod:`logging` module from the `Python
standard library <https://docs.python.org/>`_.
See also... | 1,259 | 42,119 |
structlog | src/structlog/_generic.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Generic bound logger that can wrap anything.
"""
from __future__ import annotations
fro... | 55 | 1,636 |
structlog | src/structlog/testing.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Helpers to test your application's logging behavior.
.. versionadded:: 20.1.0
See :doc:... | 223 | 5,772 |
structlog | src/structlog/tracebacks.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Extract a structured traceback from an exception.
Based on work by Will McGugan
<https:/... | 526 | 16,769 |
structlog | src/structlog/processors.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Processors useful regardless of the logging framework.
"""
from __future__ import annota... | 1,006 | 31,183 |
structlog | src/structlog/contextvars.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Primitives to deal with a concurrency supporting context, as introduced in
Python 3.7 as ... | 195 | 5,648 |
structlog | src/structlog/_native.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
structlog's native high-performance loggers.
"""
from __future__ import annotations
imp... | 287 | 9,439 |
structlog | src/structlog/typing.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Type information used throughout *structlog*.
For now, they are considered provisional. ... | 332 | 8,585 |
structlog | src/structlog/_frames.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
from __future__ import annotations
import sys
import traceback
from collections.abc import ... | 94 | 2,394 |
structlog | src/structlog/_output.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Logger classes responsible for output.
"""
from __future__ import annotations
import co... | 377 | 10,031 |
structlog | src/structlog/_log_levels.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Extracted log level data used by both stdlib and native log level filters.
"""
from __fu... | 82 | 1,973 |
structlog | src/structlog/threadlocal.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
**Deprecated** primitives to keep context global but thread (and greenlet)
local.
See `t... | 356 | 9,236 |
structlog | src/structlog/dev.py | .py | # SPDX-License-Identifier: MIT OR Apache-2.0
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
"""
Helpers that make development with *structlog* more pleasant.
See also the narrative doc... | 1,242 | 37,210 |
gunicorn | benchmarks/dirty_bench_wsgi.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
WSGI app for integration benchmarking of the dirty pool.
This simple WSGI application calls the dirty pool and returns results.
Use with gunicorn for end-to-end benchmarking that includes HTTP overhead.
Examp... | 168 | 5,605 |
gunicorn | benchmarks/dirty_streaming.py | .py | #!/usr/bin/env python
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Benchmark suite for dirty worker streaming functionality.
This script benchmarks the streaming performance of dirty workers
to measure throughput, latency, and memory usage.
Usage:
p... | 756 | 23,176 |
gunicorn | benchmarks/dirty_bench_gunicorn.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Gunicorn configuration for dirty pool integration benchmarks.
Usage:
gunicorn -c benchmarks/dirty_bench_gunicorn.py \
benchmarks.dirty_bench_wsgi:app
"""
# Bind address
bind = "127.0.0.1:8000"
# ... | 61 | 1,336 |
gunicorn | benchmarks/http_parser_benchmark.py | .py | #!/usr/bin/env python
"""
Benchmark comparing HTTP parser implementations.
Compares:
- WSGI Python parser vs Fast parser (gunicorn_h1c)
- ASGI Python parser vs Fast parser (gunicorn_h1c)
Usage:
python benchmarks/http_parser_benchmark.py
"""
import io
import time
import statistics
from typing import NamedTuple
f... | 270 | 8,490 |
gunicorn | benchmarks/simple_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Simple WSGI app for benchmarking
import time
def application(environ, start_response):
"""Basic hello world response."""
path = environ.get('PATH_INFO', '/')
if path == '/large':
body = b'... | 29 | 669 |
gunicorn | benchmarks/run_benchmark.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python3
"""
Benchmark script for gunicorn gthread worker.
This script runs various benchmarks against gunicorn and reports performance metrics.
Requires: gunicorn, requests (for warmup), and wrk or ... | 243 | 7,466 |
gunicorn | benchmarks/dirty_benchmark.py | .py | #!/usr/bin/env python3
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Pool Benchmark Runner
Stress tests and benchmarks the dirty arbiter pool to find bottlenecks
and optimization opportunities.
Test Modes:
- Isolated: Direct client -> arbiter -> wo... | 1,062 | 34,775 |
gunicorn | benchmarks/dirty_bench_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Benchmark DirtyApp for stress testing the dirty arbiter pool.
Provides configurable workloads for testing:
- Pure sleep (scheduling overhead)
- CPU-bound work (thread pool utilization)
- Mixed I/O + CPU (reali... | 224 | 6,440 |
gunicorn | docs/macros.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from importlib import import_module
def define_env(env):
"""Register template variables for MkDocs macros."""
gunicorn = import_module("gunicorn")
env.variables.update(
release=gunicorn.__versi... | 16 | 508 |
gunicorn | tests/test_asgi_http_scope.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI HTTP scope validation tests.
Tests for HTTP scope building, URL encoding, header handling,
and extension support.
"""
from unittest import mock
from gunicorn.config import Config
# ==================... | 765 | 26,230 |
gunicorn | tests/treq.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Copyright 2009 Paul J. Davis <paul.joseph.davis@gmail.com>
#
# This file is part of the pywebmachine package released
# under the MIT license.
import inspect
import importlib.machinery
import os
import random
im... | 331 | 11,321 |
gunicorn | tests/test_dirty_config.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""Tests for dirty arbiter configuration settings."""
import pytest
from gunicorn.config import Config
class TestDirtyConfig:
"""Tests for dirty arbiter configuration settings."""
def test_dirty_apps_d... | 144 | 4,653 |
gunicorn | tests/test_asgi_disconnect.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Tests for ASGI graceful disconnect handling.
Issue: https://github.com/benoitc/gunicorn/issues/3484
When a client disconnects, the ASGI worker should:
1. Send http.disconnect to the receive queue
2. Allow the... | 317 | 11,157 |
gunicorn | tests/test_asgi_error_handling.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI error handling tests.
Tests for application error scenarios and graceful shutdown behavior
to ensure robust error handling in ASGI applications.
"""
import asyncio
from unittest import mock
import pytes... | 395 | 12,245 |
gunicorn | tests/test_valid_requests.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import glob
import os
import pytest
import treq
dirname = os.path.dirname(__file__)
reqdir = os.path.join(dirname, "requests", "valid")
httpfiles = glob.glob(os.path.join(reqdir, "*.http"))
# Flags incompatible... | 38 | 1,070 |
gunicorn | tests/test_asgi_callback_parser.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""Tests for ASGI callback parsers.
Tests both PythonProtocol and H1CProtocol (if available) to ensure
consistent behavior across implementations.
"""
from gunicorn.asgi.parser import PythonProtocol
def get_par... | 615 | 19,379 |
gunicorn | tests/test_asgi_forwarded_headers.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI forwarded headers tests.
Tests for X-Forwarded-For, X-Forwarded-Proto, and related
proxy header handling in ASGI applications.
"""
from unittest import mock
import pytest
from gunicorn.config import Co... | 417 | 13,743 |
gunicorn | tests/test_dirty_worker.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""Tests for dirty worker module."""
import asyncio
import os
import signal
import tempfile
import pytest
from gunicorn.config import Config
from gunicorn.dirty.worker import DirtyWorker
from gunicorn.dirty.proto... | 1,100 | 33,802 |
gunicorn | tests/test_asgi_websocket_protocol.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
WebSocket RFC 6455 compliance tests.
Tests that gunicorn's WebSocket implementation conforms to RFC 6455:
https://tools.ietf.org/html/rfc6455
"""
import base64
import hashlib
import struct
from unittest impor... | 1,039 | 36,469 |
gunicorn | tests/test_asgi_uwsgi.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Tests for ASGI uWSGI protocol parser.
"""
import pytest
from gunicorn.asgi.unreader import AsyncUnreader
from gunicorn.asgi.uwsgi import AsyncUWSGIRequest
from gunicorn.uwsgi.errors import (
InvalidUWSGIH... | 473 | 13,252 |
gunicorn | tests/test_invalid_requests.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import glob
import os
import pytest
from gunicorn.http.errors import (
InvalidRequestLine,
InvalidRequestMethod,
InvalidSchemeHeaders,
ObsoleteFolding,
)
import treq
dirname = os.path.dirname(__f... | 69 | 2,317 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.