Skip to content

Commit 5f7cba4

Browse files
author
Gal Ben David
committed
DomainExtractor object is now shared when the default domain list is used
1 parent 1989968 commit 5f7cba4

File tree

6 files changed

+153
-55
lines changed

6 files changed

+153
-55
lines changed

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include README.md
22
include images/logo.png
33
graft tests
4-
recursive-include src *.h
4+
recursive-include src *.h *.cpp
5+
recursive-include pydomainextractor *.py *.pyi

pydomainextractor/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import typing
2+
import pydomainextractor.extractor
3+
4+
5+
class DomainExtractor:
6+
'''
7+
PyDomainExtractor is a highly optimized Domain Name Extraction library written in C++
8+
'''
9+
engine: typing.Optional[pydomainextractor.extractor.DomainExtractor] = None
10+
11+
def __new__(
12+
cls,
13+
suffix_list_data: typing.Optional[str] = None,
14+
):
15+
if suffix_list_data is None:
16+
if DomainExtractor.engine is None:
17+
DomainExtractor.engine = pydomainextractor.extractor.DomainExtractor()
18+
19+
return DomainExtractor.engine
20+
else:
21+
return pydomainextractor.extractor.DomainExtractor(suffix_list_data)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import typing
2+
3+
4+
class DomainExtractor:
5+
def __init__(
6+
self,
7+
suffix_list_data: typing.Optional[str] = None,
8+
) -> None: ...
9+
10+
def extract(
11+
self,
12+
domain: str,
13+
) -> typing.dict[str, str]: ...
14+
15+
def extract_from_url(
16+
self,
17+
url: str,
18+
) -> typing.dict[str, str]: ...
19+
20+
def is_valid_domain(
21+
self,
22+
domain: str,
23+
) -> bool: ...
24+
25+
def get_tld_list(
26+
self,
27+
) -> typing.List[str]: ...

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='PyDomainExtractor',
8-
version='0.8.5',
8+
version='0.9.0',
99
author='Gal Ben David',
1010
author_email='[email protected]',
1111
url='https://github.com/Intsights/PyDomainExtractor',
@@ -29,13 +29,15 @@
2929
install_requires=[],
3030
package_data={},
3131
include_package_data=True,
32+
packages=setuptools.find_packages(),
33+
ext_package='pydomainextractor',
3234
ext_modules=[
3335
setuptools.Extension(
34-
name='pydomainextractor',
36+
name='extractor',
3537
sources=glob.glob(
3638
pathname=os.path.join(
3739
'src',
38-
'pydomainextractor.cpp',
40+
'extractor.cpp',
3941
),
4042
),
4143
language='c++',
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,23 +560,23 @@ static PyTypeObject DomainExtractorType = {
560560
};
561561

562562

563-
static struct PyModuleDef pydomainextractor_definition = {
563+
static struct PyModuleDef extractor_definition = {
564564
PyModuleDef_HEAD_INIT,
565-
"pydomainextractor",
565+
"extractor",
566566
"Extracting domain strings into their parts",
567567
-1,
568568
NULL,
569569
};
570570

571571

572572
PyMODINIT_FUNC
573-
PyInit_pydomainextractor(void) {
573+
PyInit_extractor(void) {
574574
PyObject *m;
575575
if (PyType_Ready(&DomainExtractorType) < 0) {
576576
return NULL;
577577
}
578578

579-
m = PyModule_Create(&pydomainextractor_definition);
579+
m = PyModule_Create(&extractor_definition);
580580
if (m == NULL) {
581581
return NULL;
582582
}

0 commit comments

Comments
 (0)