Skip to content

Commit 678e49e

Browse files
authored
Merge pull request #7 from lighthouse-web3/python-3.6/support
Python 3.6/support
2 parents a8fb1f5 + 0ad8bdc commit 678e49e

File tree

11 files changed

+48
-110
lines changed

11 files changed

+48
-110
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ share/python-wheels/
2525
.installed.cfg
2626
*.egg
2727
MANIFEST
28+
Pipfile*
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template

requirements-dev.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tox==4.6.4
2+
certifi==2023.5.7
3+
charset-normalizer==3.1.0
4+
idna==3.4
5+
requests==2.31.0
6+
urllib3==2.0.2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="lighthouse-web3/Lighthouse-Python-SDK",
7-
version="0.1.1",
7+
version="0.1.4",
88
license="GNU GENERAL PUBLIC LICENSE",
99
description="Lighthouse Python SDK",
1010
author="Ravish Sharma | Ayobami Oki | Nandit Mehra",

src/lighthouseweb3/__init__.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import os
44
import io
5-
from typing import List
6-
from .functions import upload as d, types as t, deal_status, get_uploads as getUploads, download as _download
5+
from .functions import upload as d,deal_status, get_uploads as getUploads, download as _download
76

87

98
class Lighthouse:
@@ -14,7 +13,7 @@ def __init__(self, token: str = ""):
1413
"No token provided: Please provide a token or set the LIGHTHOUSE_TOKEN environment variable"
1514
)
1615

17-
def upload(self, source: str, tag: str = '') -> t.Upload:
16+
def upload(self, source: str, tag: str = ''):
1817
"""
1918
Upload a file or directory to the Lighthouse.
2019
@@ -26,7 +25,7 @@ def upload(self, source: str, tag: str = '') -> t.Upload:
2625
except Exception as e:
2726
raise e
2827

29-
def uploadBlob(self, source: io.BufferedReader, filename: str, tag: str = '') -> t.Upload:
28+
def uploadBlob(self, source: io.BufferedReader, filename: str, tag: str = ''):
3029
"""
3130
Upload Blob a file or directory to the Lighthouse.
3231
@@ -41,14 +40,13 @@ def uploadBlob(self, source: io.BufferedReader, filename: str, tag: str = '') ->
4140
raise e
4241

4342
@staticmethod
44-
def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10) -> t.Upload:
43+
def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10):
4544
"""
4645
Download a Blob (file or directory) from the Lighthouse.
4746
4847
:param dist: BufferedWriter, destination to write the downloaded data
4948
:param cid: str, Content Identifier for the data to be downloaded
5049
:param chunk_size: int, size of chunks in which the file will be downloaded (default: 10MB)
51-
:param useCidAsTag: bool, flag to use CID as a tag (default: False)
5250
:return: t.Upload, the download result
5351
"""
5452
if not (hasattr(dist, 'read') and hasattr(dist, 'close')):
@@ -57,24 +55,9 @@ def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10) ->
5755
return _download.download_file_into_writable(cid, dist, chunk_size)
5856
except Exception as e:
5957
raise e
60-
61-
@staticmethod
62-
def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10) -> t.Upload:
63-
"""
64-
Download Blob a file or directory to the Lighthouse.
65-
66-
:param source: str, path to file or directory
67-
:return: t.Upload, the upload result
68-
"""
69-
if not (hasattr(dist, 'read') and hasattr(dist, 'close')):
70-
raise TypeError("source must have 'read' and 'close' methods")
71-
try:
72-
return _download.download_file_into_writable(cid, dist, chunk_size)
73-
except Exception as e:
74-
raise e
75-
58+
7659
@staticmethod
77-
def getDealStatus(cid: str) -> List[t.DealData]:
60+
def getDealStatus(cid: str):
7861
"""
7962
Get deal status from the Lighthouse.
8063
@@ -87,7 +70,7 @@ def getDealStatus(cid: str) -> List[t.DealData]:
8770
raise e
8871

8972
@staticmethod
90-
def getUploads(publicKey: str, pageNo: int = 1) -> List[t.DealData]:
73+
def getUploads(publicKey: str, pageNo: int = 1):
9174
"""
9275
Get uploads from the Lighthouse.
9376
@@ -101,7 +84,7 @@ def getUploads(publicKey: str, pageNo: int = 1) -> List[t.DealData]:
10184
raise e
10285

10386
@staticmethod
104-
def download(cid: str) -> bytes:
87+
def download(cid: str):
10588
"""
10689
Download content from the Lighthouse using its Content Identifier (CID).
10790
@@ -114,7 +97,7 @@ def download(cid: str) -> bytes:
11497
except Exception as e:
11598
raise e
11699

117-
def getTagged(self, tag: str) -> t.Upload:
100+
def getTagged(self, tag: str):
118101
"""
119102
Retrieve an upload from the Lighthouse using its tag.
120103

src/lighthouseweb3/functions/axios.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
from io import BufferedReader
44
import json
5-
from typing import Dict, List, Tuple
65
import requests as req
7-
from . import types as t
86
from . import utils
97

108

@@ -14,15 +12,15 @@ class Axios:
1412
def __init__(self, url: str):
1513
self.url = url
1614

17-
def parse_url_query(self, query: Dict[str, str]):
15+
def parse_url_query(self, query):
1816
try:
1917
if query is not None and isinstance(query, dict):
2018
for key, value in query.items():
2119
self.url += f"&{key}={value}"
2220
except Exception as e:
2321
raise e
2422

25-
def get(self, headers: Dict[str, str] = None, **kwargs) -> dict | Exception:
23+
def get(self, headers = None, **kwargs) :
2624
try:
2725
self.parse_url_query(kwargs.get("query", None))
2826
r = req.get(self.url, headers=headers)
@@ -32,8 +30,8 @@ def get(self, headers: Dict[str, str] = None, **kwargs) -> dict | Exception:
3230
raise e
3331

3432
def post(
35-
self, body=None, headers: Dict[str, str] = None, **kwargs
36-
) -> dict | Exception:
33+
self, body=None, headers= None, **kwargs
34+
):
3735
try:
3836
self.parse_url_query(kwargs.get("query", None))
3937
r = req.post(self.url, data=body, headers=headers)
@@ -43,8 +41,8 @@ def post(
4341
raise e
4442

4543
def post_files(
46-
self, file: t.FileDict, headers: Dict[str, str] = None, **kwargs
47-
) -> dict | Exception:
44+
self, file, headers = None, **kwargs
45+
) :
4846
try:
4947
self.parse_url_query(kwargs.get("query", None))
5048
files = utils.read_files_for_upload(file)
@@ -61,8 +59,8 @@ def post_files(
6159
raise e
6260

6361
def post_blob(
64-
self, file: BufferedReader, filename: str, headers: Dict[str, str] = None, **kwargs
65-
) -> dict | Exception:
62+
self, file: BufferedReader, filename: str, headers = None, **kwargs
63+
) :
6664
try:
6765
self.parse_url_query(kwargs.get("query", None))
6866
files = [(

src/lighthouseweb3/functions/deal_status.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import requests
2-
from typing import List
32
from .config import Config
4-
from . import types as t
53

64

7-
def get_deal_status(cid: str) -> List[t.DealData]:
5+
def get_deal_status(cid: str):
86
try:
97
url = f"{Config.lighthouse_api}/api/lighthouse/deal_status?cid={cid}"
108
response = requests.get(url)

src/lighthouseweb3/functions/get_uploads.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import requests
22
from .config import Config
3-
from . import types as t
43

54

65
def bytes_to_size(bytes_size):
@@ -12,7 +11,7 @@ def bytes_to_size(bytes_size):
1211
return f"{round(bytes_size, 2)} {units[index]}"
1312

1413

15-
def get_uploads(publicKey: str, pageNo: int = 1) -> t.UploadsResponseType:
14+
def get_uploads(publicKey: str, pageNo: int = 1) :
1615
try:
1716
url = f"{Config.lighthouse_api}/api/user/files_uploaded?publicKey={publicKey}&pageNo={pageNo}"
1817
response = requests.get(url)

src/lighthouseweb3/functions/types.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/lighthouseweb3/functions/upload.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
from .axios import Axios
66
from .utils import is_dir, walk_dir_tree, extract_file_name, NamedBufferedReader
77
from .config import Config
8-
from . import types as t
98

109

11-
def upload(source: str | BufferedReader | NamedBufferedReader, token: str, tag: str = "") -> t.Upload:
10+
def upload(source, token: str, tag: str = ""):
1211
"""
1312
Deploy a file or directory to the lighthouse network
1413
@params {source}: str, path to file or directory
@@ -27,7 +26,7 @@ def upload(source: str | BufferedReader | NamedBufferedReader, token: str, tag:
2726
# create list of files to upload
2827

2928
if (isinstance(source, str)):
30-
file_dict: t.FileDict = {}
29+
file_dict = {}
3130

3231
# check if source is a directory
3332
if is_dir(source):
@@ -57,7 +56,7 @@ def upload(source: str | BufferedReader | NamedBufferedReader, token: str, tag:
5756
raise e
5857

5958

60-
def uploadBlob(source: BufferedReader, filename: str, token: str, tag: str = "") -> t.Upload:
59+
def uploadBlob(source: BufferedReader, filename: str, token: str, tag: str = ""):
6160
"""
6261
Upload a Buffer or readable Object
6362
@params {source}: str, path to file or directory

src/lighthouseweb3/functions/utils.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from io import BufferedReader, BytesIO
44
import os
5-
from typing import List, Tuple
6-
from . import types as t
75

86

97
class NamedBufferedReader:
@@ -19,7 +17,7 @@ def close(self):
1917
# walk path and return list of file paths
2018

2119

22-
def walk_dir_tree(path: str) -> Tuple[List[str], str]:
20+
def walk_dir_tree(path: str):
2321
file_list = []
2422
roots = []
2523
for root, dirs, files in os.walk(path):
@@ -30,24 +28,24 @@ def walk_dir_tree(path: str) -> Tuple[List[str], str]:
3028

3129

3230
# check if file is a directory
33-
def is_dir(path: str) -> bool:
31+
def is_dir(path: str):
3432
return os.path.isdir(path)
3533

3634

37-
def extract_file_name(file: str) -> str:
35+
def extract_file_name(file: str):
3836
return file.split("/")[-1]
3937

4038

41-
def extract_file_name_with_source(file: str, source: str) -> str:
39+
def extract_file_name_with_source(file: str, source: str):
4240
if source.endswith("/"):
4341
source = source[: len(source) - 1]
4442
base = source.split("/")[-1]
4543
return base + file.split(base)[-1]
4644

4745

4846
def read_files_for_upload(
49-
files: t.FileDict,
50-
) -> List[Tuple[str, Tuple[str, BufferedReader, str]]]:
47+
files
48+
):
5149
file_list = []
5250
for file in files["files"]:
5351
if files["is_dir"]:
@@ -76,7 +74,7 @@ def read_files_for_upload(
7674

7775

7876
def close_files_after_upload(
79-
files: List[Tuple[str, Tuple[str, BufferedReader, str]]]
77+
files
8078
) -> None:
8179
for file in files:
8280
file[1][1].close()

0 commit comments

Comments
 (0)