Skip to content
Merged
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
9 changes: 2 additions & 7 deletions openlibrary/core/processors/readableurls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import urllib
from urllib.parse import quote_plus

import web

Expand Down Expand Up @@ -174,13 +175,7 @@ def match(path):

if thing and thing.type.key == _type:
title = thing.get(_property) or default_title
try:
# Explicitly only run for python3 to solve #4033
from urllib.parse import quote_plus

middle = '/' + quote_plus(h.urlsafe(title.strip()))
except ImportError:
middle = '/' + h.urlsafe(title.strip())
middle = '/' + quote_plus(h.urlsafe(title.strip()))
else:
middle = ""

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/coverstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import random
import socket
import string
import traceback
from io import IOBase as file
from urllib.parse import parse_qsl, unquote, unquote_plus, urlsplit, urlunsplit # type: ignore[attr-defined]
from urllib.parse import urlencode as real_urlencode
Expand Down Expand Up @@ -53,7 +54,6 @@ def ol_things(key, value):
result = json.loads(result)
return result['result']
except OSError:
import traceback

traceback.print_exc()
return []
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/admin/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import socket
import subprocess
import sys
import traceback
Expand Down Expand Up @@ -218,7 +219,6 @@ def reload(self, servers):

@web.memoize
def local_ip():
import socket

return socket.gethostbyname(socket.gethostname())

Expand Down
6 changes: 3 additions & 3 deletions openlibrary/plugins/admin/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

import pytest
import yaml


@pytest.fixture
def serviceconfig(request):
import os

import yaml

root = os.path.dirname(__file__)
with open(os.path.join(root, "sample_services.yml")) as in_file:
Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/ol_infobase.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ def http_notify(site, old, new):
)
except Exception:
print('failed to send http_notify', repr(url), repr(key), file=web.debug)
import traceback

traceback.print_exc()

Expand Down
8 changes: 3 additions & 5 deletions openlibrary/plugins/openlibrary/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
"""

import datetime
import gzip
import json
import logging
import math
import os
import random
import socket
import sys
from time import time
from urllib.parse import parse_qs, urlencode

import requests
import web
import yaml

import infogami
from openlibrary.core import db
Expand Down Expand Up @@ -196,7 +199,6 @@ def visit(key):

@infogami.action
def sampleload(filename='sampledump.txt.gz'):
import gzip

with gzip.open(filename) if filename.endswith('.gz') else open(filename) as file:
queries = [json.loads(line) for line in file]
Expand Down Expand Up @@ -861,12 +863,10 @@ def get_data(self, key):
return json.loads(d)

def dump(self, d):
import yaml

return yaml.safe_dump(d, indent=4, allow_unicode=True, default_flow_style=False)

def load(self, data):
import yaml

return yaml.safe_load(data)

Expand Down Expand Up @@ -1149,8 +1149,6 @@ def save_error():
def internalerror():
name_webpy_error = save_error()

import sys

exception_type, exception_value, _ = sys.exc_info()

# TODO: move this stats stuff to plugins\openlibrary\stats.py
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/openlibrary/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from urllib.parse import urlencode

from infogami import config
from infogami.utils import delegate
Expand Down Expand Up @@ -57,7 +58,6 @@ def from_file() -> 'DevMergedStatus | None':

def get_github_search_link(self) -> str:
"""Constructs a GitHub search URL for all PRs in pr_statuses."""
from urllib.parse import urlencode

pull_ids = [pr.pull_id for pr in self.pr_statuses if pr.pull_id]

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import json
import logging
from collections.abc import Callable, Iterable, Mapping
Expand Down Expand Up @@ -1231,7 +1232,6 @@ def g(*a, **kw):


def process_goodreads_csv(i):
import csv

csv_payload = i.csv if isinstance(i.csv, str) else i.csv.decode()
csv_file = csv.reader(csv_payload.splitlines(), delimiter=',', quotechar='"')
Expand Down
5 changes: 3 additions & 2 deletions openlibrary/plugins/upstream/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
from typing import TYPE_CHECKING, Any, Literal, Protocol
from urllib.parse import (
parse_qs,
quote,
quote_plus,
urlparse,
urlunparse,
)
from urllib.parse import urlencode as og_urlencode
from urllib.parse import (
urlencode as parse_urlencode,
)
Expand Down Expand Up @@ -643,8 +646,6 @@ def urlencode(dict_or_list_of_tuples: dict | list[tuple[str, Any]], plus=True) -
You probably want to use this, if you're looking to urlencode parameters. This will
encode things to utf8 that would otherwise cause urlencode to error.
"""
from urllib.parse import quote, quote_plus
from urllib.parse import urlencode as og_urlencode

tuples = dict_or_list_of_tuples
if isinstance(dict_or_list_of_tuples, dict):
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/solr/types_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
import os
import xml.etree.ElementTree as ET

root = os.path.dirname(__file__)
OVERRIDES = {
Expand All @@ -14,7 +15,6 @@

def generate():
"""This function generates the types.py file."""
import xml.etree.ElementTree as ET

# read the managed-schema xml file
solr_schema = ET.parse(
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/tests/core/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

import web

from openlibrary.core import helpers as h
Expand Down Expand Up @@ -55,7 +57,6 @@ def test_sanitize():


def test_safesort():
from datetime import datetime

y2000 = datetime(2000, 1, 1)
y2005 = datetime(2005, 1, 1)
Expand All @@ -73,7 +74,6 @@ def test_safesort():


def test_datestr(monkeypatch):
from datetime import datetime

then = datetime(2010, 1, 1, 0, 0, 0)

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/tests/data/test_dump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import string

from openlibrary.data.dump import pgdecode, print_dump

Expand Down Expand Up @@ -56,6 +57,5 @@ def test_pgdecode_substitute(self):
assert pgdecode(r"\n\r\t\\") == "\n\r\t\\"

def test_pgdecode_ascii_printable(self):
import string

assert pgdecode(string.printable) == string.printable
2 changes: 1 addition & 1 deletion scripts/expire_accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import sys
from datetime import UTC, datetime

import web
Expand All @@ -24,6 +25,5 @@ def main():


if __name__ == "__main__":
import sys

sys.exit(main())
4 changes: 1 addition & 3 deletions scripts/manage-imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import json
import logging
import multiprocessing
import os
import sys
import time
Expand Down Expand Up @@ -51,7 +52,6 @@ def ol_import_request(item, retries=5, servername=None, require_marc=True):


def do_import(item, servername=None, require_marc=True):
import os

logger.info(f"do_import START (pid:{os.getpid()})")
response = ol_import_request(item, servername=servername, require_marc=require_marc)
Expand Down Expand Up @@ -151,7 +151,6 @@ def import_item(args, **kwargs):


def import_all(args, **kwargs):
import multiprocessing

servername = kwargs.get('servername')
require_marc = False
Expand Down Expand Up @@ -181,7 +180,6 @@ def main():
configfile = sys.argv[index + 1]
del sys.argv[index : index + 2]
else:
import os

configfile = os.path.abspath(
os.path.join(
Expand Down
2 changes: 1 addition & 1 deletion scripts/oclc_to_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Usage: python oclc_to_marc.py oclc_1 oclc_2
"""

import sys
import urllib

import requests
Expand Down Expand Up @@ -38,7 +39,6 @@ def main(oclc):


if __name__ == "__main__":
import sys

if len(sys.argv) == 1 or "-h" in sys.argv or "--help" in sys.argv:
print(__doc__, file=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion scripts/sitemaps/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import logging
import os
import re
import sys
from collections.abc import Iterator
from contextlib import contextmanager
from datetime import datetime
Expand Down Expand Up @@ -225,6 +226,5 @@ def main(dumpfile: str) -> None:


if __name__ == "__main__":
import sys

main(sys.argv[1])
Loading