Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopch authored Aug 24, 2018
2 parents 356e4a6 + f53f98d commit a22a7f5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing to edn\_format #

## Setup ##

1. Make sure you have a working Python installation (2 or 3). You may want to
use a [Virtualenv][] or a similar tool to create an isolated environment.
2. Install `edn_format`’s dependencies: `pip install -r requirements.txt`
3. Install `flake8`: `pip install flake8`

[Virtualenv]: https://virtualenv.pypa.io/en/stable/#virtualenv

## Tests ##

Run unit tests with:

python tests.py

Run a linter over the code with:

flake8 --max-line-length=100 --exclude=parsetab.py tests.py
2 changes: 2 additions & 0 deletions edn_format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from .edn_parse import parse as loads
from .edn_parse import add_tag, remove_tag, TaggedElement
from .edn_dump import dump as dumps
from .exceptions import EDNDecodeError
from .immutable_dict import ImmutableDict
from .immutable_list import ImmutableList

__all__ = (
'ImmutableList',
'EDNDecodeError',
'ImmutableDict',
'Keyword',
'Symbol',
Expand Down
5 changes: 3 additions & 2 deletions edn_format/edn_lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import ply.lex

from .exceptions import EDNDecodeError
from .immutable_dict import ImmutableDict


Expand Down Expand Up @@ -204,7 +205,7 @@ def t_FLOAT(t):
if 'e' in t.value or 'E' in t.value:
matches = re.search('[eE]([+-]?\d+)M?$', t.value)
if matches is None:
raise SyntaxError('Invalid float : {}'.format(t.value))
raise EDNDecodeError('Invalid float : {}'.format(t.value))
e_value = int(matches.group(1))
if t.value.endswith('M'):
ctx = decimal.getcontext()
Expand Down Expand Up @@ -251,7 +252,7 @@ def t_SYMBOL(t):


def t_error(t):
raise SyntaxError(
raise EDNDecodeError(
"Illegal character '{c}' with lexpos {p} in the area of ...{a}...".format(
c=t.value[0], p=t.lexpos, a=t.value[0:100]))

Expand Down
7 changes: 4 additions & 3 deletions edn_format/edn_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pyrfc3339

from .edn_lex import tokens, lex
from .exceptions import EDNDecodeError
from .immutable_dict import ImmutableDict
from .immutable_list import ImmutableList

Expand Down Expand Up @@ -94,7 +95,7 @@ def p_map(p):
"""map : MAP_START expressions MAP_OR_SET_END"""
terms = p[2]
if len(terms) % 2 != 0:
raise SyntaxError('Even number of terms required for map')
raise EDNDecodeError('Even number of terms required for map')
# partition terms in pairs
p[0] = ImmutableDict(dict([terms[i:i + 2] for i in range(0, len(terms), 2)]))

Expand Down Expand Up @@ -145,9 +146,9 @@ def p_expression_tagged_element(p):

def p_error(p):
if p is None:
raise SyntaxError('EOF Reached')
raise EDNDecodeError('EOF Reached')
else:
raise SyntaxError(p)
raise EDNDecodeError(p)


def parse(text, input_encoding='utf-8'):
Expand Down
6 changes: 6 additions & 0 deletions edn_format/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: UTF-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals


class EDNDecodeError(ValueError):
pass
7 changes: 6 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import pytz

from edn_format import edn_lex, edn_parse, \
loads, dumps, Keyword, Symbol, TaggedElement, ImmutableDict, ImmutableList, add_tag
loads, dumps, Keyword, Symbol, TaggedElement, ImmutableDict, ImmutableList, add_tag, \
EDNDecodeError


class ConsoleTest(unittest.TestCase):
Expand Down Expand Up @@ -264,6 +265,10 @@ def test_chars(self):
edn_data = "\\{}".format(ch)
self.assertEqual(ch, loads(edn_data), edn_data)

def test_exceptions(self):
with self.assertRaises(EDNDecodeError):
loads("{")

def test_keyword_keys(self):
unchanged = (
None,
Expand Down

0 comments on commit a22a7f5

Please sign in to comment.