added http auth and upload functions
This commit is contained in:
@@ -160,7 +160,7 @@ Exports the following functions:
|
||||
- `http_fetch(url, useragent=None, hdrs={})`: fetch text content from a URL into a string (returns `(status_code, content)` tuple)
|
||||
- `auth_header(username, password)`: get an dictionary fragment with the corresponding HTTP Basic Auth header according to the username and password
|
||||
- `wget(url, filename='', useragent=None, hdrs={})`: download a file into a local path (returns `(status_code, filename)` tuple)
|
||||
- `wput(url, file_path, field_name="file", method="POST", format="x-www-form-urlencoded", headers=None)`: upload a file from a local path in the `x-www-form-urlencoded` or JSON format (returns `(status_code, content)` tuple)
|
||||
- `wput(url, file_path, field_name="file", method="POST", format="x-www-form-urlencoded", headers={}, useragent=None)`: upload a file from a local path in the `x-www-form-urlencoded` or JSON format (returns `(status_code, content)` tuple)
|
||||
|
||||
### `deck.llm`
|
||||
|
||||
|
||||
+4
-3
@@ -54,10 +54,11 @@ def wget(url, filename='', useragent=None, hdrs={}):
|
||||
else: filename = ''
|
||||
return (r.status_code, filename)
|
||||
|
||||
def wput(url, file_path, field_name="file", method="POST", format="x-www-form-urlencoded", headers=None):
|
||||
def wput(url, file_path, field_name="file", method="POST", format="x-www-form-urlencoded", headers={}, useragent=None):
|
||||
"""Upload a file"""
|
||||
if headers is None:
|
||||
headers = {}
|
||||
if useragent is None:
|
||||
useragent = DEFAULT_UA
|
||||
headers['User-Agent'] = useragent
|
||||
method = method.upper()
|
||||
try:
|
||||
with open(file_path, "rb") as f:
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ from deck.input import input, input_multi
|
||||
from deck.pager import print_paged, term_size
|
||||
from deck.time import *
|
||||
from deck.hwinfo import board_id, battery_v, cpu_f, REAL_HW
|
||||
from deck.http import wget, http_fetch, http_set_ua
|
||||
from deck.http import wget, wput, http_fetch, http_set_ua, auth_header
|
||||
from deck import xlat
|
||||
from app.ed import edit, view
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user