]> git.0d.be Git - empathy.git/blobdiff - tools/libtpcodegen.py
Merge branch 'gnome-3-6'
[empathy.git] / tools / libtpcodegen.py
index 837ff2f745e5e23d4255aee9fb46f72ce8f97efb..99de66340d780e05a0fd887c11df65eff0050423 100644 (file)
@@ -20,7 +20,8 @@ please make any changes there.
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-
+import os
+import sys
 from string import ascii_letters, digits
 
 
@@ -28,11 +29,39 @@ NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
 
 _ASCII_ALNUM = ascii_letters + digits
 
+if sys.version_info[0] >= 3:
+    def u(s):
+        """Return s, which must be a str literal with no non-ASCII characters.
+        This is like a more restricted form of the Python 2 u'' syntax.
+        """
+        return s.encode('ascii').decode('ascii')
+else:
+    def u(s):
+        """Return a Unicode version of s, which must be a str literal
+        (a bytestring) in which each byte is an ASCII character.
+        This is like a more restricted form of the u'' syntax.
+        """
+        return s.decode('ascii')
+
+def file_set_contents(filename, contents):
+    try:
+        os.remove(filename)
+    except OSError:
+        pass
+    try:
+        os.remove(filename + '.tmp')
+    except OSError:
+        pass
+
+    open(filename + '.tmp', 'wb').write(contents)
+    os.rename(filename + '.tmp', filename)
 
 def cmp_by_name(node1, node2):
     return cmp(node1.getAttributeNode("name").nodeValue,
                node2.getAttributeNode("name").nodeValue)
 
+def key_by_name(node):
+    return node.getAttributeNode("name").nodeValue
 
 def escape_as_identifier(identifier):
     """Escape the given string to be a valid D-Bus object path or service
@@ -156,6 +185,9 @@ class _SignatureIter:
         self.remaining = string
 
     def next(self):
+        return self.__next__()
+
+    def __next__(self):
         if self.remaining == '':
             raise StopIteration