def getObjectTip(code):
    calltip = []
    # 99% of the time the __roles__ are useless
    drs = [ c for c in dir(code) if not c.endswith('__roles__') ]
    dirres = [_(u"Methods and attributes"), ", ".join(drs)]
    calltip.append(dirres)
    return calltip
def getZopeTip(code):
    calltip = []
    if hasattr(code, "objectIds"):
        ids = code.objectIds()
        if ids:
            objects = [_(u"Objects"), ", ".join(ids)]
            calltip.append(objects)
    if hasattr(code, "Schema"):
        fields = code.Schema().fields()
        fieldsIds = [ field.getName() for field in fields ]
        calltip.append([_(u"Schema"), ", ".join(fieldsIds)])
    if docfinder:
        if hasattr(code, "analyseDocumentation"):
            docf = code.analyseDocumentation(code)
            callables = []
            non_callables = []
            notes = []
            # show the first 5 classes, excluding item
            k = 0
            # need to change docf to support slices
            for item in docf:
                if k == 0:
                    k += 1
                    continue
                for element in item:
                    if element.Type() == "function":
                        callables.append(element.Name())
                    else:
                        non_callables.append(element.Name())
                k += 1

            # lower cased sort please
            calltip.append([ _(u"Callable"), ", ".join(lowerSort(callables))],)
            calltip.append([ _(u"Attributes"), ", ".join(lowerSort(non_callables))],)
            if notes:
                calltip.append([ _(u"Notes"), "\n".join(notes)],)

    return calltip
def getMethodTip(object):
    name = ""
    try:
        name = object.__name__
    except AttributeError:
        pass
    argspec = _(u"No arguments")

    if inspect.isbuiltin(object):
        # Builtin functions don't have an argspec that we can get.
        argspec = _(u"Not available for a bultin in function")
    else:
        # tip1 is a string like: "getCallTip(command='', locals=None)"
        argspec = apply(inspect.formatargspec, inspect.getargspec(object))
        temp = argspec.split(',')
        if len(temp) == 1:  # No other arguments.
            argspec = '()'
        elif temp[0][:2] == '(*': # first param is like *args, not self
            pass 
        else:  # Drop the first argument.
            argspec = '(' + ','.join(temp[1:]).lstrip()
        argspec = argspec[1:-1] # strip ( and )
        
    doc = None
    if callable(object):
        try:
            doc = inspect.getdoc(object)
        except:
            pass
    if not doc:
        doc = _(u"Not available")
            

    calltip = (
        [_(u"Name"), name],
        [_(u"Arguments"), argspec],
        [_(u"Documentation"), doc],
        )
    return calltip
from ZODB.POSException import ConflictError
from Products.Clouseau import ClouseauMessageFactory as _

log = getLogger("Products.Clouseau.sessions")

# if this is 1, then we skip the first line in the 
# interactions... if its 0 then we don't. This will
# hopefully get fixed later...
show_first = 1

# replace stdoout, from unit tests you probably want
# this to be false, makes getting a pdb much easier
# probably though this a matter of fixing a mess
replace_stdout = True

no_session_string = _(u"""A session was requested by a browser, but no session exists. This normally occurs when you leave a browser with a Clouseau session open and restart Zope or delete the session. Please close that browser window.""")

sessions_lock = threading.Lock()
sessions = {}
next_session_id = -1
            
class IOPairInterpreter(code.InteractiveInterpreter):

    can_commit = True

    def __init__(self, namespace):
        self.interactions = []
        self.currentOutput = []
        self.currentInput = []
        self.codeMap = {}
        code.InteractiveInterpreter.__init__(self, locals=namespace)
def getDirResults(code):
    calltip = []
    dirres = [_(u"Namespace"), ", ".join(code)]
    calltip.append(dirres)
    return calltip