mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
feat: enhance http
, urllib
type decls
This commit is contained in:
parent
c7522b1d36
commit
f6ea1d1d79
5 changed files with 295 additions and 4 deletions
31
crates/erg_compiler/lib/pystd/enum.d.er
Normal file
31
crates/erg_compiler/lib/pystd/enum.d.er
Normal file
|
@ -0,0 +1,31 @@
|
|||
.EnumType: ClassType
|
||||
.EnumType <: Type
|
||||
|
||||
.Enum: ClassType
|
||||
.Enum <: Show
|
||||
.Enum.
|
||||
name: Str
|
||||
value: Obj
|
||||
|
||||
.IntEnum: ClassType
|
||||
.IntEnum <: Enum
|
||||
.IntEnum <: Int
|
||||
.IntEnum.
|
||||
value: Int
|
||||
|
||||
.StrEnum: ClassType
|
||||
.StrEnum <: Enum
|
||||
.StrEnum <: Str
|
||||
.StrEnum.
|
||||
value: Str
|
||||
|
||||
.Flag: ClassType
|
||||
.Flag <: Enum
|
||||
|
||||
.IntFlag: ClassType
|
||||
.IntFlag <: Flag
|
||||
|
||||
.ReprEnum: ClassType
|
||||
.ReprEnum <: Enum
|
||||
|
||||
.Auto = 'auto': ClassType
|
|
@ -1 +1,94 @@
|
|||
.client = pyimport "client"
|
||||
.cookies = pyimport "cookies"
|
||||
.cookiejar = pyimport "cookiejar"
|
||||
.server = pyimport "server"
|
||||
{.IntEnum; .StrEnum} = pyimport "enum"
|
||||
|
||||
.HTTPStatus: ClassType
|
||||
.HTTPStatus <: IntEnum
|
||||
.HTTPStatus.
|
||||
value: Nat
|
||||
phrase: Str
|
||||
description: Str
|
||||
is_success: Bool
|
||||
is_client_error: Bool
|
||||
is_informational: Bool
|
||||
is_redirect: Bool
|
||||
is_server_error: Bool
|
||||
CONTINUE: .HTTPStatus
|
||||
SWITCHING_PROTOCOLS: .HTTPStatus
|
||||
PROCESSING: .HTTPStatus
|
||||
EARLY_HINTS: .HTTPStatus
|
||||
OK: .HTTPStatus
|
||||
CREATED: .HTTPStatus
|
||||
ACCEPTED: .HTTPStatus
|
||||
NON_AUTHORITATIVE_INFORMATION: .HTTPStatus
|
||||
NO_CONTENT: .HTTPStatus
|
||||
RESET_CONTENT: .HTTPStatus
|
||||
PARTIAL_CONTENT: .HTTPStatus
|
||||
MULTI_STATUS: .HTTPStatus
|
||||
ALREADY_REPORTED: .HTTPStatus
|
||||
IM_USED: .HTTPStatus
|
||||
MULTIPLE_CHOICES: .HTTPStatus
|
||||
MOVED_PERMANENTLY: .HTTPStatus
|
||||
FOUND: .HTTPStatus
|
||||
SEE_OTHER: .HTTPStatus
|
||||
NOT_MODIFIED: .HTTPStatus
|
||||
USE_PROXY: .HTTPStatus
|
||||
TEMPORARY_REDIRECT: .HTTPStatus
|
||||
PERMANENT_REDIRECT: .HTTPStatus
|
||||
BAD_REQUEST: .HTTPStatus
|
||||
UNAUTHORIZED: .HTTPStatus
|
||||
PAYMENT_REQUIRED: .HTTPStatus
|
||||
FORBIDDEN: .HTTPStatus
|
||||
NOT_FOUND: .HTTPStatus
|
||||
METHOD_NOT_ALLOWED: .HTTPStatus
|
||||
NOT_ACCEPTABLE: .HTTPStatus
|
||||
PROXY_AUTHENTICATION_REQUIRED: .HTTPStatus
|
||||
REQUEST_TIMEOUT: .HTTPStatus
|
||||
CONFLICT: .HTTPStatus
|
||||
GONE: .HTTPStatus
|
||||
LENGTH_REQUIRED: .HTTPStatus
|
||||
PRECONDITION_FAILED: .HTTPStatus
|
||||
REQUEST_ENTITY_TOO_LARGE: .HTTPStatus
|
||||
REQUEST_URI_TOO_LONG: .HTTPStatus
|
||||
UNSUPPORTED_MEDIA_TYPE: .HTTPStatus
|
||||
REQUESTED_RANGE_NOT_SATISFIABLE: .HTTPStatus
|
||||
EXPECTATION_FAILED: .HTTPStatus
|
||||
IM_A_TEAPOT: .HTTPStatus
|
||||
MISDIRECTED_REQUEST: .HTTPStatus
|
||||
UNPROCESSABLE_ENTITY: .HTTPStatus
|
||||
LOCKED: .HTTPStatus
|
||||
FAILED_DEPENDENCY: .HTTPStatus
|
||||
TOO_EARLY: .HTTPStatus
|
||||
UPGRADE_REQUIRED: .HTTPStatus
|
||||
PRECONDITION_REQUIRED: .HTTPStatus
|
||||
TOO_MANY_REQUESTS: .HTTPStatus
|
||||
REQUEST_HEADER_FIELDS_TOO_LARGE: .HTTPStatus
|
||||
UNAVAILABLE_FOR_LEGAL_REASONS: .HTTPStatus
|
||||
INTERNAL_SERVER_ERROR: .HTTPStatus
|
||||
NOT_IMPLEMENTED: .HTTPStatus
|
||||
BAD_GATEWAY: .HTTPStatus
|
||||
SERVICE_UNAVAILABLE: .HTTPStatus
|
||||
GATEWAY_TIMEOUT: .HTTPStatus
|
||||
HTTP_VERSION_NOT_SUPPORTED: .HTTPStatus
|
||||
VARIANT_ALSO_NEGOTIATES: .HTTPStatus
|
||||
INSUFFICIENT_STORAGE: .HTTPStatus
|
||||
LOOP_DETECTED: .HTTPStatus
|
||||
NOT_EXTENDED: .HTTPStatus
|
||||
NETWORK_AUTHENTICATION_REQUIRED: .HTTPStatus
|
||||
|
||||
.HTTPMethod: ClassType
|
||||
.HTTPMethod <: StrEnum
|
||||
.HTTPMethod.
|
||||
value: Nat
|
||||
description: Str
|
||||
GET: .HTTPMethod
|
||||
HEAD: .HTTPMethod
|
||||
POST: .HTTPMethod
|
||||
PUT: .HTTPMethod
|
||||
DELETE: .HTTPMethod
|
||||
CONNECT: .HTTPMethod
|
||||
OPTIONS: .HTTPMethod
|
||||
TRACE: .HTTPMethod
|
||||
PATCH: .HTTPMethod
|
||||
|
|
|
@ -1,3 +1,100 @@
|
|||
.http = pyimport "http"
|
||||
|
||||
.HTTP_PORT: Nat
|
||||
.HTTPS_PORT: Nat
|
||||
.responses: {.http.HTTPStatus: Str}
|
||||
|
||||
.HTTPConnection!: ClassType
|
||||
.HTTPConnection!.
|
||||
__call__: (
|
||||
host: Str,
|
||||
port := Nat,
|
||||
timeout := Float,
|
||||
source_address := (Str, Nat),
|
||||
blocksize := Nat,
|
||||
) -> HTTPConnection!
|
||||
blocksize: Nat
|
||||
request!: (
|
||||
self: Ref(.HTTPConnection!),
|
||||
method: Str,
|
||||
url: Str,
|
||||
body := Str,
|
||||
headers := {Str: Str},
|
||||
encode_chunked := Bool,
|
||||
) => NoneType
|
||||
get_proxy_response_headers: (self: Ref(.HTTPConnection!)) -> {Str: Str}
|
||||
getresponse!: (self: Ref(.HTTPConnection!),) => .HTTPResponse
|
||||
set_debuglevel!: (self: RefMut(.HTTPConnection!), level: Nat) => NoneType
|
||||
set_tunnel!: (
|
||||
self: RefMut(.HTTPConnection!),
|
||||
host: Str,
|
||||
port := Nat,
|
||||
headers := {Str: Str},
|
||||
) => NoneType
|
||||
connect!: (self: RefMut(.HTTPConnection!),) => NoneType
|
||||
close!: (self: RefMut(.HTTPConnection!),) => NoneType
|
||||
putrequest!: (self: Ref(.HTTPConnection!), method: Str, url: Str, skip_host := Bool, skip_accept_encoding := Bool) => NoneType
|
||||
putheader!: (self: Ref(.HTTPConnection!), header: Str, argument: Str) => NoneType
|
||||
endheaders!: (self: Ref(.HTTPConnection!), message_body := Str, encode_chunked := Bool) => NoneType
|
||||
send!: (self: RefMut(.HTTPConnection!), data: Str) => NoneType
|
||||
|
||||
.HTTPSConnection!: ClassType
|
||||
.HTTPSConnection! <: HTTPConnection!
|
||||
.HTTPSConnection!.
|
||||
__call__: (
|
||||
host: Str,
|
||||
port := Nat,
|
||||
timeout := Float,
|
||||
source_address := (Str, Nat),
|
||||
blocksize := Nat,
|
||||
) -> HTTPSConnection!
|
||||
|
||||
.HTTPException: ClassType
|
||||
.HTTPException <: Exception
|
||||
.NotConnected: ClassType
|
||||
.NotConnected <: HTTPException
|
||||
.InvalidURL: ClassType
|
||||
.InvalidURL <: HTTPException
|
||||
.UnknownProtocol: ClassType
|
||||
.UnknownProtocol <: HTTPException
|
||||
.UnknownTransferEncoding: ClassType
|
||||
.UnknownTransferEncoding <: HTTPException
|
||||
.UnimplementedFileMode: ClassType
|
||||
.UnimplementedFileMode <: HTTPException
|
||||
.IncompleteRead: ClassType
|
||||
.IncompleteRead <: HTTPException
|
||||
.ImproperConnectionState: ClassType
|
||||
.ImproperConnectionState <: HTTPException
|
||||
.CannotSendRequest: ClassType
|
||||
.CannotSendRequest <: HTTPException
|
||||
.CannotSendHeader: ClassType
|
||||
.CannotSendHeader <: HTTPException
|
||||
.ResponseNotReady: ClassType
|
||||
.ResponseNotReady <: HTTPException
|
||||
.BadStatusLine: ClassType
|
||||
.BadStatusLine <: HTTPException
|
||||
.LineTooLong: ClassType
|
||||
.LineTooLong <: HTTPException
|
||||
.RemoteDisconnected: ClassType
|
||||
.RemoteDisconnected <: BadStatusLine
|
||||
.RemoteDisconnected <: ConnectionResetError
|
||||
|
||||
.HTTPResponse: ClassType
|
||||
.HTTPResponse <: FileLike!
|
||||
.HTTPResponse.read!: (self: RefMut(.HTTPResponse),) => Bytes
|
||||
.HTTPResponse.
|
||||
msg: Str
|
||||
version: Str
|
||||
url: Str
|
||||
headers: {Str: Str}
|
||||
status: Nat
|
||||
reason: Str
|
||||
debuglevel: Nat
|
||||
closed: Bool
|
||||
read!: (self: RefMut(.HTTPResponse),) => Bytes
|
||||
readinto!: (self: RefMut(.HTTPResponse), b: RefMut ByteArray!) => Nat
|
||||
getheader: (self: Ref(.HTTPResponse), name: Str, default := Str) -> Str
|
||||
getheaders: (self: Ref(.HTTPResponse)) -> [(Str, Str); _]
|
||||
fileno: (self: Ref(.HTTPResponse)) -> Nat
|
||||
|
||||
# TODO: <: email.message.Message
|
||||
.HTTPMessage: ClassType
|
||||
|
|
20
crates/erg_compiler/lib/pystd/http.d/cookiejar.d.er
Normal file
20
crates/erg_compiler/lib/pystd/http.d/cookiejar.d.er
Normal file
|
@ -0,0 +1,20 @@
|
|||
.LoadError: ClassType
|
||||
.LoadError <: OSError
|
||||
|
||||
.CookiePolicy: ClassType
|
||||
.CookiePolicy <: InheritableType
|
||||
|
||||
.DefaultCookiePolicy: ClassType
|
||||
.DefaultCookiePolicy <: CookiePolicy
|
||||
|
||||
.CookieJar: ClassType
|
||||
.CookieJar <: InheritableType
|
||||
.CookieJar.
|
||||
__call__: (policy := CookiePolicy) -> CookieJar
|
||||
|
||||
.FileCookieJar: ClassType
|
||||
.FileCookieJar <: CookieJar
|
||||
.FileCookieJar.
|
||||
__call__: (filename := Str, policy := CookiePolicy) -> FileCookieJar
|
||||
|
||||
.Cookie: ClassType
|
|
@ -1,5 +1,55 @@
|
|||
http = pyimport "http"
|
||||
|
||||
.Request: ClassType
|
||||
.Request.data: Bytes
|
||||
.urlopen!: (url: Str or .Request, data: Bytes or NoneType := NoneType, timeout: Nat or NoneType := NoneType) -> http.client.HTTPResponse
|
||||
.OpenerDirector!: ClassType
|
||||
.OpenerDirector!.
|
||||
add_handler!: (self: RefMut OpenerDirector!, handler: BaseHandler!) => NoneType
|
||||
open!: (self: Ref OpenerDirector!, url: Str or .Request!, data: Bytes or NoneType := NoneType, timeout: Nat or NoneType := NoneType) -> http.client.HTTPResponse
|
||||
.BaseHandler!: ClassType
|
||||
.BaseHandler!.
|
||||
parent: BaseHandler! or NoneType
|
||||
add_parent!: (self: RefMut BaseHandler!, parent: BaseHandler!) => NoneType
|
||||
close!: (self: RefMut BaseHandler!) => NoneType
|
||||
.HTTPDefaultErrorHandler: ClassType
|
||||
.HTTPRedirectHandler: ClassType
|
||||
.HTTPCookieProcessor: ClassType
|
||||
.HTTPProxyHandler: ClassType
|
||||
.HTTPPasswordMgr: ClassType
|
||||
.HTTPPasswordMgrWithDefaultRealm: ClassType
|
||||
.HTTPPasswordMgrWithPriorAuth: ClassType
|
||||
|
||||
.AbstractBasicAuthHandler: ClassType
|
||||
.HTTPBasicAuthHandler: ClassType
|
||||
.ProxyBasicAuthHandler: ClassType
|
||||
.AbstractDigestAuthHandler: ClassType
|
||||
.HTTPDigestAuthHandler: ClassType
|
||||
.ProxyDigestAuthHandler: ClassType
|
||||
.HTTPHandler: ClassType
|
||||
.HTTPSHandler: ClassType
|
||||
.FileHandler: ClassType
|
||||
.DataHandler: ClassType
|
||||
.FTPHandler: ClassType
|
||||
.CacheFTPHandler: ClassType
|
||||
.UnknownHandler: ClassType
|
||||
.HTTPErrorProcessor: ClassType
|
||||
|
||||
.Request!: ClassType
|
||||
.Request!.
|
||||
full_url: Str
|
||||
type: Str
|
||||
host: Str
|
||||
origin_req_host: Str
|
||||
selector: Str
|
||||
data: Bytes or NoneType
|
||||
unverifiable: Bool
|
||||
method: Str
|
||||
get_method: (self: Ref Request!) -> Str
|
||||
get_full_url: (self: Ref Request!) -> Str
|
||||
get_header: (self: Ref Request!, header: Str, default := Str) -> Str or NoneType
|
||||
has_header: (self: Ref Request!, header: Str) -> Bool
|
||||
header_items: (self: Ref Request!) -> [(Str, Str); _]
|
||||
add_header!: (self: RefMut Request!, key: Str, val: Str) => NoneType
|
||||
remove_header!: (self: RefMut Request!, header: Str) => NoneType
|
||||
|
||||
.urlopen!: (url: Str or .Request!, data: Bytes or NoneType := NoneType, timeout: Nat or NoneType := NoneType) -> http.client.HTTPResponse
|
||||
.install_opener!: (opener: OpenerDirector!) => NoneType
|
||||
.build_opener!: (handler: BaseHandler!) => OpenerDirector!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue