# 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
_ASCII_ALNUM = ascii_letters + digits
-
-def camelcase_to_lower(s):
- out ="";
- out += s[0].lower()
- last_upper=False
- if s[0].isupper():
- last_upper=True
- for i in range(1,len(s)):
- if s[i].isupper():
- if last_upper:
- if (i+1) < len(s) and s[i+1].islower():
- out += "_" + s[i].lower()
- else:
- out += s[i].lower()
- else:
- out += "_" + s[i].lower()
- last_upper=True
- else:
- out += s[i]
- last_upper=False
- return out
-
-
-def camelcase_to_upper(s):
- return camelcase_to_lower(s).upper()
-
+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
docstring = ''
return docstring
+def get_deprecated(element):
+ text = []
+ for x in element.childNodes:
+ if hasattr(x, 'data'):
+ text.append(x.data.replace('\n', ' ').strip())
+ else:
+ # This caters for tp:dbus-ref elements, but little else.
+ if x.childNodes and hasattr(x.childNodes[0], 'data'):
+ text.append(x.childNodes[0].data.replace('\n', ' ').strip())
+ return ' '.join(text)
def get_descendant_text(element_or_elements):
if not element_or_elements:
self.remaining = string
def next(self):
+ return self.__next__()
+
+ def __next__(self):
if self.remaining == '':
raise StopIteration