-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Tag64 to convert to html tags and fixed some errors
- Loading branch information
Showing
5 changed files
with
107 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
from .core import B64 | ||
from .core import ( | ||
B64, | ||
Tag64 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
import os | ||
import requests | ||
|
||
|
||
class FileNotFound(Exception): | ||
""" Exception for file not found """ | ||
""" Exception for file not found """ | ||
|
||
def __init__(self): | ||
msg = ''' | ||
def __init__(self): | ||
msg = ''' | ||
File Not Found, please check your path, permission, and headers | ||
And Try Again''' | ||
super().__init__(msg) | ||
|
||
|
||
def download_file(source, codes=(200, ), chunk=1024, *args, **kwargs) -> bytes: | ||
""" a function to download files from internet to bytes """ | ||
file = bytes() | ||
try: | ||
r = requests.get(source, stream=True, *args, **kwargs) | ||
except Exception as e: | ||
raise FileNotFound | ||
if r.status_code not in codes: | ||
raise FileNotFound | ||
while True: | ||
r.raw.decode_content = True | ||
part = r.raw.read(chunk) | ||
if not part: | ||
break | ||
file += part | ||
return file | ||
super().__init__(msg) | ||
|
||
|
||
def download_file(source, codes=None, chunk=1024, *args, **kwargs) -> bytes: | ||
""" a function to download files from internet to bytes """ | ||
if codes is None: | ||
codes = range(100, 309) | ||
file = bytes() | ||
try: | ||
r = requests.get(fix_url(source), stream=True, *args, **kwargs) | ||
except Exception as e: | ||
raise FileNotFound | ||
if r.status_code not in codes: | ||
raise FileNotFound | ||
while True: | ||
r.raw.decode_content = True | ||
part = r.raw.read(chunk) | ||
if not part: | ||
break | ||
file += part | ||
return file | ||
|
||
|
||
def read_file(source: str) -> bytes: | ||
""" read local file bytes """ | ||
if os.path.exists(source) and os.path.isfile(source): | ||
with open(source, 'rb') as fobj: | ||
return fobj.read() | ||
raise FileNotFound | ||
|
||
|
||
def exists(source) -> bool: | ||
""" check if the source exists """ | ||
dtype = self._detect_type(source) | ||
if dtype == 'local': | ||
return os.path.exists(source) and os.path.isfile(source) | ||
elif dtype == 'remote': | ||
try: | ||
r = request.urlopen(source) | ||
except Exception as e: | ||
return False | ||
return r.status in code | ||
return bool(source) | ||
""" read local file bytes """ | ||
if os.path.exists(source) and os.path.isfile(source): | ||
with open(source, 'rb') as fobj: | ||
return fobj.read() | ||
raise FileNotFound | ||
|
||
|
||
def fix_url(url, parse=False): | ||
if parse: | ||
return requests.utils.urlparse(url) | ||
if url.startswith('//'): | ||
return f'https:{url}' | ||
return url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
from distutils.core import setup | ||
with open('README.md', 'r', encoding='utf-8') as fobj: | ||
long_description = fobj.read() | ||
|
||
setup( | ||
name='b64', | ||
packages=['b64'], | ||
version='0.1', | ||
version='0.3', | ||
license='MIT', | ||
description='convert local/online data to base64 fast, easy and clean', | ||
description='convert html/local/online data to base64 fast, easy and clean', | ||
author='n0x1s', | ||
author_email='[email protected]', | ||
url='https://github.com/n0x1s/data_b64', | ||
download_url='https://github.com/N0x1s/data_b64/archive/0.2.tar.gz', | ||
download_url='https://github.com/N0x1s/data_b64/archive/0.3.tar.gz', | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
keywords=['base64', 'image to base64', 'video to base64', | ||
'base64 convert'], | ||
'base64 convert', 'html to base64', 'data uri'], | ||
install_requires=[ | ||
'requests', | ||
'bs4', | ||
'lxml', | ||
'cached_properties', | ||
], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Intended Audience :: Developers', | ||
|