• MicroPython? Someone?

    From yeti@yeti@tilde.institute to tilde.python on Wed Dec 13 00:42:27 2023
    With it's presence in the micro-controller dimension and the possibility
    to run the same dialect on *nixens too, I thought it may or may not make
    sense to give it a chance again.

    -----------------------------------8<-----------------------------------
    $ micropython -c 'import sys ; print(sys.implementation)'
    (name='micropython', version=(1, 21, 0), _machine='linux [GCC 10.2.1] version', _mpy=2310)
    $ cat socket-0.py
    import socket

    s=socket.socket() ai=socket.getaddrinfo('news.tilde.club',119,socket.AF_INET)[0][-1]

    s.connect(ai)
    line=s.readline()

    messageId="<ul9sfr$isuf$1@tilde.club>"
    s.write(f"ARTICLE {messageId}\r\n")
    line=s.readline()

    while True:
    line=s.readline()
    if line==b".\r\n": break
    print(line.decode("UTF-8"),end="") # look for coding in headers someday

    s.write("QUIT\r\n")
    s.write(".\r\n")
    $ micropython socket-0.py | awk 'NR<9'
    Path: news.tilde.club!.POSTED.149.27.127.112!not-for-mail
    From: vort3 <vort3@tilde.club>
    Newsgroups: tilde.python
    Subject: Anyone interested in writing a NNTP client in Python?
    Date: Tue, 12 Dec 2023 20:59:09 +0600
    Organization: tilde.club
    Sender: vort3@tilde.club
    Message-ID: <ul9sfr$isuf$1@tilde.club>
    $ _
    ----------------------------------->8-----------------------------------

    It took a while to grok that the errors it did throw were because it
    preferred to resolve host names to IPV6 addresses and to find how to
    switch that off. How to make µPy on *nixens handle IPV6 is currently
    not in the upper range of my to do list, but maybe I stumble over an
    answer while looking for different things.

    I had some surprises with µPy earlier: It can be surprisingly fast.[0] ____________

    [0]: <https://yeti.tilde.institute/brain/micropython.html#emitters>
    --
    1. Hitchhiker 25: (59) Scarcely pausing for breath, Vroomfondel shouted,
    "We don't demand solid facts! What we demand is a total absence of
    solid facts. I demand that I may or may not be Vroomfondel!"
    --- Synchronet 3.19a-Linux NewsLink 1.113
  • From yeti@yeti@tilde.institute to tilde.python on Thu Dec 14 03:24:32 2023
    Next experiment. Now fetching an article via NNTPS:

    -----------------------------------8<-----------------------------------
    import socket
    import ssl
    #^^^^^^^^^ line added

    s=socket.socket() ai=socket.getaddrinfo('news.tilde.club',563,socket.AF_INET)[0][-1]
    #^^^ port changed
    s.connect(ai)
    s=ssl.wrap_socket(s)
    #^^^^^^^^^^^^^^^^^^^ line added
    line=s.readline()

    s.write(b"ARTICLE <s6t3af$3ghpr$2@tilde.club>\r\n")
    line=s.readline()

    while True:
    line=s.readline()
    if line==b".\r\n": break
    print(line.decode("UTF-8"),end="") # look for coding in headers someday

    s.write("QUIT\r\n")
    s.write(".\r\n") ----------------------------------->8-----------------------------------

    Easier than I expected. What did I overlook? Sure error handling still
    is missing. And so is closing the socket. I should look at MicroPython
    having ~with x as y:~ and whether sockets are cleanly shutdown on
    deallocation.
    --
    1. Hitchhiker 6: (24) `"Oh, that was easy," says Man, and for an encore
    goes on to prove that black is white and gets himself killed on the next
    zebra crossing.
    --- Synchronet 3.19a-Linux NewsLink 1.113
  • From yeti@yeti@tilde.institute to tilde.python on Thu Dec 14 04:26:00 2023
    yeti <yeti@tilde.institute> writes:

    I should look at MicroPython having ~with x as y:~

    Sure.

    and whether sockets are cleanly shutdown on deallocation.

    -----------------------------------8<------------------------------------
    $ cat with-socket.upy.py
    import socket

    with socket.socket() as s:
    pass
    $ micropythonhon with-socket.upy.py
    Traceback (most recent call last):
    File "with-socket.upy.py", line 3, in <module>
    AttributeError: 'socket' object has no attribute '__exit__'
    $ micropython with.upy.py
    Traceback (most recent call last):
    File "with.upy.py", line 4, in <module>
    AttributeError: 'socket' object has no attribute '__exit__' ----------------------------------->8------------------------------------

    Houston? We got an answer!
    --
    3. Hitchhiker 10: (81) The Hitch Hiker's Guide to the Galaxy has this to
    say on the subject of flying. (82) There is an art, it says, or rather
    a knack to flying. (83) The knack lies in learning how to throw
    yourself at the ground and miss.
    --- Synchronet 3.19a-Linux NewsLink 1.113
  • From yeti@yeti@tilde.institute to tilde.python on Thu Dec 14 04:27:35 2023
    yeti <yeti@tilde.institute> writes:

    I should look at MicroPython having ~with x as y:~

    Sure.

    and whether sockets are cleanly shutdown on deallocation.

    -----------------------------------8<------------------------------------
    $ cat with-socket.upy.py
    import socket

    with socket.socket() as s:
    pass
    $ micropython with-socket.upy.py
    Traceback (most recent call last):
    File "with-socket.upy.py", line 3, in <module>
    AttributeError: 'socket' object has no attribute '__exit__' ----------------------------------->8------------------------------------

    Houston? We got an answer!
    --
    3. Hitchhiker 10: (81) The Hitch Hiker's Guide to the Galaxy has this to
    say on the subject of flying. (82) There is an art, it says, or rather
    a knack to flying. (83) The knack lies in learning how to throw
    yourself at the ground and miss.
    --- Synchronet 3.19a-Linux NewsLink 1.113