• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python coerce.Coerce类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: method_initialize

 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,代码行数:8,代码来源:pointer.py


示例2: method_sub

 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
开发者ID:topazproject,项目名称:topaz,代码行数:10,代码来源:timeobject.py


示例3: method_match

 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,代码行数:11,代码来源:regexpobject.py


示例4: method_at

 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
开发者ID:topazproject,项目名称:topaz,代码行数:12,代码来源:timeobject.py


示例5: coerce_address

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,代码行数:13,代码来源:pointer.py


示例6: _rand_int

 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,代码行数:7,代码来源:randomobject.py


示例7: method_pack

 def method_pack(self, space, w_template):
     template = Coerce.str(space, w_template)
     result = RPacker(template, space.listview(self)).operate(space)
     w_result = space.newstr_fromchars(result)
     if space.is_true(space.send(w_template, "tainted?")):
         space.send(w_result, "taint")
     return w_result
开发者ID:krekoten,项目名称:topaz,代码行数:7,代码来源:arrayobject.py


示例8: method_sleep

 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)))
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:kernel.py


示例9: method_plus

 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
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:timeobject.py


示例10: wrapper

 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,代码行数:17,代码来源:math.py


示例11: singleton_method_chmod

 def singleton_method_chmod(self, space, mode, args_w):
     for arg_w in args_w:
         path = Coerce.path(space, arg_w)
         try:
             os.chmod(path, mode)
         except OSError as e:
             raise error_for_oserror(space, e)
     return space.newint(len(args_w))
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:fileobject.py


示例12: singleton_method_delete

 def singleton_method_delete(self, space, args_w):
     for w_path in args_w:
         path = Coerce.path(space, w_path)
         try:
             os.unlink(path)
         except OSError as e:
             raise error_for_oserror(space, e)
     return space.newint(len(args_w))
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:fileobject.py


示例13: method_at

 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
开发者ID:mattrobenolt,项目名称:topaz,代码行数:8,代码来源:timeobject.py


示例14: method_initialize

 def method_initialize(self, space, w_source, flags=0):
     if isinstance(w_source, W_RegexpObject):
         self.set_source(space, w_source.source, w_source.flags)
     else:
         try:
             self.set_source(space, Coerce.str(space, w_source), flags)
         except regexp.RegexpError as e:
             raise space.error(space.w_RegexpError, str(e))
     return self
开发者ID:Freidrichs,项目名称:topaz,代码行数:9,代码来源:regexpobject.py


示例15: method_div

 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)
开发者ID:babelsberg,项目名称:babelsberg-r,代码行数:10,代码来源:intobject.py


示例16: method_match_operator

 def method_match_operator(self, space, w_s):
     if w_s is space.w_nil:
         return space.w_nil
     s = Coerce.str(space, w_s)
     ctx = self.make_ctx(s)
     matched = rsre_core.search_context(ctx)
     self.get_match_result(space, ctx, s, matched)
     if matched:
         return space.newint(ctx.match_start)
     else:
         return space.w_nil
开发者ID:Fleurer,项目名称:topaz,代码行数:11,代码来源:regexpobject.py


示例17: method_subscript

    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,代码行数:41,代码来源:stringobject.py


示例18: method_module_function

 def method_module_function(self, space, args_w):
     if not args_w:
         self.set_default_visibility(space, W_FunctionObject.MODULE_FUNCTION)
         return self
     for w_arg in args_w:
         name = Coerce.symbol(space, w_arg)
         w_method = self.find_method(space, name)
         if w_method is None or isinstance(w_method, UndefMethod):
             cls_name = space.obj_to_s(self)
             raise space.error(space.w_NameError, "undefined method `%s' for class `%s'" % (name, cls_name))
         self.attach_method(space, name, w_method)
         self.set_method_visibility(space, name, W_FunctionObject.PRIVATE)
     return self
开发者ID:babelsberg,项目名称:babelsberg-r,代码行数:13,代码来源:moduleobject.py


示例19: srand

 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,代码行数:13,代码来源:randomobject.py


示例20: method_last

    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,代码行数:14,代码来源:arrayobject.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python error.error_for_oserror函数代码示例发布时间:2022-05-27
下一篇:
Python celldict.GlobalsDict类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap