Giter Site home page Giter Site logo

pfalcon / pycopy-lib Goto Github PK

View Code? Open in Web Editor NEW
245.0 15.0 71.0 3.63 MB

Standard library of the Pycopy project, minimalist and light-weight Python language implementation

Home Page: https://github.com/pfalcon/pycopy

License: Other

Makefile 0.07% Python 99.83% Shell 0.10%
minimalist suckless python pycopy micropython

pycopy-lib's Introduction

pycopy-lib

pycopy-lib is a project to develop a non-monolithic standard library for the Pycopy project (https://github.com/pfalcon/pycopy), while where possible, staying compatible with other variants and implementations of Python. The goals of the project are:

  • As the main goal, develop Pycopy standard library as close as possible matching that of CPython. It thus necessarily targets "Unix" port of Pycopy.
  • As a side goal, develop individual modules usable/useful on baremetal ports of Pycopy. This is oftentimes conflicts with the first goal (something as close as possible matching CPython functionality is just too big to run on low-memory systems), and necessitates creation of additional modules, or special "micro" (aka "u") versions of them.

Each module or package of pycopy-lib is available as a separate distribution package from PyPI. Each module comes from one of the following sources (and thus each module has its own licensing terms):

  • written from scratch specifically for Pycopy
  • ported from CPython
  • ported from some other Python implementation, e.g. PyPy
  • some modules actually aren't implemented yet and are dummy
  • some modules are extensions and are not part of CPython's standard library

As mentioned above, the main target of pycopy-lib is the "Unix" port of Pycopy.Actual system requirements vary per module. Modules not related to I/O may also work without problems on bare-metal ports, not just on "Unix" port (e.g. esp8266).

Usage

pycopy-lib packages are published on PyPI (Python Package Index), the standard Python community package repository: http://pypi.python.org/ . On PyPI, you can search for Pycopy related packages and read additional package information. All pycopy-lib package names are prefixed with "pycopy-".

Browse available packages via this URL. (Note: this may also include 3rd-party modules which are not part of pycopy-lib.)

To install packages from PyPI for usage on your local system, use the upip tool, which is Pycopy's native package manager, similar to pip, which is used to install packages for CPython. upip is bundled with Pycopy "Unix" port (i.e. if you build "Unix" port, you automatically have upip tool). Following examples assume that pycopy binary is available on your PATH:

$ pycopy -m upip install pycopy-pystone
...
$ pycopy
>>> import pystone
>>> pystone.main()
Pystone(1.2) time for 50000 passes = 0.534
This machine benchmarks at 93633 pystones/second

Run pycopy -m upip --help for more information about upip.

CPython backports

While pycopy-lib focuses on Pycopy, sometimes it may be beneficial to run Pycopy code using CPython, e.g. to use code coverage, debugging, etc. tools available for it. To facilitate such usage, pycopy-lib also provides reimplementations ("backports") of Pycopy modules, which run on CPython. This first of all applies to the builtin Pycopy "u" modules, but as time goes on, backports of pycopy-lib's own modules can be provided. Backport modules are in the directories named cpython-* of this repository. On PyPI, these named pycopy-cpython-*.

These modules should be installed with CPython's pip3 tool. Example session:

$ pip3 install --user pycopy-cpython-uhashlib
...
$ python3
...
>>> import uhashlib
>>> uhashlib.sha1(b"test").hexdigest()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'sha1' object has no attribute 'hexdigest'
# Pycopy's uhashlib doesn't have hexdigest(), use ubinascii.hexlify(.digest())
>>> uhashlib.sha1(b"test").digest()
b'\xa9J\x8f\xe5\xcc\xb1\x9b\xa6\x1cL\x08s\xd3\x91\xe9\x87\x98/\xbb\xd3'

Development

To install modules during development, use make install. By default, all available packages will be installed. To install a specific module, add the MOD=<module> parameter to the end of the make install command.

Contributing

pycopy-lib is a community project and can be implemented "fully" only by contributions from interested parties. The contributions are expected to adhere to Contribution Guidelines.

Credits

pycopy-lib is developed and maintained by Paul Sokolovsky (@pfalcon) with the help of Pycopy community.

List of modules specific to pycopy-lib

While pycopy-lib's primary way is to provide implementation of Python standard library, pycopy-lib goes further and hosts some extension modules which are deemed to be worth being a part of "Pycopy standard library". This section lists them to easy discovery:

  • byteslib - similar to string, function variants of bytes methods.
  • uaiohttpclient - HTTP client for uasyncio
  • uargparse - small subset of argparse module
  • uasyncio - asynchronous scheduling and I/O, roughly based on CPython's asyncio
  • uasyncio.core - just a scheduler part of uasyncio
  • uasyncio.queues - subset of CPython's asyncio.Queue
  • uasyncio.synchro - synchronization primitives for uasyncio (subset of asyncio's)
  • uasyncio.udp - UDP support for uasyncio
  • ucontextlib - subset of contextlib functionality
  • uctypelib - higher-level helpers to define structure for the builtin uctype module
  • uctypeslib2 - pretty printing support for uctypes structure definitions
  • ucurses - small subset of curses module
  • udnspkt - DNS packet handling (Sans I/O approach)
  • ulogging - small subset of logging module
  • umqtt.robust
  • umqtt.simple
  • uos2 - minimalist subset of the "os" module
  • upip - Pycopy package manager, modelled after "pip" tool
  • upysh - minimalistic filesystem shell using Python syntax
  • urequests - subset of "requests" module
  • urlib.urequest - small subset of urlib.request module
  • usubprocess - small subset of "subprocess" module
  • utarfile - small subset of tarfile module
  • utokenize - simple tokenizer for Python source
  • uurequests - very small subset of "requests" module
  • uwwwauth - HTTP Basic/Digest authentication algorithms
  • xmltok2 - small/simple XML tokenizer

pycopy-lib's People

Contributors

admin-slush avatar alex-robbins avatar altasoul avatar andrewleech avatar annejan avatar balloob avatar belyalov avatar candale avatar ccooper21 avatar dhylands avatar di avatar dmascord avatar dpgeorge avatar dxxb avatar levsh avatar mbuesch avatar mzdaniel avatar ngraziano avatar njouanin avatar nucflash avatar nvbn avatar peterhinch avatar pfalcon avatar puuu avatar reidwagner avatar spotlightkid avatar stinos avatar stlehmann avatar willingc avatar xrmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycopy-lib's Issues

logging: Implement custom formatting

Like discussed before it would be great to allow custom formatting by the model of CPython. This can be done by passing a Formatter object that contains the necessary format information to a handler or by passing a format parameter to basicConfig().

I'm already on this issue and opened it to keep track on it and discuss some details.

urllib.urequest SSL Error ESP-IDF 3.1

SSL connections are throwing a mbedtls_ssl_handshake error: -0x4290

I'm using the method only for a dataless get request. It is working without ssl.

My SSL certificate on the server side is a properly signed RSA 2048

error when pickle dict with float (point sign) and tuple

I need to save dict structure to persistent storage using pickle. I have tuples and floats in it. But when I try to unpickle it I got error.
To reproduce:

>>> d = {'a': 1.0, 'b': (1, 0)}
>>> pickle.loads(pickle.dumps(d))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pickle.py", line 20, in loads
ImportError: no module named '{'a': 1'
>>> 

Feature: Allow upip to install from test.pypi.org

Relates a little bit to #46

For initial testing it would be good to enable a package installation from test.pypi.org to avoid unnecessary version dumps every time.

For sure you can simply use the non-micropython pip and install it to the unix port of micropython for testing purposes.

I just want go gather some ideas and opinions before creating a pull request for a feature nobody needs. Overall I'm thinking of an additional argument at the install function to allow another installation root URL. This might be also good for self hosted packages or other package hosts, gitlab, artifact repository ...

[RFC] Using "black" compatible formatting

@andrewleech mention using the Black tool for formatting in #8 (comment) .

My immediate reaction to its motto of "The Uncompromising Code Formatter" is "uh-oh". But it has pretty well and convincing written docs, which is fun to read due to interspersed passages like "If you're paid by the line of code you write, you can ...", and the right reasonable choices made in the questions like strings delimiters, line length, etc.

So, well, let's keep it on the radar.

'pip install micropython-upip' returned error

I wanted to import machine to micropython and upip seemed like it would make my day easier. However when I typed the pip installer into the command prompt, this error appeared:

ERROR: File "setup.py" not found for legacy project micropython-upip from https://files.pythonhosted.org/packages/29/81/52df27cb7d240190c1d3ddab0c081bd3296bedcce155eed9e7016c4d92f0/micropython-upip-1.2.6.tar.gz#sha256=b9c09fc2b65f877d945142e468e0f25b5f70e9f74e98e0f43ca030bd7f47e87f.

Suggestions?

[esp8266] uasyncio "example_http_server.py" fails with EAGAIN

I'm running pycopy built from 82ec8df:

Pycopy v3.0.5-4-g82ec8dfd3a on 2020-03-16; ESP module with ESP8266                      │
Type "help()" for more information.                                                    │
>>> import server                                                                      │

I'm trying to run example_http_server.py. I have uasyncio/__init__.py and uasyncio/core.py, both from 5325a960d. When I import example_http_server, I get:

>>> import example_http_server
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "example_http_server.py", line 20, in <module>
  File "uasyncio/core.py", line 116, in run_forever
  File "uasyncio/__init__.py", line 266, in start_server
OSError: [Errno 11] EAGAIN

Is this expected to work? Could there be something wrong with my environment that is causing this?

Installing pycopy-cpython-upip 1.3.1 through pip fails

Dear Paul,

probably since cpython-upip release 1.3.1 by 6780dd6, we get this error when trying to install it on a vanilla Python 3.7.4 on our workstation.

$ pip install pycopy-cpython-upip
Collecting pycopy-cpython-upip
  Using cached https://files.pythonhosted.org/packages/e0/ac/5ddaf3cd3f86af13702721fff23623fa51382c0ac47082482a74d22f54e1/pycopy-cpython-upip-1.3.1.tar.gz
Collecting pycopy-cpython-cpython-uerrno (from pycopy-cpython-upip)
  ERROR: Could not find a version that satisfies the requirement pycopy-cpython-cpython-uerrno (from pycopy-cpython-upip) (from versions: none)
ERROR: No matching distribution found for pycopy-cpython-cpython-uerrno (from pycopy-cpython-upip)

We found that most of the dependency packages like pycopy-cpython-cpython-uerrno are missing on PyPI altogether. May we humbly ask whether we missed anything about an updated installation procedure which might be required for getting upip installed?

Using cpython-upip==1.2.6 still works well for us, so we explicitly pinned this version for now [1,2].

Thanks in advance for taking a look into this.

With kind regards,
Andreas.

[1] hiveeyes/terkin-datalogger@245b886
[2] hiveeyes/terkin-datalogger#17

[logging.RotatingFileHandler] The rotation logic doesn't take into account initial log file size.

Bug description
RotatingFileHandler opens the log file in the append ("a") mode.
The handler uses self._counter to detect when the log rotation needs to be done.
However, the self._counter is never initialized with the initial size of the log file.
It can lead to a situation when the log file will be twice what the maxBytes parameter specifies.

Proposal

  • Open the log file in the constructor and initialize the self._counter variable with the size of the log file.

Urequests error while sending HTTPS requests.

Hi there, i want to post my sensor data to my backend server. For that i used urequests library.

But i am getting the error status code of 426 which ingeneral means upgrade required. I want to kow how i can solve this problem.

i have attached the code i used
also i have checked urequests is using http 1.0, how to ugrade that also coz it is obselete now

`import machine
import urequests as requests
import network
import time
import ujson

Wifi Credentials

SSID = "xxxx"
PSK = "xxxxx"

def connect_to_wifi(ssid, psk):
# Enable Wifi in Client Mode
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Connect to Wifi, keep trying until failure or success
wlan.connect(ssid, psk)

while not wlan.isconnected() and wlan.status() >= 0:
    print("Waiting to Connect")
    time.sleep(5)
if not wlan.isconnected():
    raise Exception("Wifi not available")
print("Connected to WiFi")

connect_to_wifi(SSID, PSK)

while True:
try:

    url = "https://backend-production-e1c2.up.railway.app/api/auth/createuser"
    headers = { "Content-Type": "application/json" }
   
    insertPayload = ujson.dumps({ 'name':'sample tsdasdfsdfing','email':'[email protected]', 'password':'784989012sdfsdf4'})
    
    print("sending...")
    
    start_time = time.ticks_ms()
    
    response = requests.post(url, headers=headers, data =insertPayload)
    
    end_time = time.ticks_ms()
    content = response.headers
    print(content)
  
    print("Response: (" + str(response.status_code) + "), msg = " + str(response.text))

    if response.status_code == 201:
        print("Added Successfully")
    else:
        print("Error")

    # Always close response objects so we don't leak memory
    response.close()
    elapsed_time = end_time - start_time
    print("Request time: {} ms".format(elapsed_time))

except Exception as e:
    print(e)

`

logging: FileHandler writes to file only after closing the file

Dear All,
I'm using MicroPython v1.12 on ESP8266.
When I'm trying to write logs with logging to file, the file is empty untill I close the file.

Example:

MicroPython v1.12 on 2019-12-20; ESP module with ESP8266
Type "help()" for more information.

import os
import logging
logger = logging.getLogger("testlogger")
logger.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s;%(name)s;%(levelname)s;%(message)s')
os.remove("fh.log")
fh = logging.FileHandler("fh.log")
fh.setFormatter(fmt)
logger.addHandler(fh)
logger.debug('Level 1. Debug message')
os.stat('fh.log')[6]
0
fh.close()
os.stat('fh.log')[6]
56

A simple WA here can be rewriting FileHandler class in _init.py like this:

class FileHandler(Handler):
def init(self, filename, mode="a", encoding=None, delay=False):
super().init()

    self.encoding = encoding
    self.mode = mode
    self.delay = delay
    self.terminator = "\n"
    self.filename = filename

def emit(self, record):
    with open(self.filename, self.mode) as f:
        f.write(self.formatter.format(record) + self.terminator)

Example with the new init.py:

MicroPython v1.12 on 2019-12-20; ESP module with ESP8266
Type "help()" for more information.

import os
import logging
logger = logging.getLogger("testlogger")
logger.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s;%(name)s;%(levelname)s;%(message)s')
os.remove("fh.log")
fh = logging.FileHandler("fh.log")
fh.setFormatter(fmt)
logger.addHandler(fh)
logger.debug('Level 1. Debug message')
os.stat('fh.log')[6]
56

Best Regards,
Pavel Balobin

ENOMEM on ussl.wrap_socket() running upip on ESP32

Version info:
MicroPython v2.11.0.16 on 2019-12-03; ESP32 module with ESP32
ESPIDF_SUPHASH_V4 := 310beae373446ceb9a4ad9b36b5428d7fdf2705f (Version mentioned in the Makefile)

Problem
When trying to install a package with upip using an ESP32 it gives the following error:

>>> upip.install('picoweb')
Installing to: /lib/
Error installing 'picoweb': OSError(12,), packages may be partially installed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "upip.py", line 265, in install
  File "upip.py", line 253, in install
  File "upip.py", line 217, in install_pkg
  File "upip.py", line 195, in get_latest_url_simple
  File "upip.py", line 171, in url_open
  File "upip.py", line 151, in url_open
OSError: [Errno 12] ENOMEM

I am not sure what the error means, but in case it is memory related this is the output from gc.mem_free():

>>> gc.mem_free()
63680

I just recently switched from uPython to Pycopy so the issue might be on my side.

If you need any more information let me know.

logging module: AttributeError: 'FileIO' object has no attribute 'flush' micropython 1.18

The stream handler constructor called at the end of __init__.py initializes the _stream as stderr. This is a FileIO object, which does not have a "flush" method. This results in the above error.

Patching the StreamHandler class "flush" method to read like this solves the problem:

    def flush(self):
        if hasattr(self._stream, "flush"):
            self._stream.flush()

no module ustruct

several lib have dependency on ustruct (like pwd.py, struct.py), but i can't find ustruct.py in the package

Unable to install pycopy-xmltok2 using pip or manual install

I tried calling using pip install pycopy-xmltok comand and this same command type installed, Numby, re101, and pandas. However, when I tried to install this either locally or calling via the command line to repository I get the below output.
When I manually pull down the package the only thing inside the package that resembles a package installer is a xmltok.py file.
Anyone have the xmltok2 or pycopy-xml.etree.ElementTree installed correctly?
Thank you for anytime you might have to respond.

Requirement already satisfied: pip in c:\program files\windowsapps\pythonsoftwarefoundation.python.3.11_3.11.496.0_x64__qbz5n2kfra8p0\lib\site-packages (22.3.1)
Collecting install
Downloading install-1.3.5-py3-none-any.whl (3.2 kB)
Collecting pycopy-xmltok2
Downloading pycopy-xmltok2-0.3.tar.gz (2.2 kB)
ERROR: pycopy-xmltok2 from https://files.pythonhosted.org/packages/68/a3/7170eb8c78c3d6746a875f30d65f52d9bf0bb3d508c1288865ceb3673f48/pycopy-xmltok2-0.3.tar.gz does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

logging error on lineno formater

Getting an error on trying to add format %(lineno)d parameter

code:
logging.Formatter('%(lineno)d, %(name)s, %(message)s')

error:
TypeError: can't convert NoneType to int

Missing files in sdist

It appears that the manifest is missing at least one file necessary to build
from the sdist for version 3.6. You're in good company, about 5% of other
projects updated in the last year are also missing files.

+ /tmp/venv/bin/pip3 wheel --no-binary pycopy-uasyncio -w /tmp/ext pycopy-uasyncio==3.6
Looking in indexes: http://10.10.0.139:9191/root/pypi/+simple/
Collecting pycopy-uasyncio==3.6
  Downloading http://10.10.0.139:9191/root/pypi/%2Bf/ba6/0f9775fd541f4/pycopy-uasyncio-3.6.tar.gz (4.9 kB)
    ERROR: Command errored out with exit status 1:
     command: /tmp/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-wheel-z5h5ne9q/pycopy-uasyncio/setup.py'"'"'; __file__='"'"'/tmp/pip-wheel-z5h5ne9q/pycopy-uasyncio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-wheel-z5h5ne9q/pycopy-uasyncio/pip-egg-info
         cwd: /tmp/pip-wheel-z5h5ne9q/pycopy-uasyncio/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.8/tokenize.py", line 392, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-wheel-z5h5ne9q/pycopy-uasyncio/setup.py'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Uasyncio-udp, "sendto" Error: (function takes 3 positional arguments but 4 were given)

Dear @peterhinch ,
Dear @pfalcon ,
When i have run following code, i am receiving an error from sendto method in udp.py.

In addition to that, i want to bind the socket to the port in uasyncio-udp (as like in socket method sock.bind((IP, PORT)) to listen incoming messages from that port. Can sendto method allow me to listen that port?

def UDPListener(addr):
    s = uasyncio.udp.socket()
    yield from uasyncio.udp.sendto(s, b"!eeeeeee", addr)
    while True:
        print("Listening Started")
        try:
            resp = yield from uasyncio.wait_for(uasyncio.udp.recv(s, 1024), 1)
            print(resp)
        except uasyncio.TimeoutError:
            print("timed out")


def webServer(ipAddress):
    addr = usocket.getaddrinfo(ipAddress, 47778)[0][-1]
    loop = uasyncio.get_event_loop()
    loop.create_task(UDPListener(addr))
    loop.run_forever()

webServer("192.168.1.139")


  File "/lib/uasyncio/udp.py", line 48, in sendto
TypeError: function takes 3 positional arguments but 4 were given

Micropython v1.17 SHA1

Hi,

I'm very new to the Raspberry Pi ecosystem. I've been trying to make a Raspberry Pi Pico totp generator and have gotten to the point of displaying a totp code. Since totp is built around SHA1 by default I've been trying to do the following to no avail. I'm using Thonny as the IDE of choice to work in and have installed the micropython-hashlib v0.0.1 latest stable.

import time
import ubinascii
import uhashlib
import lcd
from machine import Pin

totp = [("Discord ", 'JBSWY3DPEHPK3PXP')]

TEST = True
ALWAYS_ON = True
ON_SECONDS = 10
EPOCH_DELTA = 1638239843
SECS_DAY = 86400
SHA1 = uhashlib.sha1
LCD = lcd.LCD_1inch14()

def HMAC(k, m):
SHA1_BLOCK_SIZE = 64
KEY_BLOCK = k + (b'\0' * (SHA1_BLOCK_SIZE - len(k)))
KEY_INNER = bytes((x ^ 0x36) for x in KEY_BLOCK)
KEY_OUTER = bytes((x ^ 0x5C) for x in KEY_BLOCK)
inner_message = KEY_INNER + m
outer_message = KEY_OUTER + SHA1(inner_message).digest()
return SHA1(outer_message)

I get the following message: AttributeError: 'module' object has no attribute 'sha1'

[logging] sys.exc_info() function doesn't exist on ESP32

Micopython version: v1.23.0
Board: ESP32 / WROOM

The error message when using the logging library:

  File "/lib/logging/__init__.py", line 72, in exception
AttributeError: 'module' object has no attribute 'exc_info'
MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32

upip - cpython issues

micropython-cpython-upip has a few issues on Python 3.8:

  1. Line 70 in upip.py: Python 3.8 does not support the size argument in open:
outf.write(file_buf, size=sz)

Fix:

outf.write(file_buf)

The following works:

  1. gc: gc.mem_free and gc.mem_free don't exist.

Workaround:

import gc
gc.mem_free = lambda : 1000000
gc.mem_alloc = lambda : 100000

import upip # now works as expected

umqtt: Compatibility with CPython

Dear Paul,

in the spirit of #49, [1] improves the umqtt module to be compatible with CPython. As I've learned, these kinds of changes are out of the scope of Pycopy to be incorporated into its module ecosystem, I just want to leave this notice as a reference to others looking for the same thing.

We needed these changes to support a CPython-based test harness for our Terkin Datalogger. The outcome where this is used can be inspected at [2].

With kind regards,
Andreas.

[1] master...daq-tools:improve-umqtt
[2] https://github.com/hiveeyes/terkin-datalogger/blob/23b8065a/test/test_wifi_mqtt.py

error on socket.py

Traceback (most recent call last):
File "", line 91, in
File "/lib/socket.py", line 48, in accept
AttributeError: 'module' object has no attribute 'sockaddr'

Feature: allow upip to install packages by URL

I am new to micropython, I am figuring out how to keep my application up to date over the air.

Since code is small and connectivity good, I was thinking on pip installing my python code on every boot.

upip seems to do most of it, download, unpack, install etc, but then:

Note: only Pycopy packages (usually, named pycopy-*) are supported

Why?

Otherwise, what is the recommended method to OTA update my micropython application?

cgi: Issues due to os.environ not implemented (workaround available)

Hi, there is libcgi which I would like to use but the html form data are not populated possibly becasue of os.environ not implemented:
environ = {"WARNING": "NOT_IMPLEMENTED"}

Could you please give any hint what is the best way to fix it ? ( could be popualting os.environ by env system call ? )

Can't cast implicit from bytes to strint in uurequests.py -> request -> Tranfert-Ecoding value error

I found this bug in uurequest.py in method

def request(method, url, data=None, json=None, headers={}, stream=None, parse_headers=True):
...
                if l.startswith(b"Transfer-Encoding:"):
                    if b"chunked" in l:
                        # decode added, can't cast implicit from bytes to string
                        raise ValueError("Unsupported " + l.decode('utf-8'))
...

I had to add the ".decode('utf-8')" otherwise get an error, when this error is thrown (at least on an ESP32)

zlib : ' object has no attribute 'func'

hello everyone,
please what is the problem in this :

File "zlib.py", line 9, in <module>
AttributeError: 'NoneType' object has no attribute 'func'

I have also the ffi.py lib but the same problem

os: getcwd does not work on bare-metal

getcwd does not work on 'bare-metal' ports of Micropython. This is in fact a major bug as getcwd is used by mfpshell. When installing os package on a 'bare-metal' port like ESP8266 or ESP32 the board will no longer be accessible via mpfshell.

Uasyncio equivalent for `asyncio.gather`/`asyncio.wait`?

I'm really confused by the uasyncio module, all the documentation I see is either out of date or just plain inapplicable.

For example, https://pycopy.readthedocs.io/en/latest/library/uasyncio.html says that uasyncio.run, uasyncio.create_task, uasyncio.current_task, uasyncio.gather exists, when in reality they don't. Nor do the Event, Lock and ThreadSafeFlag class exist either.

Apart from using run_forever and run_until_complete, is this library usable? I want to wait on 2 tasks created like uasyncio.gather, is this even possible right now?

urequest module error when calling a HTTPS url

When executing a POST to an HTTPS endpoint, I get an error from the function request at line 88:

File "/lib/urequests/__init__.py", line 162, in post
File "/lib/urequests/__init__.py", line 88, in request
AttributeError: 'module' object has no attribute 'SSLContext'

Accordingo the ussl documentation, there is no such function ussl.SSLContext(), the only method listed there is wrap_socket which is called on line 89, but against the ctx reference instead.

Add basic comment spec to uyaml

Would it be possible to add comment parsing to yaml / uyaml?

Doesn't necessarily need the full spec, just some way of delivering information to end-users.
Perhaps, any lines starting with # could be ignored?

Thank you!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

test.py

import yaml

print(yaml.safe_load(open("commented.yml")))
print(yaml.safe_load(open("uncommented.yml")))

commented.yml

# This will print, even though it is a comment.
but: "this will not"

uncommented.yml

however: "this will in fact print"

image

logging stuck not there for us

any plans to add this nice feature?
in regular python it's working. missing it here ((

    def formatStack(self, stack_info):
        raise NotImplementedError()

xml.etree.ElementTree can't handle some elements.

I try to let it handle some actual xml feed document, it seems can't handle none pairs type XML dedicated elements,
e.g.

<?xml version="1.0" encoding="utf-8" ?>
will arise :

Traceback (most recent call last):
File "", line 1, in
File "/lib/ElementTree.py", line 130, in fromstring
File "/lib/ElementTree.py", line 108, in parse_el
IndexError: list index out of range

CDATA Sections https://www.w3.org/TR/REC-xml/#sec-cdata-sect
<channel><item><cdata_section><![CDATA[something to test.]]></cdata_section></item></channel>
will arise:

Traceback (most recent call last):
File "", line 1, in
File "/lib/ElementTree.py", line 130, in fromstring
File "/lib/ElementTree.py", line 94, in parse_el
File "/lib/xmltok2.py", line 131, in tokenize
File "/lib/xmltok2.py", line 96, in expect
XMLSyntaxError:

One of actual XML document:
https://www.w3.org/blog/news/feed

Is it possible improve it ?

uasyncio: How to create tasks so they will be run immediatelly?

I try to control two relays with different delays concurently. Each of relay has own config and own task.

from machine import Pin
import uasyncio as asyncio
loop = asyncio.get_event_loop()
import utime
import logging
log = logging.getLogger("relay")
import events


# Load config and initiate pins
import config
relays = config.modules['relay']['relays']
for r in relays:
	r.update({
		'pin_obj': Pin(r['pin'], Pin.OUT)
	})


@events.on('card.card_validated')
def on_card_validated(card):
	for config in relays:
		loop.create_task(relay_task(config, card))


async def relay_task(config, card):
	if 'open_after' in config:
		log.info("Will open relay on pin %d in %d seconds", config['pin'], config['open_after'])
		await asyncio.sleep(config['open_after'])

	log.info("Opening relay on pin %d for %d seconds", config['pin'], config['close_after'])
	config['pin_obj'].on()
	await asyncio.sleep(config['close_after'])
	config['pin_obj'].off()

This code works, but there is delay few seconds between create_task and relay_task start. I need to have the delay up to one second.

Pycopy v3.0.6
Modules has current versions from PyPi.

Is it bug or I use it incorrectly?

Thank you for help.

OSError: -40

I am trying to read json data by url on ESP8266.

from urllib.urequest import urlopen
import json
url ="https://dashboard.elering.ee/api/nps/price?start=2021-12-01T21%3A00%3A00.000Z&end=2021-12-02T20%3A00%3A00.000Z"
response = urlopen(url)
data = json.loads(response.read())
print(data) 

I get error message:

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/lib/urllib/urequest.py", line 30, in urlopen
OSError: -40

However the code works fine with different URL

url="http://jsonplaceholder.typicode.com/albums/1"

logging: Name filename is not defined for FileHandler with delay.

When using logging.FileHandler with file opening deferred until the first call to emit() (delay=True) there will be the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.micropython/lib/logging/__init__.py", line 59, in warning
  File "/root/.micropython/lib/logging/__init__.py", line 50, in log
  File "/root/.micropython/lib/logging/__init__.py", line 134, in emit
NameError: name 'filename' isn't defined

The cause of the error is that filename and mode are referenced as variables and not as properties of StreamHandler.

uasyncio error on PyCom boards

Hello, Im working with uasyncio for a while now and I notice that when using it in Pycom (GPy and FiPy) boards, the amount of concurrent request i can make to an asynchronous server is very limited (less than 10). I found that in other ESP32 boards the concurrency is better (more than 100) and I don't know if I'm facing with a hardware or a software problem so I will expose what I'm doing.

First I have a picoweb server running on the board, then I run a bunch of other asynchronous tasks and they live happily together until I start to send requests to the web server. I use the ab (Apache Benchmark) tool to simulate 100 petitions with a concurrency of 10 or more and it makes the uasyncio library crash every time as seen here:

    File "/flash/lib/picoweb/__init__.py", line 298, in run
    File "/flash/lib/uasyncio/core.py", line 161, in run_forever
    File "/flash/lib/uasyncio/core.py", line 116, in run_forever
    File "/flash/lib/uasyncio/__init__.py", line 247, in start_server
OSError: 23
ets Jun  8 2016 00:22:57

This is the line 247:

    s2, client_addr = s.accept()

It does not seem to be a memory problem, as the Pycom GPy I'm using has 520KB of RAM and also my code works nicely if the petitions are done slower. It isn't a picoweb problem, as it works perfectly in other ESP32 microcontrollers, so I thought someone here might know the issue.

Thank you for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.