Skip to content

Commit

Permalink
Merge pull request #1 from untitaker/master
Browse files Browse the repository at this point in the history
Use ordereddict from PyPI for Python < 2.7
  • Loading branch information
beygi committed Mar 2, 2013
2 parents 60e9c85 + 413668e commit edf1951
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from distutils.core import setup
from sys import version_info

with open("README.md") as readmefile:
readme = readmefile.read()

dependencies = []

if version_info < (2, 7):
dependencies.append('ordereddict')

setup(name='toml',
version='0.6.5',
description="Python Library for Tom's Obvious, Minimal Language",
Expand All @@ -11,4 +18,5 @@
py_modules=['toml'],
license="License :: OSI Approved :: MIT License",
long_description=readme,
requires=dependencies
)
14 changes: 9 additions & 5 deletions toml.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import datetime
import collections

try:
from collections import OrderedDict
except ImportError: # Python < 2.7
from ordereddict import OrderedDict

def parse(s):
retval = collections.OrderedDict()
retval = OrderedDict()
currentlevel = retval
if isinstance(s, str):
sl = list(s)
Expand Down Expand Up @@ -43,7 +47,7 @@ def parse(s):
if i == len(groups) - 1:
raise Exception("What? "+group+" already exists?"+str(currentlevel))
except KeyError:
currentlevel[group] = collections.OrderedDict()
currentlevel[group] = OrderedDict()
currentlevel = currentlevel[group]
elif "=" in line:
pair = line.split('=', 1)
Expand Down Expand Up @@ -108,7 +112,7 @@ def emit(o):
addtoretval, sections = emit_sections(o)
retval += addtoretval
while sections != {}:
newsections = collections.OrderedDict()
newsections = OrderedDict()
for section in sections:
addtoretval, addtosections = emit_sections(sections[section])
if addtoretval:
Expand All @@ -121,7 +125,7 @@ def emit(o):

def emit_sections(o):
retstr = ""
retdict = collections.OrderedDict()
retdict = OrderedDict()
for section in o:
if not isinstance(o[section], dict):
retstr += section + " = " + str(emit_value(o[section])) + '\n'
Expand Down

0 comments on commit edf1951

Please sign in to comment.