src/eric7/DebugClients/Python/DebugVariables.py

branch
eric7-maintenance
changeset 10460
3b34efa2857c
parent 10439
21c28b0f9e41
child 11090
f5f5f5803935
equal deleted inserted replaced
10366:411df92e881f 10460:3b34efa2857c
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2016 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2016 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing classes and functions to dump variable contents. 7 Module implementing classes and functions to dump variable contents.
8 """ 8 """
36 def resolve(self, var, attribute): 36 def resolve(self, var, attribute):
37 """ 37 """
38 Public method to get an attribute from a variable. 38 Public method to get an attribute from a variable.
39 39
40 @param var variable to extract an attribute or value from 40 @param var variable to extract an attribute or value from
41 @type any 41 @type Any
42 @param attribute name of the attribute to extract 42 @param attribute name of the attribute to extract
43 @type str 43 @type str
44 @return value of the attribute 44 @return value of the attribute
45 @rtype any 45 @rtype Any
46 """ 46 """
47 return getattr(var, attribute, None) 47 return getattr(var, attribute, None)
48 48
49 def getVariableList(self, var): 49 def getVariableList(self, var):
50 """ 50 """
51 Public method to get the attributes of a variable as a list. 51 Public method to get the attributes of a variable as a list.
52 52
53 @param var variable to be converted 53 @param var variable to be converted
54 @type any 54 @type Any
55 @return list containing the variable attributes 55 @return list containing the variable attributes
56 @rtype list 56 @rtype list
57 """ 57 """
58 d = [] 58 d = []
59 for name in dir(var): 59 for name in dir(var):
83 def getVariableList(self, var): 83 def getVariableList(self, var):
84 """ 84 """
85 Public method to get the attributes of a variable as a list. 85 Public method to get the attributes of a variable as a list.
86 86
87 @param var variable to be converted 87 @param var variable to be converted
88 @type any 88 @type Any
89 @yield tuple containing the batch start index and a list 89 @yield tuple containing the batch start index and a list
90 containing the variable attributes 90 containing the variable attributes
91 @ytype tuple of (int, list) 91 @ytype tuple of (int, list)
92 """ 92 """
93 d = super().getVariableList(var) 93 d = super().getVariableList(var)
114 @param var variable to extract an attribute or value from 114 @param var variable to extract an attribute or value from
115 @type dict 115 @type dict
116 @param attribute name of the attribute to extract 116 @param attribute name of the attribute to extract
117 @type str 117 @type str
118 @return value of the attribute 118 @return value of the attribute
119 @rtype any 119 @rtype Any
120 """ 120 """
121 if " (ID:" not in attribute: 121 if " (ID:" not in attribute:
122 try: 122 try:
123 return var[attribute] 123 return var[attribute]
124 except Exception: 124 except Exception:
134 def keyToStr(self, key): 134 def keyToStr(self, key):
135 """ 135 """
136 Public method to get a string representation for a key. 136 Public method to get a string representation for a key.
137 137
138 @param key key to be converted 138 @param key key to be converted
139 @type any 139 @type Any
140 @return string representation of the given key 140 @return string representation of the given key
141 @rtype str 141 @rtype str
142 """ 142 """
143 if isinstance(key, str): 143 if isinstance(key, str):
144 key = repr(key) 144 key = repr(key)
152 def getVariableList(self, var): 152 def getVariableList(self, var):
153 """ 153 """
154 Public method to get the attributes of a variable as a list. 154 Public method to get the attributes of a variable as a list.
155 155
156 @param var variable to be converted 156 @param var variable to be converted
157 @type any 157 @type Any
158 @yield tuple containing the batch start index and a list 158 @yield tuple containing the batch start index and a list
159 containing the variable attributes 159 containing the variable attributes
160 @ytype tuple of (int, list) 160 @ytype tuple of (int, list)
161 """ 161 """
162 d = [] 162 d = []
207 @param var variable to extract an attribute or value from 207 @param var variable to extract an attribute or value from
208 @type tuple or list 208 @type tuple or list
209 @param attribute name of the attribute to extract 209 @param attribute name of the attribute to extract
210 @type str 210 @type str
211 @return value of the attribute 211 @return value of the attribute
212 @rtype any 212 @rtype Any
213 """ 213 """
214 try: 214 try:
215 return var[int(attribute)] 215 return var[int(attribute)]
216 except Exception: 216 except Exception:
217 return getattr(var, str(attribute), None) 217 return getattr(var, str(attribute), None)
219 def getVariableList(self, var): 219 def getVariableList(self, var):
220 """ 220 """
221 Public method to get the attributes of a variable as a list. 221 Public method to get the attributes of a variable as a list.
222 222
223 @param var variable to be converted 223 @param var variable to be converted
224 @type any 224 @type Any
225 @yield tuple containing the batch start index and a list 225 @yield tuple containing the batch start index and a list
226 containing the variable attributes 226 containing the variable attributes
227 @ytype tuple of (int, list) 227 @ytype tuple of (int, list)
228 """ 228 """
229 d = [] 229 d = []
265 @param var variable to extract an attribute or value from 265 @param var variable to extract an attribute or value from
266 @type dict_items, dict_keys or dict_values 266 @type dict_items, dict_keys or dict_values
267 @param attribute id of the value to extract 267 @param attribute id of the value to extract
268 @type str 268 @type str
269 @return value of the attribute 269 @return value of the attribute
270 @rtype any 270 @rtype Any
271 """ 271 """
272 return super().resolve(list(var), attribute) 272 return super().resolve(list(var), attribute)
273 273
274 def getVariableList(self, var): 274 def getVariableList(self, var):
275 """ 275 """
276 Public method to get the attributes of a variable as a list. 276 Public method to get the attributes of a variable as a list.
277 277
278 @param var variable to be converted 278 @param var variable to be converted
279 @type any 279 @type Any
280 @yield tuple containing the batch start index and a list 280 @yield tuple containing the batch start index and a list
281 containing the variable attributes 281 containing the variable attributes
282 @ytype tuple of (int, list) 282 @ytype tuple of (int, list)
283 """ 283 """
284 yield from super().getVariableList(list(var)) 284 yield from super().getVariableList(list(var))
301 @param var variable to extract an attribute or value from 301 @param var variable to extract an attribute or value from
302 @type tuple or list 302 @type tuple or list
303 @param attribute id of the value to extract 303 @param attribute id of the value to extract
304 @type str 304 @type str
305 @return value of the attribute 305 @return value of the attribute
306 @rtype any 306 @rtype Any
307 """ 307 """
308 if attribute.startswith("'ID: "): 308 if attribute.startswith("'ID: "):
309 attribute = attribute.split(None, 1)[1][:-1] 309 attribute = attribute.split(None, 1)[1][:-1]
310 try: 310 try:
311 attribute = int(attribute) 311 attribute = int(attribute)
321 def getVariableList(self, var): 321 def getVariableList(self, var):
322 """ 322 """
323 Public method to get the attributes of a variable as a list. 323 Public method to get the attributes of a variable as a list.
324 324
325 @param var variable to be converted 325 @param var variable to be converted
326 @type any 326 @type Any
327 @yield tuple containing the batch start index and a list 327 @yield tuple containing the batch start index and a list
328 containing the variable attributes 328 containing the variable attributes
329 @ytype tuple of (int, list) 329 @ytype tuple of (int, list)
330 """ 330 """
331 d = [] 331 d = []
381 @param var variable to extract an attribute or value from 381 @param var variable to extract an attribute or value from
382 @type ndarray 382 @type ndarray
383 @param attribute id of the value to extract 383 @param attribute id of the value to extract
384 @type str 384 @type str
385 @return value of the attribute 385 @return value of the attribute
386 @rtype any 386 @rtype Any
387 """ 387 """
388 if attribute == "min": 388 if attribute == "min":
389 if self.__isNumeric(var): 389 if self.__isNumeric(var):
390 return var.min() 390 return var.min()
391 else: 391 else:
413 def getVariableList(self, var): 413 def getVariableList(self, var):
414 """ 414 """
415 Public method to get the attributes of a variable as a list. 415 Public method to get the attributes of a variable as a list.
416 416
417 @param var variable to be converted 417 @param var variable to be converted
418 @type any 418 @type Any
419 @yield tuple containing the batch start index and a list 419 @yield tuple containing the batch start index and a list
420 containing the variable attributes 420 containing the variable attributes
421 @ytype tuple of (int, list) 421 @ytype tuple of (int, list)
422 """ 422 """
423 d = [] 423 d = []
490 @param var variable to extract an attribute or value from 490 @param var variable to extract an attribute or value from
491 @type MultiValueDict 491 @type MultiValueDict
492 @param attribute name of the attribute to extract 492 @param attribute name of the attribute to extract
493 @type str 493 @type str
494 @return value of the attribute 494 @return value of the attribute
495 @rtype any 495 @rtype Any
496 """ 496 """
497 if " (ID:" not in attribute: 497 if " (ID:" not in attribute:
498 try: 498 try:
499 return var[attribute] 499 return var[attribute]
500 except Exception: 500 except Exception:
510 def getVariableList(self, var): 510 def getVariableList(self, var):
511 """ 511 """
512 Public method to get the attributes of a variable as a list. 512 Public method to get the attributes of a variable as a list.
513 513
514 @param var variable to be converted 514 @param var variable to be converted
515 @type any 515 @type Any
516 @yield tuple containing the batch start index and a list 516 @yield tuple containing the batch start index and a list
517 containing the variable attributes 517 containing the variable attributes
518 @ytype tuple of (int, list) 518 @ytype tuple of (int, list)
519 """ 519 """
520 d = [] 520 d = []
521 start = count = 0 521 start = count = 0
522 allKeys = list(var.keys()) 522 allKeys = list(var)
523 try: 523 try:
524 # Fast path: all items from same type 524 # Fast path: all items from same type
525 allKeys.sort() 525 allKeys.sort()
526 except TypeError: 526 except TypeError:
527 # Slow path: only sort items with same type (Py3 only) 527 # Slow path: only sort items with same type (Py3 only)
581 @param var variable to extract an attribute or value from 581 @param var variable to extract an attribute or value from
582 @type array.array 582 @type array.array
583 @param attribute id of the value to extract 583 @param attribute id of the value to extract
584 @type str 584 @type str
585 @return value of the attribute 585 @return value of the attribute
586 @rtype any 586 @rtype Any
587 """ 587 """
588 try: 588 try:
589 return var[int(attribute)] 589 return var[int(attribute)]
590 except Exception: 590 except Exception:
591 return getattr(var, attribute, None) 591 return getattr(var, attribute, None)
595 def getVariableList(self, var): 595 def getVariableList(self, var):
596 """ 596 """
597 Public method to get the attributes of a variable as a list. 597 Public method to get the attributes of a variable as a list.
598 598
599 @param var variable to be converted 599 @param var variable to be converted
600 @type any 600 @type Any
601 @yield tuple containing the batch start index and a list 601 @yield tuple containing the batch start index and a list
602 containing the variable attributes 602 containing the variable attributes
603 @ytype tuple of (int, list) 603 @ytype tuple of (int, list)
604 """ 604 """
605 d = [] 605 d = []
647 @param var variable to extract an attribute or value from 647 @param var variable to extract an attribute or value from
648 @type Qt objects 648 @type Qt objects
649 @param attribute name of the attribute to extract 649 @param attribute name of the attribute to extract
650 @type str 650 @type str
651 @return value of the attribute 651 @return value of the attribute
652 @rtype any 652 @rtype Any
653 """ 653 """
654 if attribute == "internalPointer": 654 if attribute == "internalPointer":
655 return var.internalPointer() 655 return var.internalPointer()
656 656
657 return getattr(var, attribute, None) 657 return getattr(var, attribute, None)
659 def getVariableList(self, var): 659 def getVariableList(self, var):
660 """ 660 """
661 Public method to get the attributes of a variable as a list. 661 Public method to get the attributes of a variable as a list.
662 662
663 @param var variable to be converted 663 @param var variable to be converted
664 @type any 664 @type Any
665 @yield tuple containing the batch start index and a list 665 @yield tuple containing the batch start index and a list
666 containing the variable attributes 666 containing the variable attributes
667 @ytype tuple of (int, list) 667 @ytype tuple of (int, list)
668 """ 668 """
669 d = [] 669 d = []
843 def getResolver(obj): 843 def getResolver(obj):
844 """ 844 """
845 Public method to get the resolver based on the type info of an object. 845 Public method to get the resolver based on the type info of an object.
846 846
847 @param obj object to get resolver for 847 @param obj object to get resolver for
848 @type any 848 @type Any
849 @return resolver 849 @return resolver
850 @rtype BaseResolver 850 @rtype BaseResolver
851 """ 851 """
852 # Between PyQt and PySide the returned type is different (class vs. type) 852 # Between PyQt and PySide the returned type is different (class vs. type)
853 typeStr = str(type(obj)).split(" ", 1)[-1] 853 typeStr = str(type(obj)).split(" ", 1)[-1]

eric ide

mercurial