Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def _get_builtin_name(self, type_name):
pytype = rope.base.builtins.builtins[type_name].get_object()
return rope.base.pynames.UnboundName(
rope.base.pyobjects.PyObject(pytype))
def _handle_first_parameter(pyobject, parameters):
kind = pyobject.get_kind()
if parameters is None or kind not in ['method', 'classmethod']:
pass
if not parameters:
if not pyobject.get_param_names(special_args=False):
return
parameters.append(rope.base.pyobjects.get_unknown())
if kind == 'method':
parameters[0] = rope.base.pyobjects.PyObject(pyobject.parent)
if kind == 'classmethod':
parameters[0] = pyobject.parent
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)
py2_self_methods = ["__getslice__", "decode"]
for method in py2_self_methods:
try:
collector(method, self_object)
except AttributeError:
def _FunctionDef(self, node):
pyfunction = PyFunction(self.pycore, node, self.owner_object)
for decorator in pyfunction.decorators:
if isinstance(decorator, ast.Name) and decorator.id == 'property':
if isinstance(self, _ClassVisitor):
type_ = rope.base.builtins.Property(pyfunction)
arg = pynames.UnboundName(
rope.base.pyobjects.PyObject(self.owner_object))
def _eval(type_=type_, arg=arg):
return type_.get_property_object(
arguments.ObjectArguments([arg]))
self.names[node.name] = pynames.EvaluatedName(
_eval, module=self.get_module(), lineno=node.lineno)
break
else:
self.names[node.name] = pynames.DefinedName(pyfunction)
self.defineds.append(pyfunction)
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)
def get_unknown():
"""Return a pyobject whose type is unknown
Note that two unknown objects are equal. So for example you can
write::
if pyname.get_object() == get_unknown():
print('cannot determine what this pyname holds')
Rope could have used `None` for indicating unknown objects but
we had to check that in many places. So actually this method
returns a null object.
"""
if PyObject._unknown is None:
PyObject._unknown = PyObject(get_base_type('Unknown'))
return PyObject._unknown
def _FunctionDef(self, node):
pyfunction = PyFunction(self.pycore, node, self.owner_object)
for decorator in pyfunction.decorators:
if isinstance(decorator, ast.Name) and decorator.id == 'property':
if isinstance(self, _ClassVisitor):
type_ = rope.base.builtins.Property(pyfunction)
arg = pynames.UnboundName(
rope.base.pyobjects.PyObject(self.owner_object))
def _eval(type_=type_, arg=arg):
return type_.get_property_object(
arguments.ObjectArguments([arg]))
self.names[node.name] = pynames.EvaluatedName(
_eval, module=self.get_module(), lineno=node.lineno)
break
else:
self.names[node.name] = pynames.DefinedName(pyfunction)
self.defineds.append(pyfunction)
def _property_function(args):
parameters = args.get_arguments(['fget', 'fset', 'fdel', 'fdoc'])
return pyobjects.PyObject(Property(parameters[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)