Skip to main content

A cross-language type library

Project description

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 string representations 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.

email

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enotype-0.3.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

enotype-0.3.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file enotype-0.3.0.tar.gz.

File metadata

  • Download URL: enotype-0.3.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for enotype-0.3.0.tar.gz
Algorithm Hash digest
SHA256 89c92ac0fae0a52aab4ff90a2fe4018fab4d72200bb145f772b83760ffd0bb4d
MD5 21044b932c2413a6e0f0e5673aa9a8aa
BLAKE2b-256 1c22c80a7cc4e9563725bf210838327026e1356e87c22b07da57f336b27495d6

See more details on using hashes here.

File details

Details for the file enotype-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: enotype-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for enotype-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc383cfff975d271fe39827502bc3874612d12cca3869dc2e99b61e1783b9970
MD5 498669cf10f73e9cc95c5a02e2eb6f08
BLAKE2b-256 4b3a388c5e2aff9454e3b66247aa8258c85d2cf691e069b01bcc88c1ad617f84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page