Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
neob91-close committed Dec 12, 2024
1 parent 337a273 commit 749c5ee
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 344 deletions.
1 change: 0 additions & 1 deletion bin/inbox-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from inbox.util.startup import load_overrides

syncback = None
http_server = None


@click.command()
Expand Down
56 changes: 0 additions & 56 deletions inbox/api/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import logging
import sys

import json_log_formatter
from gunicorn.workers.gthread import ThreadWorker

from inbox.error_handling import maybe_enable_rollbar
Expand All @@ -28,58 +26,4 @@ def init_process(self) -> None:
LOGLEVEL = config.get("LOGLEVEL", 10)


class JsonRequestFormatter(json_log_formatter.JSONFormatter):
"""
Custom JSON log formatter for gunicorn access logs.
Adapted from https://til.codeinthehole.com/posts/how-to-get-gunicorn-to-log-as-json/
"""

def json_record(
self,
message: str,
extra: "dict[str, str | int | float]",
record: logging.LogRecord,
) -> "dict[str, str | int | float]":
# Convert the log record to a JSON object.
# See https://docs.gunicorn.org/en/stable/settings.html#access-log-format

url = record.args["U"]
if record.args["q"]:
url += f"?{record.args['q']}"

method = record.args["m"]
log_context = record.args.get("{log_context}e", {})

return dict(
response_bytes=record.args["B"],
request_time=float(record.args["L"]),
remote_address=record.args["h"],
http_status=record.args["s"],
http_request=f"{method} {url}",
request_method=method,
**log_context,
)


class JsonErrorFormatter(json_log_formatter.JSONFormatter):
"""
Custom JSON log formatter for gunicorn error logs.
Adapted from https://til.codeinthehole.com/posts/how-to-get-gunicorn-to-log-as-json/
"""

def json_record(
self,
message: str,
extra: "dict[str, str | int | float]",
record: logging.LogRecord,
) -> "dict[str, str | int | float]":
payload: "dict[str, str | int | float]" = super().json_record(
message, extra, record
)
payload["level"] = record.levelname
return payload


__all__ = ["NylasWSGIWorker"]
126 changes: 0 additions & 126 deletions inbox/contacts/vcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,116 +33,10 @@

import vobject


def list_clean(string): # noqa: ANN201
"""
Transforms a comma seperated string to a list, stripping whitespaces
"HOME, WORK,pref" -> ['HOME', 'WORK', 'pref']
string: string of comma seperated elements
returns: list()
""" # noqa: D401
string = string.split(",")
rstring = list()
for element in string:
rstring.append(element.strip(" "))
return rstring


NO_STRINGS = ["n", "no"]
YES_STRINGS = ["y", "yes"]

PROPERTIES = ["EMAIL", "TEL"]
PROPS_ALL = [
"FN",
"N",
"VERSION",
"NICKNAME",
"PHOTO",
"BDAY",
"ADR",
"LABEL",
"TEL",
"EMAIL",
"MAILER",
"TZ",
"GEO",
"TITLE",
"ROLE",
"LOGO",
"AGENT",
"ORG",
"NOTE",
"REV",
"SOUND",
"URL",
"UID",
"KEY",
"CATEGORIES",
"PRODID",
"REV",
"SORT-STRING",
"SOUND",
"URL",
"VERSION",
"UTC-OFFSET",
]
PROPS_ALLOWED = [
"NICKNAME",
"BDAY",
"ADR",
"LABEL",
"TEL",
"EMAIL",
"MAILER",
"TZ",
"GEO",
"TITLE",
"ROLE",
"AGENT",
"ORG",
"NOTE",
"REV",
"SOUND",
"URL",
"UID",
"KEY",
"CATEGORIES",
"PRODID",
"REV",
"SORT-STRING",
"SOUND",
"URL",
"VERSION",
"UTC-OFFSET",
]
PROPS_ONCE = ["FN", "N", "VERSION"]
PROPS_LIST = ["NICKNAME", "CATEGORIES"]
PROPS_BIN = ["PHOTO", "LOGO", "SOUND", "KEY"]


RTEXT = "\x1b[7m"
NTEXT = "\x1b[0m"
BTEXT = "\x1b[1m"


def get_names(display_name): # noqa: ANN201
first_name, last_name = "", display_name

if display_name.find(",") > 0:
# Parsing something like 'Doe, John Abraham'
last_name, first_name = display_name.split(",")

elif display_name.find(" "):
# Parsing something like 'John Abraham Doe'
# TODO: This fails for compound names. What is the most common case?
name_list = display_name.split(" ")
last_name = "".join(name_list[-1])
first_name = " ".join(name_list[:-1])

return (first_name.strip().capitalize(), last_name.strip().capitalize())


def fix_vobject(vcard): # noqa: ANN201
"""
Trying to fix some more or less common errors in vcards
Expand Down Expand Up @@ -193,26 +87,6 @@ def vcard_from_string(vcard_string): # noqa: ANN201
return vcard_from_vobject(vcard)


def vcard_from_email(display_name, email): # noqa: ANN201
fname, lname = get_names(display_name)
vcard = vobject.vCard()
vcard.add("n")
vcard.n.value = vobject.vcard.Name(family=lname, given=fname)
vcard.add("fn")
vcard.fn.value = display_name
vcard.add("email")
vcard.email.value = email
vcard.email.type_param = "INTERNET"
return vcard_from_vobject(vcard)


def cards_from_file(cards_f): # noqa: ANN201
collector = list()
for vcard in vobject.readComponents(cards_f):
collector.append(vcard_from_vobject(vcard))
return collector


class VCard(defaultdict):
"""
internal representation of a VCard. This is dict with some
Expand Down
8 changes: 0 additions & 8 deletions inbox/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@ class OAuthError(ValidationError):
pass


class ConfigurationError(Exception):
pass


class UserRecoverableConfigError(Exception):
pass


class SettingUpdateError(Exception):
pass


class GmailSettingError(ValidationError):
pass

Expand Down
3 changes: 0 additions & 3 deletions inbox/heartbeat/status.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import time
from collections import namedtuple
from datetime import timedelta

from inbox.heartbeat.config import ALIVE_EXPIRY
from inbox.heartbeat.store import HeartbeatStore
from inbox.logging import get_logger

ALIVE_THRESHOLD = timedelta(seconds=ALIVE_EXPIRY)

log = get_logger()


Expand Down
2 changes: 0 additions & 2 deletions inbox/models/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Size constants, set in this file to avoid annoying circular import
# errors
MAX_INDEXABLE_LENGTH = 191
MAX_FOLDER_NAME_LENGTH = MAX_INDEXABLE_LENGTH
MAX_LABEL_NAME_LENGTH = MAX_INDEXABLE_LENGTH
21 changes: 0 additions & 21 deletions inbox/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,6 @@
MAX_SANE_TRX_TIME_MS = 30000


def two_phase_session(engine_map, versioned=True): # noqa: ANN201, D417
"""
Returns a session that implements two-phase-commit.
Parameters
----------
engine_map: dict
Mapping of Table cls instance: database engine
versioned: bool
""" # noqa: D401
session = Session(
binds=engine_map, twophase=True, autoflush=True, autocommit=False
)
if versioned:
session = configure_versioning(session)
# TODO[k]: Metrics for transaction latencies!
return session


def new_session(engine, versioned=True): # noqa: ANN201
"""Returns a session bound to the given engine.""" # noqa: D401
session = Session(bind=engine, autoflush=True, autocommit=False)
Expand Down
2 changes: 0 additions & 2 deletions inbox/sendmail/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

from inbox import VERSION

REPLYSTR = "Re: "


# Patch flanker to use base64 rather than quoted-printable encoding for
# MIME parts with long lines. Flanker's implementation of quoted-printable
Expand Down
3 changes: 0 additions & 3 deletions inbox/sendmail/smtp/postel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

from .util import SMTP_ERRORS # noqa: E402

# TODO[k]: Other types (LOGIN, XOAUTH, PLAIN-CLIENTTOKEN, CRAM-MD5)
AUTH_EXTNS = {"oauth2": "XOAUTH2", "password": "PLAIN"}

SMTP_MAX_RETRIES = 1
# Timeout in seconds for blocking operations. If no timeout is specified,
# attempts to, say, connect to the wrong port may hang forever.
Expand Down
29 changes: 0 additions & 29 deletions inbox/sqlalchemy_ext/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,35 +350,6 @@ def receive_connect(dbapi_connection, connection_record) -> None:
dbapi_connection.encoding = "utf8-surrogate-fix"


def safer_yield_per(query, id_field, start_id, count): # noqa: ANN201, D417
"""
Incautious execution of 'for result in query.yield_per(N):' may cause
slowness or OOMing over large tables. This is a less general but less
dangerous alternative.
Parameters
----------
query: sqlalchemy.Query
The query to yield windowed results from.
id_field: A SQLAlchemy attribute to use for windowing. E.g.,
`Transaction.id`
start_id: The value of id_field at which to start iterating.
count: int
The number of results to fetch at a time.
"""
cur_id = start_id
while True:
results = (
query.filter(id_field >= cur_id)
.order_by(id_field)
.limit(count)
.all()
)
yield from results
cur_id = results[-1].id + 1


def get_db_api_cursor_with_query(session, query): # noqa: ANN201
"""
Return a DB-API cursor with the given SQLAlchemy query executed.
Expand Down
21 changes: 0 additions & 21 deletions inbox/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,13 @@ def __exit__(self, exc_type, exc_value, traceback): # noqa: ANN204
return False


class ProviderSpecificException(Exception):
pass


def or_none(value, selector): # noqa: ANN201
if value is None:
return None
else:
return selector(value)


def parse_ml_headers(headers): # noqa: ANN201
"""
Parse the mailing list headers described in RFC 4021,
these headers are optional (RFC 2369).
"""
return {
"List-Archive": headers.get("List-Archive"),
"List-Help": headers.get("List-Help"),
"List-Id": headers.get("List-Id"),
"List-Owner": headers.get("List-Owner"),
"List-Post": headers.get("List-Post"),
"List-Subscribe": headers.get("List-Subscribe"),
"List-Unsubscribe": headers.get("List-Unsubscribe"),
}


def parse_references(references: str, in_reply_to: str) -> list[str]:
"""
Parse a References: header and returns an array of MessageIDs.
Expand Down
Loading

0 comments on commit 749c5ee

Please sign in to comment.