Compare two code-objects. This is the main part of this module.
(version, is_pypy, code_obj1, code_obj2, verify, name="")
| 170 | |
| 171 | |
| 172 | def cmp_code_objects(version, is_pypy, code_obj1, code_obj2, verify, name=""): |
| 173 | """ |
| 174 | Compare two code-objects. |
| 175 | |
| 176 | This is the main part of this module. |
| 177 | """ |
| 178 | # print code_obj1, type(code_obj2) |
| 179 | assert iscode( |
| 180 | code_obj1 |
| 181 | ), "cmp_code_object first object type is %s, not code" % type(code_obj1) |
| 182 | assert iscode( |
| 183 | code_obj2 |
| 184 | ), "cmp_code_object second object type is %s, not code" % type(code_obj2) |
| 185 | # print dir(code_obj1) |
| 186 | if isinstance(code_obj1, object): |
| 187 | # new style classes (Python 2.2) |
| 188 | # assume _both_ code objects to be new style classes |
| 189 | assert dir(code_obj1) == dir(code_obj2) |
| 190 | else: |
| 191 | # old style classes |
| 192 | assert dir(code_obj1) == code_obj1.__members__ |
| 193 | assert dir(code_obj2) == code_obj2.__members__ |
| 194 | assert code_obj1.__members__ == code_obj2.__members__ |
| 195 | |
| 196 | if name == "__main__": |
| 197 | name = code_obj1.co_name |
| 198 | else: |
| 199 | name = "%s.%s" % (name, code_obj1.co_name) |
| 200 | if name == ".?": |
| 201 | name = "__main__" |
| 202 | |
| 203 | if isinstance(code_obj1, object) and code_equal(code_obj1, code_obj2): |
| 204 | # use the new style code-classes' __cmp__ method, which |
| 205 | # should be faster and more sophisticated |
| 206 | # if this compare fails, we use the old routine to |
| 207 | # find out, what exactly is nor equal |
| 208 | # if this compare succeeds, simply return |
| 209 | # return |
| 210 | pass |
| 211 | |
| 212 | if isinstance(code_obj1, object): |
| 213 | members = [x for x in dir(code_obj1) if x.startswith("co_")] |
| 214 | else: |
| 215 | members = dir(code_obj1) |
| 216 | members.sort() # ; members.reverse() |
| 217 | |
| 218 | tokens1 = None |
| 219 | for member in members: |
| 220 | if member in __IGNORE_CODE_MEMBERS__ or verify != "verify": |
| 221 | pass |
| 222 | elif member == "co_code": |
| 223 | if verify != "strong": |
| 224 | continue |
| 225 | scanner = get_scanner(version, is_pypy, show_asm=False) |
| 226 | |
| 227 | global JUMP_OPS |
| 228 | JUMP_OPS = list(JUMP_OPS) + ["JUMP_BACK"] |
| 229 |
no test coverage detected