enotype
A cross-language type library
from enotype import color
color('#fff') # returns "#fff"
color('#xyz') # raises ValueError("A color is required, for instance '#B6D918', '#fff' or '#01b'.")
from enotype.es import color # with localized error messages
color('#xyz') # raises ValueError("Se requiere un color, por ejemplo '#B6D918', '#fff' o '#01b'.")
Installation
pip install enotype
Features
- Validation and conversion of
stringrepresentations into language-native types. - Implemented as a collection of minimalist functions, so called loaders.
- Zero-cost localization (currently
de,en,es) through statically generated code. - Generically usable in a multitude of contexts through a plain and simple design.
- Standard type library for the eno notation language.
Documentation
boolean
import boolean from enotype
boolean('true') # returns True
'true' returns True.
'false' returns False.
'yes' returns True.
'no' returns False.
'nope' raises an exception.
color
import color from enotype
color('#abcdef') # returns '#abcdef'
'#abcdef' returns '#abcdef'.
'#ABCDEF' returns '#ABCDEF'.
'#012345' returns '#012345'.
'#678' returns '#678'.
'#89a' returns '#89a'.
'#ab' raises an exception.
'#abcd' raises an exception.
'#abcde' raises an exception.
'#bcdefg' raises an exception.
'blue' raises an exception.
comma_separated
import comma_separated from enotype
comma_separated('one,two,three') # returns ['one', 'two', 'three']
'one,two,three' returns ['one', 'two', 'three'].
' one,two,three ' returns ['one', 'two', 'three'].
'one , two , three' returns ['one', 'two', 'three'].
' one , two , three ' returns ['one', 'two', 'three'].
',,' returns ['', '', ''].
'one two three' returns ['one two three'].
'one;two;three' returns ['one;two;three'].
' ' returns [''].
date
import date from enotype
date('1992-02-02') # returns python_date(1992, 2, 2)
'1992-02-02' returns python_date(1992, 2, 2).
'1990' raises an exception.
'1991-01' raises an exception.
'1993-03-03T1920+01:00' raises an exception.
'1994-04-04T1920:30+01:00' raises an exception.
'1995-05-05T1920:30.45+01:00' raises an exception.
'1996-06-06T0815:30-05:00' raises an exception.
'1997-07-07T1315:30Z' raises an exception.
'2002 12 14' raises an exception.
'2002-12-14 20:15' raises an exception.
'January' raises an exception.
'13:00' raises an exception.
datetime
import datetime from enotype
datetime('1990') # returns python_datetime.strptime('1990-01-01T00:00:00.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z')
'1990' returns python_datetime.strptime('1990-01-01T00:00:00.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'1991-01' returns python_datetime.strptime('1991-01-01T00:00:00.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'1992-02-02' returns python_datetime.strptime('1992-02-02T00:00:00.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'1993-03-03T19:20+01:00' returns python_datetime.strptime('1993-03-03T18:20:00.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'1994-04-04T19:20:30+01:00' returns python_datetime.strptime('1994-04-04T18:20:30.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'1995-05-05T19:20:30.45+01:00' returns python_datetime.strptime('1995-05-05T18:20:30.450+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'1996-06-06T08:15:30-05:00' returns python_datetime.strptime('1996-06-06T08:15:30.000-0500', '%Y-%m-%dT%H:%M:%S.%f%z').
'1997-07-07T13:15:30Z' returns python_datetime.strptime('1997-07-07T13:15:30.000+0000', '%Y-%m-%dT%H:%M:%S.%f%z').
'2002 12 14' raises an exception.
'2002-12-14 20:15' raises an exception.
'January' raises an exception.
'13:00' raises an exception.
import email from enotype
email('john.doe@eno-lang.org') # returns 'john.doe@eno-lang.org'
'john.doe@eno-lang.org' returns 'john.doe@eno-lang.org'.
'john.doe@eno-lang' raises an exception.
'@eno-lang.org' raises an exception.
'john.doe@.org' raises an exception.
float
import float from enotype
float('42') # returns 42.0
'42' returns 42.0.
'-42' returns -42.0.
'42.0' returns 42.0.
'42,0' raises an exception.
'4 2.0' raises an exception.
'fortytwo' raises an exception.
integer
import integer from enotype
integer('42') # returns 42
'42' returns 42.
'-42' returns -42.
'42.0' raises an exception.
'42,0' raises an exception.
'4 2' raises an exception.
'fortytwo' raises an exception.
ipv4
import ipv4 from enotype
ipv4('0.0.0.0') # returns '0.0.0.0'
'0.0.0.0' returns '0.0.0.0'.
'255.255.255.255' returns '255.255.255.255'.
'192.168.0.1' returns '192.168.0.1'.
'10.10.10.10' returns '10.10.10.10'.
'255.255.255.256' raises an exception.
'localhost' raises an exception.
'4.staging.production.lan' raises an exception.
json
import json from enotype
json('{ "valid": true }') # returns { 'valid': True }
'{ "valid": true }' returns { 'valid': True }.
'42' returns 42.
'["valid", true]' returns ['valid', True].
'invalid' raises an exception.
'{ invalid: true }' raises an exception.
'{ "invalid": true, }' raises an exception.
lat_lng
import lat_lng from enotype
lat_lng('48.205870, 16.413690') # returns { 'lat': 48.205870, 'lng': 16.413690 }
'48.205870, 16.413690' returns { 'lat': 48.205870, 'lng': 16.413690 }.
'41.25, -120.9762' returns { 'lat': 41.25, 'lng': -120.9762 }.
'-31.96, 115.84' returns { 'lat': -31.96, 'lng': 115.84 }.
'90, 0' returns { 'lat': 90, 'lng': 0 }.
' 0 , 0 ' returns { 'lat': 0, 'lng': 0 }.
'-0,-0' returns { 'lat': -0, 'lng': -0 }.
'1000,10' raises an exception.
'10,1000' raises an exception.
'48.205870,' raises an exception.
', 16.413690' raises an exception.
'48,205870, 16,413690' raises an exception.
slug
import slug from enotype
slug('eno-lang-article') # returns 'eno-lang-article'
'eno-lang-article' returns 'eno-lang-article'.
'eno_lang_article' returns 'eno_lang_article'.
'eno-lang-article!' raises an exception.
'%eno-lang-article' raises an exception.
'eno lang article' raises an exception.
'enö-läng-ärticle' raises an exception.
'énó-láng-ártíclé' raises an exception.
url
import url from enotype
url('http://www.valid.com') # returns 'http://www.valid.com'
'http://www.valid.com' returns 'http://www.valid.com'.
'https://valid.com' returns 'https://valid.com'.
'https://www.valid.com' returns 'https://www.valid.com'.
'invalid' raises an exception.
'www.invalid' raises an exception.
'www.invalid.com' raises an exception.
'htp://www.invalid.com' raises an exception.
'http:/invalid.com' raises an exception.
'https//invalid.com' raises an exception.
'https://invalid' raises an exception.
Metadata
Release files for enotype 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| enotype-0.3.0.tar.gz | 6.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| enotype-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.2 kB
Release files / enotype-0.3.0.tar.gz
| Download URL | enotype-0.3.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89c92ac0fae0a52aab4ff90a2fe4018fab4d72200bb145f772b83760ffd0bb4d
|
|
BLAKE2b-256 checksum How to use checksums |
1c22c80a7cc4e9563725bf210838327026e1356e87c22b07da57f336b27495d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
|
Release files / enotype-0.3.0-py3-none-any.whl
| Download URL | enotype-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc383cfff975d271fe39827502bc3874612d12cca3869dc2e99b61e1783b9970
|
|
BLAKE2b-256 checksum How to use checksums |
4b3a388c5e2aff9454e3b66247aa8258c85d2cf691e069b01bcc88c1ad617f84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
|
Security for enotype 0.3.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.