示例#1
0
    def __init__(self, filename=None, mode='r', *args):
        self.filename = filename
        self.mode = mode
        self.args = args
        str_object = get_str()
        str_list = get_list(get_str())
        attributes = {}

        def add(name, returned=None, function=None):
            builtin = getattr(io.TextIOBase, name, None)
            attributes[name] = BuiltinName(
                BuiltinFunction(returned=returned,
                                function=function,
                                builtin=builtin))

        add('__iter__', get_iterator(str_object))
        add('__enter__', returned=pyobjects.PyObject(self))
        for method in ['next', 'read', 'readline', 'readlines']:
            add(method, str_list)
        for method in [
                'close', 'flush', 'lineno', 'isatty', 'seek', 'tell',
                'truncate', 'write', 'writelines'
        ]:
            add(method)
        super(File, self).__init__(open, attributes)
示例#2
0
    def __init__(self, filename=None, mode="r", *args):
        self.filename = filename
        self.mode = mode
        self.args = args
        str_object = get_str()
        str_list = get_list(get_str())
        attributes = {}

        def add(name, returned=None, function=None):
            builtin = getattr(io.TextIOBase, name, None)
            attributes[name] = BuiltinName(
                BuiltinFunction(returned=returned,
                                function=function,
                                builtin=builtin))

        add("__iter__", get_iterator(str_object))
        add("__enter__", returned=pyobjects.PyObject(self))
        for method in ["next", "read", "readline", "readlines"]:
            add(method, str_list)
        for method in [
                "close",
                "flush",
                "lineno",
                "isatty",
                "seek",
                "tell",
                "truncate",
                "write",
                "writelines",
        ]:
            add(method)
        super(File, self).__init__(open, attributes)
示例#3
0
文件: builtins.py 项目: falcom520/vim
def _super_function(args):
    passed_class, passed_self = args.get_arguments(['type', 'self'])
    if passed_self is None:
        return passed_class
    else:
        #pyclass = passed_self.get_type()
        pyclass = passed_class
        if isinstance(pyclass, pyobjects.AbstractClass):
            supers = pyclass.get_superclasses()
            if supers:
                return pyobjects.PyObject(supers[0])
        return passed_self
示例#4
0
 def __init__(self, *objects):
     self.objects = objects
     first = None
     if objects:
         first = objects[0]
     attributes = {
         '__getitem__': BuiltinName(BuiltinFunction(first)),
         '__getslice__':
         BuiltinName(BuiltinFunction(pyobjects.PyObject(self))),
         '__new__': BuiltinName(BuiltinFunction(function=self._new_tuple)),
         '__iter__': BuiltinName(BuiltinFunction(get_iterator(first)))}
     super(Tuple, self).__init__(tuple, attributes)
示例#5
0
    def __init__(self):
        self_object = pyobjects.PyObject(self)
        collector = _AttributeCollector(str)
        collector('__iter__', get_iterator(self_object), check_existence=False)

        self_methods = [
            '__getitem__', 'capitalize', 'center', 'encode', 'expandtabs',
            'join', 'ljust', 'lower', 'lstrip', 'replace', 'rjust', 'rstrip',
            'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'
        ]
        for method in self_methods:
            collector(method, self_object)

        for method in ['rsplit', 'split', 'splitlines']:
            collector(method, get_list(self_object))

        super(Str, self).__init__(str, collector.attributes)
示例#6
0
文件: soa.py 项目: climbus/rope
 def _Call(self, node):
     for child in rope.base.ast.get_child_nodes(node):
         rope.base.ast.walk(child, self)
     primary, pyname = evaluate.eval_node2(self.scope, node.func)
     if pyname is None:
         return
     pyfunction = pyname.get_object()
     if isinstance(pyfunction, pyobjects.AbstractFunction):
         args = arguments.create_arguments(primary, pyfunction, node, self.scope)
     elif isinstance(pyfunction, pyobjects.PyClass):
         pyclass = pyfunction
         if "__init__" in pyfunction:
             pyfunction = pyfunction["__init__"].get_object()
         pyname = rope.base.pynames.UnboundName(pyobjects.PyObject(pyclass))
         args = self._args_with_self(primary, pyname, pyfunction, node)
     elif "__call__" in pyfunction:
         pyfunction = pyfunction["__call__"].get_object()
         args = self._args_with_self(primary, pyname, pyfunction, node)
     else:
         return
     self._call(pyfunction, args)
示例#7
0
    def __init__(self):
        self_object = pyobjects.PyObject(self)
        str_object = get_str()
        str_list = get_list(get_str())
        attributes = {}

        def add(name, returned=None, function=None):
            builtin = getattr(file, name, None)
            attributes[name] = BuiltinName(
                BuiltinFunction(returned=returned,
                                function=function,
                                builtin=builtin))

        add('__iter__', get_iterator(str_object))
        for method in ['next', 'read', 'readline', 'readlines']:
            add(method, str_list)
        for method in [
                'close', 'flush', 'lineno', 'isatty', 'seek', 'tell',
                'truncate', 'write', 'writelines'
        ]:
            add(method)
        super(File, self).__init__(file, attributes)
示例#8
0
    def __init__(self):
        self_object = pyobjects.PyObject(self)
        collector = _AttributeCollector(str)
        collector("__iter__", get_iterator(self_object), check_existence=False)

        self_methods = [
            "__getitem__",
            "capitalize",
            "center",
            "encode",
            "expandtabs",
            "join",
            "ljust",
            "lower",
            "lstrip",
            "replace",
            "rjust",
            "rstrip",
            "strip",
            "swapcase",
            "title",
            "translate",
            "upper",
            "zfill",
        ]
        for method in self_methods:
            collector(method, self_object, parent=self)

        py2_self_methods = ["__getslice__", "decode"]
        for method in py2_self_methods:
            try:
                collector(method, self_object)
            except AttributeError:
                pass

        for method in ["rsplit", "split", "splitlines"]:
            collector(method, get_list(self_object), parent=self)

        super(Str, self).__init__(str, collector.attributes)
示例#9
0
文件: builtins.py 项目: falcom520/vim
def _property_function(args):
    parameters = args.get_arguments(['fget', 'fset', 'fdel', 'fdoc'])
    return pyobjects.PyObject(Property(parameters[0]))
示例#10
0
文件: builtins.py 项目: falcom520/vim
 def _get_builtin(*args):
     return pyobjects.PyObject(type_getter(*args))
示例#11
0
def _property_function(args):
    parameters = args.get_arguments(["fget", "fset", "fdel", "fdoc"])
    return pyobjects.PyObject(Property(parameters[0]))