Skip to content

Commit 424e65d

Browse files
committed
[fix]: python3.6 support by removed typing
1 parent a8fb1f5 commit 424e65d

File tree

8 files changed

+30
-93
lines changed

8 files changed

+30
-93
lines changed

.gitignore

+1
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

src/lighthouseweb3/__init__.py

+9-10
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,7 +40,7 @@ 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
@@ -59,7 +58,7 @@ def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10) ->
5958
raise e
6059

6160
@staticmethod
62-
def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10) -> t.Upload:
61+
def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10):
6362
"""
6463
Download Blob a file or directory to the Lighthouse.
6564
@@ -74,7 +73,7 @@ def downloadBlob(dist: io.BufferedWriter, cid: str, chunk_size=1024*1024*10) ->
7473
raise e
7574

7675
@staticmethod
77-
def getDealStatus(cid: str) -> List[t.DealData]:
76+
def getDealStatus(cid: str):
7877
"""
7978
Get deal status from the Lighthouse.
8079
@@ -87,7 +86,7 @@ def getDealStatus(cid: str) -> List[t.DealData]:
8786
raise e
8887

8988
@staticmethod
90-
def getUploads(publicKey: str, pageNo: int = 1) -> List[t.DealData]:
89+
def getUploads(publicKey: str, pageNo: int = 1):
9190
"""
9291
Get uploads from the Lighthouse.
9392
@@ -101,7 +100,7 @@ def getUploads(publicKey: str, pageNo: int = 1) -> List[t.DealData]:
101100
raise e
102101

103102
@staticmethod
104-
def download(cid: str) -> bytes:
103+
def download(cid: str):
105104
"""
106105
Download content from the Lighthouse using its Content Identifier (CID).
107106
@@ -114,7 +113,7 @@ def download(cid: str) -> bytes:
114113
except Exception as e:
115114
raise e
116115

117-
def getTagged(self, tag: str) -> t.Upload:
116+
def getTagged(self, tag: str):
118117
"""
119118
Retrieve an upload from the Lighthouse using its tag.
120119

src/lighthouseweb3/functions/axios.py

+8-10
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

+1-3
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

+1-2
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

-55
This file was deleted.

src/lighthouseweb3/functions/upload.py

+3-4
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

+7-9
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)