# Path: src/settings.py
# class Settings(BaseSettings):
#     pg_dsn = 'postgresql://postgres@localhost:5432/morpheus'
#     sql_path: Path = THIS_DIR / 'models.sql'
#     patch_paths: List[str] = ['app.patches']
# 
#     cookie_name = 'morpheus'
#     auth_key = 'insecure'
#     app: str = 'src.main:app'
# 
#     locale = ''  # Required, don't delete
#     host_name: NoneStr = 'localhost'
#     click_host_name = 'click.example.com'
#     mandrill_key = ''
#     mandrill_url = 'https://mandrillapp.com/api/1.0'
#     mandrill_webhook_key: str = ''
#     log_level = 'INFO'
#     verbose_http_errors = True
#     user_auth_key: bytes = b'insecure'
#     # Used to sign Mandrill webhooks
#     webhook_auth_key: bytes = b'insecure'
# 
#     worker_func = 'src.worker:main'
#     admin_basic_auth_password = 'testing'
#     test_output: Path = None
# 
#     delete_old_emails: bool = False
#     update_aggregation_view: bool = False
#     pg_server_settings: dict = {}
# 
#     # messagebird
#     messagebird_key = ''
#     messagebird_url = 'https://rest.messagebird.com'
# 
#     # Have to use a US number as the originator to send to the US
#     # https://support.messagebird.com/hc/en-us/articles/208747865-United-States
#     us_send_number = '15744445663'
# 
#     @validator('pg_dsn')
#     def heroku_ready_pg_dsn(cls, v):
#         return v.replace('gres://', 'gresql://')
# 
#     @property
#     def mandrill_webhook_url(self):
#         return f'https://{self.host_name}/webhook/mandrill/'
# 
#     class Config:
#         fields = {
#             'port': {'env': 'PORT'},
#             'pg_dsn': {'env': 'DATABASE_URL'},
#             'redis_settings': {'env': ['REDISCLOUD_URL', 'REDIS_URL']},
#             'sentry_dsn': {'env': 'SENTRY_DSN'},
#             'delete_old_emails': {'env': 'DELETE_OLD_EMAILS'},
#             'update_aggregation_view': {'env': 'UPDATE_AGGREGATION_VIEW'},
#             'release': {'env': ['COMMIT', 'RELEASE', 'HEROKU_SLUG_COMMIT']},
#             'messagebird_key': {'env': 'MESSAGEBIRD_KEY'},
#             'mandrill_key': {'env': 'MANDRILL_KEY'},
#             'stats_token': {'env': 'STATS_TOKEN'},
#             'click_host_name': {'env': 'CLICK_HOST_NAME'},
#             'mandrill_webhook_key': {'env': 'MANDRILL_WEBHOOK_KEY'},
#             'auth_key': {'env': 'AUTH_KEY'},
#             'user_auth_key': {'env': 'USER_AUTH_KEY'},
#             'host_name': {'env': 'HOST_NAME'},
#         }


import json
import logging
from foxglove import glove
from httpx import Response
from .settings import Settings
    async def delete(self, uri, *, allowed_statuses=(200,), **data) -> Response:
        return await self._request('DELETE', uri, allowed_statuses=allowed_statuses, **data)

    async def post(self, uri, *, allowed_statuses=(200, 201), **data) -> Response:
        return await self._request('POST', uri, allowed_statuses=allowed_statuses, **data)

    async def put(self, uri, *, allowed_statuses=(200, 201), **data) -> Response:
        return await self._request('PUT', uri, allowed_statuses=allowed_statuses, **data)

    async def _request(self, method, uri, allowed_statuses=(200, 201), **data) -> Response:
        method, url, data = self._modify_request(method, self.root + str(uri).lstrip('/'), data)
        kwargs = {}
        headers = data.pop('headers_', None)
        if headers is not None:
            kwargs['headers'] = headers
        if timeout := data.pop('timeout_', None):
            kwargs['timeout'] = timeout
        r = await glove.http.request(method, url, json=data or None, **kwargs)
        if isinstance(allowed_statuses, int):
            allowed_statuses = (allowed_statuses,)
        if allowed_statuses != '*' and r.status_code not in allowed_statuses:
            data = {
                'request_real_url': str(r.request.url),
                'request_headers': dict(r.request.headers),
                'request_data': data,
                'response_headers': dict(r.headers),
                'response_content': lenient_json(r.text),
            }
            logger.warning(
                '%s unexpected response %s /%s -> %s',

# Path: src/settings.py
# class Settings(BaseSettings):
#     pg_dsn = 'postgresql://postgres@localhost:5432/morpheus'
#     sql_path: Path = THIS_DIR / 'models.sql'
#     patch_paths: List[str] = ['app.patches']
# 
#     cookie_name = 'morpheus'
#     auth_key = 'insecure'
#     app: str = 'src.main:app'
# 
#     locale = ''  # Required, don't delete
#     host_name: NoneStr = 'localhost'
#     click_host_name = 'click.example.com'
#     mandrill_key = ''
#     mandrill_url = 'https://mandrillapp.com/api/1.0'
#     mandrill_webhook_key: str = ''
#     log_level = 'INFO'
#     verbose_http_errors = True
#     user_auth_key: bytes = b'insecure'
#     # Used to sign Mandrill webhooks
#     webhook_auth_key: bytes = b'insecure'
# 
#     worker_func = 'src.worker:main'
#     admin_basic_auth_password = 'testing'
#     test_output: Path = None
# 
#     delete_old_emails: bool = False
#     update_aggregation_view: bool = False
#     pg_server_settings: dict = {}
# 
#     # messagebird
#     messagebird_key = ''
#     messagebird_url = 'https://rest.messagebird.com'
# 
#     # Have to use a US number as the originator to send to the US
#     # https://support.messagebird.com/hc/en-us/articles/208747865-United-States
#     us_send_number = '15744445663'
# 
#     @validator('pg_dsn')
#     def heroku_ready_pg_dsn(cls, v):
#         return v.replace('gres://', 'gresql://')
# 
#     @property
#     def mandrill_webhook_url(self):
#         return f'https://{self.host_name}/webhook/mandrill/'
# 
#     class Config:
#         fields = {
#             'port': {'env': 'PORT'},
#             'pg_dsn': {'env': 'DATABASE_URL'},
#             'redis_settings': {'env': ['REDISCLOUD_URL', 'REDIS_URL']},
#             'sentry_dsn': {'env': 'SENTRY_DSN'},
#             'delete_old_emails': {'env': 'DELETE_OLD_EMAILS'},
#             'update_aggregation_view': {'env': 'UPDATE_AGGREGATION_VIEW'},
#             'release': {'env': ['COMMIT', 'RELEASE', 'HEROKU_SLUG_COMMIT']},
#             'messagebird_key': {'env': 'MESSAGEBIRD_KEY'},
#             'mandrill_key': {'env': 'MANDRILL_KEY'},
#             'stats_token': {'env': 'STATS_TOKEN'},
#             'click_host_name': {'env': 'CLICK_HOST_NAME'},
#             'mandrill_webhook_key': {'env': 'MANDRILL_WEBHOOK_KEY'},
#             'auth_key': {'env': 'AUTH_KEY'},
#             'user_auth_key': {'env': 'USER_AUTH_KEY'},
#             'host_name': {'env': 'HOST_NAME'},
#         }


# Path: src/ext.py
import json
import logging
from foxglove import glove
from httpx import Response
from .settings import Settings

    async def delete(self, uri, *, allowed_statuses=(200,), **data) -> Response:
        return await self._request('DELETE', uri, allowed_statuses=allowed_statuses, **data)

    async def post(self, uri, *, allowed_statuses=(200, 201), **data) -> Response:
        return await self._request('POST', uri, allowed_statuses=allowed_statuses, **data)

    async def put(self, uri, *, allowed_statuses=(200, 201), **data) -> Response:
        return await self._request('PUT', uri, allowed_statuses=allowed_statuses, **data)

    async def _request(self, method, uri, allowed_statuses=(200, 201), **data) -> Response:
        method, url, data = self._modify_request(method, self.root + str(uri).lstrip('/'), data)
        kwargs = {}
        headers = data.pop('headers_', None)
        if headers is not None:
            kwargs['headers'] = headers
        if timeout := data.pop('timeout_', None):
            kwargs['timeout'] = timeout
        r = await glove.http.request(method, url, json=data or None, **kwargs)
        if isinstance(allowed_statuses, int):
            allowed_statuses = (allowed_statuses,)
        if allowed_statuses != '*' and r.status_code not in allowed_statuses:
            data = {
                'request_real_url': str(r.request.url),
                'request_headers': dict(r.request.headers),
                'request_data': data,
                'response_headers': dict(r.headers),
                'response_content': lenient_json(r.text),
            }
            logger.warning(
                '%s unexpected response %s /%s -> %s',

                self.__class__.__name__,