本文整理汇总了Python中topaz.coerce.Coerce类的典型用法代码示例。如果您正苦于以下问题:Python Coerce类的具体用法?Python Coerce怎么用?Python Coerce使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Coerce类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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)
示例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
示例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)
示例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))
示例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
示例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)))
示例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
示例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)
示例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))
示例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))
示例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
示例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
示例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)