|
1 | | -# -*- coding: utf-8 -*- |
2 | 1 | """ |
3 | 2 | c_annotations.py |
4 | 3 | ~~~~~~~~~~~~~~~~ |
|
34 | 33 |
|
35 | 34 | REST_ROLE_MAP = { |
36 | 35 | 'function': 'func', |
37 | | - 'var': 'data', |
38 | | - 'type': 'type', |
39 | 36 | 'macro': 'macro', |
40 | | - 'type': 'type', |
41 | 37 | 'member': 'member', |
| 38 | + 'type': 'type', |
| 39 | + 'var': 'data', |
42 | 40 | } |
43 | 41 |
|
44 | 42 |
|
@@ -63,15 +61,15 @@ def __init__(self, name): |
63 | 61 | class Annotations: |
64 | 62 | def __init__(self, refcount_filename, stable_abi_file): |
65 | 63 | self.refcount_data = {} |
66 | | - with open(refcount_filename, 'r') as fp: |
| 64 | + with open(refcount_filename, encoding='utf8') as fp: |
67 | 65 | for line in fp: |
68 | 66 | line = line.strip() |
69 | 67 | if line[:1] in ("", "#"): |
70 | 68 | # blank lines and comments |
71 | 69 | continue |
72 | 70 | parts = line.split(":", 4) |
73 | 71 | if len(parts) != 5: |
74 | | - raise ValueError("Wrong field count in %r" % line) |
| 72 | + raise ValueError(f"Wrong field count in {line!r}") |
75 | 73 | function, type, arg, refcount, comment = parts |
76 | 74 | # Get the entry, creating it if needed: |
77 | 75 | try: |
@@ -91,9 +89,8 @@ def __init__(self, refcount_filename, stable_abi_file): |
91 | 89 | entry.result_refs = refcount |
92 | 90 |
|
93 | 91 | self.stable_abi_data = {} |
94 | | - with open(stable_abi_file, 'r') as fp: |
| 92 | + with open(stable_abi_file, encoding='utf8') as fp: |
95 | 93 | for record in csv.DictReader(fp): |
96 | | - role = record['role'] |
97 | 94 | name = record['name'] |
98 | 95 | self.stable_abi_data[name] = record |
99 | 96 |
|
@@ -180,13 +177,17 @@ def add_annotations(self, app, doctree): |
180 | 177 | continue |
181 | 178 | elif not entry.result_type.endswith("Object*"): |
182 | 179 | continue |
| 180 | + classes = ['refcount'] |
183 | 181 | if entry.result_refs is None: |
184 | 182 | rc = sphinx_gettext('Return value: Always NULL.') |
| 183 | + classes.append('return_null') |
185 | 184 | elif entry.result_refs: |
186 | 185 | rc = sphinx_gettext('Return value: New reference.') |
| 186 | + classes.append('return_new_ref') |
187 | 187 | else: |
188 | 188 | rc = sphinx_gettext('Return value: Borrowed reference.') |
189 | | - node.insert(0, nodes.emphasis(rc, rc, classes=['refcount'])) |
| 189 | + classes.append('return_borrowed_ref') |
| 190 | + node.insert(0, nodes.emphasis(rc, rc, classes=classes)) |
190 | 191 |
|
191 | 192 |
|
192 | 193 | def init_annotations(app): |
@@ -228,6 +229,7 @@ def setup(app): |
228 | 229 | 'stableabi': directives.flag, |
229 | 230 | } |
230 | 231 | old_handle_signature = CObject.handle_signature |
| 232 | + |
231 | 233 | def new_handle_signature(self, sig, signode): |
232 | 234 | signode.parent['stableabi'] = 'stableabi' in self.options |
233 | 235 | return old_handle_signature(self, sig, signode) |
|