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

Skip to content

Commit 5cfa5df

Browse files
committed
* calendar.py: all libC functionality now moved to built-in time module
* imghdr.py: added jpeg recognition * torgb.py: added jpeg conversion * tzparse.py: use functions from time instead of calendar * whatsound.py: add /ufs/guido/biin/sgi to $PATH when calling 'whatsound'
1 parent 9b3bc71 commit 5cfa5df

7 files changed

Lines changed: 48 additions & 41 deletions

File tree

Lib/calendar.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
1-
##############################
2-
# Calendar support functions #
3-
##############################
1+
###############################
2+
# Calendar printing functions #
3+
###############################
44

5-
# Revision 2: uses funtions from built-in time module where possible.
5+
# Revision 2: uses funtions from built-in time module
66

77
# Import functions and variables from time module
8-
from time import gmtime, localtime, mktime
8+
from time import gmtime, localtime, mktime, asctime, ctime
99
from time import timezone, altzone, daylight, tzname
1010

1111
# Exception raised for bad input (with string parameter for details)
1212
error = 'calendar.error'
1313

14-
# Abbreviated names of months (1-based arrays!!!)
15-
month_abbr = [' ', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \
16-
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
17-
18-
# Turn calendar time as returned by localtime() into a string
19-
def asctime(arg):
20-
year, month, day, hours, mins, secs, wday, yday, isdst = arg
21-
return '%s %s %02d %02d:%02d:%02d %04d' % (
22-
day_abbr[wday], month_abbr[month], day,
23-
hours, mins, secs, year)
24-
25-
# UNIX-style ctime (except it doesn't append '\n'!)
26-
def ctime(secs):
27-
return asctime(localtime(secs))
28-
29-
######################
30-
# Non-UNIX additions #
31-
######################
32-
33-
# Calendar printing etc.
34-
3514
# Note when comparing these calendars to the ones printed by cal(1):
3615
# My calendars have Monday as the first day of the week, and Sunday as
3716
# the last! (I believe this is the European convention.)
@@ -48,10 +27,12 @@ def ctime(secs):
4827
'Friday', 'Saturday', 'Sunday']
4928
day_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
5029

51-
# Full names of months (1-based arrays!!!)
30+
# Full and abbreviated names of months (1-based arrays!!!)
5231
month_name = ['', 'January', 'February', 'March', 'April', \
5332
'May', 'June', 'July', 'August', \
5433
'September', 'October', 'November', 'December']
34+
month_abbr = [' ', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \
35+
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
5536

5637
# Return 1 for leap years, 0 for non-leap years
5738
def isleap(year):

Lib/imghdr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def test_xbm(h, f):
8181

8282
tests.append(test_xbm)
8383

84+
def test_jpeg(h, f):
85+
# JPEG data in JFIF format
86+
if h[6:10] == 'JFIF':
87+
return 'jpeg'
88+
89+
tests.append(test_jpeg)
8490

8591
#--------------------#
8692
# Small test program #

Lib/irix5/torgb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
t.append('fromppm $IN $OUT', 'ff')
4141
table['rast'] = t
4242

43+
t = pipes.Template().init()
44+
t.append('djpeg', '--')
45+
t.append('pnmtoppm', '--')
46+
t.append('fromppm $IN $OUT', 'ff')
47+
table['jpeg'] = t
48+
4349
uncompress = pipes.Template().init()
4450
uncompress.append('uncompress', '--')
4551

Lib/lib-old/whatsound.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def whatraw(filename):
5656
from stat import ST_SIZE
5757
# XXX "whatsound" should be part of the distribution somehow...
5858
cmd = 'whatsound ' + filename + ' 2>/dev/null'
59+
cmd = 'PATH=$PATH:/ufs/guido/bin/sgi\n' + cmd
5960
pipe = os.popen(cmd, 'r')
6061
data = pipe.read()
6162
sts = pipe.close()

Lib/plat-irix5/torgb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
t.append('fromppm $IN $OUT', 'ff')
4141
table['rast'] = t
4242

43+
t = pipes.Template().init()
44+
t.append('djpeg', '--')
45+
t.append('pnmtoppm', '--')
46+
t.append('fromppm $IN $OUT', 'ff')
47+
table['jpeg'] = t
48+
4349
uncompress = pipes.Template().init()
4450
uncompress.append('uncompress', '--')
4551

Lib/tzparse.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def tzparse(tzstr):
2424
[tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs
2525
return (tzname, delta, dstname, daystart, hourstart, dayend, hourend)
2626

27-
def tzlocaltime(time, params):
28-
import calendar
27+
def tzlocaltime(secs, params):
28+
import time
2929
(tzname, delta, dstname, daystart, hourstart, dayend, hourend) = params
30-
year, month, days, hours, mins, secs, yday, wday = \
31-
calendar.gmtime(time - delta*3600)
30+
year, month, days, hours, mins, secs, yday, wday, isdst = \
31+
time.gmtime(secs - delta*3600)
3232
if (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend):
3333
tzname = dstname
3434
hours = hours + 1
@@ -44,33 +44,39 @@ def tzset():
4444
daylight = 1
4545
tzname = tzparams[0], tzparams[2]
4646

47-
def isdst(time):
48-
import calendar
47+
def isdst(secs):
48+
import time
4949
(tzname, delta, dstname, daystart, hourstart, dayend, hourend) = \
5050
tzparams
5151
year, month, days, hours, mins, secs, yday, wday, isdst = \
52-
calendar.gmtime(time - delta*3600)
52+
time.gmtime(secs - delta*3600)
5353
return (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend)
5454

5555
tzset()
5656

57-
def localtime(time):
58-
return tzlocaltime(time, tzparams)
57+
def localtime(secs):
58+
return tzlocaltime(secs, tzparams)
5959

6060
def test():
61-
from calendar import asctime, gmtime
61+
from time import asctime, gmtime
6262
import time, sys
6363
now = time.time()
6464
x = localtime(now)
65-
print 'now =', now, '=', asctime(x[:-1]), x[-1]
65+
tm = x[:-1] + (0,)
66+
print 'now =', now, '=', asctime(tm), x[-1]
6667
now = now - now % (24*3600)
6768
if sys.argv[1:]: now = now + eval(sys.argv[1])
6869
x = gmtime(now)
69-
print 'gmtime =', now, '=', asctime(x), 'yday =', x[-2]
70+
tm = x[:-1] + (0,)
71+
print 'gmtime =', now, '=', asctime(tm), 'yday =', x[-2]
7072
jan1 = now - x[-2]*24*3600
7173
x = localtime(jan1)
72-
print 'jan1 =', jan1, '=', asctime(x[:-1]), x[-1]
74+
tm = x[:-1] + (0,)
75+
print 'jan1 =', jan1, '=', asctime(tm), x[-1]
7376
for d in range(85, 95) + range(265, 275):
7477
t = jan1 + d*24*3600
7578
x = localtime(t)
76-
print 'd =', d, 't =', t, '=', asctime(x[:-1]), x[-1]
79+
tm = x[:-1] + (0,)
80+
print 'd =', d, 't =', t, '=', asctime(tm), x[-1]
81+
82+
test()

Lib/whatsound.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def whatraw(filename):
5656
from stat import ST_SIZE
5757
# XXX "whatsound" should be part of the distribution somehow...
5858
cmd = 'whatsound ' + filename + ' 2>/dev/null'
59+
cmd = 'PATH=$PATH:/ufs/guido/bin/sgi\n' + cmd
5960
pipe = os.popen(cmd, 'r')
6061
data = pipe.read()
6162
sts = pipe.close()

0 commit comments

Comments
 (0)