diff --git a/twisted/internet/base.py b/twisted/internet/base.py
index 46e9217..5f10c6c 100644
|
a
|
b
|
|
| 176 | 176 | if self._str is not None: |
| 177 | 177 | return self._str |
| 178 | 178 | if hasattr(self, 'func'): |
| 179 | | # This code should be replaced by a utility function in reflect; |
| 180 | | # see ticket #6066: |
| 181 | | if hasattr(self.func, '__qualname__'): |
| 182 | | func = self.func.__qualname__ |
| 183 | | elif hasattr(self.func, '__name__'): |
| 184 | | func = self.func.func_name |
| 185 | | if hasattr(self.func, 'im_class'): |
| 186 | | func = self.func.im_class.__name__ + '.' + func |
| 187 | | else: |
| 188 | | func = reflect.safe_repr(self.func) |
| | 179 | func = reflect.getFunctionName(self.func) |
| 189 | 180 | else: |
| 190 | 181 | func = None |
| 191 | 182 | |
diff --git a/twisted/internet/task.py b/twisted/internet/task.py
index 6e7b908..11afa17 100644
|
a
|
b
|
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | def __repr__(self): |
| 247 | | if hasattr(self.f, '__qualname__'): |
| 248 | | func = self.f.__qualname__ |
| 249 | | elif hasattr(self.f, '__name__'): |
| 250 | | func = self.f.__name__ |
| 251 | | if hasattr(self.f, 'im_class'): |
| 252 | | func = self.f.im_class.__name__ + '.' + func |
| 253 | | else: |
| 254 | | func = reflect.safe_repr(self.f) |
| 255 | | |
| 256 | 247 | return 'LoopingCall<%r>(%s, *%s, **%s)' % ( |
| 257 | | self.interval, func, reflect.safe_repr(self.a), |
| | 248 | self.interval, reflect.getFunctionName(self.f), reflect.safe_repr(self.a), |
| 258 | 249 | reflect.safe_repr(self.kw)) |
| 259 | 250 | |
| 260 | 251 | |
diff --git a/twisted/python/_reflectpy3.py b/twisted/python/_reflectpy3.py
index c0451e9..04c6856 100644
|
a
|
b
|
|
| 286 | 286 | return '<BROKEN CLASS AT 0x%x>' % unsignedID(c) |
| 287 | 287 | |
| 288 | 288 | |
| | 289 | def getFunctionName(function): |
| | 290 | """ |
| | 291 | Return name of the function passed. |
| | 292 | |
| | 293 | @param funptr: Searched function. |
| | 294 | |
| | 295 | @return: Function name |
| | 296 | """ |
| | 297 | if hasattr( function , '__qualname__'): |
| | 298 | func = function.__qualname__ |
| | 299 | elif hasattr( function, '__name__'): |
| | 300 | func = function.func_name |
| | 301 | if hasattr(function, 'im_class'): |
| | 302 | func = function.im_class.__name__ + '.' + func |
| | 303 | else: |
| | 304 | func = safe_repr(function) |
| | 305 | return func |
| | 306 | |
| | 307 | |
| 289 | 308 | def _safeFormat(formatter, o): |
| 290 | 309 | """ |
| 291 | 310 | Helper function for L{safe_repr} and L{safe_str}. |
diff --git a/twisted/python/reflect.py b/twisted/python/reflect.py
index 541d99f..9c87b1d 100644
|
a
|
b
|
|
| 37 | 37 | addMethodNamesToDict) |
| 38 | 38 | from twisted.python._reflectpy3 import namedModule, namedObject, namedClass |
| 39 | 39 | from twisted.python._reflectpy3 import InvalidName, ModuleNotFound |
| 40 | | from twisted.python._reflectpy3 import ObjectNotFound, namedAny |
| | 40 | from twisted.python._reflectpy3 import ObjectNotFound, namedAny, getFunctionName |
| 41 | 41 | from twisted.python._reflectpy3 import filenameToModuleName |
| 42 | 42 | from twisted.python._reflectpy3 import qual, safe_str, safe_repr |
| 43 | 43 | |
| … |
… |
|
| 249 | 249 | |
| 250 | 250 | deprecatedModuleAttribute( |
| 251 | 251 | Version("Twisted", 12, 1, 0), |
| 252 | | "Summer is a child class of twisted.python.reflect.Accessor which is " |
| | 252 | "Summer is a child class of twisted.python.reflect.Accessor which is " |
| 253 | 253 | "deprecated.", "twisted.python.reflect", "Summer") |
| 254 | 254 | |
| 255 | 255 | def reallySet(self, k,v): |
| … |
… |
|
| 412 | 412 | |
| 413 | 413 | class Soy: |
| 414 | 414 | properties = {\"taste\": \"bland\"} |
| 415 | | |
| | 415 | |
| 416 | 416 | class Plant: |
| 417 | 417 | properties = {\"colour\": \"green\"} |
| 418 | | |
| | 418 | |
| 419 | 419 | class Seaweed(Plant): |
| 420 | 420 | pass |
| 421 | | |
| | 421 | |
| 422 | 422 | class Lunch(Soy, Seaweed): |
| 423 | 423 | properties = {\"vegan\": 1 } |
| 424 | | |
| | 424 | |
| 425 | 425 | dct = {} |
| 426 | | |
| | 426 | |
| 427 | 427 | accumulateClassDict(Lunch, \"properties\", dct) |
| 428 | | |
| | 428 | |
| 429 | 429 | print dct |
| 430 | 430 | |
| 431 | 431 | {\"taste\": \"bland\", \"colour\": \"green\", \"vegan\": 1} |
| … |
… |
|
| 534 | 534 | 'accumulateMethods', |
| 535 | 535 | 'accumulateClassDict', 'accumulateClassList', 'isSame', 'isLike', |
| 536 | 536 | 'modgrep', 'isOfType', 'findInstances', 'objgrep', 'filenameToModuleName', |
| 537 | | 'fullyQualifiedName'] |
| | 537 | 'fullyQualifiedName', 'getFunctionName'] |
diff --git a/twisted/python/test/test_reflectpy3.py b/twisted/python/test/test_reflectpy3.py
index acd8f8d..e942dc4 100644
|
a
|
b
|
|
| 350 | 350 | |
| 351 | 351 | |
| 352 | 352 | |
| | 353 | class GetFunctionNameTestCase(TestCase): |
| | 354 | """ |
| | 355 | Tests for L{getFunctionName}. |
| | 356 | """ |
| | 357 | |
| | 358 | def test_function(self): |
| | 359 | """ |
| | 360 | L{getFunctionName} should return function name passed in the argument. |
| | 361 | """ |
| | 362 | self.assertEqual( |
| | 363 | reflect.getFunctionName(reflect.getFunctionName), |
| | 364 | "getFunctionName") |
| | 365 | |
| | 366 | |
| | 367 | def test_memberFunction(self): |
| | 368 | """ |
| | 369 | L{getFunctionName} should return fully qualified function name passed in the argument. |
| | 370 | """ |
| | 371 | self.assertEqual( |
| | 372 | reflect.getFunctionName(self.test_memberFunction), |
| | 373 | "GetFunctionNameTestCase.test_memberFunction") |
| | 374 | |
| | 375 | |
| | 376 | def test_safeRepr(self): |
| | 377 | """ |
| | 378 | L{getFunctionName} should return string representation of non-function object passed. |
| | 379 | """ |
| | 380 | i = 45 |
| | 381 | self.assertEqual(reflect.getFunctionName(i), "45") |
| | 382 | string = "string" |
| | 383 | self.assertEqual(reflect.getFunctionName(string), "'string'") |
| | 384 | |
| | 385 | |
| | 386 | |
| 353 | 387 | class Breakable(object): |
| 354 | 388 | |
| 355 | 389 | breakRepr = False |