def iter(self): if self.stop is null: start = space.to_int(self.start) step = space.to_int(self.step) return SliceStep(start, step) else: start = space.to_int(self.start) stop = space.to_int(self.stop) step = space.to_int(self.step) return SliceRange(start, stop, step)
def configured_stringify(obj, config): if config is None: ub = UnicodeBuilder() quick_stringify(ub, obj) return ub.build() margin = space.to_int(get_config(config, u"margin", space.Integer(80))) scan = Scanner(Printer(margin)) scan.indent = space.to_int(get_config(config, u"indent", space.Integer(2))) scan.sort_keys = space.is_true( get_config(config, u"sort_keys", space.false)) stringify(scan, obj) scan.finish() return scan.printer.result.build()
def store(self, pool, offset, value): for rtype in signed_types: if self.size == rffi.sizeof(rtype): pnt = rffi.cast(rffi.CArrayPtr(rtype), offset) pnt[0] = rffi.cast(rtype, to_int(value)) break else: raise unwind(LTypeError(u"undefined ffi type: %s" % self.repr())) return value
def clamped(self, low, high): step = space.to_int(self.step) if self.start is null: if step < 0: a = high else: a = low else: a = space.to_int(self.start) a = max(low, min(high, a)) if self.stop is null: if step < 0: b = low - 1 else: b = high + 1 else: b = space.to_int(self.stop) b = max(low - 1, min(high + 1, b)) return (a, b, step)
def clamped(self, start, stop): step = space.to_int(self.step) if self.start is null: if step < 0: a = stop - 1 else: a = start else: a = space.to_int(self.start) a = max(start, min(stop-1, a)) if self.stop is null: if step < 0: b = start - 1 else: b = stop else: b = space.to_int(self.stop) b = max(start-1, min(stop, b)) return (a, b, step)
def configured_stringify(obj, config): if config is None: ub = UnicodeBuilder() quick_stringify(ub, obj) return ub.build() scan = Scanner() scan.indent = space.to_int(get_config(config, u"indent", space.Integer(2))) scan.sort_keys = space.is_true(get_config(config, u"sort_keys", space.false)) stringify(scan, obj) scan.finish() return scan.printer.result.build()