if error: interp.space.ec.warn("DateTime::modify(): %s" % error) return interp.space.w_False return this @wrap_method(['interp', ThisUnwrapper(W_DateTime)], name="DateTime::getTimestamp") def get_timestamp(interp, this): return common.date_timestamp_get(interp, this) @wrap_method(['interp', ThisUnwrapper(W_DateTime), LongArg(None)], name='DateTime::setTimestamp') def set_timestamp(interp, this, timestamp): timelib.timelib_unixtime2local(this.timelib_time, timestamp) timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return this @wrap_method(['space', ThisUnwrapper(W_DateTime)], name='DateTime::getTimezone') def get_timezone(space, this): return this.w_datetimezone
return space.newstr(n) def getmxrr(): """ Get MX records corresponding to a given Internet host name""" return NotImplementedError() @wrap(['space', StringArg(None)]) def getprotobyname(space, name): """ Get protocol number associated with protocol name""" n = rsocket.getprotobyname(name) return space.newint(n) @wrap(['space', LongArg(None)]) def getprotobynumber(space, pnum): """ Get protocol name associated with protocol number""" try: n = rsocket.getservbyport(pnum) return space.newstr(n) except rsocket.RSocketError: return space.w_False @wrap(['space', StringArg(None), StringArg(None)]) def getservbyname(space, name, proto): """ Get port number associated with an Internet service and protocol""" try: n = rsocket.getservbyname(name, proto) return space.newint(n)
return space.w_True def _fits_in_base(c, base): if ord('0') <= ord(c) <= ord('9'): if ord(c) - ord('0') < base: return True return False if ord('a') <= ord(c) <= ord('z'): if ord(c) - ord('a') < base - 10: return True return False return False @wrap(['space', W_Root, Optional(LongArg(None))]) def intval(space, w_obj, base=10): """ Get the integer value of a variable""" if w_obj.tp == space.tp_array: if space.arraylen(w_obj) == 0: return space.wrap(0) return space.wrap(1) elif w_obj.tp == space.tp_int: return w_obj elif w_obj.tp == space.tp_bool: return space.as_number(w_obj) elif w_obj.tp == space.tp_null: return space.wrap(0) elif w_obj.tp == space.tp_float: try: res = intmask(int(space.float_w(w_obj)))
@wrap(['space', int], error=False) def posix_setgid(space, gid): """ posix_setgid - Set the GID of the current process """ try: os.setgid(gid) return space.newbool(True) except OSError, e: space.set_errno(e.errno) return space.newbool(False) except OverflowError: return space.newbool(False) @wrap(['space', LongArg(False), LongArg(False)]) def posix_setpgid(space, pid, pgrp): """ posix_setpgid - Set process group id for job control """ try: os.setpgid(pid, pgrp) return space.newbool(True) except OSError, e: space.set_errno(e.errno) return space.newbool(False) @wrap(['space']) def posix_setsid(space): """ posix_setsid - Make the current process a session leader """ try: os.setsid()
except ValueError: return space.wrap(rfloat.NAN) @wrap(['space', float]) def atanh(space, d): """ atanh - Inverse hyperbolic tangent """ try: return space.wrap(math.atanh(d)) except OverflowError: return space.wrap(rfloat.INFINITY) except ValueError: return space.wrap(rfloat.NAN) @wrap(['space', W_Root, LongArg(None), LongArg(None)]) def base_convert(space, w_number, frombase, tobase): """ base_convert - Convert a number between arbitrary bases""" # problem with big numbers # php casts 10000000000000000000 to 1.0E+19 # py casts to 1e+19 so we are missing '0' ;-) if w_number.tp == space.tp_array: space.ec.notice("Array to string conversion") return space.newstr("0") number = space.str_w(w_number) if number == "": return space.newstr("0") if frombase < 2 or frombase > 36: space.ec.warn("base_convert(): Invalid `from base' (%d)" % frombase)
(space.wrap("offset"), space.wrap(int(o))), (space.wrap("timezone_id"), space.wrap(f)) ]) )) i += 1 results.append((space.wrap(k), space.new_array_from_pairs(w_arr_x))) return space.new_array_from_pairs(results) @wrap_method(['space'], name='DateTimeZone::listAbbreviations', flags=consts.ACC_STATIC) def list_abbreviations(space): return _abbreviations_list(space) @wrap_method(['space', Optional(LongArg(None)), Optional(StringArg(None))], name='DateTimeZone::listIdentifiers', flags=consts.ACC_STATIC) def identifiers_list(space, what=2047, country=None): return common.timezone_identifiers_list(space, what, country) @wrap_method(['interp', ThisUnwrapper(W_DateTimeZone), Optional(int), Optional(int)], name='DateTimeZone::getTransitions', error=False) def get_transition(interp, this, timestamp_begin=-sys.maxint - 1, timestamp_end=sys.maxint): return common.timezone_transitions_get( interp, this, timestamp_begin, timestamp_end) @wrap_method(['interp', ThisUnwrapper(W_DateTimeZone)],
(space.wrap("timezone_id"), space.wrap(f)) ]))) i += 1 results.append((space.wrap(k), space.new_array_from_pairs(w_arr_x))) return space.new_array_from_pairs(results) @wrap_method(['space'], name='DateTimeZone::listAbbreviations', flags=consts.ACC_STATIC) def list_abbreviations(space): return _abbreviations_list(space) @wrap_method( ['space', Optional(LongArg(None)), Optional(StringArg(None))], name='DateTimeZone::listIdentifiers', flags=consts.ACC_STATIC) def identifiers_list(space, what=2047, country=None): return common.timezone_identifiers_list(space, what, country) @wrap_method( ['interp', ThisUnwrapper(W_DateTimeZone), Optional(int), Optional(int)], name='DateTimeZone::getTransitions') def get_transition(interp, this,
@wrap(['space', str, Optional(int)], error=False) def gmdate(space, date_format, timestamp=int(pytime.time())): timelib_timezone = timelib.timelib_timezone('GMT') timelib_time = timelib.timelib_time_from_timestamp(timestamp, timelib_timezone) return space.wrap(timelib.date_format(date_format, timelib_time)) @wrap(['space']) def time(space): return space.wrap(int(pytime.time())) @wrap(['interp', str, Optional(LongArg(None))], error=False) def strtotime(interp, str_time, now=-1): timelib_timezone = interp.get_default_timezone( "strtotime").timelib_timezone res = timelib.strtotime(str_time, now, timelib_timezone) if res == -1: return interp.space.w_False return interp.space.wrap(res) def _mktime(interp, is_gmt, hour, minute, second, month, day, year, dst=-1): now = timelib.timelib_time_ctor() adjust_seconds = 0