예제 #1
0
 def method_sub(self, space, w_other):
     if isinstance(w_other, W_TimeObject):
         return space.newfloat(self.epoch_seconds -
                               Coerce.float(space, w_other))
     else:
         w_time = space.send(space.getclassfor(W_TimeObject), "allocate")
         w_time._set_epoch_seconds(self.epoch_seconds -
                                   Coerce.float(space, w_other))
         w_time._set_offset(self.offset)
         return w_time
예제 #2
0
 def method_sub(self, space, w_other):
     if isinstance(w_other, W_TimeObject):
         return space.newfloat(
             self.epoch_seconds - Coerce.float(space, w_other))
     else:
         w_time = space.send(space.getclassfor(W_TimeObject), "allocate")
         w_time._set_epoch_seconds(
             self.epoch_seconds - Coerce.float(space, w_other))
         w_time._set_offset(self.offset)
         return w_time
예제 #3
0
 def method_at(self, space, w_time, w_microtime=None):
     if not (w_time.is_kind_of(space, space.w_numeric)
             or w_time.is_kind_of(space, space.getclassfor(W_TimeObject))):
         raise space.error(space.w_TypeError)
     if w_microtime is not None:
         microtime = Coerce.float(space, w_microtime) * 0.000001
     else:
         microtime = 0.0
     timestamp = Coerce.float(space, w_time)
     w_time = space.send(self, "new")
     w_time._set_epoch_seconds(timestamp + microtime)
     return w_time
예제 #4
0
 def method_at(self, space, w_time, w_microtime=None):
     if not (w_time.is_kind_of(space, space.w_numeric) or
             w_time.is_kind_of(space, space.getclassfor(W_TimeObject))):
         raise space.error(space.w_TypeError)
     if w_microtime is not None:
         microtime = Coerce.float(space, w_microtime) * 0.000001
     else:
         microtime = 0.0
     timestamp = Coerce.float(space, w_time)
     w_time = space.send(self, "new")
     w_time._set_epoch_seconds(timestamp + microtime)
     return w_time
예제 #5
0
    def method_gm(self, space, args_w):
        if len(args_w) == 0:
            raise space.error(
                space.w_ArgumentError,
                "wrong number of arguments (given 0, expected 1..8)"
            )
        elif len(args_w) == 10:
            # sec, min, hour, day, month, year, dummy, dummy, dummy, dummy
            sec = Coerce.int(space, args_w[0])
            minute = Coerce.int(space, args_w[1])
            hour = Coerce.int(space, args_w[2])
            day = Coerce.int(space, args_w[3])
            month = W_TimeObject.month_arg_to_month(space, args_w[4])
            year = Coerce.int(space, args_w[5])
            usecfrac = 0.0
        else:
            month = day = 1
            hour = minute = sec = 0
            usecfrac = 0.0
            year = Coerce.int(space, args_w[0])
            if len(args_w) > 1:
                month = W_TimeObject.month_arg_to_month(space, args_w[1])
            if len(args_w) > 2:
                day = Coerce.int(space, args_w[2])
            if len(args_w) > 3:
                hour = Coerce.int(space, args_w[3])
            if len(args_w) > 4:
                minute = Coerce.int(space, args_w[4])
            if len(args_w) > 6:
                sec = Coerce.int(space, args_w[5])
                usecfrac = Coerce.float(space, args_w[6]) / 1000000
            if len(args_w) > 5:
                fsec = Coerce.float(space, args_w[5])
                sec = int(math.floor(fsec))
                usecfrac = fsec - sec

        if not (1 <= month < 12):
            raise space.error(space.w_ArgumentError, "mon out of range")
        if not (1 <= day < 31):
            raise space.error(space.w_ArgumentError, "argument out of range")
        if not (0 <= hour < 24):
            raise space.error(space.w_ArgumentError, "argument out of range")
        if not (0 <= minute < 60):
            raise space.error(space.w_ArgumentError, "argument out of range")
        if not (0 <= sec < 60):
            raise space.error(space.w_ArgumentError, "argument out of range")

        w_time = space.send(space.getclassfor(W_TimeObject), "new")
        w_time._set_epoch_seconds(
            mktime(year, month, day, hour, minute, sec) + usecfrac)
        return w_time
예제 #6
0
    def method_gm(self, space, args_w):
        if len(args_w) == 0:
            raise space.error(
                space.w_ArgumentError,
                "wrong number of arguments (given 0, expected 1..8)")
        elif len(args_w) == 10:
            # sec, min, hour, day, month, year, dummy, dummy, dummy, dummy
            sec = Coerce.int(space, args_w[0])
            minute = Coerce.int(space, args_w[1])
            hour = Coerce.int(space, args_w[2])
            day = Coerce.int(space, args_w[3])
            month = W_TimeObject.month_arg_to_month(space, args_w[4])
            year = Coerce.int(space, args_w[5])
            usecfrac = 0.0
        else:
            month = day = 1
            hour = minute = sec = 0
            usecfrac = 0.0
            year = Coerce.int(space, args_w[0])
            if len(args_w) > 1:
                month = W_TimeObject.month_arg_to_month(space, args_w[1])
            if len(args_w) > 2:
                day = Coerce.int(space, args_w[2])
            if len(args_w) > 3:
                hour = Coerce.int(space, args_w[3])
            if len(args_w) > 4:
                minute = Coerce.int(space, args_w[4])
            if len(args_w) > 6:
                sec = Coerce.int(space, args_w[5])
                usecfrac = Coerce.float(space, args_w[6]) / 1000000
            if len(args_w) > 5:
                fsec = Coerce.float(space, args_w[5])
                sec = int(math.floor(fsec))
                usecfrac = fsec - sec

        if not (1 <= month < 12):
            raise space.error(space.w_ArgumentError, "mon out of range")
        if not (1 <= day < 31):
            raise space.error(space.w_ArgumentError, "argument out of range")
        if not (0 <= hour < 24):
            raise space.error(space.w_ArgumentError, "argument out of range")
        if not (0 <= minute < 60):
            raise space.error(space.w_ArgumentError, "argument out of range")
        if not (0 <= sec < 60):
            raise space.error(space.w_ArgumentError, "argument out of range")

        w_time = space.send(space.getclassfor(W_TimeObject), "new")
        w_time._set_epoch_seconds(
            mktime(year, month, day, hour, minute, sec) + usecfrac)
        return w_time
예제 #7
0
 def method_plus(self, space, w_other):
     if isinstance(w_other, W_TimeObject):
         raise space.error(space.w_TypeError, "time + time?")
     w_time = space.send(space.getclassfor(W_TimeObject), "allocate")
     w_time._set_epoch_seconds(self.epoch_seconds +
                               Coerce.float(space, w_other))
     w_time._set_offset(self.offset)
     return w_time
예제 #8
0
파일: kernel.py 프로젝트: nightsailer/topaz
 def method_sleep(self, space, w_duration=None):
     if w_duration is None:
         raise space.error(space.w_NotImplementedError)
     elif space.is_kind_of(w_duration, space.w_string):
         raise space.error(space.w_TypeError, "can't convert String into time interval")
     start = time.time()
     time.sleep(Coerce.float(space, w_duration))
     return space.newint(int(round_double(time.time() - start, 0)))
예제 #9
0
 def method_at(self, space, w_time):
     if not (w_time.is_kind_of(space, space.w_numeric) or
             w_time.is_kind_of(space, space.getclassfor(W_TimeObject))):
         raise space.error(space.w_TypeError)
     timestamp = Coerce.float(space, w_time)
     w_time = space.send(self, "new")
     w_time._set_epoch_seconds(timestamp)
     return w_time
예제 #10
0
파일: math.py 프로젝트: gemoe100/topaz
 def wrapper(self, space, args_w):
     if len(args_w) == 2:
         w_value1, w_value2 = args_w
     else:
         # delegate and hope that the gateway will raise an
         # ArgumentError
         args = [Coerce.float(space, w_arg) for w_arg in args_w]
         return func(self, space, args)
     if space.is_kind_of(w_value1, space.w_numeric):
         if space.is_kind_of(w_value2, space.w_numeric):
             value1 = Coerce.float(space, w_value1)
             value2 = Coerce.int(space, w_value2)
             return func(self, space, value1, value2)
         else:
             raise_type_error(space, w_value2)
     else:
         raise_type_error(space, w_value1)
예제 #11
0
 def method_plus(self, space, w_other):
     if isinstance(w_other, W_TimeObject):
         raise space.error(space.w_TypeError, "time + time?")
     w_time = space.send(space.getclassfor(W_TimeObject), "allocate")
     w_time._set_epoch_seconds(
         self.epoch_seconds + Coerce.float(space, w_other))
     w_time._set_offset(self.offset)
     return w_time
예제 #12
0
 def method_sleep(self, space, w_duration=None):
     if w_duration is None:
         raise space.error(space.w_NotImplementedError)
     elif space.is_kind_of(w_duration, space.w_string):
         raise space.error(space.w_TypeError, "can't convert String into time interval")
     start = time.time()
     time.sleep(Coerce.float(space, w_duration))
     return space.newint(int(round_double(time.time() - start, 0)))
예제 #13
0
파일: math.py 프로젝트: gemoe100/topaz
 def wrapper(self, space, args_w):
     f_args = []
     for w_arg in args_w:
         if space.is_kind_of(w_arg, space.w_numeric):
             f_arg = Coerce.float(space, w_arg)
             f_args.append(f_arg)
         else:
             raise_type_error(space, w_arg)
     return func(self, space, *f_args)
예제 #14
0
 def method_div(self, space, w_other):
     if space.is_kind_of(w_other, space.w_float):
         if space.float_w(w_other) == 0.0:
             self.raise_zero_division_error(space)
         else:
             w_float = space.send(space.newfloat(space.float_w(self)), "/", [w_other])
             w_float = space.newfloat(math.floor(Coerce.float(space, w_float)))
             return space.send(w_float, "to_i")
     else:
         return self.divide(space, w_other)
예제 #15
0
 def method_div(self, space, w_other):
     if space.is_kind_of(w_other, space.w_float):
         if space.float_w(w_other) == 0.0:
             self.raise_zero_division_error(space)
         else:
             w_float = space.send(space.newfloat(space.float_w(self)), "/",
                                  [w_other])
             w_float = space.newfloat(
                 math.floor(Coerce.float(space, w_float)))
             return space.send(w_float, "to_i")
     else:
         return self.divide(space, w_other)
예제 #16
0
 def method_ceil(self, space):
     return space.newint(int(math.ceil(Coerce.float(space, self))))
예제 #17
0
 def _rand_float(self, space, float):
     random = self.random.random()
     max = Coerce.float(space, float)
     if max <= 0:
         raise space.error(space.w_ArgumentError, "invalid argument")
     return space.newfloat(random * max)
예제 #18
0
 def method_floor(self, space):
     return space.newint(int(math.floor(Coerce.float(space, self))))
예제 #19
0
 def method_ceil(self, space):
     return space.newint(int(math.ceil(Coerce.float(space, self))))
예제 #20
0
 def _rand_bignum(self, space, bignum):
     random = self.random.random()
     max = Coerce.float(space, bignum)
     if max <= 0:
         raise space.error(space.w_ArgumentError, "invalid argument")
     return space.newbigint_fromfloat(random * max)
예제 #21
0
 def fmt_f(self, space, width):
     num = Coerce.float(space, self._next_item())
     return self._fmt_num(space, formatd(num, "f", 6), width)
예제 #22
0
 def _rand_bignum(self, space, bignum):
     random = self.random.random()
     max = Coerce.float(space, bignum)
     if max <= 0:
         raise space.error(space.w_ArgumentError, "invalid argument")
     return space.newbigint_fromfloat(random * max)
예제 #23
0
 def fmt_f(self, space, width, precision, format_char):
     num = Coerce.float(space, self._next_item())
     return self._fmt_num(space, formatd(num, "f", precision), width)
예제 #24
0
 def method_floor(self, space):
     return space.newint(int(math.floor(Coerce.float(space, self))))
예제 #25
0
 def method_round(self, space):
     return space.newint(int(round_away(Coerce.float(space, self))))
예제 #26
0
 def method_round(self, space):
     return space.newint(int(round_away(Coerce.float(space, self))))
예제 #27
0
 def _rand_float(self, space, float):
     random = self.random.random()
     max = Coerce.float(space, float)
     if max <= 0:
         raise space.error(space.w_ArgumentError, "invalid argument")
     return space.newfloat(random * max)