From 82b8e4444e00e8ef3c5ce1f5446a8948db803a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Ded=C3=ADk?= Date: Wed, 14 Jul 2021 17:46:31 +0200 Subject: [PATCH] Add support for binary and octal numbers --- neon/__init__.py | 2 +- neon/tokens.py | 10 +--------- tests/test_types.py | 4 ++++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/neon/__init__.py b/neon/__init__.py index b9ddd48..46d8901 100644 --- a/neon/__init__.py +++ b/neon/__init__.py @@ -2,7 +2,7 @@ __author__ = "Pavel Dedik" -__version__ = "0.1.6" +__version__ = "0.1.7" from .decoder import parse diff --git a/neon/tokens.py b/neon/tokens.py index 5985da3..745bc8d 100644 --- a/neon/tokens.py +++ b/neon/tokens.py @@ -3,8 +3,6 @@ from __future__ import unicode_literals -import re - import dateutil.parser from . import errors @@ -15,9 +13,6 @@ #: List of all tokens. TOKENS = [] -#: Pattern for matching hexadecimal numbers. -PATTERN_HEX = re.compile(r"0x[0-9a-fA-F]+") - def token(cls): """Registers a token class.""" @@ -108,10 +103,7 @@ class Integer(Primitive): @classmethod def convert(cls, string): try: - if string.isdigit(): - return int(string) - if PATTERN_HEX.match(string): - return int(string, base=16) + return int(string, 0) except ValueError: return diff --git a/tests/test_types.py b/tests/test_types.py index 666dfda..4cdb911 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -23,6 +23,8 @@ def test_entity(): string: "a () #' text" integer: 5902 hexint: 0xAA +octint: 0o666 +binint: 0b111000111 float: 5.234 floatbig: 5e10 nones: [NULL, null, Null] @@ -36,6 +38,8 @@ def test_types(): "string": "a () #' text", "integer": 5902, "hexint": 0xAA, + "octint": 0o666, + "binint": 0b111000111, "float": 5.234, "floatbig": 5e10, "nones": [None] * 3,