Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2db9135

Browse files
committed
Misc changes and new modules. whrandom is "objectified". SOCKET.py
is moved to the sgi subdirectory.
1 parent 0cb8e8c commit 2db9135

10 files changed

Lines changed: 778 additions & 46 deletions

File tree

Lib/calendar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# - Monday is the first day of the week (numbered 0)
1212

1313
# These are really parameters of the 'time' module:
14-
epoch = 1970 # Time began on January 1 of this year (00:00:00 UCT)
14+
epoch = 1970 # Time began on January 1 of this year (00:00:00 UTC)
1515
day_0 = 3 # The epoch begins on a Thursday (Monday = 0)
1616

1717
# Return 1 for leap years, 0 for non-leap years
@@ -58,7 +58,7 @@ def leapdays(y1, y2):
5858
return (y2+3)/4 - (y1+3)/4
5959

6060
# Inverse of gmtime():
61-
# Turn UCT calendar time (less yday, wday) into seconds since epoch
61+
# Turn UTC calendar time (less yday, wday) into seconds since epoch
6262
def mktime(year, month, day, hours, mins, secs):
6363
days = day - 1
6464
for m in range(January, month): days = days + mdays[m]
@@ -96,8 +96,8 @@ def asctime(year, month, day, hours, mins, secs, yday, wday):
9696
return s + ' ' + `year`
9797

9898
# Localization: Minutes West from Greenwich
99-
# timezone = -2*60 # Middle-European time with DST on
100-
timezone = 5*60 # EST (sigh -- THINK time() doesn't return UCT)
99+
timezone = -2*60 # Middle-European time with DST on
100+
# timezone = 5*60 # EST (sigh -- THINK time() doesn't return UTC)
101101

102102
# Local time ignores DST issues for now -- adjust 'timezone' to fake it
103103
def localtime(secs):

Lib/imghdr.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,29 @@ def test_gif(h, f):
3535

3636
tests.append(test_gif)
3737

38-
def test_pnm(h, f):
39-
# PBM, PGM, PPM (portable {bit,gray,pix}map; together portable anymap)
38+
def test_pbm(h, f):
39+
# PBM (portable bitmap)
4040
if len(h) >= 3 and \
41-
h[0] == 'P' and h[1] in '123456' and h[2] in ' \t\n\r':
42-
return 'pnm'
41+
h[0] == 'P' and h[1] in '14' and h[2] in ' \t\n\r':
42+
return 'pbm'
4343

44-
tests.append(test_pnm)
44+
tests.append(test_pbm)
45+
46+
def test_pgm(h, f):
47+
# PGM (portable graymap)
48+
if len(h) >= 3 and \
49+
h[0] == 'P' and h[1] in '25' and h[2] in ' \t\n\r':
50+
return 'pgm'
51+
52+
tests.append(test_pgm)
53+
54+
def test_ppm(h, f):
55+
# PPM (portable pixmap)
56+
if len(h) >= 3 and \
57+
h[0] == 'P' and h[1] in '36' and h[2] in ' \t\n\r':
58+
return 'ppm'
59+
60+
tests.append(test_ppm)
4561

4662
def test_tiff(h, f):
4763
# TIFF (can be in Motorola or Intel byte order)

Lib/irix5/torgb.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Convert "arbitrary" image files to rgb files (SGI's image format).
2+
# Input may be compressed.
3+
# The uncompressed file type may be PBM, PGM, PPM, GIF, TIFF, or Sun raster.
4+
# An exception is raised if the file is not of a recognized type.
5+
# Returned filename is either the input filename or a temporary filename;
6+
# in the latter case the caller must ensure that it is removed.
7+
# Other temporary files used are removed by the function.
8+
9+
import os
10+
import tempfile
11+
import pipes
12+
import imghdr
13+
14+
table = {}
15+
16+
t = pipes.Template().init()
17+
t.append('fromppm $IN $OUT', 'ff')
18+
table['ppm'] = t
19+
20+
t = pipes.Template().init()
21+
t.append('pnmtoppm', '--')
22+
t.append('fromppm $IN $OUT', 'ff')
23+
table['pnm'] = t
24+
table['pgm'] = t
25+
table['pbm'] = t
26+
27+
t = pipes.Template().init()
28+
t.append('fromgif $IN $OUT', 'ff')
29+
table['gif'] = t
30+
31+
t = pipes.Template().init()
32+
t.append('tifftopnm', '--')
33+
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
34+
t.append('fromppm $IN $OUT', 'ff')
35+
table['tiff'] = t
36+
37+
t = pipes.Template().init()
38+
t.append('rasttopnm', '--')
39+
t.append('pnmtoppm', '--')
40+
t.append('fromppm $IN $OUT', 'ff')
41+
table['rast'] = t
42+
43+
uncompress = pipes.Template().init()
44+
uncompress.append('uncompress', '--')
45+
46+
47+
error = 'torgb.error' # Exception
48+
49+
def torgb(filename):
50+
temps = []
51+
ret = None
52+
try:
53+
ret = _torgb(filename, temps)
54+
finally:
55+
for temp in temps[:]:
56+
if temp <> ret:
57+
try:
58+
os.unlink(temp)
59+
except os.error:
60+
pass
61+
temps.remove(temp)
62+
return ret
63+
64+
def _torgb(filename, temps):
65+
if filename[-2:] == '.Z':
66+
fname = tempfile.mktemp()
67+
temps.append(fname)
68+
sts = uncompress.copy(filename, fname)
69+
if sts:
70+
raise error, filename + ': uncompress failed'
71+
else:
72+
fname = filename
73+
try:
74+
ftype = imghdr.what(fname)
75+
except IOError, msg:
76+
if type(msg) == type(()) and len(msg) == 2 and \
77+
type(msg[0]) == type(0) and type(msg[1]) == type(''):
78+
msg = msg[1]
79+
if type(msg) <> type(''):
80+
msg = `msg`
81+
raise error, filename + ': ' + msg
82+
if ftype == 'rgb':
83+
return fname
84+
if ftype == None or not table.has_key(ftype):
85+
raise error, \
86+
filename + ': unsupported image file type ' + `ftype`
87+
temp = tempfile.mktemp()
88+
sts = table[ftype].copy(fname, temp)
89+
if sts:
90+
raise error, filename + ': conversion to rgb failed'
91+
return temp

0 commit comments

Comments
 (0)