Changeset View
Changeset View
Standalone View
Standalone View
tools/libtpcodegen.py
Show All 14 Lines | |||||
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | # Lesser General Public License for more details. | 17 | # Lesser General Public License for more details. | ||
18 | # | 18 | # | ||
19 | # You should have received a copy of the GNU Lesser General Public | 19 | # You should have received a copy of the GNU Lesser General Public | ||
20 | # License along with this library; if not, write to the Free Software | 20 | # License along with this library; if not, write to the Free Software | ||
21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | 22 | | |||
23 | 23 | import os | |||
24 | import sys | ||||
24 | from string import ascii_letters, digits | 25 | from string import ascii_letters, digits | ||
25 | 26 | | |||
26 | 27 | | |||
27 | NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" | 28 | NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" | ||
28 | 29 | | |||
29 | _ASCII_ALNUM = ascii_letters + digits | 30 | _ASCII_ALNUM = ascii_letters + digits | ||
30 | 31 | | |||
32 | if sys.version_info[0] >= 3: | ||||
33 | def u(s): | ||||
34 | """Return s, which must be a str literal with no non-ASCII characters. | ||||
35 | This is like a more restricted form of the Python 2 u'' syntax. | ||||
36 | """ | ||||
37 | return s.encode('ascii').decode('ascii') | ||||
38 | else: | ||||
39 | def u(s): | ||||
40 | """Return a Unicode version of s, which must be a str literal | ||||
41 | (a bytestring) in which each byte is an ASCII character. | ||||
42 | This is like a more restricted form of the u'' syntax. | ||||
43 | """ | ||||
44 | return s.decode('ascii') | ||||
45 | | ||||
46 | def file_set_contents(filename, contents): | ||||
47 | try: | ||||
48 | os.remove(filename) | ||||
49 | except OSError: | ||||
50 | pass | ||||
51 | try: | ||||
52 | os.remove(filename + '.tmp') | ||||
53 | except OSError: | ||||
54 | pass | ||||
55 | | ||||
56 | open(filename + '.tmp', 'wb').write(contents) | ||||
57 | os.rename(filename + '.tmp', filename) | ||||
31 | 58 | | |||
32 | def cmp_by_name(node1, node2): | 59 | def cmp_by_name(node1, node2): | ||
33 | return cmp(node1.getAttributeNode("name").nodeValue, | 60 | return cmp(node1.getAttributeNode("name").nodeValue, | ||
34 | node2.getAttributeNode("name").nodeValue) | 61 | node2.getAttributeNode("name").nodeValue) | ||
35 | 62 | | |||
63 | def key_by_name(node): | ||||
64 | return node.getAttributeNode("name").nodeValue | ||||
36 | 65 | | |||
37 | def escape_as_identifier(identifier): | 66 | def escape_as_identifier(identifier): | ||
38 | """Escape the given string to be a valid D-Bus object path or service | 67 | """Escape the given string to be a valid D-Bus object path or service | ||
39 | name component, using a reversible encoding to ensure uniqueness. | 68 | name component, using a reversible encoding to ensure uniqueness. | ||
40 | 69 | | |||
41 | The reversible encoding is as follows: | 70 | The reversible encoding is as follows: | ||
42 | 71 | | |||
43 | * The empty string becomes '_' | 72 | * The empty string becomes '_' | ||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 179 | class _SignatureIter: | |||
151 | """Iterator over a D-Bus signature. Copied from dbus-python 0.71 so we | 180 | """Iterator over a D-Bus signature. Copied from dbus-python 0.71 so we | ||
152 | can run genginterface in a limited environment with only Python | 181 | can run genginterface in a limited environment with only Python | ||
153 | (like Scratchbox). | 182 | (like Scratchbox). | ||
154 | """ | 183 | """ | ||
155 | def __init__(self, string): | 184 | def __init__(self, string): | ||
156 | self.remaining = string | 185 | self.remaining = string | ||
157 | 186 | | |||
158 | def next(self): | 187 | def next(self): | ||
188 | return self.__next__() | ||||
189 | | ||||
190 | def __next__(self): | ||||
159 | if self.remaining == '': | 191 | if self.remaining == '': | ||
160 | raise StopIteration | 192 | raise StopIteration | ||
161 | 193 | | |||
162 | signature = self.remaining | 194 | signature = self.remaining | ||
163 | block_depth = 0 | 195 | block_depth = 0 | ||
164 | block_type = None | 196 | block_type = None | ||
165 | end = len(signature) | 197 | end = len(signature) | ||
166 | 198 | | |||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |