Coder Social home page Coder Social logo

toml's Introduction

TOML

image

image

image

A Python library for parsing and creating TOML.

The module passes the TOML test suite.

See also:

Installation

To install the latest release on PyPI, simply run:

pip install toml

Or to install the latest development version, run:

git clone https://github.com/uiri/toml.git
cd toml
python setup.py install

Quick Tutorial

toml.loads takes in a string containing standard TOML-formatted data and returns a dictionary containing the parsed data.

>>> import toml
>>> toml_string = """
... # This is a TOML document.
...
... title = "TOML Example"
...
... [owner]
... name = "Tom Preston-Werner"
... dob = 1979-05-27T07:32:00-08:00 # First class dates
...
... [database]
... server = "192.168.1.1"
... ports = [ 8001, 8001, 8002 ]
... connection_max = 5000
... enabled = true
...
... [servers]
...
...   # Indentation (tabs and/or spaces) is allowed but not required
...   [servers.alpha]
...   ip = "10.0.0.1"
...   dc = "eqdc10"
...
...   [servers.beta]
...   ip = "10.0.0.2"
...   dc = "eqdc10"
...
... [clients]
... data = [ ["gamma", "delta"], [1, 2] ]
...
... # Line breaks are OK when inside arrays
... hosts = [
...   "alpha",
...   "omega"
... ]
... """
>>> parsed_toml = toml.loads(toml_string)

toml.dumps takes a dictionary and returns a string containing the corresponding TOML-formatted data.

>>> new_toml_string = toml.dumps(parsed_toml)
>>> print(new_toml_string)
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002,]
connection_max = 5000
enabled = true
[clients]
data = [ [ "gamma", "delta",], [ 1, 2,],]
hosts = [ "alpha", "omega",]
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"

toml.dump takes a dictionary and a file descriptor and returns a string containing the corresponding TOML-formatted data.

>>> with open('new_toml_file.toml', 'w') as f:
...     new_toml_string = toml.dump(parsed_toml, f)
>>> print(new_toml_string)
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002,]
connection_max = 5000
enabled = true
[clients]
data = [ [ "gamma", "delta",], [ 1, 2,],]
hosts = [ "alpha", "omega",]
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"

For more functions, view the API Reference below.

Note

For Numpy users, by default the data types np.floatX will not be translated to floats by toml, but will instead be encoded as strings. To get around this, specify the TomlNumpyEncoder when saving your data.

>>> import toml
>>> import numpy as np
>>> a = np.arange(0, 10, dtype=np.double)
>>> output = {'a': a}
>>> toml.dumps(output)
'a = [ "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0",]\n'
>>> toml.dumps(output, encoder=toml.TomlNumpyEncoder())
'a = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,]\n'

API Reference

toml.load(f, _dict=dict)

Parse a file or a list of files as TOML and return a dictionary.

Args
  • f: A path to a file, list of filepaths (to be read into single object) or a file descriptor
  • _dict: The class of the dictionary object to be returned
Returns

A dictionary (or object _dict) containing parsed TOML data

Raises
  • TypeError: When f is an invalid type or is a list containing invalid types
  • TomlDecodeError: When an error occurs while decoding the file(s)
toml.loads(s, _dict=dict)

Parse a TOML-formatted string to a dictionary.

Args
  • s: The TOML-formatted string to be parsed
  • _dict: Specifies the class of the returned toml dictionary
Returns

A dictionary (or object _dict) containing parsed TOML data

Raises
  • TypeError: When a non-string object is passed
  • TomlDecodeError: When an error occurs while decoding the TOML-formatted string
toml.dump(o, f, encoder=None)

Write a dictionary to a file containing TOML-formatted data

Args
  • o: An object to be converted into TOML
  • f: A File descriptor where the TOML-formatted output should be stored
  • encoder: An instance of TomlEncoder (or subclass) for encoding the object. If None, will default to TomlEncoder
Returns

A string containing the TOML-formatted data corresponding to object o

Raises
  • TypeError: When anything other than file descriptor is passed
toml.dumps(o, encoder=None)

Create a TOML-formatted string from an input object

Args
  • o: An object to be converted into TOML
  • encoder: An instance of TomlEncoder (or subclass) for encoding the object. If None, will default to TomlEncoder
Returns

A string containing the TOML-formatted data corresponding to object o

Licensing

This project is released under the terms of the MIT Open Source License. View LICENSE.txt for more information.

toml's People

Contributors

abrahammurciano avatar abred avatar arp242 avatar bobotig avatar huangsam avatar jdufresne avatar jenselme avatar jpsca avatar jsancio avatar kosukemizuno avatar mgorny avatar mottosso avatar mraspberry avatar nateprewitt avatar nicoe avatar niklasrosenstein avatar nikolas avatar pearcedavis avatar prajwalm2212 avatar progval avatar ryanhiebert avatar samvasko avatar seifertm avatar sivel avatar tharvik avatar thombashi avatar uiri avatar warchant avatar x10an14 avatar zed 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  avatar  avatar  avatar  avatar  avatar

toml's Issues

floats with exponents outputted with leading 0s

Floats with exponents with leading 0s (such as 1e-05) are outputted with the leading 0 still attached, which is apparently not allowed under a strict interpretation of the toml spec. Float exponent fields are int fields, which are not allowed to have leading 0s.

The problem comes from other toml parsers which take this (too?) seriously (for instance https://github.com/alexcrichton/toml-rs) and fail to load output generated by this lib

Is there any easy way to override the default formatting for a certain type?

Exception with keys with embedded ='s in string

The following toml:

[foo]
"checksum browserhtml 0.1.15 (git+https://github.com/browserhtml/browserhtml?branch=gh-pages)" = "<none>"

raises the following exception when parsed with toml.py:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "toml.py", line 298, in loads
    if load_date(pair[-1]) != None:
  File "toml.py", line 350, in load_date
    tz = TomlTz(val[19:24])
  File "toml.py", line 9, in __new__
    self._hours = int(toml_offset[:3])

To reproduce:

import toml
toml.loads("[foo]\n\"checksum browserhtml 0.1.15 (git+https://github.com/browserhtml/browserhtml?branch=gh-pages)\" = \"<none>\"\n")

Newline handling issue

It seems the toml parser has issues with "carriage return + newline style" newlines

import toml
toml.loads('broken = "no"\n\n')

Works fine

import toml
toml.loads('broken = "yes"\r\n\r\n')

Gives us a traceback

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/techdragon/.pyenv/versions/test/lib/python3.4/site-packages/toml.py", line 55, in loads
    raise Exception("Key name found without value. Reached end of line.")
Exception: Key name found without value. Reached end of line.

The most simple test case being.

import toml
toml.loads('')

{}

import toml
toml.loads('\n')

{}

import toml
toml.loads('\r\n')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/techdragon/.pyenv/versions/test/lib/python3.4/site-packages/toml.py", line 55, in loads
    raise Exception("Key name found without value. Reached end of line.")
Exception: Key name found without value. Reached end of line.

inline tables do not parse

In the example file example-v0.4.0.toml

The following TOML snippet that contains in-line tables throws an error when trying to load:

name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }

The error is:

File "C:\Python27\lib\site-packages\toml.py", line 331, in loads
value, vtype = load_value(pair[1])
File "C:\Python27\lib\site-packages\toml.py", line 453, in load_value
parsed_date = load_date(v)
File "C:\Python27\lib\site-packages\toml.py", line 350, in load_date
tz = TomlTz(val[19:24])
File "C:\Python27\lib\site-packages\toml.py", line 9, in new
self._hours = int(toml_offset[:3])
ValueError: invalid literal for int() with base 10: 'st '

inline table error

hello, i parse toml with this is ok:

toml.loads("""name= { first = "Tom", last = "Preston-Werner" }""")

however when i delete the whitespace after equal sign, it break:

toml.loads("""name={ first = "Tom", last = "Preston-Werner" }""")

with exception:

TomlDecodeError                           Traceback (most recent call last)
<ipython-input-29-46de2853da46> in <module>()
----> 1 toml.loads("""name={ first = "Tom", last = "Preston-Werner" }""")

/Users/luke0922/.virtualenvs/test/lib/python2.7/site-packages/toml.pyc in loads(s, _dict)
    284             _load_inline_object(line, currentlevel, multikey, multibackslash)
    285         elif "=" in line:
--> 286             ret = _load_line(line, currentlevel, multikey, multibackslash)
    287             if ret is not None:
    288                 multikey, multilinestr, multibackslash = ret

/Users/luke0922/.virtualenvs/test/lib/python2.7/site-packages/toml.pyc in _load_line(line, currentlevel, multikey, multibackslash)
    351         multikey = pair[0]
    352     else:
--> 353         value, vtype = _load_value(pair[1])
    354     try:
    355         currentlevel[pair[0]]

/Users/luke0922/.virtualenvs/test/lib/python2.7/site-packages/toml.pyc in _load_value(v)
    461                 if not oddbackslash:
    462                     if closed:
--> 463                         raise TomlDecodeError("Stuff after closed string. WTF?")
    464                     else:
    465                         closed = True

TomlDecodeError: Stuff after closed string. WTF?

my enviroment is:

  • python 2.7.11
  • toml==0.9.2

Option to load many config files

I like from Python ConfigParser option to load many config files:

from ConfigParser import SafeConfigParser

parser = SafeConfigParser()

parser.read(['does_not_exist.ini', 'config.ini', 'config_dev.ini', ])

print 'Log level:', parser.get('logging', 'log_level')
print 'Prefix:', parser.get('logging', 'prefix')

if 'config.ini:

[logging]
log_level = info
prefix = 'my_prefix'

and config_dev.ini:

[logging]
log_level = debug

Output would be:

Log level: debug
Prefix: "my_prefix"

If I remove config_dev.ini, output will be:

Log level: info
Prefix: "my_prefix"

ConfigParser overwrites the keys with each successive file, the order in which the files are read is determined by the order of the file names in the list passed to ConfigParser.read

Docs: http://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser.read

If files not exists instead of throwing error:

If none of the named files exist, the ConfigParser instance will contain an empty dataset.

From http://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser.read

Would be nice if you could add something similar.

Best regards,
Dobrosล‚aw ลปybort

P.S. Now, to merge multi-level dicts, I need to use http://stackoverflow.com/a/10704003/1722542

unicode support for loads

I meat exception when I deal with unicode string :

Exception("What exactly are you trying to pull?")

How about changing toml.py#L8 to

if isinstance(s, basestring):

Hangs when parsing "x=1_2"

toml-0.8.2 hangs on either of these lines:

toml.loads("x=1_2")
toml.loads("x=2015-01-01T12:30:30") # no 'Z' at the end
toml.loads("x=2015-01-01_12:30:30Z")

Inline table support

When I try to parse a file that contains an inline table (as defined by toml 0.4, the parser crashes. For intance, with:

origins_to_ranks = {nomderue = 20, communes = 10}

I get.

  File "/home/jenselme/Stage3A/geo-api3/chsdi/tests/functional/test_sphinx.py", line 26, in test_sphinx_api_query
    config = toml.load(config_file)
  File "/home/jenselme/Stage3A/geo-api3/.venv/lib/python3.4/site-packages/toml.py", line 43, in load
    return loads(f.read(), _dict)
  File "/home/jenselme/Stage3A/geo-api3/.venv/lib/python3.4/site-packages/toml.py", line 331, in loads
    value, vtype = load_value(pair[1])
  File "/home/jenselme/Stage3A/geo-api3/.venv/lib/python3.4/site-packages/toml.py", line 453, in load_value
    parsed_date = load_date(v)
  File "/home/jenselme/Stage3A/geo-api3/.venv/lib/python3.4/site-packages/toml.py", line 350, in load_date
    tz = TomlTz(val[19:24])
  File "/home/jenselme/Stage3A/geo-api3/.venv/lib/python3.4/site-packages/toml.py", line 9, in __new__
    self._hours = int(toml_offset[:3])
ValueError: invalid literal for int() with base 10: 'omm'

Can you add support for this syntax please?

datetime-malformed-no-z fails

$ toml-test -testdir ~/src/toml-test/tests ./toml_test3.py
Test: datetime-malformed-no-z (invalid)

Expected an error, but no error was reported.

77 passed, 1 failed

OrderedDict to dumps

Any chance of toml.dumps getting the ability to dump out the toml file in the set order when passing in an OrderedDict? Not sure how hard it would be to implementโ€ฆ

Cant parse toml 0.3.1 language example

toml_string = """# This is a TOML document. Boom.

title = "TOML Example"

[owner]
name = "Lance Uppercut"
dob = 1979-05-27T07:32:00-08:00 # First class dates? Why not?

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

  # You can indent as you please. Tabs or spaces. TOML don't care.
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

  [servers.beta]
  ip = "10.0.0.2"
  dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

# Line breaks are OK when inside arrays
hosts = [
  "alpha",
  "omega"
]"""
import toml
toml.loads(toml_string)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/techdragon/.pyenv/versions/test/lib/python3.4/site-packages/toml.py", line 283, in loads
    value, vtype = load_value(pair[1])
  File "/Users/techdragon/.pyenv/versions/test/lib/python3.4/site-packages/toml.py", line 431, in load_value
    v = int(v)
ValueError: invalid literal for int() with base 10: '1979-05-27T07:32:00-08:00'

Indentation and whitespaces are being stripped away in multiline strings

Hi,

the current implementation of the parser strips away whitespace from all lines using strip().
To reproduce use this snippet:

import toml

t = '''
foo = """
test
  test
  test2
test3
    test5
    test6
test7
"""
'''

p = toml.loads(t)
print p["foo"]

Acutal Output

test
test
test2
test3
test5
test6
test7

Expected Output

test
  test
  test2
test3
    test5
    test6
test7

This violates the toml spec (see https://github.com/toml-lang/toml#string)

Multi-line basic strings are surrounded by three quotation marks on each side and allow newlines. A newline immediately following the opening delimiter will be trimmed. All other whitespace and newline characters remain intact.

furthermore

A newline immediately following the opening delimiter will be trimmed. All other content between the delimiters is interpreted as-is without modification.

dict does not have "append".

pylint reports:

************* Module toml E: 37,12: Instance of 'dict' has no 'append' member (but some types could not be inferred) (maybe-no-member)

It appears a clear bug in that line.

Another newline issue

>>> import toml
>>> x = toml.dumps({'a': 'b\n\n\nc'})
>>> x
'a = "b\\n\\n\\nc"\n'
>>> toml.loads(x)
{'a': 'b\n\\n\nc'}

Loading the dumped object with multiple consecutive newlines does not equal the original object

cannot round-trip key with odd characters

Trying to write some toml.

[section]
":sys_platform==\"win32\"" = ["sdl2_lib"]

I had several problems. First, had to quote the key (fair enough), second, when quoted incorrectly the toml parser thought the == separated the key and value, third, it wanted to parse "sdl2_lib" as a number or possibly a date.

Please let me know if this is a bug with uiri/toml or if I'm just writing it wrong. Thanks.

Escaping the backslash

According to the toml spec, it should be possible to escape the backslash with \\, but it doesn't seem to work at all.

>>> toml.loads('a = "\\"\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/toml.py", line 80, in loads
    raise Exception("Unbalanced quotes")
Exception: Unbalanced quotes

>>> toml.loads('a = "\\ "\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/toml.py", line 169, in loads
    value, vtype = load_value(pair[1])
  File "/usr/local/lib/python2.7/site-packages/toml.py", line 202, in load_value
    raise Exception("Reserved escape sequence used")
Exception: Reserved escape sequence used

>>> toml.loads('a = "\\bar"\n')
{'a': '\x08ar'}

Very small or large floats?

Try this:

s = toml.dumps({'a':1e-24})
print(s)
toml.loads(s)

Result (python 3.3, toml 0.8.1):

a = 1e-24
...
ValueError: invalid literal for int() with base 10: '1e-24'

As far as I can tell, there is no specification for using exponent notation in a float in the TOML spec. Perhaps that should be fixed? Or do you have to use a = 0.000000000000000000000001 to specify 10^-24?

Emitting: blank line between tables

print(toml.dumps({'foo':{'a':1}, 'bar': {'b': 2}}))

Gives:

[foo]
a = 1
[bar]
b = 2

That's valid, but I think it's more readable with a blank line between tables (i.e. just before [bar]). The examples are generally written with blank lines between tables.

escaping forward slashes

when i serialize paths (loaded from a toml file) with this library they end up getting escaped to this form.
dir = "/opt/influxdb/shared/data/db"

Comma in string

Part of my file is

[plot]
title = [
"Client: XXXX, Job: XXXX",
"Code: XXXX"
]

when parsed gives the error
ValueError: invalid literal for int() with base 10: 'Job XXXX"'

C:\Anaconda>pip show toml

Name: toml
Version: 0.8.1
Location: c:\anaconda\lib\site-packages
Requires:

The comma in the first string of the array causes a parsing error, it is expecting that the Job part be an integer.

Hash arrays inserted in reverse order

The TOML 0.2.0 spec says "The tables are inserted in the order encountered."

However, if I make test.toml:

[[foo]]
N = 1

[[foo]]
N = 2

[[foo]]
N = 3

It parses as {'foo': [{'N': 3}, {'N': 2}, {'N': 1}]}.

Failure to parse long float

Hi!

I'm using version 0.9.1 from pypi. The following fails:

>>> import toml
>>> toml.loads('x=0.1234567891234567891')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bertik/.local/lib/python2.7/site-packages/toml.py", line 331, in loads
    value, vtype = load_value(pair[1])
  File "/home/bertik/.local/lib/python2.7/site-packages/toml.py", line 453, in load_value
    parsed_date = load_date(v)
  File "/home/bertik/.local/lib/python2.7/site-packages/toml.py", line 350, in load_date
    tz = TomlTz(val[19:24])
  File "/home/bertik/.local/lib/python2.7/site-packages/toml.py", line 10, in __new__
    self._minutes = int(toml_offset[4:6])
ValueError: invalid literal for int() with base 10: ''

It seems that it is trying to parse a long float as a date.

Shorter floats of course work:

>>> toml.loads('x=0.123456789123456789')
{'x': 0.12345678912345678}

Clarify "What exactly are you trying to pull?"

toml/toml.py

Lines 61 to 62 in df2b2df

if not isinstance(s, basestring):
raise TypeError("What exactly are you trying to pull?")

    if not isinstance(s, basestring):
        raise TypeError("What exactly are you trying to pull?")

It's not a very useful error message if you have to dig into the source to figure out what it means. In this case, a bytes was being passed in, which is not permissible in python 3. Better would be to avoid basestring at all, as it is basically nonsense. Check for bytes or unicode and encode or decode appropriately.

Error parsing strings with curly brackets

For this file:

command = ['{text1}', "text2"]

I get

In [17]: toml.load(open('my.toml', 'rt'))
Out[17]: {'command': ['{text1']}

The list has been truncated at the first closing curly bracket.

Underline characters ignored in string values

Using the latest git commit, it seems that underline characters in string values are being ignored:

>>> toml.loads('x="a_b"')
{'x': 'ab'}

I don't think that I'm missing some escape character, because if I start from a valid python string, then dump it into toml format, and then parse it back, the underline characters are still lost:

>>> toml.loads(toml.dumps({'x': 'a_b'}))
{'x': 'ab'}

toml.py, line 379, commit 93236c2

This TomlDecodeError doesn't get properly raised.

I was trying to parse a file with:

[[control]]
in = "data"
out = "data"
  [control.out]
  someSetting = 1.0

And I got this as output instead:
TypeError: string indices must be integers

TOML emitter is wrong?

This seems incorrect:

>>> import toml
>>> m = {'a': {}, 'b': {}}
>>> toml.dumps(m)
''

I would have expected:

[a]

[b]

I'm not super familiar with all the edge cases of the TOML format so perhaps this is expected, but it seems weird to say a Map of Empty Map's becomes equivalent to empty string.

Python 3 compatibility

toml is not compatible with python 3.

There is at least xrange which is not available.

NameError: global name 'xrange' is not defined

Add support for specifiying dict types

ConfigParser takes a dict_type argument (and, in python2.7, defaults to collections.OrderedDict). It would be useful to have the option of specifying an ordered dict when loading TOML files.

New lines in multi-line literal strings trimmed incorrectly

The library is incorrectly parsing/generating code from multi-line literal strings by condensing multiple new lines in the string into a single one.

Example:

EXPECTED:

import toml
toml.loads("a = '''\nhello\nworld\n\n\nbye'''")
{u'a': u'hello\nworld\n\nbye'}

ACTUAL:

import toml
toml.loads("a = '''\nhello\nworld\n\n\nbye'''")
{u'a': u'hello\nworld\nbye'}

We expect two new lines between world and bye, but we get one. According to the specification (emphasis mine):

Multi-line literal strings are surrounded by three single quotes on each side and allow newlines. Like literal strings, there is no escaping whatsoever. A newline immediately following the opening delimiter will be trimmed. All other content between the delimiters is interpreted as-is without modification.

I'll take a look at the code and propose a fix.

Release 0.8.3

You have made many improvements since version 0.8.2. Any plans to release version 0.8.3 in the near future?

Parsing datetime objects doesn't parse their timezone

Setup

[section]
date = 2016-02-24T13:05:09Z

Note the Z on the end: it's saying that this datetime is in Zulu time, or UTC.

Observed behavior

>>> with open('test.toml', 'r') as fp:
...     data = toml.loads(fp.read())
... 
>>> data['section']['date']
datetime.datetime(2016, 2, 24, 13, 5, 9)

Expected behavior

>>> data['section']['date']
datetime.datetime(2016, 2, 24, 13, 5, 9, tzinfo=<UTC>)

Per the TOML spec, it would be fine to return naive objects if no TZ were specified, but in the case that the TZ is in fact specified, I'd like to receive a TZ-aware object.

Tests fail with Burn

I tried to launch your test suite but I get some failures:

Test: datetime-malformed-no-z (invalid)

Expected an error, but no error was reported.
-------------------------------------------------------------------------------
Test: key-special-chars (valid)

Traceback (most recent call last):
  File "/tmp/toml-test/toml_test3.py", line 9, in <module>
    tdata = toml.loads(sys.stdin.read())
  File "/usr/lib/python3.4/site-packages/toml.py", line 72, in loads
    raise Exception("Found invalid character in key name: '#'")
Exception: Found invalid character in key name: '#'

-------------------------------------------------------------------------------
Test: key-with-pound (valid)

Traceback (most recent call last):
  File "/tmp/toml-test/toml_test3.py", line 9, in <module>
    tdata = toml.loads(sys.stdin.read())
  File "/usr/lib/python3.4/site-packages/toml.py", line 72, in loads
    raise Exception("Found invalid character in key name: '#'")
Exception: Found invalid character in key name: '#'

-------------------------------------------------------------------------------
Test: string-escapes (valid)

Traceback (most recent call last):
  File "/tmp/toml-test/toml_test3.py", line 9, in <module>
    tdata = toml.loads(sys.stdin.read())
  File "/usr/lib/python3.4/site-packages/toml.py", line 300, in loads
    value, vtype = load_value(pair[1])
  File "/usr/lib/python3.4/site-packages/toml.py", line 402, in load_value
    raise Exception("Reserved escape sequence used")
Exception: Reserved escape sequence used


59 passed, 4 failed

Command used: PATH="$PATH:$(pwd)/toml_test3.py" toml-test $(pwd)/toml_test3.py (same problems with toml_test.py.

I used version 0.2.0 of toml-test suite and the lastest from master with version 0.9.0 of your software. If I use the lastest version of your test suite, I get more failures:

Test: datetime-malformed-no-z (invalid)

Expected an error, but no error was reported.
-------------------------------------------------------------------------------
Test: key-space (invalid)

Expected an error, but no error was reported.
-------------------------------------------------------------------------------
Test: table-whitespace (invalid)

Expected an error, but no error was reported.
-------------------------------------------------------------------------------
Test: table-with-pound (invalid)

Expected an error, but no error was reported.
-------------------------------------------------------------------------------
Test: key-space (valid)

Could not find key 'a b' in parser output.
-------------------------------------------------------------------------------
Test: key-special-chars (valid)

Could not find key '~!@$^&*()_+-`1234567890[]|/?><.,;:'' in parser output.
-------------------------------------------------------------------------------
Test: table-whitespace (valid)

Could not find key 'valid key' in parser output.
-------------------------------------------------------------------------------
Test: table-with-pound (valid)

Could not find key 'key#group' in parser output.
-------------------------------------------------------------------------------
Test: unicode-escape (valid)

Traceback (most recent call last):
  File "/tmp/toml-test/toml_test.py", line 53, in <module>
    tdata = toml.loads(sys.stdin.read())
  File "/usr/lib/python2.7/site-packages/toml.py", line 300, in loads
    value, vtype = load_value(pair[1])
  File "/usr/lib/python2.7/site-packages/toml.py", line 402, in load_value
    raise Exception("Reserved escape sequence used")
Exception: Reserved escape sequence used


69 passed, 9 failed

Did I do something wrong? According to http://j.xqz.ca/toml-status, all tests succeeds.

Comma in string

Part of my file is

[plot]
title = [
"Client: XXXX, Job: XXXX",
"Code: XXXX"
]

when parsed gives the error
ValueError: invalid literal for int() with base 10: 'Job XXXX"'

C:\Anaconda>pip show toml
Name: toml
Version: 0.8.1
Location: c:\anaconda\lib\site-packages
Requires:

The comma in the first string of the array causes a parsing error, it is expecting that the Job part be an integer.

Add a license header

Hi,

I am currently packaging this software in fedora. During the review, I was signaled that the main file, toml.py doesn't have a license header. It is non blocking but perceived as a good practice.

Can you add this header? A simple one stating the license would be OK.

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.