Skip to main content
#+TITLE: iotools.hy

IO tools for Hy.

* iotools

** iotools.buffer

Flexible buffer data struct.

#+begin_src hy
(setv buffer (Buffer b"hello"))

#(buffer.pos buffer.data) ; 0 b"hello"

(.read buffer 2) ; b"he"
#(buffer.pos buffer.data) ; 2 b"hello"

(.strip buffer)
#(buffer.pos buffer.data) ; 0 b"llo"
#+end_src

=Buffer.readexactly= or =Buffer.readuntil= will raise
=BufferWantReadError= if there has no enough data, in this case, user
should revert buffer.pos, push more data to buffer, and then read
again.

** iotools.struct

DSL used to describe data structures.

*** simple struct spec

#+begin_src hy
(defstruct Short [int :len 2])
(Short.pack 1) ; b"\x00\x01"
(Short.unapck b"\x00\x01") ; 1
#+end_src

*** complex struct spec

#+begin_src hy
(defstruct ShortPair
[[first [int :len 2]]
[second [int :len 2]]])
(ShortPair.pack #(1 2)) ; b"\x00\x01\x00\x02"
(ShortPair.unpack b"\x00\x01\x00\x02") ; #(1 2)
#+end_src

*** class struct spec

#+begin_src hy
(defstruct int2 [int :len 2])
(defstruct Short int2)
(defstruct ShortPair [[first Short] [second Short]])
#+end_src

*** more complex struct spec

See =iotools.proto= or =iotools-tls13.struct= for more examples.

** iotools.stream

Sync/Async stream abstraction, based on =dash.do/a!=.

This module inspired by Python built-in =ssl.SSLObject=: for any read
function =f= that read data from read buffer, reapeatedly push new
data from stream to read buffer and call =f= on read buffer, while
=BufferWantReadError= was raised.

** iotools.util

Sync/Async object alias, and basic stream implementation.

Alias:

- =(name/a! sleep)=: =time.sleep= =asyncio.sleep=
- =(name/a! Lock)=: =threading.Lock= =asyncio.Look=
- =(name/a! Queue)=: =queue.Queue= =asyncio.Queue=
- ...


Basic streams: =IOStream=, =FileStream=, =BytesStream=,
=SocketStream=, =AIOStream=, =(name/a! TCPStream)=.

* iotools.proto

Simple protocol implementation based on iotools.

** iotools.proto.ssl

=ssl.SSLObject= wrapper.

#+begin_src hy
(with [stream (SyncTCPStream.open host port)]
(let [connector (SyncSSLConnector :ssl-context (ssl.create-default-context)
:server-hostname host)]
(with [stream (.handshake connector stream)]
...)))
#+end_src

** iotools.proto.http

*** HTTPChunkedStream

#+begin_src hy
(with stream [SyncTCPStream.open host port]
(.write stream (HTTPRequest.pack "GET" "/" "HTTP/1.1" {"Host" host}))
(.flush stream)
(let [#(version status reason headers) (.read-loop stream HTTPResponse.read)
stream (if (= (-get headers "Transfer-Encoding") "chunked")
(SyncHTTPChunkedStream :next-layer stream)
stream)]
...))
#+end_src

*** HTTPProxyConnector/Acceptor

#+begin_src hy
(with [stream (SyncTCPStream.open proxy-host proxy-port)]
(let [connector (SyncHTTPProxyConnector :host host :port port)]
(with [stream (.handshake connector stream)]
...)))
#+end_src

** iotools.proto.ws

#+begin_src hy
(with [stream (SyncTCPStream.open host port)]
(let [connector (SyncWSConnector :host host)]
(with [stream (.handshake connector stream)]
...)))
#+end_src

** iotools.proto.socks5

Similar with =iotools.proto.http=.

Metadata

Release files for iotools-hy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iotools-hy 0.1.0
File Size Uploaded Provenance Actions
iotools_hy-0.1.0.tar.gz 12.1 kB Without provenance Details for iotools_hy-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iotools-hy 0.1.0
File Interpreter ABI Platform Actions
iotools_hy-0.1.0-py3-none-any.whl Python 3 none any Details for iotools_hy-0.1.0-py3-none-any.whl

Total release size: 27.9 kB

Release files / iotools_hy-0.1.0.tar.gz

Download URL iotools_hy-0.1.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7e88e11cf2dbf0e7d50a50443e7a95728b4e303deca7aa84fef440c6e37126be
BLAKE2b-256 checksum
How to use checksums
a360a719d1ed41f6d47bed97bf43b784a713fe28e77f4aa02b2d21d6e8465dfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Linux/6.5.0-17-generic

Release files / iotools_hy-0.1.0-py3-none-any.whl

Download URL iotools_hy-0.1.0-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a41bf93898328ef619c138effa2885c9f207969f1a5917cb1359c45ab1338e89
BLAKE2b-256 checksum
How to use checksums
2919db47b0f8c4ff5fd52d7114ff1d06a017228064e39470d3b4a867204f1c1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Linux/6.5.0-17-generic

Security for iotools-hy 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page