Skip to content

Commit e8b8c04

Browse files
authored
Add files via upload
1 parent a594018 commit e8b8c04

8 files changed

Lines changed: 498 additions & 0 deletions

PyWWW/pywwwget_chatgpt.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,68 @@ def unquote_to_bytes(s):
116116
_BIN_MIME_DEFAULT = 'application/octet-stream'
117117
PY2 = (sys.version_info[0] == 2)
118118

119+
# get_readable_size by Lipis
120+
# http://stackoverflow.com/posts/14998888/revisions
121+
122+
123+
def get_readable_size(bytes, precision=1, unit="IEC"):
124+
unit = unit.upper()
125+
if(unit != "IEC" and unit != "SI"):
126+
unit = "IEC"
127+
if(unit == "IEC"):
128+
units = [" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB"]
129+
unitswos = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"]
130+
unitsize = 1024.0
131+
if(unit == "SI"):
132+
units = [" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB"]
133+
unitswos = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]
134+
unitsize = 1000.0
135+
return_val = {}
136+
orgbytes = bytes
137+
for unit in units:
138+
if abs(bytes) < unitsize:
139+
strformat = "%3."+str(precision)+"f%s"
140+
pre_return_val = (strformat % (bytes, unit))
141+
pre_return_val = re.sub(
142+
r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
143+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
144+
alt_return_val = pre_return_val.split()
145+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
146+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
147+
return return_val
148+
bytes /= unitsize
149+
strformat = "%."+str(precision)+"f%s"
150+
pre_return_val = (strformat % (bytes, "YiB"))
151+
pre_return_val = re.sub(r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
152+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
153+
alt_return_val = pre_return_val.split()
154+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
155+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
156+
return return_val
157+
158+
159+
def get_readable_size_from_file(infile, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
160+
unit = unit.upper()
161+
usehashtypes = usehashtypes.lower()
162+
getfilesize = os.path.getsize(infile)
163+
return_val = get_readable_size(getfilesize, precision, unit)
164+
if(usehashes):
165+
hashtypelist = usehashtypes.split(",")
166+
openfile = open(infile, "rb")
167+
filecontents = openfile.read()
168+
openfile.close()
169+
listnumcount = 0
170+
listnumend = len(hashtypelist)
171+
while(listnumcount < listnumend):
172+
hashtypelistlow = hashtypelist[listnumcount].strip()
173+
hashtypelistup = hashtypelistlow.upper()
174+
filehash = hashlib.new(hashtypelistup)
175+
filehash.update(filecontents)
176+
filegethash = filehash.hexdigest()
177+
return_val.update({hashtypelistup: filegethash})
178+
listnumcount += 1
179+
return return_val
180+
119181

120182
def _is_probably_text(data_bytes):
121183
"""

PyWWW/pywwwget_deepseek.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,67 @@ def unquote_to_bytes(s):
9292
_BIN_MIME_DEFAULT = 'application/octet-stream'
9393
PY2 = (sys.version_info[0] == 2)
9494

95+
# get_readable_size by Lipis
96+
# http://stackoverflow.com/posts/14998888/revisions
97+
98+
99+
def get_readable_size(bytes, precision=1, unit="IEC"):
100+
unit = unit.upper()
101+
if(unit != "IEC" and unit != "SI"):
102+
unit = "IEC"
103+
if(unit == "IEC"):
104+
units = [" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB"]
105+
unitswos = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"]
106+
unitsize = 1024.0
107+
if(unit == "SI"):
108+
units = [" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB"]
109+
unitswos = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]
110+
unitsize = 1000.0
111+
return_val = {}
112+
orgbytes = bytes
113+
for unit in units:
114+
if abs(bytes) < unitsize:
115+
strformat = "%3."+str(precision)+"f%s"
116+
pre_return_val = (strformat % (bytes, unit))
117+
pre_return_val = re.sub(
118+
r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
119+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
120+
alt_return_val = pre_return_val.split()
121+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
122+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
123+
return return_val
124+
bytes /= unitsize
125+
strformat = "%."+str(precision)+"f%s"
126+
pre_return_val = (strformat % (bytes, "YiB"))
127+
pre_return_val = re.sub(r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
128+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
129+
alt_return_val = pre_return_val.split()
130+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
131+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
132+
return return_val
133+
134+
135+
def get_readable_size_from_file(infile, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
136+
unit = unit.upper()
137+
usehashtypes = usehashtypes.lower()
138+
getfilesize = os.path.getsize(infile)
139+
return_val = get_readable_size(getfilesize, precision, unit)
140+
if(usehashes):
141+
hashtypelist = usehashtypes.split(",")
142+
openfile = open(infile, "rb")
143+
filecontents = openfile.read()
144+
openfile.close()
145+
listnumcount = 0
146+
listnumend = len(hashtypelist)
147+
while(listnumcount < listnumend):
148+
hashtypelistlow = hashtypelist[listnumcount].strip()
149+
hashtypelistup = hashtypelistlow.upper()
150+
filehash = hashlib.new(hashtypelistup)
151+
filehash.update(filecontents)
152+
filegethash = filehash.hexdigest()
153+
return_val.update({hashtypelistup: filegethash})
154+
listnumcount += 1
155+
return return_val
95156

96157
def _is_probably_text(data_bytes):
97158
"""

PyWWW/pywwwget_merged.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,69 @@ def unquote_to_bytes(s):
120120
PY2 = (sys.version_info[0] == 2)
121121

122122

123+
# get_readable_size by Lipis
124+
# http://stackoverflow.com/posts/14998888/revisions
125+
126+
127+
def get_readable_size(bytes, precision=1, unit="IEC"):
128+
unit = unit.upper()
129+
if(unit != "IEC" and unit != "SI"):
130+
unit = "IEC"
131+
if(unit == "IEC"):
132+
units = [" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB"]
133+
unitswos = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"]
134+
unitsize = 1024.0
135+
if(unit == "SI"):
136+
units = [" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB"]
137+
unitswos = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]
138+
unitsize = 1000.0
139+
return_val = {}
140+
orgbytes = bytes
141+
for unit in units:
142+
if abs(bytes) < unitsize:
143+
strformat = "%3."+str(precision)+"f%s"
144+
pre_return_val = (strformat % (bytes, unit))
145+
pre_return_val = re.sub(
146+
r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
147+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
148+
alt_return_val = pre_return_val.split()
149+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
150+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
151+
return return_val
152+
bytes /= unitsize
153+
strformat = "%."+str(precision)+"f%s"
154+
pre_return_val = (strformat % (bytes, "YiB"))
155+
pre_return_val = re.sub(r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
156+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
157+
alt_return_val = pre_return_val.split()
158+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
159+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
160+
return return_val
161+
162+
163+
def get_readable_size_from_file(infile, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
164+
unit = unit.upper()
165+
usehashtypes = usehashtypes.lower()
166+
getfilesize = os.path.getsize(infile)
167+
return_val = get_readable_size(getfilesize, precision, unit)
168+
if(usehashes):
169+
hashtypelist = usehashtypes.split(",")
170+
openfile = open(infile, "rb")
171+
filecontents = openfile.read()
172+
openfile.close()
173+
listnumcount = 0
174+
listnumend = len(hashtypelist)
175+
while(listnumcount < listnumend):
176+
hashtypelistlow = hashtypelist[listnumcount].strip()
177+
hashtypelistup = hashtypelistlow.upper()
178+
filehash = hashlib.new(hashtypelistup)
179+
filehash.update(filecontents)
180+
filegethash = filehash.hexdigest()
181+
return_val.update({hashtypelistup: filegethash})
182+
listnumcount += 1
183+
return return_val
184+
185+
123186
def _is_probably_text(data_bytes):
124187
"""
125188
Heuristic: treat as text if it decodes as UTF-8 and does not contain many

PyWWW/pywwwget_nextver.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,69 @@ def unquote_to_bytes(s):
120120
PY2 = (sys.version_info[0] == 2)
121121

122122

123+
# get_readable_size by Lipis
124+
# http://stackoverflow.com/posts/14998888/revisions
125+
126+
127+
def get_readable_size(bytes, precision=1, unit="IEC"):
128+
unit = unit.upper()
129+
if(unit != "IEC" and unit != "SI"):
130+
unit = "IEC"
131+
if(unit == "IEC"):
132+
units = [" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB"]
133+
unitswos = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"]
134+
unitsize = 1024.0
135+
if(unit == "SI"):
136+
units = [" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB"]
137+
unitswos = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]
138+
unitsize = 1000.0
139+
return_val = {}
140+
orgbytes = bytes
141+
for unit in units:
142+
if abs(bytes) < unitsize:
143+
strformat = "%3."+str(precision)+"f%s"
144+
pre_return_val = (strformat % (bytes, unit))
145+
pre_return_val = re.sub(
146+
r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
147+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
148+
alt_return_val = pre_return_val.split()
149+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
150+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
151+
return return_val
152+
bytes /= unitsize
153+
strformat = "%."+str(precision)+"f%s"
154+
pre_return_val = (strformat % (bytes, "YiB"))
155+
pre_return_val = re.sub(r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
156+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
157+
alt_return_val = pre_return_val.split()
158+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
159+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
160+
return return_val
161+
162+
163+
def get_readable_size_from_file(infile, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
164+
unit = unit.upper()
165+
usehashtypes = usehashtypes.lower()
166+
getfilesize = os.path.getsize(infile)
167+
return_val = get_readable_size(getfilesize, precision, unit)
168+
if(usehashes):
169+
hashtypelist = usehashtypes.split(",")
170+
openfile = open(infile, "rb")
171+
filecontents = openfile.read()
172+
openfile.close()
173+
listnumcount = 0
174+
listnumend = len(hashtypelist)
175+
while(listnumcount < listnumend):
176+
hashtypelistlow = hashtypelist[listnumcount].strip()
177+
hashtypelistup = hashtypelistlow.upper()
178+
filehash = hashlib.new(hashtypelistup)
179+
filehash.update(filecontents)
180+
filegethash = filehash.hexdigest()
181+
return_val.update({hashtypelistup: filegethash})
182+
listnumcount += 1
183+
return return_val
184+
185+
123186
def _is_probably_text(data_bytes):
124187
"""
125188
Heuristic: treat as text if it decodes as UTF-8 and does not contain many

pywwwget_chatgpt.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,68 @@ def unquote_to_bytes(s):
116116
_BIN_MIME_DEFAULT = 'application/octet-stream'
117117
PY2 = (sys.version_info[0] == 2)
118118

119+
# get_readable_size by Lipis
120+
# http://stackoverflow.com/posts/14998888/revisions
121+
122+
123+
def get_readable_size(bytes, precision=1, unit="IEC"):
124+
unit = unit.upper()
125+
if(unit != "IEC" and unit != "SI"):
126+
unit = "IEC"
127+
if(unit == "IEC"):
128+
units = [" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB"]
129+
unitswos = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"]
130+
unitsize = 1024.0
131+
if(unit == "SI"):
132+
units = [" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB"]
133+
unitswos = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]
134+
unitsize = 1000.0
135+
return_val = {}
136+
orgbytes = bytes
137+
for unit in units:
138+
if abs(bytes) < unitsize:
139+
strformat = "%3."+str(precision)+"f%s"
140+
pre_return_val = (strformat % (bytes, unit))
141+
pre_return_val = re.sub(
142+
r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
143+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
144+
alt_return_val = pre_return_val.split()
145+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
146+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
147+
return return_val
148+
bytes /= unitsize
149+
strformat = "%."+str(precision)+"f%s"
150+
pre_return_val = (strformat % (bytes, "YiB"))
151+
pre_return_val = re.sub(r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
152+
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
153+
alt_return_val = pre_return_val.split()
154+
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
155+
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
156+
return return_val
157+
158+
159+
def get_readable_size_from_file(infile, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
160+
unit = unit.upper()
161+
usehashtypes = usehashtypes.lower()
162+
getfilesize = os.path.getsize(infile)
163+
return_val = get_readable_size(getfilesize, precision, unit)
164+
if(usehashes):
165+
hashtypelist = usehashtypes.split(",")
166+
openfile = open(infile, "rb")
167+
filecontents = openfile.read()
168+
openfile.close()
169+
listnumcount = 0
170+
listnumend = len(hashtypelist)
171+
while(listnumcount < listnumend):
172+
hashtypelistlow = hashtypelist[listnumcount].strip()
173+
hashtypelistup = hashtypelistlow.upper()
174+
filehash = hashlib.new(hashtypelistup)
175+
filehash.update(filecontents)
176+
filegethash = filehash.hexdigest()
177+
return_val.update({hashtypelistup: filegethash})
178+
listnumcount += 1
179+
return return_val
180+
119181

120182
def _is_probably_text(data_bytes):
121183
"""

0 commit comments

Comments
 (0)