changeset 158:0a01e8cd26d0 trunk

Minor cleanup in the `pofile` module.
author cmlenz
date Thu, 21 Jun 2007 12:10:59 +0000
parents 22bc386e2bc3
children 23005b4efc99
files babel/messages/pofile.py
diffstat 1 files changed, 51 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -31,7 +31,57 @@
 from babel.messages.catalog import Catalog
 from babel.util import LOCALTZ
 
-__all__ = ['escape', 'normalize', 'read_po', 'write_po']
+__all__ = ['unescape', 'denormalize', 'read_po', 'escape', 'normalize',
+           'write_po']
+
+def unescape(string):
+    r"""Reverse `escape` the given string.
+    
+    >>> print unescape('"Say:\\n  \\"hello, world!\\"\\n"')
+    Say:
+      "hello, world!"
+    <BLANKLINE>
+    
+    :param string: the string to unescape
+    :return: the unescaped string
+    :rtype: `str` or `unicode`
+    """
+    return string[1:-1].replace('\\\\', '\\') \
+                       .replace('\\t', '\t') \
+                       .replace('\\r', '\r') \
+                       .replace('\\n', '\n') \
+                       .replace('\\"', '\"')
+
+def denormalize(string):
+    r"""Reverse the normalization done by the `normalize` function.
+    
+    >>> print denormalize(r'''""
+    ... "Say:\n"
+    ... "  \"hello, world!\"\n"''')
+    Say:
+      "hello, world!"
+    <BLANKLINE>
+    
+    >>> print denormalize(r'''""
+    ... "Say:\n"
+    ... "  \"Lorem ipsum dolor sit "
+    ... "amet, consectetur adipisicing"
+    ... " elit, \"\n"''')
+    Say:
+      "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
+    <BLANKLINE>
+    
+    :param string: the string to denormalize
+    :return: the denormalized string
+    :rtype: `unicode` or `str`
+    """
+    if string.startswith('""'):
+        lines = []
+        for line in string.splitlines()[1:]:
+            lines.append(unescape(line))
+        return ''.join(lines)
+    else:
+        return unescape(string)
 
 def read_po(fileobj):
     """Read messages from a ``gettext`` PO (portable object) file from the given
@@ -172,24 +222,6 @@
                           .replace('\n', '\\n') \
                           .replace('\"', '\\"')
 
-def unescape(string):
-    r"""Reverse escape the given string.
-    
-    >>> print unescape('"Say:\\n  \\"hello, world!\\"\\n"')
-    Say:
-      "hello, world!"
-    <BLANKLINE>
-    
-    :param string: the string to unescape
-    :return: the unescaped string
-    :rtype: `str` or `unicode`
-    """
-    return string[1:-1].replace('\\\\', '\\') \
-                       .replace('\\t', '\t') \
-                       .replace('\\r', '\r') \
-                       .replace('\\n', '\n') \
-                       .replace('\\"', '\"')
-
 def normalize(string, width=76):
     r"""Convert a string into a format that is appropriate for .po files.
     
@@ -250,37 +282,6 @@
         lines[-1] += '\n'
     return u'""\n' + u'\n'.join([escape(l) for l in lines])
 
-def denormalize(string):
-    r"""Reverse the normalization done by the `normalize` function.
-    
-    >>> print denormalize(r'''""
-    ... "Say:\n"
-    ... "  \"hello, world!\"\n"''')
-    Say:
-      "hello, world!"
-    <BLANKLINE>
-    
-    >>> print denormalize(r'''""
-    ... "Say:\n"
-    ... "  \"Lorem ipsum dolor sit "
-    ... "amet, consectetur adipisicing"
-    ... " elit, \"\n"''')
-    Say:
-      "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
-    <BLANKLINE>
-    
-    :param string: the string to denormalize
-    :return: the denormalized string
-    :rtype: `unicode` or `str`
-    """
-    if string.startswith('""'):
-        lines = []
-        for line in string.splitlines()[1:]:
-            lines.append(unescape(line))
-        return ''.join(lines)
-    else:
-        return unescape(string)
-
 def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
              sort_output=False, sort_by_file=False):
     r"""Write a ``gettext`` PO (portable object) template file for a given
Copyright (C) 2012-2017 Edgewall Software