Skip to content

Instantly share code, notes, and snippets.

@andrewshadura
Created August 27, 2015 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewshadura/bc31eac7209994987d6a to your computer and use it in GitHub Desktop.
Save andrewshadura/bc31eac7209994987d6a to your computer and use it in GitHub Desktop.
From 47946d0a8a68a8e260c9a44e8b2ab448b86f946e Mon Sep 17 00:00:00 2001
From: Andrew Shadura <andrew@shadura.me>
Date: Thu, 27 Aug 2015 18:59:12 +0200
Subject: Add Python3 compatibility
diff --git a/reconfigure/parsers/iniparse/config.py b/reconfigure/parsers/iniparse/config.py
index d007f16..cc37ac4 100644
--- a/reconfigure/parsers/iniparse/config.py
+++ b/reconfigure/parsers/iniparse/config.py
@@ -143,7 +143,7 @@ class BasicConfig(ConfigNamespace):
>>> n.aaa = 42
>>> del n.x
- >>> print n
+ >>> print(n)
aaa = 42
name.first = paramjit
name.last = oberoi
@@ -152,7 +152,7 @@ class BasicConfig(ConfigNamespace):
>>> isinstance(n.name, ConfigNamespace)
True
- >>> print n.name
+ >>> print(n.name)
first = paramjit
last = oberoi
>>> sorted(list(n.name))
@@ -160,8 +160,8 @@ class BasicConfig(ConfigNamespace):
Finally, values can be read from a file as follows:
- >>> from StringIO import StringIO
- >>> sio = StringIO('''
+ >>> from io import StringIO
+ >>> sio = StringIO(u'''
... # comment
... ui.height = 100
... ui.width = 150
@@ -171,7 +171,7 @@ class BasicConfig(ConfigNamespace):
... ''')
>>> n = BasicConfig()
>>> n._readfp(sio)
- >>> print n
+ >>> print(n)
complexity = medium
data.secret.password = goodness=gracious me
have_python
@@ -199,7 +199,7 @@ class BasicConfig(ConfigNamespace):
def __str__(self, prefix=''):
lines = []
- keys = self._data.keys()
+ keys = list(self._data.keys())
keys.sort()
for name in keys:
value = self._data[name]
@@ -258,7 +258,7 @@ def update_config(target, source):
>>> n.ui.display_clock = True
>>> n.ui.display_qlength = True
>>> n.ui.width = 150
- >>> print n
+ >>> print(n)
playlist.expand_playlist = True
ui.display_clock = True
ui.display_qlength = True
@@ -267,7 +267,7 @@ def update_config(target, source):
>>> from iniparse import ini
>>> i = ini.INIConfig()
>>> update_config(i, n)
- >>> print i
+ >>> print(i)
[playlist]
expand_playlist = True
<BLANKLINE>
@@ -277,7 +277,7 @@ def update_config(target, source):
width = 150
"""
- for name in source:
+ for name in sorted(source):
value = source[name]
if isinstance(value, ConfigNamespace):
if name in target:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment