summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-15 13:52:33 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-15 17:01:06 +0000
commit2cc11a34cf32eeeba34ddd38dc901cc15bdffb64 (patch)
treee6b21dfcb09f6b1f39177a9a6f450829d647fb42 /morphlib
parent555c581ff4f75aea2ab21bb4a9ff7d9838a5ea9f (diff)
downloadmorph-2cc11a34cf32eeeba34ddd38dc901cc15bdffb64.tar.gz
Drop use of explicit StringIO with the yaml module
It turns out the yaml module can handle strings directly, and does not need explicit file handles. Suggested by Richard Maw.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/morphloader.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py
index 843c6957..5b2c1063 100644
--- a/morphlib/morphloader.py
+++ b/morphlib/morphloader.py
@@ -17,7 +17,6 @@
import logging
-import StringIO
import yaml
import morphlib
@@ -162,7 +161,7 @@ class MorphologyLoader(object):
'''
try:
- obj = yaml.safe_load(StringIO.StringIO(string))
+ obj = yaml.safe_load(string)
except yaml.error.YAMLError as e:
logging.error('Could not load morphology as YAML:\n%s' % str(e))
raise MorphologySyntaxError(whence)
@@ -199,9 +198,7 @@ class MorphologyLoader(object):
def save_to_string(self, morphology):
'''Return normalised textual form of morphology.'''
- f = StringIO.StringIO()
- yaml.safe_dump(morphology.data, stream=f, default_flow_style=False)
- return f.getvalue()
+ return yaml.safe_dump(morphology.data, default_flow_style=False)
def save_to_file(self, filename, morphology):
'''Save a morphology object to a named file.'''