当前位置: 首页>>代码示例>>Python>>正文


Python Coerce.int方法代码示例

本文整理汇总了Python中topaz.coerce.Coerce.int方法的典型用法代码示例。如果您正苦于以下问题:Python Coerce.int方法的具体用法?Python Coerce.int怎么用?Python Coerce.int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在topaz.coerce.Coerce的用法示例。


在下文中一共展示了Coerce.int方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: coerce_address

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
def coerce_address(space, w_addressable):
    if space.is_kind_of(w_addressable, space.w_bignum):
        return Coerce.int(space, w_addressable)
    elif space.is_kind_of(w_addressable, space.w_fixnum):
        return Coerce.int(space, w_addressable)
    elif space.is_kind_of(w_addressable,
                          space.getclassfor(W_PointerObject)):
        w_address = space.send(w_addressable, 'address')
        return coerce_address(space, w_address)
    else:
        errmsg = ("can't convert %s into FFI::Pointer" %
                  space.getclass(w_addressable).name)
        raise space.error(space.w_TypeError, errmsg)
开发者ID:mswart,项目名称:topaz,代码行数:15,代码来源:pointer.py

示例2: method_gm

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
    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
开发者ID:topazproject,项目名称:topaz,代码行数:53,代码来源:timeobject.py

示例3: _rand_int

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def _rand_int(self, space, integer):
     random = self.random.random()
     max = Coerce.int(space, integer)
     if max <= 0:
         raise space.error(space.w_ArgumentError, "invalid argument")
     else:
         return space.newint(int(random * max))
开发者ID:Freidrichs,项目名称:topaz,代码行数:9,代码来源:randomobject.py

示例4: method_initialize

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def method_initialize(self, space, args_w):
     if len(args_w) == 1:
         address = Coerce.ffi_address(space, args_w[0])
         return self._initialize(space, address)
     elif len(args_w) == 2:
         sizeof_type = Coerce.int(space, args_w[0])
         address = Coerce.ffi_address(space, args_w[1])
         return self._initialize(space, address, sizeof_type)
开发者ID:mswart,项目名称:topaz,代码行数:10,代码来源:pointer.py

示例5: method_match

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def method_match(self, space, w_s, w_offset=None):
     if w_s is space.w_nil:
         return space.w_nil
     s = Coerce.str(space, w_s)
     if w_offset is not None:
         offset = Coerce.int(space, w_offset)
     else:
         offset = 0
     ctx = self.make_ctx(s, offset)
     matched = rsre_core.search_context(ctx)
     return self.get_match_result(space, ctx, s, matched)
开发者ID:Fleurer,项目名称:topaz,代码行数:13,代码来源:regexpobject.py

示例6: srand

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def srand(self, space, seed=None):
     previous_seed = self.w_seed
     if seed is None:
         seed = intmask(self._generate_seed())
     else:
         seed = Coerce.int(space, seed)
     self.w_seed = space.newint(seed)
     if previous_seed is None:
         value = space.newfloat(self.random.random())
     else:
         value = previous_seed
     self.random = Random(abs(seed))
     return value
开发者ID:Freidrichs,项目名称:topaz,代码行数:15,代码来源:randomobject.py

示例7: method_last

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
    def method_last(self, space, w_count=None):
        if w_count is not None:
            count = Coerce.int(space, w_count)
            if count < 0:
                raise space.error(space.w_ArgumentError, "negative array size")
            start = len(self.items_w) - count
            if start < 0:
                start = 0
            return space.newarray(self.items_w[start:])

        if len(self.items_w) == 0:
            return space.w_nil
        else:
            return self.items_w[len(self.items_w) - 1]
开发者ID:krekoten,项目名称:topaz,代码行数:16,代码来源:arrayobject.py

示例8: month_arg_to_month

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def month_arg_to_month(space, w_arg):
     w_month = space.convert_type(w_arg, space.w_string, "to_str",
                                  raise_error=False)
     if w_month is space.w_nil:
         month = Coerce.int(space, w_arg)
     else:
         try:
             month = MONTHNAMES.index(space.str_w(w_month)) + 1
         except ValueError:
             raise space.error(
                 space.w_ArgumentError,
                 "mon out of range"
             )
     return month
开发者ID:topazproject,项目名称:topaz,代码行数:16,代码来源:timeobject.py

示例9: wrapper

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 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)
开发者ID:gemoe100,项目名称:topaz,代码行数:19,代码来源:math.py

示例10: method_new

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def method_new(self, space, args_w):
     if len(args_w) > 7:
         raise space.error(
             space.w_ArgumentError,
             ("wrong number of arguments (given %d, expected 0..7)" %
                 len(args_w)))
     if len(args_w) > 6:
         utc_offset = Coerce.int(space, args_w.pop())
         w_time = space.send(self, "gm", args_w)
         w_time._set_offset(utc_offset)
         return w_time
     elif len(args_w) > 1:
         return space.send(self, "gm", args_w)
     else:
         w_time = space.send(self, "allocate")
         space.send(w_time, "initialize")
         return w_time
开发者ID:topazproject,项目名称:topaz,代码行数:19,代码来源:timeobject.py

示例11: method_initialize

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def method_initialize(self, space, w_fd_or_io, w_mode_str_or_int=None, w_opts=None):
     if isinstance(w_fd_or_io, W_IOObject):
         fd = w_fd_or_io.fd
     else:
         fd = Coerce.int(space, w_fd_or_io)
     if isinstance(w_mode_str_or_int, W_StringObject):
         mode = space.str_w(w_mode_str_or_int)
     elif w_mode_str_or_int is None:
         mode = None
     else:
         raise space.error(space.w_NotImplementedError, "int mode for IO.new")
     if w_opts is not None:
         raise space.error(space.w_NotImplementedError, "options hash for IO.new")
     if mode is None:
         mode = "r"
     self.fd = fd
     return self
开发者ID:Fleurer,项目名称:topaz,代码行数:19,代码来源:ioobject.py

示例12: method_to_i

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
 def method_to_i(self, space, w_radix=None):
     if w_radix is None:
         is_radix = False
         radix = 10
     else:
         is_radix = True
         radix = Coerce.int(space, w_radix)
     s = space.str_w(self)
     i = 0
     length = len(s)
     while i < length:
         if not s[i].isspace():
             break
         i += 1
     neg = i < length and s[i] == "-"
     if neg:
         i += 1
     if i < length and s[i] == "+":
         i += 1
     if i < length and s[i] == "0":
         if i + 1 < length:
             try:
                 r = RADIX_MAP[s[i + 1]]
             except KeyError:
                 if radix == 0:
                     radix = 8
             else:
                 if not is_radix or radix == r or radix == 0:
                     radix = r
                     i += 2
     if radix == 0:
         radix = 10
     if not 2 <= radix <= 36:
         raise space.error(space.w_ArgumentError, "invalid radix %d" % radix)
     try:
         value = self.to_int(s, neg, i, radix)
     except OverflowError:
         value = self.to_bigint(s, neg, i, radix)
         return space.newbigint_fromrbigint(value)
     else:
         return space.newint(value)
开发者ID:alehander42,项目名称:topaz,代码行数:43,代码来源:stringobject.py

示例13: method_subscript

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import int [as 别名]
    def method_subscript(self, space, w_idx, w_count, w_other=None):
        if w_other is None:
            w_other = w_count
            w_count = None

        other = Coerce.str(space, w_other)
        start_idx = -1
        end_idx = -1
        if space.is_kind_of(w_idx, space.w_string):
            other_str = space.str_w(w_idx)
            start_idx = space.str_w(self).find(other_str)
            end_idx = start_idx + len(other_str)
        elif space.is_kind_of(w_idx, space.w_regexp):
            ctx = w_idx.make_ctx(space.str_w(self))
            if self.search_context(space, ctx):
                if w_count is None:
                    start_idx = ctx.match_start
                    end_idx = ctx.match_end
                elif space.is_kind_of(w_count, space.w_string):
                    raise space.error(
                        space.w_NotImplementedError,
                        "string subscript replace with regexp and named group"
                    )
                else:
                    groupnum = Coerce.int(space, w_count)
                    try:
                        start_idx, end_idx = ctx.span(groupnum)
                    except IndexError:
                        pass
        else:
            start_idx, end_idx, as_range, nil = space.subscript_access(self.length(), w_idx, w_count=w_count)
            if not w_count:
                end_idx = start_idx + 1

        if start_idx < 0 or end_idx < 0:
            raise space.error(space.w_IndexError, "cannot find substring in string to replace")

        self.strategy.to_mutable(space, self)
        self.strategy.delslice(space, self.str_storage, start_idx, end_idx)
        self.strategy.insert(self.str_storage, start_idx, other)
        return self
开发者ID:topazproject,项目名称:topaz,代码行数:43,代码来源:stringobject.py


注:本文中的topaz.coerce.Coerce.int方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。