Coverage for jseval/pyproxies : 73%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2013-2014, 2017, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
""""Behaviour shared between arrays and objects - useless on its own."""
# __dict__ to circumvent the custom __setattr__ implementation
return isinstance(property, self.__class__)
"""A proxy object that makes it possible to threat an Array QJSValue like a Python list
"""
raise self.NotFound(idx)
self._splice([self._normalize(idx), 1])
items = ('[...]' if self._possiblyRecursive(item) else repr(item) for item in self) return '<%s[%s]>' % (self.__class__.__name__, ', '.join(items))
return list(self)
return [copy.deepcopy(item, memo) for item in self]
"""Makes it possible to access the keys of a dictionary-like as properties (assuming there is no actual property of the same name that takes precendence)
""" except KeyError as e: raise AttributeError(e)
try: del self[attr] except KeyError as e: raise AttributeError(e)
"""A proxy object that makes it possible to threat an Object QJSValue like a Python dictionary (and also a normal Python object).
Note that JS functions are also objects, and are thus also wrapped in this class. To cater to them, ``__call__`` and ``new()`` are defined.
"""
# __dict__ to circumvent the custom __setattr__ implementation
except TypeError: return False
raise self.NotFound(key)
raise self.NotFound(key)
# kwargs is added as an object as the last argument
pairs = ((key, self[key]) for key in self) filtered = ((k, '{...}' if self._possiblyRecursive(v) else v) for k, v in pairs) strings = ("%s: %s" % pair for pair in filtered) return "<%s{%s}>" % (self.__class__.__name__, ', '.join(strings))
return JSObjectCopy(self)
return JSObjectCopy((key, copy.deepcopy(value, memo)) for key, value in self.items())
"""Represents a JS error. No proxying, but as error objects are not normally modified after their initialization that's not a big loss. The advantage (nice Python integration) is worth it.
""" self.name = name self.message = message
return "%s: %s" % (self.name, self.message) |