diff --git a/LICENSE.txt b/LICENSE similarity index 98% rename from LICENSE.txt rename to LICENSE index c86b0db..ad76d80 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/m3u_parser/__init__.py b/m3u_parser/__init__.py index a433c63..88570c0 100644 --- a/m3u_parser/__init__.py +++ b/m3u_parser/__init__.py @@ -1,4 +1,4 @@ -from .m3u_parser import M3uParser, ParseConfig, SortConfig, FilterConfig from .exceptions import * +from .m3u_parser import FilterConfig, M3uParser, ParseConfig, SortConfig __version__ = '0.3.0' diff --git a/m3u_parser/helper.py b/m3u_parser/helper.py index 661568a..881fe48 100644 --- a/m3u_parser/helper.py +++ b/m3u_parser/helper.py @@ -1,9 +1,9 @@ import asyncio import csv import ipaddress +import logging import re from typing import Union -import logging from urllib.parse import urlsplit, urlunsplit # URLValidator diff --git a/m3u_parser/m3u_parser.py b/m3u_parser/m3u_parser.py index afb3555..648c8da 100755 --- a/m3u_parser/m3u_parser.py +++ b/m3u_parser/m3u_parser.py @@ -1,64 +1,38 @@ #!/usr/bin/env python3 import asyncio +import csv import json import random import re import ssl import time -from typing import Union from dataclasses import dataclass, field +from typing import Union import aiohttp import pycountry import requests -import csv - -try: - from helper import ( - get_by_regex, - is_valid_url, - ndict_to_csv, - run_until_completed, - setup_logger, - schemes, - default_useragent, - ) -except ModuleNotFoundError: - from .helper import ( - get_by_regex, - is_valid_url, - ndict_to_csv, - run_until_completed, - setup_logger, - schemes, - default_useragent, - ) - - -try: - from exceptions import ( - UrlReadException, - NoStreamsException, - NestedKeyException, - KeyNotFoundException, - FiltersMissingException, - SavingNotSupportedException, - UnrecognizedFormatException, - NoContentToParseException, - ) -except ModuleNotFoundError: - from .exceptions import ( - UrlReadException, - NoStreamsException, - NestedKeyException, - KeyNotFoundException, - FiltersMissingException, - SavingNotSupportedException, - UnrecognizedFormatException, - NoContentToParseException, - ) +from .exceptions import ( + FiltersMissingException, + KeyNotFoundException, + NestedKeyException, + NoContentToParseException, + NoStreamsException, + SavingNotSupportedException, + UnrecognizedFormatException, + UrlReadException, +) +from .helper import ( + default_useragent, + get_by_regex, + is_valid_url, + ndict_to_csv, + run_until_completed, + schemes, + setup_logger, +) ssl.match_hostname = lambda cert, hostname: hostname == cert["subjectAltName"][0][1] diff --git a/pyproject.toml b/pyproject.toml index 1d4688a..3a50680 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.black] line-length = 119 skip-string-normalization = true -target-version = ['py36'] +target-version = ['py37'] include = '\.pyi?$' exclude = ''' /( @@ -17,4 +17,4 @@ exclude = ''' line_length = 119 multi_line_output = 3 use_parentheses = true -include_trailing_comma = true \ No newline at end of file +include_trailing_comma = true diff --git a/tests/test_m3uparser.py b/tests/test_m3uparser.py index 21be0a1..31e71c0 100644 --- a/tests/test_m3uparser.py +++ b/tests/test_m3uparser.py @@ -1,12 +1,14 @@ -import sys, os, pytest +import os +import sys from pathlib import Path +import pytest + file = Path(__file__).resolve() package_root_directory = file.parents[1] sys.path.append(str(package_root_directory)) -from m3u_parser import M3uParser, ParseConfig, SortConfig, FilterConfig - +from m3u_parser import FilterConfig, M3uParser, ParseConfig, SortConfig # Sample M3U content for testing SAMPLE_M3U_CONTENT = """