def construct(interp, this, format_string=None, w_datetimezone=None): error = common.initialize_date(interp, 'DateTime::__construct', this, format_string, w_datetimezone) if error: raise PHPException(k_Exception.call_args( interp, [interp.space.wrap("%s(): %s" % ('DateTime::__construct', error))] ))
def construct(interp, this, spec): exc_obj = k_Exception.call_args( interp, [interp.space.wrap('Unknown or bad format (%s)' % spec)] ) if not (len(spec) > 1 and spec[0] == 'P'): raise PHPException(exc_obj) index = 1 time = False formats = {'y': 0, 'm': 0, 'd':0, 'h':0, 'i':0 ,'s': 0} while index < len(spec): format = None times = 0 if spec[index] == 'T': index += 1 time = True while spec[index].isdigit(): times = times * 10 times = times + (ord(spec[index]) - ord('0')) index += 1 if times: if spec[index] == 'Y': format = 'y' elif spec[index] == 'M' and not time: format = 'm' elif spec[index] == 'D': format = 'd' elif spec[index] == 'W': format = 'd' times *= 7 elif spec[index] == 'H': format = 'h' elif spec[index] == 'M' and time: format = 'i' elif spec[index] == 'S': format = 's' if not formats[format]: formats[format] = times else: raise PHPException(exc_obj) index += 1 this.time_diff = timelib.timelib_rel_time_ctor() this.time_diff.c_y = rffi.cast(lltype.Signed, formats['y']) this.time_diff.c_m = rffi.cast(lltype.Signed, formats['m']) this.time_diff.c_d = rffi.cast(lltype.Signed, formats['d']) this.time_diff.c_h = rffi.cast(lltype.Signed, formats['h']) this.time_diff.c_i = rffi.cast(lltype.Signed, formats['i']) this.time_diff.c_s = rffi.cast(lltype.Signed, formats['s'])
def construct(interp, this, format_string=None, w_datetimezone=None): error = common.initialize_date(interp, 'DateTime::__construct', this, format_string, w_datetimezone) if error: raise PHPException( k_Exception.call_args(interp, [ interp.space.wrap("%s(): %s" % ('DateTime::__construct', error)) ]))
def initialize_timezone(interp, func_name, this, name, warning=False): this.timelib_timezone = timelib.timelib_parse_tzfile( rffi.str2charp(name), timelib.timelib_builtin_db()) if this.timelib_timezone == lltype.nullptr(timelib.timelib_tzinfo.TO): message = "%s(): Unknown or bad timezone (%s)" % (func_name, name) if warning: interp.space.ec.warn(message) else: raise PHPException( k_Exception.call_args(interp, [interp.space.wrap(message)])) return False return True
def initialize_timezone(interp, func_name, this, name, warning=False): this.timelib_timezone = timelib.timelib_parse_tzfile( rffi.str2charp(name), timelib.timelib_builtin_db() ) if this.timelib_timezone == lltype.nullptr(timelib.timelib_tzinfo.TO): message = "%s(): Unknown or bad timezone (%s)" % (func_name, name) if warning: interp.space.ec.warn(message) else: raise PHPException(k_Exception.call_args( interp, [interp.space.wrap(message)] )) return False return True
def _create_iter(self, space, contextclass, byref): klass = self.getclass() if klass.is_iterator: return InstanceIterator(space, self) elif klass.is_iterable: interp = space.ec.interpreter w_iterator = interp.getmeth(self, 'getIterator').call_args(interp, []) if not (isinstance(w_iterator, W_InstanceObject) and w_iterator.klass.is_subclass_of_class_or_intf_name('Traversable')): from hippy.builtin_klass import k_Exception raise PHPException(k_Exception.call_args(interp, [space.wrap( "Objects returned by %s::getIterator() must be " "traversable or implement interface Iterator" % klass.name)])) return w_iterator.create_iter(space) else: return self._create_fixed_iter(space, contextclass, byref)
def _create_iter(self, space, contextclass, byref): klass = self.getclass() if klass.is_iterator: return InstanceIterator(space, self) elif klass.is_iterable: interp = space.ec.interpreter w_iterator = interp.getmeth(self, 'getIterator').call_args(interp, []) if not (isinstance(w_iterator, W_InstanceObject) and w_iterator.getclass().is_subclass_of_class_or_intf_name('Traversable')): from hippy.builtin_klass import k_Exception raise PHPException(k_Exception.call_args(interp, [space.wrap( "Objects returned by %s::getIterator() must be " "traversable or implement interface Iterator" % klass.name)])) return w_iterator.create_iter(space) else: return self._create_fixed_iter(space, contextclass, byref)
def handle_as_exception(interp, message): from hippy.builtin_klass import k_Exception raise Throw(k_Exception.call_args( interp, [interp.space.wrap(message)]))
def handle_as_exception(interp, message): from hippy.builtin_klass import k_Exception raise PHPException(k_Exception.call_args( interp, [interp.space.wrap(message)]))