id
int64
0
458k
file_name
stringlengths
4
119
file_path
stringlengths
14
227
content
stringlengths
24
9.96M
size
int64
24
9.96M
language
stringclasses
1 value
extension
stringclasses
14 values
total_lines
int64
1
219k
avg_line_length
float64
2.52
4.63M
max_line_length
int64
5
9.91M
alphanum_fraction
float64
0
1
repo_name
stringlengths
7
101
repo_stars
int64
100
139k
repo_forks
int64
0
26.4k
repo_open_issues
int64
0
2.27k
repo_license
stringclasses
12 values
repo_extraction_date
stringclasses
433 values
200
solr_types.py
internetarchive_openlibrary/openlibrary/solr/solr_types.py
# This file is auto-generated by types_generator.py # fmt: off from typing import Literal, TypedDict, Optional class SolrDocument(TypedDict): key: str type: Literal['work', 'author', 'subject'] redirects: Optional[list[str]] has_fulltext: Optional[bool] title: Optional[str] title_suggest: Opti...
3,176
Python
.py
91
30.087912
104
0.703115
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
201
query_utils.py
internetarchive_openlibrary/openlibrary/solr/query_utils.py
from typing import Literal, Optional from collections.abc import Callable from luqum.parser import parser from luqum.tree import Item, SearchField, BaseOperation, Group, Word, Unary import re class EmptyTreeError(Exception): pass def luqum_remove_child(child: Item, parents: list[Item]): """ Removes a ch...
10,787
Python
.py
256
33.011719
91
0.584692
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
202
utils.py
internetarchive_openlibrary/openlibrary/solr/utils.py
from dataclasses import dataclass, field import json import logging import httpx from httpx import HTTPError, HTTPStatusError, TimeoutException from openlibrary import config from openlibrary.solr.solr_types import SolrDocument from openlibrary.utils.retry import MaxRetriesExceeded, RetryStrategy logger = logging.ge...
6,011
Python
.py
162
28.697531
86
0.601723
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
203
types_generator.py
internetarchive_openlibrary/openlibrary/solr/types_generator.py
#!/usr/bin/env python import os root = os.path.dirname(__file__) OVERRIDES = { 'type': "Literal['work', 'author', 'subject']", 'public_scan_b': 'Optional[bool]', 'printdisabled_s': 'Optional[str]', 'lending_edition_s': 'Optional[str]', 'ia_collection_s': 'Optional[str]', 'ebook_count_i': 'Optio...
2,981
Python
.py
81
27.111111
80
0.539528
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
204
update.py
internetarchive_openlibrary/openlibrary/solr/update.py
import functools import logging from pathlib import Path from typing import Literal, cast import aiofiles import json import web from openlibrary.catalog.utils.query import set_query_host from openlibrary.solr.data_provider import ( get_data_provider, DataProvider, ExternalDataProvider, ) from openlibrar...
7,160
Python
.py
174
33.241379
117
0.645941
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
205
data_provider.py
internetarchive_openlibrary/openlibrary/solr/data_provider.py
"""Module to provide data for solr indexer. This module has all the logic for querying different sources for getting the data required for solr. Multiple data providers are supported, each is good for different use case. """ import asyncio import itertools import logging import re from typing import Optional, TypedD...
18,714
Python
.py
458
31.360262
99
0.580283
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
206
author.py
internetarchive_openlibrary/openlibrary/solr/updater/author.py
from typing import cast import typing import httpx from openlibrary.solr.solr_types import SolrDocument from openlibrary.solr.updater.abstract import AbstractSolrBuilder, AbstractSolrUpdater from openlibrary.solr.utils import SolrUpdateRequest, get_solr_base_url from openlibrary.solr.data_provider import WorkReadingLog...
4,951
Python
.py
122
30.47541
88
0.569288
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
207
edition.py
internetarchive_openlibrary/openlibrary/solr/updater/edition.py
from functools import cached_property import logging import re from typing import TYPE_CHECKING, cast import requests import openlibrary.book_providers as bp from openlibrary.solr.solr_types import SolrDocument from openlibrary.solr.updater.abstract import AbstractSolrBuilder, AbstractSolrUpdater from openlibrary.solr...
11,402
Python
.py
292
28.705479
97
0.549358
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
208
work.py
internetarchive_openlibrary/openlibrary/solr/updater/work.py
from collections import defaultdict from collections.abc import Iterable import datetime from functools import cached_property import itertools import logging from math import ceil import re from statistics import median import time from typing import Optional, TypedDict, cast from openlibrary.core import helpers as h ...
23,289
Python
.py
587
29.529813
98
0.562085
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
209
abstract.py
internetarchive_openlibrary/openlibrary/solr/updater/abstract.py
from collections.abc import Iterable from typing import cast import openlibrary.book_providers as bp from openlibrary.solr.data_provider import DataProvider from openlibrary.solr.solr_types import SolrDocument from openlibrary.solr.utils import SolrUpdateRequest class AbstractSolrUpdater: key_prefix: str thin...
1,838
Python
.py
45
31.622222
83
0.629277
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
210
list.py
internetarchive_openlibrary/openlibrary/solr/updater/list.py
from collections import defaultdict import re from typing import cast import httpx from openlibrary.plugins.openlibrary.lists import ( SeedType, seed_key_to_seed_type, ) from openlibrary.plugins.worksearch.subjects import SubjectType from openlibrary.solr.solr_types import SolrDocument from openlibrary.solr.up...
3,819
Python
.py
98
29.44898
86
0.571043
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
211
get_ia.py
internetarchive_openlibrary/openlibrary/catalog/get_ia.py
import requests from infogami import config from lxml import etree from time import sleep from openlibrary.catalog.marc.marc_binary import MarcBinary from openlibrary.catalog.marc.marc_xml import MarcXml from openlibrary.core import ia import lxml.etree IA_BASE_URL = config.get('ia_base_url') IA_DOWNLOAD_URL = f'{I...
3,774
Python
.py
90
34.677778
114
0.651842
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
212
match.py
internetarchive_openlibrary/openlibrary/catalog/add_book/match.py
import re import unicodedata import web # fields needed for matching: # title, subtitle, isbn, publish_country, lccn, publishers, publish_date, number_of_pages, authors re_amazon_title_paren = re.compile(r'^(.*) \([^)]+?\)$') re_brackets = re.compile(r'^(.+)\[.*?\]$') re_whitespace_and_punct = re.compile(r'[-\s,;:.]+...
15,119
Python
.py
394
31.147208
126
0.59828
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
213
__init__.py
internetarchive_openlibrary/openlibrary/catalog/add_book/__init__.py
"""Module to load books into Open Library. This is used to load books from various MARC sources, including Internet Archive. For loading a book, the available metadata is compiled as a dict, called a record internally. Here is a sample record: { "title": "The Adventures of Tom Sawyer", "source_re...
32,077
Python
.py
833
31.103241
118
0.618973
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
214
load_book.py
internetarchive_openlibrary/openlibrary/catalog/add_book/load_book.py
from typing import TYPE_CHECKING, Any, Final import web from openlibrary.catalog.utils import flip_name, author_dates_match, key_int from openlibrary.core.helpers import extract_year if TYPE_CHECKING: from openlibrary.plugins.upstream.models import Author # Sort by descending length to remove the _longest_ match...
9,244
Python
.py
265
27.211321
97
0.5717
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
215
conftest.py
internetarchive_openlibrary/openlibrary/catalog/add_book/tests/conftest.py
import pytest @pytest.fixture def add_languages(mock_site): languages = [ ('eng', 'English'), ('spa', 'Spanish'), ('fre', 'French'), ('yid', 'Yiddish'), ('fri', 'Frisian'), ('fry', 'Frisian'), ] for code, name in languages: mock_site.save( ...
504
Python
.py
20
15.9
50
0.417012
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
216
test_match.py
internetarchive_openlibrary/openlibrary/catalog/add_book/tests/test_match.py
import pytest from copy import deepcopy from openlibrary.catalog.add_book import load from openlibrary.catalog.add_book.match import ( THRESHOLD, add_db_name, build_titles, compare_authors, compare_publisher, editions_match, expand_record, normalize, mk_norm, threshold_match, )...
14,923
Python
.py
374
30.010695
93
0.559343
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
217
test_load_book.py
internetarchive_openlibrary/openlibrary/catalog/add_book/tests/test_load_book.py
import pytest from openlibrary.catalog.add_book import load_book from openlibrary.catalog.add_book.load_book import ( find_entity, import_author, build_query, InvalidLanguage, remove_author_honorifics, ) from openlibrary.core.models import Author @pytest.fixture def new_import(monkeypatch): mo...
11,307
Python
.py
287
29.916376
93
0.56219
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
218
test_add_book.py
internetarchive_openlibrary/openlibrary/catalog/add_book/tests/test_add_book.py
import os import pytest from datetime import datetime from infogami.infobase.client import Nothing from infogami.infobase.core import Text from openlibrary.catalog import add_book from openlibrary.catalog.add_book import ( build_pool, editions_matched, find_match, IndependentlyPublished, isbns_fro...
59,742
Python
.py
1,614
27.512392
106
0.529031
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
219
edit.py
internetarchive_openlibrary/openlibrary/catalog/utils/edit.py
import re import requests import web from openlibrary.catalog.utils.query import get_mc from openlibrary.api import unmarshal from time import sleep re_meta_mrc = re.compile('([^/]+)_(meta|marc).(mrc|xml)') re_skip = re.compile(r'\b([A-Z]|Co|Dr|Jr|Capt|Mr|Mrs|Ms|Prof|Rev|Revd|Hon)\.$') db_amazon = web.database(dbn='p...
3,388
Python
.py
91
30.263736
85
0.582468
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
220
__init__.py
internetarchive_openlibrary/openlibrary/catalog/utils/__init__.py
import datetime import re from typing import TYPE_CHECKING import web from unicodedata import normalize if TYPE_CHECKING: from openlibrary.plugins.upstream.models import Author EARLIEST_PUBLISH_YEAR_FOR_BOOKSELLERS = 1400 BOOKSELLERS_WITH_ADDITIONAL_VALIDATION = ['amazon', 'bwb'] def cmp(x, y): return (x >...
12,779
Python
.py
333
31.531532
130
0.599158
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
221
query.py
internetarchive_openlibrary/openlibrary/catalog/utils/query.py
import requests import web import json from time import sleep import urllib import sys query_host = 'openlibrary.org' def urlopen(url, data=None): version = "%s.%s.%s" % sys.version_info[:3] user_agent = f'Mozilla/5.0 (openlibrary; {__name__}) Python/{version}' headers = {'User-Agent': user_agent} ...
4,179
Python
.py
145
20.862069
84
0.542407
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
222
marc_binary.py
internetarchive_openlibrary/openlibrary/catalog/marc/marc_binary.py
from pymarc import MARC8ToUnicode from unicodedata import normalize from collections.abc import Iterator from openlibrary.catalog.marc import mnemonics from openlibrary.catalog.marc.marc_base import ( MarcBase, MarcFieldBase, MarcException, BadMARC, ) marc8 = MARC8ToUnicode(quiet=True) class BadLen...
6,266
Python
.py
162
28.839506
103
0.561678
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
223
marc_base.py
internetarchive_openlibrary/openlibrary/catalog/marc/marc_base.py
import re from abc import abstractmethod from collections import defaultdict from collections.abc import Iterator re_isbn = re.compile(r'([^ ()]+[\dX])(?: \((?:v\. (\d+)(?: : )?)?(.*)\))?') # handle ISBN like: 1402563884c$26.95 re_isbn_and_price = re.compile(r'^([-\d]+X?)c\$[\d.]+$') class MarcException(Exception): ...
3,200
Python
.py
80
31.725
88
0.597805
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
224
get_subjects.py
internetarchive_openlibrary/openlibrary/catalog/marc/get_subjects.py
from collections import defaultdict import re from openlibrary.catalog.utils import remove_trailing_dot, flip_name re_flip_name = re.compile('^(.+), ([A-Z].+)$') # 'Rhodes, Dan (Fictitious character)' re_fictitious_character = re.compile(r'^(.+), (.+)( \(.* character\))$') re_etc = re.compile('^(.+?)[, .]+etc[, .]?$'...
4,088
Python
.py
93
35.645161
94
0.540588
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
225
html.py
internetarchive_openlibrary/openlibrary/catalog/marc/html.py
import re from pymarc.record import Record trans = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '\n': '<br>', '\x1b': '<b>[esc]</b>'} re_html_replace = re.compile('([&<>\n\x1b])') def esc(s): return re_html_replace.sub(lambda m: trans[m.group(1)], s) def subfields(line): if isinstance(line, str): retu...
924
Python
.py
26
28.038462
86
0.514061
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
226
parse.py
internetarchive_openlibrary/openlibrary/catalog/marc/parse.py
import logging import re from typing import Any from collections.abc import Callable from openlibrary.catalog.marc.get_subjects import subjects_for_work from openlibrary.catalog.marc.marc_base import ( MarcBase, MarcFieldBase, BadMARC, NoTitle, MarcException, ) from openlibrary.catalog.utils import...
26,720
Python
.py
667
31.923538
119
0.573283
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
227
mnemonics.py
internetarchive_openlibrary/openlibrary/catalog/marc/mnemonics.py
# read MARC mnemonics # result is in MARC8 and still needs to be converted to Unicode import re re_brace = re.compile(b'(\\{.+?\\})') mapping = { b'{00}': b'\x00', b'{01}': b'\x01', b'{02}': b'\x02', b'{03}': b'\x03', b'{04}': b'\x04', b'{05}': b'\x05', b'{06}': b'\x06', b'{07}': b'\x...
16,118
Python
.py
710
17.678873
77
0.369481
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
228
marc_xml.py
internetarchive_openlibrary/openlibrary/catalog/marc/marc_xml.py
from lxml import etree from unicodedata import normalize from collections.abc import Iterator from openlibrary.catalog.marc.marc_base import MarcBase, MarcFieldBase, MarcException data_tag = '{http://www.loc.gov/MARC21/slim}datafield' control_tag = '{http://www.loc.gov/MARC21/slim}controlfield' subfield_tag = '{http:...
3,278
Python
.py
83
30.746988
85
0.600567
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
229
test_marc.py
internetarchive_openlibrary/openlibrary/catalog/marc/tests/test_marc.py
from openlibrary.catalog.marc.get_subjects import subjects_for_work from openlibrary.catalog.marc.marc_base import MarcBase from openlibrary.catalog.marc.parse import read_isbn, read_pagination, read_title class MockField: def __init__(self, subfields): self.subfield_sequence = subfields self.cont...
6,578
Python
.py
180
25.644444
122
0.500314
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
230
test_get_subjects.py
internetarchive_openlibrary/openlibrary/catalog/marc/tests/test_get_subjects.py
from openlibrary.catalog.marc.marc_xml import MarcXml from openlibrary.catalog.marc.marc_binary import MarcBinary from openlibrary.catalog.marc.get_subjects import four_types, read_subjects from lxml import etree from pathlib import Path import pytest import lxml.etree xml_samples = [ ('bijouorannualofl1828cole', ...
8,063
Python
.py
259
21.467181
88
0.481272
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
231
test_mnemonics.py
internetarchive_openlibrary/openlibrary/catalog/marc/tests/test_mnemonics.py
from openlibrary.catalog.marc.mnemonics import read def test_read_conversion_to_marc8(): input_ = ( b'Tha{mllhring}{macr}alib{macr}i, {mllhring}Abd al-Malik ibn Mu{dotb}hammad,' ) output = b'Tha\xb0\xe5alib\xe5i, \xb0Abd al-Malik ibn Mu\xf2hammad,' assert read(input_) == output def test_read...
485
Python
.py
10
43.9
116
0.707006
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
232
test_marc_html.py
internetarchive_openlibrary/openlibrary/catalog/marc/tests/test_marc_html.py
from pathlib import Path from openlibrary.catalog.marc.html import html_record TEST_DATA = Path(__file__).with_name('test_data') / 'bin_input' def test_html_line_marc8(): filepath = TEST_DATA / 'uoft_4351105_1626.mrc' expected_utf8 = ( '<b>700</b> <code>1 <b>$a</b>Ovsi︠a︡nnikov, Mikhail Fedotovich....
453
Python
.py
11
36.545455
84
0.679724
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
233
test_marc_binary.py
internetarchive_openlibrary/openlibrary/catalog/marc/tests/test_marc_binary.py
from pathlib import Path from openlibrary.catalog.marc.marc_binary import BinaryDataField, MarcBinary TEST_DATA = Path(__file__).with_name('test_data') / 'bin_input' class MockMARC: def __init__(self, encoding): """ :param encoding str: 'utf8' or 'marc8' """ self.encoding = encodi...
2,631
Python
.py
65
32.4
88
0.607843
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
234
test_parse.py
internetarchive_openlibrary/openlibrary/catalog/marc/tests/test_parse.py
import json import pytest from openlibrary.catalog.marc.parse import ( read_author_person, read_edition, NoTitle, SeeAlsoAsTitle, ) from openlibrary.catalog.marc.marc_binary import MarcBinary from openlibrary.catalog.marc.marc_xml import DataField, MarcXml from lxml import etree from pathlib import Pat...
7,077
Python
.py
177
32.723164
109
0.64541
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
235
__init__.py
internetarchive_openlibrary/openlibrary/olbase/__init__.py
"""Infobase extension for Open Library. """ from . import events from ..plugins import ol_infobase def init_plugin(): ol_infobase.init_plugin() events.setup()
170
Python
.py
7
21.714286
39
0.7375
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
236
events.py
internetarchive_openlibrary/openlibrary/olbase/events.py
"""Infobase event hooks for Open Library. Triggers and handles various events from Infobase. All the events are triggered using eventer. List of events: * infobase.all: Triggered for any change in Infobase. The infobase event object is passed as argument. * infobase.edit: Triggered for edits. Changeset is pa...
4,406
Python
.py
102
35.343137
106
0.631172
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
237
test_events.py
internetarchive_openlibrary/openlibrary/olbase/tests/test_events.py
from .. import events class TestMemcacheInvalidater: def test_seed_to_key(self): m = events.MemcacheInvalidater() assert m.seed_to_key({"key": "/books/OL1M"}) == "/books/OL1M" assert m.seed_to_key("subject:love") == "/subjects/love" assert m.seed_to_key("place:san_francisco") == "/...
3,137
Python
.py
85
23.364706
86
0.431624
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
238
test_ol_infobase.py
internetarchive_openlibrary/openlibrary/olbase/tests/test_ol_infobase.py
from openlibrary.plugins.ol_infobase import OLIndexer class TestOLIndexer: def test_expand_isbns(self): indexer = OLIndexer() isbn_10 = ['123456789X'] isbn_13 = ['9781234567897'] both = isbn_10 + isbn_13 assert indexer.expand_isbns([]) == [] assert sorted(indexer.ex...
468
Python
.py
11
35.181818
60
0.650549
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
239
showmarc.py
internetarchive_openlibrary/openlibrary/views/showmarc.py
""" Hook to show MARC or other source record details in Open Library. """ from .. import app import web import re import requests class old_show_marc(app.view): path = "/show-marc/(.*)" def GET(self, param): raise web.seeother('/show-records/' + param) class show_ia(app.view): path = "/show-...
4,403
Python
.py
115
28.252174
93
0.554013
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
240
loanstats.py
internetarchive_openlibrary/openlibrary/views/loanstats.py
"""Loan Stats""" import web from infogami.utils import delegate from ..core.lending import get_availabilities from infogami.utils.view import public from ..utils import dateutil from .. import app from ..core import cache from ..core.observations import Observations from ..core.booknotes import Booknotes from ..core...
6,853
Python
.py
190
28.221053
84
0.628286
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
241
processors.py
internetarchive_openlibrary/openlibrary/utils/processors.py
"""Generic web.py application processors. """ import web import time __all__ = ["RateLimitProcessor"] class RateLimitProcessor: """Application processor to ratelimit the access per ip.""" def __init__( self, limit: int, window_size: int = 600, path_regex: str = "/.*" ) -> None: """Creat...
1,699
Python
.py
45
29.311111
97
0.608643
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
242
compress.py
internetarchive_openlibrary/openlibrary/utils/compress.py
# incremental zlib compression, written by solrize, August 2009 import zlib __doc__ = """ Compressor object for medium-sized, statistically-similar strings. The idea is that you have a lot of moderate-sized strings (short email messages or the like) that you would like to compress independently, for storage in a look...
3,422
Python
.py
74
41.094595
77
0.70447
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
243
lccn.py
internetarchive_openlibrary/openlibrary/utils/lccn.py
import re REV_RE = re.compile(r'rev.*') REMOVESUFFIX_RE = re.compile(r'[^\/]+') HYPHEN_RE = re.compile(r'(.+)-+([0-9]+)') # Validates the syntax described at https://www.loc.gov/marc/lccn-namespace.html LCCN_NORM_RE = re.compile( r'([a-z]|[a-z]?([a-z]{2}|[0-9]{2})|[a-z]{2}[0-9]{2})?[0-9]{8}$' ) def normalize_lc...
687
Python
.py
19
32.210526
80
0.591867
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
244
olmemcache.py
internetarchive_openlibrary/openlibrary/utils/olmemcache.py
"""Memcache interface to store data in memcached.""" import memcache from openlibrary.utils.olcompress import OLCompressor import web class Client: """Wrapper to memcache Client to enable OL specific compression and unicode keys. Compatible with memcache Client API. """ def __init__(self, servers): ...
1,594
Python
.py
36
37.055556
85
0.663001
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
245
dateutil.py
internetarchive_openlibrary/openlibrary/utils/dateutil.py
"""Generic date utilities. """ import calendar import datetime from contextlib import contextmanager from sys import stderr from time import perf_counter from infogami.utils.view import public MINUTE_SECS = 60 HALF_HOUR_SECS = MINUTE_SECS * 30 HOUR_SECS = MINUTE_SECS * 60 HALF_DAY_SECS = HOUR_SECS * 12 DAY_SECS = H...
3,499
Python
.py
94
32.5
87
0.659745
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
246
form.py
internetarchive_openlibrary/openlibrary/utils/form.py
"""New form library to use instead of web.form. (this should go to web.py) """ import web import copy import re from infogami.utils.view import render class AttributeList(dict): """List of attributes of input. >>> a = AttributeList(type='text', name='x', value=20) >>> a <attrs: 'type="text" name="...
4,912
Python
.py
154
24.324675
95
0.568657
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
247
sentry.py
internetarchive_openlibrary/openlibrary/utils/sentry.py
from dataclasses import dataclass import logging import re import sentry_sdk import web from sentry_sdk.utils import capture_internal_exceptions from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE from infogami.utils.app import find_page, find_view, modes from infogami.utils.types import type_patterns...
5,526
Python
.py
142
28.78169
80
0.582383
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
248
solr.py
internetarchive_openlibrary/openlibrary/utils/solr.py
"""Python library for accessing Solr""" import logging import re from typing import Optional, TypeVar from collections.abc import Callable, Iterable import requests import web from urllib.parse import urlencode, urlsplit logger = logging.getLogger("openlibrary.logger") T = TypeVar('T') class Solr: def __in...
6,506
Python
.py
172
27.133721
112
0.517554
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
249
olcompress.py
internetarchive_openlibrary/openlibrary/utils/olcompress.py
"""Initial seed to create compress object. see compress module for details. """ from openlibrary.utils.compress import Compressor # using 4 random records from OL seed seed1 = '{"subject_place": ["Great Britain", "Great Britain."], "lc_classifications": ["RT85.5 .K447 1994"], "contributions": ["Richardson, Eileen, ...
3,189
Python
.py
13
243.153846
1,209
0.655727
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
250
__init__.py
internetarchive_openlibrary/openlibrary/utils/__init__.py
"""Generic utilities""" from enum import Enum import re from subprocess import CalledProcessError, run from typing import TypeVar, Literal from collections.abc import Iterable, Callable to_drop = set(''';/?:@&=+$,<>#%"{}|\\^[]`\n\r''') def str_to_key(s: str) -> str: """ >>> str_to_key("?H$e##l{o}[0] -world!...
5,931
Python
.py
191
25.120419
83
0.555595
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
251
ia.py
internetarchive_openlibrary/openlibrary/utils/ia.py
from socket import socket, AF_INET, SOCK_DGRAM, SOL_UDP, SO_BROADCAST import re re_loc = re.compile(r'^(ia\d+\.us\.archive\.org):(/\d+/items/(.*))$') class FindItemError(Exception): pass def find_item(ia): s = socket(AF_INET, SOCK_DGRAM, SOL_UDP) s.setblocking(1) s.settimeout(2.0) s.setsockopt(...
631
Python
.py
19
27.473684
69
0.610561
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
252
retry.py
internetarchive_openlibrary/openlibrary/utils/retry.py
import time class MaxRetriesExceeded(Exception): last_exception: Exception def __init__(self, last_exception: Exception): self.last_exception = last_exception class RetryStrategy: retry_count = 0 last_exception: Exception | None = None def __init__(self, exceptions: list[type[Exception...
929
Python
.py
25
27.32
82
0.601117
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
253
bulkimport.py
internetarchive_openlibrary/openlibrary/utils/bulkimport.py
"""Utility to bulk import documents into Open Library database without going through infobase API. """ import json import os import web import datetime from collections import defaultdict class DocumentLoader: def __init__(self, **params): params = params.copy() params.setdefault('dbn', 'postgres...
16,125
Python
.py
414
26.898551
109
0.521937
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
254
isbn.py
internetarchive_openlibrary/openlibrary/utils/isbn.py
from __future__ import annotations from isbnlib import canonical def check_digit_10(isbn): """Takes the first 9 digits of an ISBN10 and returns the calculated final checkdigit.""" if len(isbn) != 9: raise ValueError("%s is not a valid ISBN 10" % isbn) sum = 0 for i in range(len(isbn)): ...
4,242
Python
.py
119
29.142857
93
0.601807
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
255
ddc.py
internetarchive_openlibrary/openlibrary/utils/ddc.py
""" Dewey Decimal Numbers Known issues ## Further Reading https://www.oclc.org/bibformats/en/0xx/082.html """ from __future__ import annotations import re from string import printable from collections.abc import Iterable MULTIPLE_SPACES_RE = re.compile(r'\s+') DDC_RE = re.compile( r''' ( # Prefix ...
4,798
Python
.py
139
26.482014
86
0.557239
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
256
lcc.py
internetarchive_openlibrary/openlibrary/utils/lcc.py
""" Crash course Library of Congress Classification (LCC) Examples: - HB1951 .R64 1995 - DP402.C8 O46 1995 - CS879 .R3 1995 - NC248.S22 A4 1992 - TJ563 .P66 1998 - PQ3919.2.M2866 C83 1994 - NA2500 .H64 1995 - DT423.E26 9th.ed. 2012 - PZ73.S758345255 2011 - PZ8.3.G276Lo 1971 Has 3 parts: 1. The class number...
7,492
Python
.py
177
38.067797
88
0.668087
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
257
schema.py
internetarchive_openlibrary/openlibrary/utils/schema.py
"""utility to generate db schema for any database engine. (should go to web.py) """ __all__ = [ "Schema", "Table", "Column", "register_datatype", "register_constant", ] _datatypes = {} def register_datatype(name, datatype): _datatypes[name] = datatype _adapters = {} def register_adapter(...
11,039
Python
.py
316
26.971519
85
0.578373
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
258
open_syllabus_project.py
internetarchive_openlibrary/openlibrary/utils/open_syllabus_project.py
import logging import os import json import sqlite3 import gzip from contextlib import closing from pathlib import Path osp_dump_location: Path | None = None logger = logging.getLogger("openlibrary.open_syllabus_project") def get_osp_dump_location() -> Path | None: """ Get whether the location of the Open Sy...
3,885
Python
.py
89
34.348315
115
0.621385
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
259
decorators.py
internetarchive_openlibrary/openlibrary/utils/decorators.py
import web from functools import wraps from openlibrary.accounts import get_current_user def authorized_for(*expected_args): """Check for membership in any given usergroup before proceeding.""" def decorator_authorized(func): @wraps(func) def wrapper_authorized(*args, **kwargs): ...
876
Python
.py
21
31.142857
77
0.634752
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
260
test_dateutil.py
internetarchive_openlibrary/openlibrary/utils/tests/test_dateutil.py
from .. import dateutil import datetime def test_parse_date(): assert dateutil.parse_date("2010") == datetime.date(2010, 1, 1) assert dateutil.parse_date("2010-02") == datetime.date(2010, 2, 1) assert dateutil.parse_date("2010-02-03") == datetime.date(2010, 2, 3) def test_nextday(): assert dateutil....
1,622
Python
.py
32
45.40625
87
0.667724
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
261
test_lccn.py
internetarchive_openlibrary/openlibrary/utils/tests/test_lccn.py
import pytest from openlibrary.utils.lccn import normalize_lccn def test_normalize_lccn_prenormalized(): prenormalized = '94200274' assert normalize_lccn(prenormalized) == prenormalized lccns = [ ('96-39190', '96039190'), ('agr 62000298', 'agr62000298'), ('agr 62-298', 'agr62000298'), ('agr6...
821
Python
.py
25
29.12
57
0.661168
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
262
test_utils.py
internetarchive_openlibrary/openlibrary/utils/tests/test_utils.py
from openlibrary.utils import ( extract_numeric_id_from_olid, str_to_key, ) def test_str_to_key(): assert str_to_key('x') == 'x' assert str_to_key('X') == 'x' assert str_to_key('[X]') == 'x' assert str_to_key('!@<X>;:') == '!x' assert str_to_key('!@(X);:') == '!(x)' def test_extract_nume...
465
Python
.py
13
31.692308
65
0.595982
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
263
test_retry.py
internetarchive_openlibrary/openlibrary/utils/tests/test_retry.py
from unittest.mock import Mock import pytest from openlibrary.utils.retry import MaxRetriesExceeded, RetryStrategy class TestRetryStrategy: def test_exception_filter(self, monkeytime): foo = Mock(side_effect=ZeroDivisionError) retry = RetryStrategy([ZeroDivisionError], max_retries=3) with ...
1,440
Python
.py
34
33.529412
70
0.66
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
264
test_processors.py
internetarchive_openlibrary/openlibrary/utils/tests/test_processors.py
import web import time from ..processors import RateLimitProcessor class TestRateLimitProcessor: """py.test testcase for testing RateLimitProcessor.""" def setup_method(self, method): web.ctx.ip = "127.0.0.1" def test_check_rate(self, monkeypatch): monkeypatch.setattr(time, "time", lamb...
974
Python
.py
25
31.28
65
0.624733
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
265
test_solr.py
internetarchive_openlibrary/openlibrary/utils/tests/test_solr.py
from ..solr import Solr def test_prepare_select(): solr = Solr("http://localhost:8983/solr") assert solr._prepare_select("foo") == "foo" assert solr._prepare_select({"isbn": "1234567890"}) == 'isbn:"1234567890"' assert ( solr._prepare_select({"isbn": ["1234567890", "9876543210"]}) == ...
490
Python
.py
13
31.769231
78
0.598309
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
266
test_lcc.py
internetarchive_openlibrary/openlibrary/utils/tests/test_lcc.py
import pytest from openlibrary.utils.lcc import ( choose_sorting_lcc, normalize_lcc_prefix, normalize_lcc_range, short_lcc_to_sortable_lcc, sortable_lcc_to_short_lcc, ) TESTS = [ ('PZ-0073.00000000', 'pz73', 'PZ73', 'lower case'), ('PZ-0000.00000000', 'PZ', 'PZ', 'just class'), ('PZ-01...
5,438
Python
.py
125
39.336
88
0.639735
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
267
test_isbn.py
internetarchive_openlibrary/openlibrary/utils/tests/test_isbn.py
import pytest from openlibrary.utils.isbn import ( get_isbn_10_and_13, isbn_10_to_isbn_13, isbn_13_to_isbn_10, normalize_identifier, normalize_isbn, opposite_isbn, get_isbn_10s_and_13s, ) def test_isbn_13_to_isbn_10(): assert isbn_13_to_isbn_10('978-0-940787-08-7') == '0940787083' ...
3,320
Python
.py
89
32.393258
89
0.639539
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
268
test_ddc.py
internetarchive_openlibrary/openlibrary/utils/tests/test_ddc.py
import pytest from openlibrary.utils.ddc import ( choose_sorting_ddc, normalize_ddc, normalize_ddc_prefix, normalize_ddc_range, ) # Src: https://www.oclc.org/bibformats/en/0xx/082.html TESTS_FROM_OCLC = [ ("370.19'342", ['370.19342'], "Segmentation (prime) marks"), ("370.19/342", ['370.19342']...
5,634
Python
.py
141
34.758865
88
0.574877
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
269
__init__.py
internetarchive_openlibrary/openlibrary/accounts/__init__.py
import web # FIXME: several modules import things from accounts.model # directly through openlibrary.accounts from .model import * # noqa: F403 from .model import Account, Link from typing import TYPE_CHECKING if TYPE_CHECKING: from openlibrary.plugins.upstream.models import User # Unconfirmed functions (I'm ...
3,526
Python
.py
88
33.488636
87
0.661096
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
270
model.py
internetarchive_openlibrary/openlibrary/accounts/model.py
""" """ import secrets import time import datetime import hashlib import hmac import random import string from typing import TYPE_CHECKING, Any import uuid import logging import requests from validate_email import validate_email import web from infogami import config from infogami.utils.view import render_template,...
32,512
Python
.py
794
31.309824
97
0.602953
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
271
test_dump.py
internetarchive_openlibrary/openlibrary/tests/data/test_dump.py
import json from openlibrary.data.dump import print_dump, pgdecode class TestPrintDump: def test_fixes_prefixes(self, capsys): records = [ { "key": "/b/OL1M", "type": {"key": "/type/edition"}, "revision": 1, "last_modified": {"va...
1,737
Python
.py
50
22.48
78
0.4642
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
272
test_utils.py
internetarchive_openlibrary/openlibrary/tests/solr/test_utils.py
import json from unittest.mock import MagicMock import httpx from httpx import Response, ConnectError from openlibrary.solr.utils import SolrUpdateRequest, solr_update class TestSolrUpdate: def sample_response_200(self): return Response( 200, request=MagicMock(), cont...
4,647
Python
.py
123
23.439024
92
0.492109
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
273
test_types_generator.py
internetarchive_openlibrary/openlibrary/tests/solr/test_types_generator.py
import os from openlibrary.solr.types_generator import generate root = os.path.dirname(__file__) def test_up_to_date(): types_path = os.path.join(root, '..', '..', 'solr', 'solr_types.py') assert ( generate().strip() == open(types_path).read().strip() ), """ This auto-generated file is out-...
419
Python
.py
11
33.727273
76
0.650124
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
274
test_update.py
internetarchive_openlibrary/openlibrary/tests/solr/test_update.py
import pytest from openlibrary.core.ratings import WorkRatingsSummary from openlibrary.solr import update from openlibrary.solr.data_provider import DataProvider, WorkReadingLogSolrSummary author_counter = 0 edition_counter = 0 work_counter = 0 def make_author(**kw): """ Create a fake author :param kw:...
3,860
Python
.py
116
25.362069
86
0.569123
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
275
test_data_provider.py
internetarchive_openlibrary/openlibrary/tests/solr/test_data_provider.py
from unittest.mock import MagicMock import pytest from infogami.infobase.client import Thing from openlibrary.solr.data_provider import BetterDataProvider class TestBetterDataProvider: @pytest.mark.asyncio async def test_get_document(self): mock_site = MagicMock() dp = BetterDataProvider( ...
1,634
Python
.py
50
21.82
61
0.522483
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
276
test_query_utils.py
internetarchive_openlibrary/openlibrary/tests/solr/test_query_utils.py
import pytest from openlibrary.solr.query_utils import ( EmptyTreeError, luqum_parser, luqum_remove_child, luqum_replace_child, luqum_traverse, luqum_replace_field, luqum_remove_field, ) REMOVE_TESTS = { 'Complete match': ('title:foo', 'title:foo', ''), 'Binary Op Left': ('title:foo...
4,376
Python
.py
108
33.851852
88
0.605461
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
277
test_author.py
internetarchive_openlibrary/openlibrary/tests/solr/updater/test_author.py
import httpx import pytest from openlibrary.solr.updater.author import AuthorSolrUpdater from openlibrary.tests.solr.test_update import FakeDataProvider, make_author class MockResponse: def __init__(self, json_data, status_code=200): self.json_data = json_data self.status_code = status_code d...
1,756
Python
.py
42
27
76
0.490035
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
278
test_work.py
internetarchive_openlibrary/openlibrary/tests/solr/updater/test_work.py
import pytest from openlibrary.solr.updater.work import ( WorkSolrBuilder, WorkSolrUpdater, ) from openlibrary.tests.solr.test_update import ( FakeDataProvider, make_author, make_edition, make_work, ) def sorted_split_semicolon(s): """ >>> sorted_split_semicolon("z;c;x;a;y;b") ['a'...
19,960
Python
.py
521
27.570058
88
0.509443
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
279
test_edition.py
internetarchive_openlibrary/openlibrary/tests/solr/updater/test_edition.py
import pytest from openlibrary.solr.updater.edition import EditionSolrUpdater from openlibrary.tests.solr.test_update import FakeDataProvider class TestEditionSolrUpdater: @pytest.mark.asyncio async def test_deletes_old_orphans(self): req, new_keys = await EditionSolrUpdater(FakeDataProvider()).updat...
969
Python
.py
24
31.625
80
0.597444
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
280
test_get_ia.py
internetarchive_openlibrary/openlibrary/tests/catalog/test_get_ia.py
import pytest from pathlib import Path from openlibrary.catalog import get_ia from openlibrary.core import ia from openlibrary.catalog.marc.marc_xml import MarcXml from openlibrary.catalog.marc.marc_binary import MarcBinary, BadLength, BadMARC TEST_DATA = Path(__file__).parents[2] / 'catalog' / 'marc' / 'tests' / 'te...
4,747
Python
.py
108
36.037037
134
0.664719
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
281
test_utils.py
internetarchive_openlibrary/openlibrary/tests/catalog/test_utils.py
import pytest from datetime import datetime, timedelta from openlibrary.catalog.utils import ( author_dates_match, flip_name, get_missing_fields, get_non_isbn_asin, get_publication_year, is_asin_only, is_independently_published, is_promise_item, match_with_bad_chars, needs_isbn_...
13,158
Python
.py
378
27.537037
88
0.554605
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
282
test_models.py
internetarchive_openlibrary/openlibrary/tests/accounts/test_models.py
from openlibrary.accounts import model, InternetArchiveAccount, OpenLibraryAccount from requests.models import Response from unittest import mock def get_username(account): return account and account.value def test_verify_hash(): secret_key = b"aqXwLJVOcV" hash = model.generate_hash(secret_key, b"foo") ...
3,011
Python
.py
80
31.2
82
0.665179
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
283
conftest.py
internetarchive_openlibrary/openlibrary/tests/core/conftest.py
import os import pytest @pytest.fixture def dummy_crontabfile(request): "Creates a dummy crontab file that can be used for to try things" cronfile = os.tmpnam() ip = """* * * * * /bin/true * * * * * /bin/true""" f = open(cronfile, "w") f.write(ip) f.close() request.addfinalizer(lambda: os....
1,680
Python
.py
53
26.584906
70
0.656541
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
284
test_ia.py
internetarchive_openlibrary/openlibrary/tests/core/test_ia.py
from openlibrary.core import ia def test_get_metadata(monkeypatch, mock_memcache): metadata = { "metadata": { "title": "Foo", "identifier": "foo00bar", "collection": ["printdisabled", "inlibrary"], } } monkeypatch.setattr(ia, 'get_api_response', lambda ...
731
Python
.py
20
29.3
71
0.603399
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
285
test_observations.py
internetarchive_openlibrary/openlibrary/tests/core/test_observations.py
from openlibrary.core.observations import _sort_values def test_sort_values(): orders_list = [3, 4, 2, 1] values_list = [ {'id': 1, 'name': 'order'}, {'id': 2, 'name': 'in'}, {'id': 3, 'name': 'this'}, {'id': 4, 'name': 'is'}, ] # sorted values returned given unsorted ...
831
Python
.py
17
43.117647
83
0.605686
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
286
test_processors_invalidation.py
internetarchive_openlibrary/openlibrary/tests/core/test_processors_invalidation.py
import web import datetime from infogami.infobase import client from openlibrary.core.processors import invalidation from openlibrary.mocks.mock_infobase import MockSite class MockHook: def __init__(self): self.call_count = 0 self.recent_doc = None def on_new_version(self, doc): self...
6,150
Python
.py
144
33.666667
96
0.621222
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
287
test_unmarshal.py
internetarchive_openlibrary/openlibrary/tests/core/test_unmarshal.py
from datetime import datetime import re import pytest from openlibrary.api import unmarshal class Text(str): __slots__ = () def __repr__(self): return "<text: %s>" % str.__repr__(self) class Reference(str): __slots__ = () def __repr__(self): return "<ref: %s>" % str.__repr__(self...
2,116
Python
.py
60
26.383333
82
0.493392
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
288
test_connections.py
internetarchive_openlibrary/openlibrary/tests/core/test_connections.py
# This will be moved to core soon. from openlibrary.plugins.openlibrary import connection as connections import json class MockConnection: def __init__(self): self.docs = {} def request(self, sitename, path, method="GET", data=None): data = data or {} if path == "/get": ke...
3,476
Python
.py
105
21.161905
82
0.430746
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
289
test_helpers.py
internetarchive_openlibrary/openlibrary/tests/core/test_helpers.py
import web from openlibrary.core import helpers as h from openlibrary.mocks.mock_infobase import MockSite def _load_fake_context(): app = web.application() env = { "PATH_INFO": "/", "HTTP_METHOD": "GET", } app.load(env) def _monkeypatch_web(monkeypatch): monkeypatch.setattr(web, ...
3,995
Python
.py
94
37.244681
88
0.609428
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
290
test_imports.py
internetarchive_openlibrary/openlibrary/tests/core/test_imports.py
import pytest from typing import Final import web from openlibrary.core.db import get_db from openlibrary.core.imports import Batch, ImportItem IMPORT_ITEM_DDL: Final = """ CREATE TABLE import_item ( id serial primary key, batch_id integer, status text default 'pending', error text, ia_id text, ...
4,775
Python
.py
157
24.191083
85
0.589107
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
291
test_olmarkdown.py
internetarchive_openlibrary/openlibrary/tests/core/test_olmarkdown.py
from openlibrary.core.olmarkdown import OLMarkdown def test_olmarkdown(): def md(text): return OLMarkdown(text).convert().strip() def p(html): # markdown always wraps the result in <p>. return "<p>%s\n</p>" % html assert md("**foo**") == p("<strong>foo</strong>") assert md("<...
706
Python
.py
19
30.842105
76
0.56305
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
292
test_lists_model.py
internetarchive_openlibrary/openlibrary/tests/core/test_lists_model.py
from typing import cast from openlibrary.core.lists.model import List, Seed, ThingReferenceDict def test_seed_with_string(): lst = List(None, "/list/OL1L", None) seed = Seed(lst, "subject/Politics and government") assert seed._list == lst assert seed.value == "subject/Politics and government" ass...
710
Python
.py
16
40.0625
72
0.698113
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
293
test_db.py
internetarchive_openlibrary/openlibrary/tests/core/test_db.py
import web from openlibrary.core.db import get_db from openlibrary.core.bookshelves import Bookshelves from openlibrary.core.bookshelves_events import BookshelvesEvents from openlibrary.core.booknotes import Booknotes from openlibrary.core.edits import CommunityEditsQueue from openlibrary.core.observations import Obser...
19,855
Python
.py
567
24.555556
88
0.52613
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
294
test_vendors.py
internetarchive_openlibrary/openlibrary/tests/core/test_vendors.py
from dataclasses import dataclass from unittest.mock import patch import pytest from openlibrary.core.vendors import ( get_amazon_metadata, split_amazon_title, clean_amazon_metadata_for_load, betterworldbooks_fmt, AmazonAPI, is_dvd, ) def test_clean_amazon_metadata_for_load_non_ISBN(): # ...
12,035
Python
.py
337
28.593472
103
0.596913
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
295
test_cache.py
internetarchive_openlibrary/openlibrary/tests/core/test_cache.py
import time from openlibrary.core import cache from openlibrary.mocks import mock_memcache class Test_memcache_memoize: def test_encode_args(self): m = cache.memcache_memoize(None, key_prefix="foo") assert m.encode_args([]) == '' assert m.encode_args(["a"]) == '"a"' assert m.enco...
4,564
Python
.py
127
26.685039
89
0.538812
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
296
test_lending.py
internetarchive_openlibrary/openlibrary/tests/core/test_lending.py
from unittest.mock import Mock, patch from openlibrary.core import lending class TestAddAvailability: def test_reads_ocaids(self, monkeypatch): def mock_get_availability_of_ocaids(ocaids): return {'foo': {'status': 'available'}} monkeypatch.setattr( lending, "get_availabi...
3,084
Python
.py
71
31.915493
82
0.528019
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
297
test_waitinglist.py
internetarchive_openlibrary/openlibrary/tests/core/test_waitinglist.py
from openlibrary.core.waitinglist import WaitingLoan from openlibrary.core import lending import json import pytest class TestWaitingLoan: def test_new(self, monkeypatch): user_key = '/people/user1' identifier = 'foobar' monkeypatch.setattr( lending.ia_lending_api, 'join_waitin...
1,526
Python
.py
38
32.368421
89
0.633603
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
298
test_fulltext.py
internetarchive_openlibrary/openlibrary/tests/core/test_fulltext.py
from json.decoder import JSONDecodeError from unittest.mock import Mock, patch import requests from infogami import config from openlibrary.core import fulltext class Test_fulltext_search_api: def test_no_config(self): response = fulltext.fulltext_search_api({}) assert response == {"error": "Unabl...
1,426
Python
.py
29
39.586207
87
0.641523
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)
299
test_lists_engine.py
internetarchive_openlibrary/openlibrary/tests/core/test_lists_engine.py
from openlibrary.core.lists import engine def test_reduce(): def test_reduce(self): d1 = [1, 2, 1, "2010-11-11 10:20:30", {"subjects": ["Love", "Hate"]}] d2 = [1, 1, 0, "2009-01-02 10:20:30", {"subjects": ["Love"]}] assert engine.reduce([d1, d2]) == { "works": 2, "...
600
Python
.py
15
29.466667
77
0.457045
internetarchive/openlibrary
5,078
1,311
956
AGPL-3.0
9/5/2024, 5:07:13 PM (Europe/Amsterdam)