diff options
| author | Guido van Rossum <guido@python.org> | 1996-07-21 02:09:54 +0000 | 
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 1996-07-21 02:09:54 +0000 | 
| commit | 7a1c7918e0459909673bec6da6a94e57ec96a1e8 (patch) | |
| tree | 3cf52bb66085a83984429d738f485cc70fd33fac | |
| parent | 024a387f89cd4c08b67ffca0d8df311a34cc8a49 (diff) | |
| download | cpython-git-7a1c7918e0459909673bec6da6a94e57ec96a1e8.tar.gz | |
add mac compatibility
| -rw-r--r-- | Demo/rpc/rpc.py | 30 | 
1 files changed, 29 insertions, 1 deletions
diff --git a/Demo/rpc/rpc.py b/Demo/rpc/rpc.py index 83cc954b3d..f44b3e4426 100644 --- a/Demo/rpc/rpc.py +++ b/Demo/rpc/rpc.py @@ -163,9 +163,37 @@ def make_auth_unix_default():  	except ImportError:  		uid = gid = 0  	import time -	return make_auth_unix(int(time.time()), \ +	return make_auth_unix(int(time.time()-unix_epoch()), \  		  socket.gethostname(), uid, gid, []) +_unix_epoch = -1 +def unix_epoch(): +    """Very painful calculation of when the Unix Epoch is. + +    This is defined as the return value of time.time() on Jan 1st, +    1970, 00:00:00 GMT. + +    On a Unix system, this should always return 0.0.  On a Mac, the +    calculations are needed -- and hard because of integer overflow +    and other limitations. + +    """ +    global _unix_epoch +    if _unix_epoch >= 0: return _unix_epoch +    import time +    now = time.time() +    localt = time.localtime(now)	# (y, m, d, hh, mm, ss, ..., ..., ...) +    gmt = time.gmtime(now) +    offset = time.mktime(localt) - time.mktime(gmt) +    y, m, d, hh, mm, ss = 1970, 1, 1, 0, 0, 0 +    offset, ss = divmod(ss + offset, 60) +    offset, mm = divmod(mm + offset, 60) +    offset, hh = divmod(hh + offset, 24) +    d = d + offset +    _unix_epoch = time.mktime((y, m, d, hh, mm, ss, 0, 0, 0)) +    print "Unix epoch:", time.ctime(_unix_epoch) +    return _unix_epoch +  # Common base class for clients  | 
