utils.py
changeset 6067 efca814587e2
parent 6044 9e48ebd5400c
child 6141 b8287e54b528
equal deleted inserted replaced
6066:953578709324 6067:efca814587e2
    22 import os
    22 import os
    23 import sys
    23 import sys
    24 import decimal
    24 import decimal
    25 import datetime
    25 import datetime
    26 import random
    26 import random
       
    27 from inspect import getargspec
    27 from itertools import repeat
    28 from itertools import repeat
    28 from uuid import uuid4
    29 from uuid import uuid4
    29 from warnings import warn
    30 from warnings import warn
    30 
    31 
    31 from logilab.mtconverter import xml_escape
    32 from logilab.mtconverter import xml_escape
    62     # __autogenerated__ attribute is just a marker
    63     # __autogenerated__ attribute is just a marker
    63     return type(str(clsname), (cls,), {'__autogenerated__': True,
    64     return type(str(clsname), (cls,), {'__autogenerated__': True,
    64                                        '__doc__': cls.__doc__,
    65                                        '__doc__': cls.__doc__,
    65                                        '__module__': cls.__module__})
    66                                        '__module__': cls.__module__})
    66 
    67 
       
    68 def support_args(callable, *argnames):
       
    69     """return true if the callable support given argument names"""
       
    70     argspec = getargspec(callable)
       
    71     if argspec[2]:
       
    72         return True
       
    73     for argname in argnames:
       
    74         if argname not in argspec[0]:
       
    75             return False
       
    76     return True
    67 
    77 
    68 # use networkX instead ?
    78 # use networkX instead ?
    69 # http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
    79 # http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
    70 def transitive_closure_of(entity, relname, _seen=None):
    80 def transitive_closure_of(entity, relname, _seen=None):
    71     """return transitive closure *for the subgraph starting from the given
    81     """return transitive closure *for the subgraph starting from the given