コード例 #1
0
ファイル: cmd-examine.py プロジェクト: qtinsider/opera-presto
def cmdExamine(invoker):
    preprocess = not invoker.hasOption("*")
    expandPrototypes = invoker.hasOption("p")
    expandObjects = invoker.hasOption("x")
    filterIn = invoker.hasOption("+")
    filterOut = invoker.hasOption("-")
    invoker.checkUnsupportedOptions()

    if not invoker.getArguments():
        raise CommandError, "%s: missing argument" % invoker.getName()
    if filterIn and filterOut:
        raise CommandError, "%s: options '+' and '-' are mutually exclusive" % invoker.getName(
        )

    arguments = invoker.getArguments()
    limit = 0xffff

    if expandObjects or expandPrototypes:
        words = arguments.split(' ', 1)
        if len(words) > 1:
            try:
                limit = int(words[0])
                arguments = words[1]
            except ValueError:
                pass

    if filterIn or filterOut:
        words = arguments.split(' ', 1)
        if len(words) != 2:
            raise CommandError, "%s: missing filter argument" % invoker.getName(
            )
        filterArgument = words[0]
        arguments = words[1]
        if filterArgument[0] != '{' or filterArgument[-1] != '}':
            raise CommandError, "%s: invalid filter argument: %s" % (
                invoker.getName(), filterArgument)
        names = filterArgument[1:-1].split(',')
        if len(names) == 0:
            raise CommandError, "%s: invalid filter argument: %s" % (
                invoker.getName(), filterArgument)
    else:
        names = []

    try:
        result = invoker.getRuntime().eval(arguments, True, preprocess)
    except KeyboardInterrupt:
        result = None

    if result:
        if not result.isObject():
            raise CommandError, "%s: not an object: %s" % (invoker.getName(),
                                                           arguments)

        examiner = Examiner(invoker.getRuntime(), result.getValue(),
                            expandPrototypes and limit or 0,
                            expandObjects and limit or 0, filterIn, filterOut,
                            names, False)
        examiner.update()

        return examiner.getObjectPropertiesAsStrings(result.getValue())
コード例 #2
0
ファイル: cmd-examine.py プロジェクト: prestocore/browser
def cmdExamine(invoker):
    preprocess = not invoker.hasOption("*")
    expandPrototypes = invoker.hasOption("p")
    expandObjects = invoker.hasOption("x")
    filterIn = invoker.hasOption("+")
    filterOut = invoker.hasOption("-")
    invoker.checkUnsupportedOptions()

    if not invoker.getArguments(): raise CommandError, "%s: missing argument" % invoker.getName()
    if filterIn and filterOut: raise CommandError, "%s: options '+' and '-' are mutually exclusive" % invoker.getName()

    arguments = invoker.getArguments()
    limit = 0xffff

    if expandObjects or expandPrototypes:
        words = arguments.split(' ', 1)
        if len(words) > 1:
            try:
                limit = int(words[0])
                arguments = words[1]
            except ValueError: pass

    if filterIn or filterOut:
        words = arguments.split(' ', 1)
        if len(words) != 2: raise CommandError, "%s: missing filter argument" % invoker.getName()
        filterArgument = words[0]
        arguments = words[1]
        if filterArgument[0] != '{' or filterArgument[-1] != '}': raise CommandError, "%s: invalid filter argument: %s" % (invoker.getName(), filterArgument)
        names = filterArgument[1:-1].split(',')
        if len(names) == 0: raise CommandError, "%s: invalid filter argument: %s" % (invoker.getName(), filterArgument)
    else:
        names = []

    try: result = invoker.getRuntime().eval(arguments, True, preprocess)
    except KeyboardInterrupt: result = None

    if result:
        if not result.isObject(): raise CommandError, "%s: not an object: %s" % (invoker.getName(), arguments)

        examiner = Examiner(invoker.getRuntime(), result.getValue(), expandPrototypes and limit or 0, expandObjects and limit or 0, filterIn, filterOut, names, False)
        examiner.update()

        return examiner.getObjectPropertiesAsStrings(result.getValue())
コード例 #3
0
ファイル: tabcompleter.py プロジェクト: prestocore/browser
    def __call__(self, buffer, cursor, showCandidates):
        failure = (False, buffer, cursor)

        if not buffer or cursor == 0: return failure

        before = buffer[:cursor]
        after = buffer[cursor:]

        if re_command.match(before):
            return self.__findCompletion(buffer, cursor, before, self.__debugger.getCommandNames(), showCandidates, True)

        runtime = self.__debugger.getCurrentRuntime()
        match = re_property.match(before)
        if runtime and match and self.__argumentIsScript(buffer):
            command = match.group(1)
            expression = match.group(3)
            identifier = match.group(4)

            inScope = True
            base = ""
            parens = []

            if expression and expression.strip()[-1] == '.':
                expression = expression.strip()[:-1]
                inScope = False

                while expression:
                    match = re_whitespace_at_end.match(expression)
                    if match:
                        base = match.group(2) + base
                        expression = expression[:match.start(2)]
                        
                    if not expression: break

                    match = re_identifier_at_end.match(expression)
                    if match:
                        base = match.group(2) + base
                        expression = expression[:match.start(2)]
                        continue

                    ch = expression[-1]
                    if ch in (')', ']'):
                        parens.append({ ')': '(', ']': '[' }[ch])
                        base = ch + base
                        expression = expression[:-1]
                        continue

                    if ch in ('(', '['):
                        if not parens or parens[-1] != ch: break
                        parens.pop(-1)
                        base = ch + base
                        expression = expression[:-1]
                        continue

                    if expression[-1] == '.':
                        base = '.' + base
                        expression = expression[:-1]
                        continue

                    if len(expression) >= 3 and expression[-3:] in operators3:
                        if not parens: break
                        base = expression[-3:] + base
                        expression = expression[:-3]
                        continue

                    if len(expression) >= 2 and expression[-2:] in operators2:
                        if not parens: break
                        base = expression[-2:] + base
                        expression = expression[:-2]
                        continue

                    if len(expression) >= 1 and expression[-1:] in operators1:
                        if not parens: break
                        base = expression[-1:] + base
                        expression = expression[:-1]
                        continue

                    return failure

            if not parens:
                if inScope:
                    object = None
                else:
                    try: result = runtime.eval(base, True, True)
                    except KeyboardInterrupt: return failure

                    if result and result.isObject(): object = result.getValue()
                    else: return failure

                examiner = Examiner(runtime, object, 0xffff, 0, False, False, [], inScope)

                try: examiner.update()
                except KeyboardInterrupt: return failure

                if inScope: scope = examiner.getScope()
                else: scope = [object]

                propertyNames = []

                for object in scope:
                    while object:
                        propertyNames.extend([name for name, value in examiner.getObjectProperties(object)])
                        object = object.getPrototype()

                return self.__findCompletion(buffer, cursor, identifier, propertyNames, showCandidates, False)

        return failure
コード例 #4
0
    def __call__(self, buffer, cursor, showCandidates):
        failure = (False, buffer, cursor)

        if not buffer or cursor == 0: return failure

        before = buffer[:cursor]
        after = buffer[cursor:]

        if re_command.match(before):
            return self.__findCompletion(buffer, cursor, before,
                                         self.__debugger.getCommandNames(),
                                         showCandidates, True)

        runtime = self.__debugger.getCurrentRuntime()
        match = re_property.match(before)
        if runtime and match and self.__argumentIsScript(buffer):
            command = match.group(1)
            expression = match.group(3)
            identifier = match.group(4)

            inScope = True
            base = ""
            parens = []

            if expression and expression.strip()[-1] == '.':
                expression = expression.strip()[:-1]
                inScope = False

                while expression:
                    match = re_whitespace_at_end.match(expression)
                    if match:
                        base = match.group(2) + base
                        expression = expression[:match.start(2)]

                    if not expression: break

                    match = re_identifier_at_end.match(expression)
                    if match:
                        base = match.group(2) + base
                        expression = expression[:match.start(2)]
                        continue

                    ch = expression[-1]
                    if ch in (')', ']'):
                        parens.append({')': '(', ']': '['}[ch])
                        base = ch + base
                        expression = expression[:-1]
                        continue

                    if ch in ('(', '['):
                        if not parens or parens[-1] != ch: break
                        parens.pop(-1)
                        base = ch + base
                        expression = expression[:-1]
                        continue

                    if expression[-1] == '.':
                        base = '.' + base
                        expression = expression[:-1]
                        continue

                    if len(expression) >= 3 and expression[-3:] in operators3:
                        if not parens: break
                        base = expression[-3:] + base
                        expression = expression[:-3]
                        continue

                    if len(expression) >= 2 and expression[-2:] in operators2:
                        if not parens: break
                        base = expression[-2:] + base
                        expression = expression[:-2]
                        continue

                    if len(expression) >= 1 and expression[-1:] in operators1:
                        if not parens: break
                        base = expression[-1:] + base
                        expression = expression[:-1]
                        continue

                    return failure

            if not parens:
                if inScope:
                    object = None
                else:
                    try:
                        result = runtime.eval(base, True, True)
                    except KeyboardInterrupt:
                        return failure

                    if result and result.isObject(): object = result.getValue()
                    else: return failure

                examiner = Examiner(runtime, object, 0xffff, 0, False, False,
                                    [], inScope)

                try:
                    examiner.update()
                except KeyboardInterrupt:
                    return failure

                if inScope: scope = examiner.getScope()
                else: scope = [object]

                propertyNames = []

                for object in scope:
                    while object:
                        propertyNames.extend([
                            name for name, value in
                            examiner.getObjectProperties(object)
                        ])
                        object = object.getPrototype()

                return self.__findCompletion(buffer, cursor, identifier,
                                             propertyNames, showCandidates,
                                             False)

        return failure