class W_ReflectionParameter(W_InstanceObject): pass def _get_name(interp, this): return interp.space.wrap(this.ref_parameter.name) def _set_name(interp, this, w_value): pass k_ReflectionParameter = def_class( 'ReflectionParameter', ['__construct', 'getName'], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [], instance_class=W_ReflectionParameter ) @k_ReflectionParameter.def_method(['interp', 'this', W_Root, int]) def __construct(interp, this, function, parameter): if isinstance(function, W_ConstStringObject): name = interp.space.str_w(function) function = interp.lookup_function(name) assert function is not None signature = function.get_signature() this.ref_parameter = signature.args[parameter] else: args = function.as_rdict().values()
def ArrayIterator_current(): pass @wrap_method([], name='ArrayIterator::next') def ArrayIterator_next(): pass @wrap_method([], name='ArrayIterator::key') def ArrayIterator_key(): pass @wrap_method([], name='ArrayIterator::rewind') def ArrayIterator_rewind(): pass @wrap_method([], name='ArrayIterator::valid') def ArrayIterator_valid(): pass k_ArrayIterator = def_class('ArrayIterator', [ ArrayIterator_construct, ArrayIterator_current, ArrayIterator_next, ArrayIterator_key, ArrayIterator_rewind, ArrayIterator_valid ], [('storage', consts.ACC_PRIVATE)], instance_class=W_ApplevelArrayIterator, implements=[k_Iterator])
def _get_name(interp, this): return interp.space.wrap(this.refl_klass.name) def _set_name(interp, this, w_value): pass k_ReflectionClass = def_class( 'ReflectionClass', ["__construct", "newInstance", "newInstanceArgs", "hasConstant", "getConstant", "getConstants", "getConstructor", "getDefaultProperties", "getDocComment", "getEndLine", "getInterfaces", "getInterfaceNames", "getMethod", "getMethods", "getModifiers", "getName", "getStartLine", "getFileName", "getExtension", "getExtensionName", "getNamespaceName", "getStaticProperties", "getProperties", "getProperty", "hasProperty", "isSubclassOf", "isInstantiable", "hasMethod", "isAbstract"], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_IMPLICIT_ABSTRACT', W_IntObject(IS_IMPLICIT_ABSTRACT)), ('IS_EXPLICIT_ABSTRACT', W_IntObject(IS_EXPLICIT_ABSTRACT)), ('IS_FINAL', W_IntObject(IS_FINAL))], instance_class=W_ReflectionClass ) @k_ReflectionClass.def_method(['interp', 'this', W_Root]) def __construct(interp, this, klass): space = interp.space if isinstance(klass, W_ConstStringObject): name = space.str_w(klass) this.refl_klass = interp.lookup_class_or_intf(name)
if not w_dir.is_valid(): interp.warn( "Directory::rewind(): %d is not a valid Directory resource" % w_dir.res_id) return interp.space.w_False else: w_dir.rewind() return interp.space.w_Null @wrap_method([ 'interp', ThisUnwrapper(W_Directory), Optional(Resource(W_DirResource, True)) ], name='Directory::close') def dir_close(interp, this, w_dir=None): if not w_dir: w_dir = this.handle assert isinstance(w_dir, W_DirResource) w_dir.close() return interp.space.w_Null k_Directory = def_class('Directory', [dir_read, dir_rewind, dir_close], [ GetterSetterWrapper(_get_path, _set_path, "path", consts.ACC_PUBLIC), GetterSetterWrapper(_get_handle, _set_handle, "handle", consts.ACC_PUBLIC) ], instance_class=W_Directory)
def _set_class(interp, this, w_value): pass def _get_name(interp, this): return interp.space.wrap(this.ref_method.get_name()) def _set_name(interp, this, w_value): pass def_class( 'ReflectionMethod', [construct, is_public, is_static, get_doc_comment, get_parameters, get_declaring_class], [GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC), GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE)), ('IS_ABSTRACT', W_IntObject(IS_ABSTRACT)), ('IS_FINAL', W_IntObject(IS_FINAL))], instance_class=W_ReflectionMethodObject, extends=ReflectionFunctionAbstract )
def ArrayIterator_next(): pass @wrap_method([], name='ArrayIterator::key') def ArrayIterator_key(): pass @wrap_method([], name='ArrayIterator::rewind') def ArrayIterator_rewind(): pass @wrap_method([], name='ArrayIterator::valid') def ArrayIterator_valid(): pass k_ArrayIterator = def_class('ArrayIterator', [ ArrayIterator_construct, ArrayIterator_current, ArrayIterator_next, ArrayIterator_key, ArrayIterator_rewind, ArrayIterator_valid], [('storage', consts.ACC_PRIVATE)], instance_class=W_ApplevelArrayIterator, implements=["Iterator"] )
def _set_class(interp, this, w_value): pass def _get_name(interp, this): return interp.space.newstr(this.ref_prop.name) def _set_name(interp, this, w_value): pass def_class( 'ReflectionProperty', [construct, get_name, get_value, set_value, is_public, is_private, is_protected, is_static], [GetterSetterWrapper(_get_name, _set_name, 'name', consts.ACC_PUBLIC), GetterSetterWrapper(_get_class, _set_class, 'class', consts.ACC_PUBLIC)], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE))], instance_class=W_ReflectionPropertyObject )
return space.wrap("\n".join(msg)) @wrap_method(['interp', ThisUnwrapper(W_ExceptionObject)], name='Exception::getTraceAsString') def exc_getTraceAsString(interp, this): msg = [] for i, (filename, funcname, line, source) in enumerate(this.traceback): msg.append("#%d %s(%d): %s()" % (i, filename, line, funcname)) return interp.space.wrap("\n".join(msg)) k_Exception = def_class('Exception', [ new_exception, exc_getMessage, exc_getCode, exc_getPrevious, exc_getTrace, exc_getFile, exc_getLine, exc___toString, exc_getTraceAsString ], [('message', consts.ACC_PROTECTED), ('code', consts.ACC_PROTECTED), ('previous', consts.ACC_PRIVATE), ('file', consts.ACC_PROTECTED), ('line', consts.ACC_PROTECTED)], instance_class=W_ExceptionObject) def_class('OutOfBoundsException', [], extends=k_Exception) k_stdClass = def_class('stdClass', []) k_incomplete = def_class('__PHP_Incomplete_Class', []) k_RuntimeException = def_class('RuntimeException', [], extends=k_Exception) k_LogicException = def_class('LogicException', [], extends=k_Exception) k_DomainException = def_class('DomainException', [], extends=k_Exception) k_UnexpectedValueException = def_class('UnexpectedValueException', [], extends=k_Exception) def new_abstract_method(args, **kwds):
def _get_name(interp, this): return interp.space.wrap(this.refl_klass.name) def _set_name(interp, this, w_value): pass def_class('ReflectionClass', [ reflection_class_construct, reflection_class_new_instance, reflection_class_new_instance_args, reflection_class_has_constant, reflection_class_get_constant, reflection_class_get_constants, reflection_class_get_constructor, reflection_class_get_default_properties, reflection_class_get_doc_comment, reflection_class_get_end_line, reflection_class_get_interfaces, reflection_class_get_interface_names, reflection_class_get_method, reflection_class_get_methods, reflection_class_get_modifiers, reflection_class_get_name, reflection_class_get_start_line, reflection_class_get_file_name, reflection_class_get_extension, reflection_class_get_extension_name, reflection_class_get_namespace_name, reflection_class_get_static_properties, reflection_class_get_properties, reflection_class_get_property, reflection_class_has_property, reflection_class_is_subclass_of, reflection_class_is_instantiable, reflection_class_has_method, reflection_class_is_abstract ], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_IMPLICIT_ABSTRACT', W_IntObject(IS_IMPLICIT_ABSTRACT)), ('IS_EXPLICIT_ABSTRACT', W_IntObject(IS_EXPLICIT_ABSTRACT)), ('IS_FINAL', W_IntObject(IS_FINAL))], instance_class=W_ReflectionClass)
from hippy.klass import def_class from hippy.builtin_klass import k_Exception k_LogicException = def_class('LogicException', [], extends=k_Exception) k_BadFunctionCallException = def_class('BadFunctionCallException', [], extends=k_LogicException) k_BadMethodCallException = def_class('BadMethodCallException', [], extends=k_BadFunctionCallException) k_InvalidArgumentException = def_class('InvalidArgumentException', [], extends=k_BadFunctionCallException) k_DomainException = def_class('DomainException', [], extends=k_LogicException) k_RuntimeException = def_class('RuntimeException', [], extends=k_Exception) k_UnexpectedValueException = def_class('UnexpectedValueException', [], extends=k_RuntimeException)
thisclass = w_this.getclass() if w_this is not None else None return W_CallClosure(thisclass, self._func, w_this, self.closure_args) def put_closure(self, args_w): n = len(self.closure_args) for i, w_arg in enumerate(args_w): self.closure_args[n - i - 1] = w_arg def getmeth(self, space, name, contextclass=None): if name.lower() == "__invoke": return self.get_callable() return W_InstanceObject.getmeth(self, space, name, contextclass) @wrap_method(['interp', ThisUnwrapper(W_ClosureObject), 'args_w'], name='Closure::__invoke') def closure_invoke(interp, this, args_w): return this._func.call_args(interp, args_w) k_Closure = def_class('Closure', [closure_invoke]) def new_closure(space, func, w_this, static=False): w_res = W_ClosureObject(func, k_Closure, k_Closure.get_initial_storage_w(space)[:], w_this=w_this, static=static) return w_res
pass def _get_name(interp, this): return interp.space.wrap(this.ref_method.get_name()) def _set_name(interp, this, w_value): pass k_ReflectionMethod = def_class( 'ReflectionMethod', ['__construct', 'isPublic', 'isstatic', 'getDocComment', 'getParameters', 'getDeclaringClass'], [GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC), GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE)), ('IS_ABSTRACT', W_IntObject(IS_ABSTRACT)), ('IS_FINAL', W_IntObject(IS_FINAL))], instance_class=W_ReflectionMethodObject, extends=k_ReflectionFunctionAbstract) @k_ReflectionMethod.def_method(['interp', 'this', str, str]) def __construct(interp, this, class_name, method_name): klass = interp.lookup_class_or_intf(class_name) this.ref_klass = klass try: this.ref_method = klass.methods[method_name]
return interp.space.newstr(this.name) def _set_name(interp, this, w_value): pass k_ReflectionProperty = def_class( 'ReflectionProperty', [export, construct, get_name, get_value, set_value, get_declaring_class, is_public, is_private, is_protected, is_static, is_default, get_modifiers, toString], [GetterSetterWrapper(_get_name, _set_name, 'name', consts.ACC_PUBLIC), GetterSetterWrapper(_get_class, _set_class, 'class', consts.ACC_PUBLIC)], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE))], instance_class=W_ReflectionProperty )
k_DateInterval = def_class( 'DateInterval', [construct, create_from_date_string, format], [GetterSetterWrapper(get_y, set_y, "y", consts.ACC_PUBLIC), GetterSetterWrapper(get_m, set_m, "m", consts.ACC_PUBLIC), GetterSetterWrapper(get_d, set_d, "d", consts.ACC_PUBLIC), GetterSetterWrapper(get_h, set_h, "h", consts.ACC_PUBLIC), GetterSetterWrapper(get_i, set_i, "i", consts.ACC_PUBLIC), GetterSetterWrapper(get_s, set_s, "s", consts.ACC_PUBLIC), GetterSetterWrapper(get_weekday, set_weekday, "weekday", consts.ACC_PUBLIC), GetterSetterWrapper(get_weekday_behavior, set_weekday_behavior, "weekday_behavior", consts.ACC_PUBLIC), GetterSetterWrapper(get_first_last_day_of, set_first_last_day_of, "first_last_day_of", consts.ACC_PUBLIC), GetterSetterWrapper(get_invert, set_invert, "invert", consts.ACC_PUBLIC), GetterSetterWrapper(get_days, set_days, "days", consts.ACC_PUBLIC), GetterSetterWrapper(get_special_type, set_special_type, "special_type", consts.ACC_PUBLIC), GetterSetterWrapper(get_special_amount, set_special_amount, "special_amount", consts.ACC_PUBLIC), GetterSetterWrapper(get_have_weekday_relative, set_have_weekday_relative, "have_weekday_relative", consts.ACC_PUBLIC), GetterSetterWrapper(get_have_special_relative, set_have_special_relative, "have_special_relative", consts.ACC_PUBLIC)], instance_class=W_DateInterval )
return space.wrap("\n".join(msg)) @wrap_method(['interp', ThisUnwrapper(W_ExceptionObject)], name='Exception::getTraceAsString') def exc_getTraceAsString(interp, this): msg = [] for i, (filename, funcname, line, source) in enumerate(this.traceback): msg.append("#%d %s(%d): %s()" % (i, filename, line, funcname)) return interp.space.wrap("\n".join(msg)) k_Exception = def_class('Exception', [ new_exception, exc_getMessage, exc_getCode, exc_getPrevious, exc_getTrace, exc_getFile, exc_getLine, exc___toString, exc_getTraceAsString ], [('message', consts.ACC_PROTECTED), ('code', consts.ACC_PROTECTED), ('previous', consts.ACC_PRIVATE), ('file', consts.ACC_PROTECTED), ('line', consts.ACC_PROTECTED)], instance_class=W_ExceptionObject) def_class('OutOfBoundsException', [], extends=k_Exception) k_stdClass = def_class('stdClass', []) k_incomplete = def_class('__PHP_Incomplete_Class', []) def new_abstract_method(args, **kwds): name = kwds['name'] assert args[0] == 'interp' kwds['flags'] = kwds.get('flags', 0) | consts.ACC_ABSTRACT def method(interp, *args):
return w_arr class W_ArrayIterator(W_SplArray): _iter = None def _get_storage(interp, this): return this.w_arr def _set_storage(interp, this, w_arr): raise NotImplementedError k_ArrayObject = def_class( 'ArrayObject', ['__construct', 'offsetExists', 'offsetGet', 'offsetSet', 'offsetUnset', 'append', 'count', 'getIterator'], [GetterSetterWrapper(_get_storage, _set_storage, 'storage', consts.ACC_PRIVATE)], instance_class=W_SplArray, implements=[k_IteratorAggregate, k_ArrayAccess]) k_ArrayIterator = def_class( 'ArrayIterator', ['__construct', 'offsetExists', 'offsetGet', 'offsetSet', 'offsetUnset', 'append', 'count', 'current', 'next', 'key', 'rewind', 'valid'], [GetterSetterWrapper(_get_storage, _set_storage, 'storage', consts.ACC_PRIVATE)], instance_class=W_ArrayIterator, implements=[k_ArrayAccess, k_Iterator])
@wrap_method(['interp', ThisUnwrapper(W_ExceptionObject)], name='Exception::getTraceAsString') def exc_getTraceAsString(interp, this): msg = [] for i, (filename, funcname, line, source) in enumerate(this.traceback): msg.append("#%d %s(%d): %s()" % (i, filename, line, funcname)) return interp.space.wrap("\n".join(msg)) k_Exception = def_class('Exception', [ new_exception, exc_getMessage, exc_getCode, exc_getPrevious, exc_getTrace, exc_getFile, exc_getLine, exc___toString, exc_getTraceAsString ], [ ('message', consts.ACC_PROTECTED), ('code', consts.ACC_PROTECTED), ('previous', consts.ACC_PRIVATE), ('file', consts.ACC_PROTECTED), ('line', consts.ACC_PROTECTED), ], instance_class=W_ExceptionObject) def_class('OutOfBoundsException', [], extends=k_Exception, instance_class=W_ExceptionObject) k_stdClass = def_class('stdClass', []) k_incomplete = def_class('__PHP_Incomplete_Class', []) k_RuntimeException = def_class('RuntimeException', [], extends=k_Exception, instance_class=W_ExceptionObject) k_LogicException = def_class('LogicException', [],
return space.wrap("\n".join(msg)) @wrap_method(['interp', ThisUnwrapper(W_ExceptionObject)], name='Exception::getTraceAsString') def exc_getTraceAsString(interp, this): msg = [] for i, (filename, funcname, line, source) in enumerate(this.traceback): msg.append("#%d %s(%d): %s()" % (i, filename, line, funcname)) return interp.space.wrap("\n".join(msg)) k_Exception = def_class('Exception', [new_exception, exc_getMessage, exc_getCode, exc_getPrevious, exc_getTrace, exc_getFile, exc_getLine, exc___toString, exc_getTraceAsString], [('message', consts.ACC_PROTECTED), ('code', consts.ACC_PROTECTED), ('previous', consts.ACC_PRIVATE), ('file', consts.ACC_PROTECTED), ('line', consts.ACC_PROTECTED)], instance_class=W_ExceptionObject) def_class('OutOfBoundsException', [], extends=k_Exception) k_stdClass = def_class('stdClass', []) k_incomplete = def_class('__PHP_Incomplete_Class', []) def new_abstract_method(args, **kwds): name = kwds['name'] assert args[0] == 'interp' kwds['flags'] = kwds.get('flags', 0) | consts.ACC_ABSTRACT
def _get_name(interp, this): return interp.space.newstr(this.name) def _set_name(interp, this, w_value): pass k_ReflectionProperty = def_class( 'ReflectionProperty', ['export', '__construct', 'getName', 'getValue', 'setValue', 'getDeclaringClass', "isPublic", "isPrivate", "isProtected", "isStatic", "isDefault", "getModifiers", "__toString"], [GetterSetterWrapper(_get_name, _set_name, 'name', consts.ACC_PUBLIC), GetterSetterWrapper(_get_class, _set_class, 'class', consts.ACC_PUBLIC)], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE))], instance_class=W_ReflectionProperty) @k_ReflectionProperty.def_method(['interp', W_Root, str, Optional(bool)], flags=consts.ACC_STATIC) def export(interp, w_klass, name, return_string=False): refl = k_ReflectionProperty.call_args(interp, [w_klass, interp.space.wrap(name)]) result = refl.get_str() if return_string: return interp.space.wrap(result)
return self.space.new_array_from_pairs(parameters) def _get_name(interp, this): return this.ref_fun.get_name() def _set_name(interp, this, w_value): pass k_ReflectionFunction = def_class( "ReflectionFunction", ["__construct", "getName", "getDocComment", "getParameters"], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [("IS_DEPRECATED", W_IntObject(IS_DEPRECATED))], instance_class=W_ReflectionFunction, extends=k_ReflectionFunctionAbstract, ) @k_ReflectionFunction.def_method(["interp", "this", W_Root]) def __construct(interp, this, function): if isinstance(function, W_ClosureObject): this.ref_fun = ClosureWrapper(interp, function) else: this.ref_fun = NameWrapper(interp, function) @k_ReflectionFunction.def_method(["interp", "this"]) def getName(interp, this):
def _get_name(interp, this): return interp.space.newstr(this.name) def _set_name(interp, this, w_value): pass k_ReflectionProperty = def_class('ReflectionProperty', [ 'export', '__construct', 'getName', 'getValue', 'setValue', 'getDeclaringClass', "isPublic", "isPrivate", "isProtected", "isStatic", "isDefault", "getModifiers", "__toString" ], [ GetterSetterWrapper(_get_name, _set_name, 'name', consts.ACC_PUBLIC), GetterSetterWrapper(_get_class, _set_class, 'class', consts.ACC_PUBLIC) ], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE))], instance_class=W_ReflectionProperty) @k_ReflectionProperty.def_method( ['interp', W_Root, str, Optional(bool)], flags=consts.ACC_STATIC) def export(interp, w_klass, name, return_string=False): refl = k_ReflectionProperty.call_args( interp, [w_klass, interp.space.wrap(name)]) result = refl.get_str() if return_string: return interp.space.wrap(result)
from hippy.klass import def_class from hippy.builtin_klass import k_Exception, W_ExceptionObject k_ReflectionException = def_class( 'ReflectionException', [], extends=k_Exception, instance_class=W_ExceptionObject )
k_ReflectionProperty = def_class( "ReflectionProperty", [ "export", "__construct", "getName", "getValue", "setValue", "getDeclaringClass", "isPublic", "isPrivate", "isProtected", "isStatic", "isDefault", "getModifiers", "__toString", ], [ GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC), GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC), ], [ ("IS_STATIC", W_IntObject(IS_STATIC)), ("IS_PUBLIC", W_IntObject(IS_PUBLIC)), ("IS_PROTECTED", W_IntObject(IS_PROTECTED)), ("IS_PRIVATE", W_IntObject(IS_PRIVATE)), ], instance_class=W_ReflectionProperty, )
k_DateTimeZone = def_class( 'DateTimeZone', [construct, get_name, get_offset, list_abbreviations, identifiers_list, get_transition, get_location], [], [('AFRICA', space.wrap(common.AFRICA)), ('AMERICA', space.wrap(common.AMERICA)), ('ANTARCTICA', space.wrap(common.ANTARCTICA)), ('ARCTIC', space.wrap(common.ARCTIC)), ('ASIA', space.wrap(common.ASIA)), ('ATLANTIC', space.wrap(common.ATLANTIC)), ('AUSTRALIA', space.wrap(common.AUSTRALIA)), ('EUROPE', space.wrap(common.EUROPE)), ('INDIAN', space.wrap(common.INDIAN)), ('PACIFIC', space.wrap(common.PACIFIC)), ('UTC', space.wrap(common.UTC)), ('ALL', space.wrap(common.ALL)), ('ALL_WITH_BC', space.wrap(common.ALL_WITH_BC)), ('PER_COUNTRY', space.wrap(common.PER_COUNTRY))], instance_class=W_DateTimeZone )
@wrap_method(['interp', ThisUnwrapper(W_IteratorIterator)], name='IteratorIterator::rewind') def ii_rewind(interp, this): return interp.getmeth(this.inner, 'rewind').call_args(interp, []) @wrap_method(['interp', ThisUnwrapper(W_IteratorIterator)], name='IteratorIterator::valid') def ii_valid(interp, this): return interp.getmeth(this.inner, 'valid').call_args(interp, []) k_IteratorIterator = def_class('IteratorIterator', [ ii_construct, ii_current, ii_getInnerIterator, ii_key, ii_next, ii_rewind, ii_valid ], implements=[k_OuterIterator], instance_class=W_IteratorIterator) class W_AppendIterator(W_IteratorIterator): w_iterators = None def check_state(self, interp): if self.w_iterators is None: interp.throw( "The object is in an invalid state as the parent " "constructor was not called", klass=k_LogicException) def valid(self, interp):
@wrap_method(['interp', ThisUnwrapper(W_ExceptionObject)], name='Exception::getTraceAsString') def exc_getTraceAsString(interp, this): msg = [] for i, (filename, funcname, line, source) in enumerate(this.traceback): msg.append("#%d %s(%d): %s()" % (i, filename, line, funcname)) return interp.space.wrap("\n".join(msg)) k_Exception = def_class('Exception', [new_exception, exc_getMessage, exc_getCode, exc_getPrevious, exc_getTrace, exc_getFile, exc_getLine, exc___toString, exc_getTraceAsString], [('message', consts.ACC_PROTECTED), ('code', consts.ACC_PROTECTED), ('previous', consts.ACC_PRIVATE), ('file', consts.ACC_PROTECTED), ('line', consts.ACC_PROTECTED), ], instance_class=W_ExceptionObject) def_class('OutOfBoundsException', [], extends=k_Exception, instance_class=W_ExceptionObject) k_stdClass = def_class('stdClass', []) k_incomplete = def_class('__PHP_Incomplete_Class', []) k_RuntimeException = def_class('RuntimeException', [], extends=k_Exception, instance_class=W_ExceptionObject) k_LogicException = def_class('LogicException', [], extends=k_Exception, instance_class=W_ExceptionObject) k_DomainException = def_class('DomainException', [], extends=k_Exception, instance_class=W_ExceptionObject) class W_ReflectionObject(W_InstanceObject):
return _get_name(interp, this) def _get_class(interp, this): return interp.space.wrap(this.ref_klass.name) def _set_class(interp, this, w_value): pass def _get_name(interp, this): return interp.space.wrap(this.ref_method.get_name()) def _set_name(interp, this, w_value): pass ReflectionFunctionAbstract = def_class( "ReflectionFunctionAbstract", [get_name], [ GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC), GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC), ], [], flags=consts.ACC_ABSTRACT, instance_class=W_ReflectionFunctionAbstract, )
"""Interfaces defined by the SPL extension""" from hippy import consts from hippy.klass import def_class from hippy.builtin_klass import new_abstract_method, k_Iterator k_Countable = def_class('Countable', [new_abstract_method(["interp"], name="Countable::count")], flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT) k_OuterIterator = def_class('OuterIterator', [new_abstract_method(["interp"], name="OuterIterator::getInnerIterator")], flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT, extends=k_Iterator) k_RecursiveIterator = def_class('RecursiveIterator', [new_abstract_method(["interp"], name="RecursiveIterator::hasChildren"), new_abstract_method(["interp"], name="RecursiveIterator::getChildren")], flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT, extends=k_Iterator) k_SeekableIterator = def_class('SeekableIterator', [new_abstract_method(["interp"], name="SeekableIterator::seek")], flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT, extends=k_Iterator)
)) return self.space.new_array_from_pairs(parameters) def _get_name(interp, this): return this.ref_fun.get_name() def _set_name(interp, this, w_value): pass k_ReflectionFunction = def_class( 'ReflectionFunction', ["__construct", "getName", "getDocComment", "getParameters"], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_DEPRECATED', W_IntObject(IS_DEPRECATED))], instance_class=W_ReflectionFunction, extends=k_ReflectionFunctionAbstract ) @k_ReflectionFunction.def_method(['interp', 'this', W_Root]) def __construct(interp, this, function): if isinstance(function, W_ClosureObject): this.ref_fun = ClosureWrapper(interp, function) else: this.ref_fun = NameWrapper(interp, function) @k_ReflectionFunction.def_method(['interp', 'this']) def getName(interp, this):
k_DateTime = def_class( 'DateTime', [construct, format, modify, get_timestamp, set_timestamp, get_timezone, set_date, set_iso_date, set_time, set_timezone, # create_from_format, get_last_errors, sub, add, diff, get_offset], [GetterSetterWrapper(_get_date, _set_date, "date", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone_type, _set_timezone_type, "timezone_type", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone, _set_timezone, "timezone", consts.ACC_PUBLIC)], [('ATOM', space.wrap("Y-m-d\TH:i:sP")), ('COOKIE', space.wrap("l, d-M-y H:i:s T")), ('ISO8601', space.wrap("Y-m-d\TH:i:sO")), ('RFC822', space.wrap("D, d M y H:i:s O")), ('RFC850', space.wrap("l, d-M-y H:i:s T")), ('RFC1036', space.wrap("D, d M y H:i:s O")), ('RFC1123', space.wrap("D, d M Y H:i:s O")), ('RFC2822', space.wrap("D, d M Y H:i:s O")), ('RFC3339', space.wrap("Y-m-d\TH:i:sP")), ('RSS', space.wrap("D, d M Y H:i:s O")), ('W3C', space.wrap("Y-m-d\TH:i:sP"))], instance_class=W_DateTime )
def dir_rewind(interp, this, w_dir=None): if w_dir is None: w_dir = this.handle if not w_dir.is_valid(): interp.warn("Directory::rewind(): %d is not a valid Directory resource" % w_dir.res_id) return interp.space.w_False else: w_dir.rewind() return interp.space.w_Null @wrap_method(['interp', ThisUnwrapper(W_Directory), Optional(Resource(W_DirResource, True))], name='Directory::close') def dir_close(interp, this, w_dir=None): if not w_dir: w_dir = this.handle assert isinstance(w_dir, W_DirResource) w_dir.close() return interp.space.w_Null k_Directory = def_class('Directory', [dir_read, dir_rewind, dir_close], [GetterSetterWrapper(_get_path, _set_path, "path", consts.ACC_PUBLIC), GetterSetterWrapper(_get_handle, _set_handle, "handle", consts.ACC_PUBLIC)], instance_class=W_Directory )
k_DateTime = def_class( "DateTime", [ construct, format, modify, get_timestamp, set_timestamp, get_timezone, set_date, set_iso_date, set_time, set_timezone, create_from_format, get_last_errors, sub, add, diff, get_offset, ], [ GetterSetterWrapper(_get_date, _set_date, "date", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone_type, _set_timezone_type, "timezone_type", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone, _set_timezone, "timezone", consts.ACC_PUBLIC), ], [ ("ATOM", space.wrap("Y-m-d\TH:i:sP")), ("COOKIE", space.wrap("l, d-M-y H:i:s T")), ("ISO8601", space.wrap("Y-m-d\TH:i:sO")), ("RFC822", space.wrap("D, d M y H:i:s O")), ("RFC850", space.wrap("l, d-M-y H:i:s T")), ("RFC1036", space.wrap("D, d M y H:i:s O")), ("RFC1123", space.wrap("D, d M Y H:i:s O")), ("RFC2822", space.wrap("D, d M Y H:i:s O")), ("RFC3339", space.wrap("Y-m-d\TH:i:sP")), ("RSS", space.wrap("D, d M Y H:i:s O")), ("W3C", space.wrap("Y-m-d\TH:i:sP")), ], instance_class=W_DateTime, )
from hippy.klass import def_class from hippy.builtin_klass import k_Exception, W_ExceptionObject k_ReflectionException = def_class('ReflectionException', [], extends=k_Exception, instance_class=W_ExceptionObject)
k_DateTimeZone = def_class( 'DateTimeZone', [construct, get_name, get_offset, list_abbreviations, identifiers_list, get_transition], [], [('AFRICA', space.wrap(common.AFRICA)), ('AMERICA', space.wrap(common.AMERICA)), ('ANTARCTICA', space.wrap(common.ANTARCTICA)), ('ARCTIC', space.wrap(common.ARCTIC)), ('ASIA', space.wrap(common.ASIA)), ('ATLANTIC', space.wrap(common.ATLANTIC)), ('AUSTRALIA', space.wrap(common.AUSTRALIA)), ('EUROPE', space.wrap(common.EUROPE)), ('INDIAN', space.wrap(common.INDIAN)), ('PACIFIC', space.wrap(common.PACIFIC)), ('UTC', space.wrap(common.UTC)), ('ALL', space.wrap(common.ALL)), ('ALL_WITH_BC', space.wrap(common.ALL_WITH_BC)), ('PER_COUNTRY', space.wrap(common.PER_COUNTRY))], instance_class=W_DateTimeZone )
def ii_next(interp, this): return interp.getmeth(this.inner, 'next').call_args(interp, []) @wrap_method(['interp', ThisUnwrapper(W_IteratorIterator)], name='IteratorIterator::rewind') def ii_rewind(interp, this): return interp.getmeth(this.inner, 'rewind').call_args(interp, []) @wrap_method(['interp', ThisUnwrapper(W_IteratorIterator)], name='IteratorIterator::valid') def ii_valid(interp, this): return interp.getmeth(this.inner, 'valid').call_args(interp, []) k_IteratorIterator = def_class( 'IteratorIterator', [ii_construct, ii_current, ii_getInnerIterator, ii_key, ii_next, ii_rewind, ii_valid], implements=[k_OuterIterator], instance_class=W_IteratorIterator) class W_AppendIterator(W_IteratorIterator): w_iterators = None def check_state(self, interp): if self.w_iterators is None: interp.throw("The object is in an invalid state as the parent " "constructor was not called", klass=k_LogicException) def valid(self, interp): if self.inner is None: return False
return space.wrap("\n".join(msg)) @wrap_method(['interp', ThisUnwrapper(W_ExceptionObject)], name='Exception::getTraceAsString') def exc_getTraceAsString(interp, this): msg = [] for i, (filename, funcname, line, source) in enumerate(this.traceback): msg.append("#%d %s(%d): %s()" % (i, filename, line, funcname)) return interp.space.wrap("\n".join(msg)) k_Exception = def_class('Exception', [new_exception, exc_getMessage, exc_getCode, exc_getPrevious, exc_getTrace, exc_getFile, exc_getLine, exc___toString, exc_getTraceAsString], [('message', consts.ACC_PROTECTED), ('code', consts.ACC_PROTECTED), ('previous', consts.ACC_PRIVATE), ('file', consts.ACC_PROTECTED), ('line', consts.ACC_PROTECTED)], instance_class=W_ExceptionObject) def_class('OutOfBoundsException', [], extends=k_Exception) k_stdClass = def_class('stdClass', []) k_incomplete = def_class('__PHP_Incomplete_Class', []) k_RuntimeException = def_class('RuntimeException', [], extends=k_Exception) k_LogicException = def_class('LogicException', [], extends=k_Exception) k_DomainException = def_class('DomainException', [], extends=k_Exception) k_UnexpectedValueException = def_class('UnexpectedValueException', [], extends=k_Exception)
@wrap_method(['interp', ThisUnwrapper(W_ReflectionFunctionAbstractObject)], name='ReflectionFunction::getParameters') def get_parameters(interp, this): return this.ref_fun.get_parameters() @wrap_method(['interp', ThisUnwrapper(W_ReflectionFunctionAbstractObject)], name='ReflectionFunction::getDocComment') def get_doc_comment(interp, this): return interp.space.wrap("") def _get_name(interp, this): return this.ref_fun.get_name() def _set_name(interp, this, w_value): pass def_class( 'ReflectionFunction', [construct, get_name, get_doc_comment, get_parameters], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_DEPRECATED', W_IntObject(IS_DEPRECATED))], instance_class=W_ReflectionFunctionObject, extends=ReflectionFunctionAbstract )
def _get_name(interp, this): return interp.space.wrap(this.ref_method.get_name()) def _set_name(interp, this, w_value): pass k_ReflectionMethod = def_class('ReflectionMethod', [ '__construct', 'isPublic', 'isstatic', 'getDocComment', 'getParameters', 'getDeclaringClass' ], [ GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC), GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC) ], [('IS_STATIC', W_IntObject(IS_STATIC)), ('IS_PUBLIC', W_IntObject(IS_PUBLIC)), ('IS_PROTECTED', W_IntObject(IS_PROTECTED)), ('IS_PRIVATE', W_IntObject(IS_PRIVATE)), ('IS_ABSTRACT', W_IntObject(IS_ABSTRACT)), ('IS_FINAL', W_IntObject(IS_FINAL))], instance_class=W_ReflectionMethodObject, extends=k_ReflectionFunctionAbstract) @k_ReflectionMethod.def_method(['interp', 'this', str, str]) def __construct(interp, this, class_name, method_name): klass = interp.lookup_class_or_intf(class_name) this.ref_klass = klass try: this.ref_method = klass.methods[method_name]
def_class( "ReflectionClass", [ reflection_class_construct, reflection_class_new_instance, reflection_class_new_instance_args, reflection_class_has_constant, reflection_class_get_constant, reflection_class_get_constants, reflection_class_get_constructor, reflection_class_get_default_properties, reflection_class_get_doc_comment, reflection_class_get_end_line, reflection_class_get_interfaces, reflection_class_get_interface_names, reflection_class_get_method, reflection_class_get_methods, reflection_class_get_modifiers, reflection_class_get_name, reflection_class_get_start_line, reflection_class_get_file_name, reflection_class_get_extension, reflection_class_get_extension_name, reflection_class_get_namespace_name, reflection_class_get_static_properties, reflection_class_get_properties, reflection_class_get_property, reflection_class_has_property, reflection_class_is_subclass_of, reflection_class_is_instantiable, reflection_class_has_method, reflection_class_is_abstract, ], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [ ("IS_IMPLICIT_ABSTRACT", W_IntObject(IS_IMPLICIT_ABSTRACT)), ("IS_EXPLICIT_ABSTRACT", W_IntObject(IS_EXPLICIT_ABSTRACT)), ("IS_FINAL", W_IntObject(IS_FINAL)), ], instance_class=W_ReflectionClass, )
return this.ref_fun.get_name() @wrap_method(['interp', ThisUnwrapper(W_ReflectionFunction)], name='ReflectionFunction::getParameters') def get_parameters(interp, this): return this.ref_fun.get_parameters() @wrap_method(['interp', ThisUnwrapper(W_ReflectionFunction)], name='ReflectionFunction::getDocComment') def get_doc_comment(interp, this): return interp.space.wrap("") def _get_name(interp, this): return this.ref_fun.get_name() def _set_name(interp, this, w_value): pass def_class( 'ReflectionFunction', [construct, get_name, get_doc_comment, get_parameters], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [('IS_DEPRECATED', W_IntObject(IS_DEPRECATED))], instance_class=W_ReflectionFunction, extends=ReflectionFunctionAbstract)
return interp.getmeth(this.inner, "next").call_args(interp, []) @wrap_method(["interp", ThisUnwrapper(W_IteratorIterator)], name="IteratorIterator::rewind") def ii_rewind(interp, this): return interp.getmeth(this.inner, "rewind").call_args(interp, []) @wrap_method(["interp", ThisUnwrapper(W_IteratorIterator)], name="IteratorIterator::valid") def ii_valid(interp, this): return interp.getmeth(this.inner, "valid").call_args(interp, []) k_IteratorIterator = def_class( "IteratorIterator", [ii_construct, ii_current, ii_getInnerIterator, ii_key, ii_next, ii_rewind, ii_valid], implements=[k_OuterIterator], instance_class=W_IteratorIterator, ) class W_AppendIterator(W_IteratorIterator): w_iterators = None def check_state(self, interp): if self.w_iterators is None: interp.throw( "The object is in an invalid state as the parent " "constructor was not called", klass=k_LogicException ) def valid(self, interp): if self.inner is None:
@wrap_method(['interp', ThisUnwrapper(W_ReflectionFunctionAbstract)], name='ReflectionFunctionAbstract::getName') def get_name(interp, this): return _get_name(interp, this) def _get_class(interp, this): return interp.space.wrap(this.ref_klass.name) def _set_class(interp, this, w_value): pass def _get_name(interp, this): return interp.space.wrap(this.ref_method.get_name()) def _set_name(interp, this, w_value): pass ReflectionFunctionAbstract = def_class( 'ReflectionFunctionAbstract', [get_name], [ GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC), GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC) ], [], flags=consts.ACC_ABSTRACT, instance_class=W_ReflectionFunctionAbstract)
def get_callable(self): w_this = self.w_this if self.static is False else None thisclass = w_this.klass if w_this is not None else None return W_CallClosure(thisclass, self._func, w_this, self.closure_args) def put_closure(self, args_w): n = len(self.closure_args) for i, w_arg in enumerate(args_w): self.closure_args[n - i - 1] = w_arg def getmeth(self, space, name, contextclass=None): if name.lower() == "__invoke": return self.get_callable() return W_InstanceObject.getmeth(self, space, name, contextclass) @wrap_method(['interp', ThisUnwrapper(W_ClosureObject), 'args_w'], name='Closure::__invoke') def closure_invoke(interp, this, args_w): return this._func.call_args(interp, args_w) k_Closure = def_class('Closure', [closure_invoke]) def new_closure(space, func, w_this, static=False): if k_Closure.initial_storage_w is None: k_Closure._create_initial_storage(space) w_res = W_ClosureObject(func, k_Closure, k_Closure.initial_storage_w[:], w_this=w_this, static=static) return w_res
def _set_timezone_type(interp, this, w_value): pass space = getspace() k_DateTime = def_class('DateTime', [ construct, format, modify, get_timestamp, set_timestamp, get_timezone, set_date, set_iso_date, set_time, set_timezone, create_from_format, get_last_errors, sub, add, diff, get_offset ], [ GetterSetterWrapper(_get_date, _set_date, "date", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone_type, _set_timezone_type, "timezone_type", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone, _set_timezone, "timezone", consts.ACC_PUBLIC) ], [('ATOM', space.wrap("Y-m-d\TH:i:sP")), ('COOKIE', space.wrap("l, d-M-y H:i:s T")), ('ISO8601', space.wrap("Y-m-d\TH:i:sO")), ('RFC822', space.wrap("D, d M y H:i:s O")), ('RFC850', space.wrap("l, d-M-y H:i:s T")), ('RFC1036', space.wrap("D, d M y H:i:s O")), ('RFC1123', space.wrap("D, d M Y H:i:s O")), ('RFC2822', space.wrap("D, d M Y H:i:s O")), ('RFC3339', space.wrap("Y-m-d\TH:i:sP")), ('RSS', space.wrap("D, d M Y H:i:s O")), ('W3C', space.wrap("Y-m-d\TH:i:sP"))], instance_class=W_DateTime)
klass_name = interp.space.str_w(args[0]) method_name = interp.space.str_w(args[1]) klass = interp.lookup_class_or_intf(klass_name) method = klass.methods[method_name] signature = method.get_signature() this.ref_parameter = signature.args[parameter] @wrap_method(['interp', ThisUnwrapper(W_ReflectionParameterObject)], name='ReflectionParameter::getName') def get_name(interp, this): return _get_name(interp, this) def _get_name(interp, this): return interp.space.wrap(this.ref_parameter.name) def _set_name(interp, this, w_value): pass ReflectionParameter = def_class( 'ReflectionParameter', [construct, get_name], [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)], [], instance_class=W_ReflectionParameterObject )