1.1 --- a/imiptools/data.py Sun Mar 06 19:19:23 2016 +0100
1.2 +++ b/imiptools/data.py Sun Mar 06 19:22:43 2016 +0100
1.3 @@ -617,6 +617,19 @@
1.4
1.5 return None
1.6
1.7 +def parse_string(s, encoding, objtype=None):
1.8 +
1.9 + """
1.10 + Parse the iTIP content from 's' having the given 'encoding'. If 'objtype' is
1.11 + given, only objects of that type will be returned. Otherwise, the root of
1.12 + the content will be returned as a dictionary with a single key indicating
1.13 + the object type.
1.14 +
1.15 + Return None if the content was not readable or suitable.
1.16 + """
1.17 +
1.18 + return parse_object(StringIO(s), encoding, objtype)
1.19 +
1.20 def to_part(method, calendar):
1.21
1.22 """
1.23 @@ -638,6 +651,15 @@
1.24 def to_stream(out, fragment, encoding="utf-8"):
1.25 iterwrite(out, encoding=encoding).append(fragment)
1.26
1.27 +def to_string(fragment, encoding="utf-8"):
1.28 + out = StringIO()
1.29 + try:
1.30 + to_stream(out, fragment, encoding)
1.31 + return out.getvalue()
1.32 +
1.33 + finally:
1.34 + out.close()
1.35 +
1.36 # Structure access functions.
1.37
1.38 def get_items(d, name, all=True):