コード例 #1
0
ファイル: datetime_klass.py プロジェクト: LewisGet/hippyvm
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))]
        ))
コード例 #2
0
ファイル: dateinterval_klass.py プロジェクト: youaani/hippyvm
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'])
コード例 #3
0
ファイル: datetime_klass.py プロジェクト: netyum/hippyvm
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))
            ]))
コード例 #4
0
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
コード例 #5
0
ファイル: common.py プロジェクト: LewisGet/hippyvm
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
コード例 #6
0
ファイル: instanceobject.py プロジェクト: cklein/hippyvm
 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)
コード例 #7
0
ファイル: instanceobject.py プロジェクト: xhava/hippyvm
 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)
コード例 #8
0
ファイル: builtin.py プロジェクト: LegendZhu/hippyvm
def handle_as_exception(interp, message):
    from hippy.builtin_klass import k_Exception
    raise Throw(k_Exception.call_args(
        interp, [interp.space.wrap(message)]))
コード例 #9
0
ファイル: builtin.py プロジェクト: netyum/hippyvm
def handle_as_exception(interp, message):
    from hippy.builtin_klass import k_Exception
    raise PHPException(k_Exception.call_args(
        interp, [interp.space.wrap(message)]))