The DAP.Network module is designed to work with a network.
DAP.Network.ServerCore
A server class.DAP.Network.Events
An events class.DAP.Network.Http
A class for working with HTTP.DAP.Network.HttpCode
A HTTP code class.DAP.Network.HttpSimple
A simple HTTP server class.DAP.Network.EncHttp
An ecrypted HTTP class.DAP.Network.Stream
A class for working with streams.DAP.Network.StreamCtr
A class for controling streams.DAP.Network.JSONRPCRequest
A JSON request class.DAP.Network.JSONRPCResponse
A JSON response class.class DAP.Network.ServerCore
This class provides methods for working with a server.
static method DAP.Network.ServerCore.listen(events: CellFrame.Events, address: str, port: int, type: int) -> DAP.Network.ServerCore
Сreates a new server at the address that listens on the port. The events
is an instance of the Events
class created by an init
function. The type
specifies the type of server being created. If 0
is specified, a TCP server is created, if 1
, then UDP server. Returns the ServerCore
object.
class DAP.Network.Events
This class provides methods for working with events.
object method DAP.Network.Events.start() -> int
Starts a new server. Returns 0
if successful.
object method DAP.Network.Events.wait() -> int
Waits for the server thread to finish executing. Returns 0
.
object method DAP.Network.Events.killSocket(socket: DAP.Network.EventsSocket) -> int
Stops an instance of a socket. The socket
should be a EventsSocket
object. Returns 0
.
object method CellFrame.Events.removeAndDeleteSocket(socket: DAP.Network.EventsSocket, preserveInheritor=True: bool) -> int
Removes and deletes a socket. The socket
should be a EventsSocket
#eventssocket) object. Returns 0
.
class DAP.Network.EventsSocket
This class provides methods for working with an events socket.
object method DAP.Network.EventsSocket.createAfter() -> int
Creates a worker to an instance. Returns 0
.
object method DAP.Network.EventsSocket.setReadable(isReady: bool) -> int
Sets a Readable flag. Returns 0
.
object method DAP.Network.EventsSocket.setWritable(isWrite: bool) -> int
Sets a Writable flag. Returns 0
.
object method DAP.Network.EventsSocket.write(data: bytes, size: int) -> int
Writes data into a socket. The data
should be a bytes-liky object. Returns the size of the writed data.
object method DAP.Network.EventsSocket.writeF(format: str, ...) ->int
Writes a formatted text to the client. Returns the size of the writed data.
object method DAP.Network.EventsSocket.read(size: int) -> (int, bytes)
Reads data. Returns a tuple consisting of the read size and the data.
object method DAP.Network.EventsSocket.delete(in: bool) -> int
Deletes a socket. Returns 0
.
object method DAP.Network.EventsSocket.shringBufIn(size: int) -> int
Shrinks a input buffer. Returns 0
.
class DAP.Network.Http
This class provides methods for working with HTTP. It is a wrapper over the dap_http
plain C structure of CellFrame SDK.
staic method DAP.Network.Http.new(server: DAP.Network.Server, name: str) -> int
Initializes a HTTP server. Returns 0
if successful. This function wraps a dap_http_new
C function.
class DAP.Network.HttpCode
This class provides methods for working with a HTTP status code. It is a wrapper over the http_status_code
plain C enumeration of CellFrame SDK.
object method DAP.Network.HttpCode.set(code: int) -> None
Sets a HTTP response status code. Returns None
.
Existing status codes:
Value | Plain C enumeration | Description |
---|---|---|
100 |
Http_Status_Continue |
Indicates that the initial part of a request has been received and has not yet been rejected by the server. |
101 |
Http_Status_SwitchingProtocols |
Indicates that the server understands and is willing to comply with the client's request, via the Upgrade header field, for a change in the application protocol being used on this connection. |
102 |
Http_Status_Processing |
Is an interim response used to inform the client that the server has accepted the complete request, but has not yet completed it. |
103 |
Http_Status_EarlyHints |
Indicates to the client that the server is likely to send a final response with the header fields included in the informational response. |
200 |
Http_Status_OK |
Indicates that the request has succeeded. |
201 |
Http_Status_Created |
Indicates that the request has been fulfilled and has resulted in one or more new resources being created. |
202 |
Http_Status_Accepted |
Indicates that the request has been accepted for processing, but the processing has not been completed |
203 |
Http_Status_NonAuthoritativeInformation |
Indicates that the request was successful but the enclosed payload has been modified from that of the origin server's 200 (OK) response by a transforming proxy. |
204 |
Http_Status_NoContent |
Indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. |
205 |
Http_Status_ResetContent |
Indicates that the server has fulfilled the request and desires that the user agent reset the "document view", which caused the request to be sent, to its original state as received from the origin server. |
206 |
Http_Status_PartialContent |
Indicates that the server is successfully fulfilling a range request for the target resource by transferring one or more parts of the selected representation that correspond to the satisfiable ranges found in the requests's Range header field. |
207 |
Http_Status_MultiStatus |
Provides status for multiple independent operations. |
208 |
Http_Status_AlreadyReported |
Used inside a DAV:propstat response element to avoid enumerating the internal members of multiple bindings to the same collection repeatedly. (RFC 5842) |
226 |
Http_Status_IMUsed |
The server has fulfilled a GET request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance. |
300 |
Http_Status_MultipleChoices |
Indicates that the target resource has more than one representation, each with its own more specific identifier, and information about the alternatives is being provided so that the user (or user agent) can select a preferred representation by redirecting its request to one or more of those identifiers. |
301 |
Http_Status_MovedPermanently |
Indicates that the target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs. |
302 |
Http_Status_Found |
Indicates that the target resource resides temporarily under a different URI. |
303 |
Http_Status_SeeOther |
Indicates that the server is redirecting the user agent to a different resource, as indicated by a URI in the Location header field, that is intended to provide an indirect response to the original request. |
304 |
Http_Status_NotModified |
Indicates that a conditional GET request has been received and would have resulted in a 200 (OK) response if it were not for the fact that the condition has evaluated to false. |
305 |
Http_Status_UseProxy |
Due to security concerns regarding in-band configuration of a proxy. The requested resource MUST be accessed through the proxy given by the Location field. |
307 |
Http_Status_TemporaryRedirect |
Indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI. |
308 |
Http_Status_PermanentRedirect |
The target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs. This status code is similar to 301 Moved Permanently (Section 7.3.2 of rfc7231), except that it does not allow rewriting the request method from POST to GET. |
400 |
Http_Status_BadRequest |
Indicates that the server cannot or will not process the request because the received syntax is invalid, nonsensical, or exceeds some limitation on what the server is willing to process. |
401 |
Http_Status_Unauthorized |
Indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. |
402 |
Http_Status_PaymentRequired |
Reserved |
403 |
Http_Status_Forbidden |
Indicates that the server understood the request but refuses to authorize it. |
404 |
Http_Status_NotFound |
Indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists. |
405 |
Http_Status_MethodNotAllowed |
Indicates that the method specified in the request-line is known by the origin server but not supported by the target resource. |
406 |
Http_Status_NotAcceptable |
Indicates that the target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation. |
407 |
Http_Status_ProxyAuthenticationRequired |
Is similar to 401 (Unauthorized), but indicates that the client needs to authenticate itself in order to use a proxy. |
408 |
Http_Status_RequestTimeout |
Indicates that the server did not receive a complete request message within the time that it was prepared to wait. |
409 |
Http_Status_Conflict |
Indicates that the request could not be completed due to a conflict with the current state of the resource. |
410 |
Http_Status_Gone |
Indicates that access to the target resource is no longer available at the origin server and that this condition is likely to be permanent. |
411 |
Http_Status_LengthRequired |
Indicates that the server refuses to accept the request without a defined Content-Length. |
412 |
Http_Status_PreconditionFailed |
Indicates that one or more preconditions given in the request header fields evaluated to false when tested on the server. |
413 |
Http_Status_PayloadTooLarge |
Indicates that the server is refusing to process a request because the request payload is larger than the server is willing or able to process. |
414 |
Http_Status_URITooLong |
Indicates that the server is refusing to service the request because the request-target is longer than the server is willing to interpret. |
415 |
Http_Status_UnsupportedMediaType |
Indicates that the origin server is refusing to service the request because the payload is in a format not supported by the target resource for this method. |
416 |
Http_Status_RangeNotSatisfiable |
Indicates that none of the ranges in the request's Range header field overlap the current extent of the selected resource or that the set of ranges requested has been rejected due to invalid ranges or an excessive request of small or overlapping ranges. |
417 |
Http_Status_ExpectationFailed |
Indicates that the expectation given in the request's Expect header field could not be met by at least one of the inbound servers. |
418 |
Http_Status_ImATeapot |
Any attempt to brew coffee with a teapot should result in the error code 418 I'm a teapot. |
422 |
Http_Status_UnprocessableEntity |
Means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. |
423 |
Http_Status_Locked |
Means the source or destination resource of a method is locked. |
424 |
Http_Status_FailedDependency |
Means that the method could not be performed on the resource because the requested action depended on another action and that action failed. |
426 |
Http_Status_UpgradeRequired |
Indicates that the server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. |
428 |
Http_Status_PreconditionRequired |
Indicates that the origin server requires the request to be conditional. |
429 |
Http_Status_TooManyRequests |
Indicates that the user has sent too many requests in a given amount of time ("rate limiting"). |
431 |
Http_Status_RequestHeaderFieldsTooLarge |
Indicates that the server is unwilling to process the request because its header fields are too large. |
451 |
Http_Status_UnavailableForLegalReasons |
This status code indicates that the server is denying access to the resource in response to a legal demand. |
object method DAP.Network.HttpCode.OK(code: int) -> None
Sets a OK status code (200). Returns None
.
object method DAP.Network.HttpCode.BadRequest() -> None
Sets a bad request status code (400). Returns None
.
class DAP.Network.HttpSimple
This class provides methods for working with a simple HTTP server.
staic method DAP.Network.HttpSimple.init() -> int
Initializes a simple HTTP server. Returns 0
if successful.
staic method DAP.Network.HttpSimple.deinit() -> None
Deinitializes a simple HTTP server. Returns None
.
staic method DAP.Network.HttpSimple.addProc(server: DAP.Network.Server, url: str, replySizeMax: int, funcCallback: Callable) -> None
Adds URL and a callback function into a HTTP server. The funcCallback
must have a folowing signature f(DAP.Network.HttpSimple, DAP.Network.HttpCode)
.Returns None
.
staic method DAP.Network.HttpSimple.setPassUnknownUserAgents(pass: bool) -> None
Sets pass for unkonow user agents. Returns None
.
object method DAP.Network.HttpSimple.replyAdd(data: bytes) -> int
Adds a data to the reply buffer. Returns a copied data size.
getter DAP.Network.HttpSimple.action -> str
Returns an action of a request.
getter DAP.Network.HttpSimple.request -> bytes
Returns a request in view bytes.
getter DAP.Network.HttpSimple.urlPath -> str
Returns a URL string.
getter DAP.Network.HttpSimple.query -> str
class DAP.Network.EncHttp
This class provides methods for working with encrypted HTTP server. It is a wrapper over the enc_http_delegate
plain C structure of CellFrame SDK.
staic method DAP.Network.EncHttp.requestDecode(httpSimple: DAP.Network.HttpSimple) -> DAP.Network.EncHttp
Decodes a request. Returns the EncHttp
object if successful. This function wraps a enc_http_request_decode
C function.
object method DAP.Network.EncHttp.isNull(httpSimple: CellFrame.HttpSimple) -> bool
Checks if object is null. Returns True
if it is, otherwise False
.
object method DAP.Network.EncHttp.reply(data: bytes) -> int
Adds data to a reply. Returns a added data size if successful.
object method DAP.Network.EncHttp.replyEncode(httpSimple: CellFrame.HttpSimple) -> None
Encodes a reply. Returns None
.
staic method DAP.Network.EncHttp.replyEncode(server: CellFrame.Server, HttpUrl: str) -> int
Adds a simple HTTP processor.
getter DAP.Network.action -> str
Returns an action request.
getter DAP.Network.EncHttp.request -> Optional[bytes]
Returns a request.
getter DAP.Network.EncHttp.urlPath -> str
Returns an URL string.
getter DAP.Network.EncHttp.query -> str
Returns an input query string.
class DAP.Network.Stream
This class provides methods for work with stream object.
staic method DAP.Network.Stream.addProcHttp(server: CellFrame.Server, streamUrl: str) -> int
Adds an URL processor callback for streaming. Returns 0
if successful.
class DAP.Network.Stream
This class provides methods for work with stream object.
staic method DAP.Network.addProcHttp(server: CellFrame.Server, streamUrl: str) -> int
Adds an URL processor callback for streaming. Returns 0
if successful.
class DAP.Network.StreamCtr
This class provides methods for work with stream object.
staic method DAP.Network.StreamCtr.addProcHttp(server: DAP.Network.Server, streamCtrUrl: str) -> int
Adds an URL processor callback for streaming. Returns 0
if successful.
class DAP.Network.JSONRPCRequest
This class provides working with JSON-RPC requests.
staic method DAP.Network.JSONRPCRequest.registrationHandler(methodName: str, function: callable) -> None
Registrations a method. The methodName
is a method name. The function
should have the f(args: List[], response : DAP.Network.JSONRPCResponse) -> None
signature where the args
is list with arguments and the response
is a JSONRPCResponce
.
class DAP.Network.JSONRPCResponse
This class provides working with JSON-RPC requests.
getter DAP.Network.JSONRPCResponse.ID -> int
Gets an ID.
getter DAP.Network.JSONRPCResponse.Error -> (int, msg)
Gets an error. Returns a tuple contains an error code and a message.
setter DAP.Network.JSONRPCResponse.Error((int, msg))
Sets an error. Accepts a tuple contains an error code and a message.
getter DAP.Network.JSONRPCResponse.Error -> Any
Gets a result.
setter DAP.Network.JSONRPCResponse.Error(Any)
Sets a result. Accepts bool
, int
, float
, str
value.