Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code #987

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion inbox/api/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ def valid_display_name( # noqa: ANN201

display_name = display_name.rstrip()
if len(display_name) > MAX_INDEXABLE_LENGTH:
# Set as MAX_FOLDER_LENGTH, MAX_LABEL_LENGTH
raise InputError('"display_name" is too long')

if (
Expand Down
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
neob91-close marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 0 additions & 23 deletions inbox/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@
MAX_SANE_TRX_TIME_MS = 30000


def two_phase_session( # noqa: ANN201, D417
engine_map, versioned: bool = True
):
"""
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: bool = 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 @@ -23,9 +23,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 @@ -22,34 +22,13 @@ def __exit__(
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
35 changes: 0 additions & 35 deletions inbox/util/sharding.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
import random

from inbox.config import config
from inbox.ignition import engine_manager


def get_shards(): # noqa: ANN201
return list(engine_manager.engines)


def get_open_shards(): # noqa: ANN201
# Can't use engine_manager.engines here because it does not track
# shard state (open/ closed)
database_hosts = config.get_required("DATABASE_HOSTS")
open_shards: list[int] = []
for host in database_hosts:
open_shards.extend(
shard["ID"]
for shard in host["SHARDS"]
if shard["OPEN"] and not shard.get("DISABLED")
)

return open_shards


def get_shard_schemas(): # noqa: ANN201
Expand All @@ -35,16 +13,3 @@ def get_shard_schemas(): # noqa: ANN201
schema_name = shard["SCHEMA_NAME"]
shard_schemas[shard_id] = schema_name
return shard_schemas


def generate_open_shard_key(): # noqa: ANN201
"""
Return the key that can be passed into session_scope() for an open shard,
picked at random.

"""
open_shards = get_open_shards()
# TODO[k]: Always pick min()instead?
shard_id = random.choice(open_shards)
key = shard_id << 48
return key
7 changes: 0 additions & 7 deletions inbox/util/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
log = get_logger()


def _absolute_path(relative_path):
return os.path.join( # noqa: PTH118
os.path.dirname(os.path.abspath(__file__)), # noqa: PTH100, PTH120
relative_path,
)


def check_sudo() -> None:
if os.getuid() == 0:
raise Exception("Don't run the Nylas Sync Engine as root!")
Expand Down
Loading