]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
* calendar.py: all libC functionality now moved to built-in time module
authorGuido van Rossum <guido@python.org>
Wed, 23 Jun 1993 09:30:50 +0000 (09:30 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 23 Jun 1993 09:30:50 +0000 (09:30 +0000)
* 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'

Lib/calendar.py
Lib/imghdr.py
Lib/irix5/torgb.py
Lib/lib-old/whatsound.py
Lib/plat-irix5/torgb.py
Lib/tzparse.py
Lib/whatsound.py

index 9ef9e3d5431f94fc0ae88c5cfc169481057bb9ff..b4e3aaddbfa7a2a368cac4b9178df7750613aae9 100644 (file)
@@ -1,37 +1,16 @@
-##############################
-# Calendar support functions #
-##############################
+###############################
+# Calendar printing functions #
+###############################
 
-# Revision 2: uses funtions from built-in time module where possible.
+# Revision 2: uses funtions from built-in time module
 
 # Import functions and variables from time module
-from time import gmtime, localtime, mktime
+from time import gmtime, localtime, mktime, asctime, ctime
 from time import timezone, altzone, daylight, tzname
 
 # Exception raised for bad input (with string parameter for details)
 error = 'calendar.error'
 
-# Abbreviated names of months (1-based arrays!!!)
-month_abbr =       ['   ', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \
-                          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
-
-# Turn calendar time as returned by localtime() into a string
-def asctime(arg):
-       year, month, day, hours, mins, secs, wday, yday, isdst = arg
-       return '%s %s %02d %02d:%02d:%02d %04d' % (
-               day_abbr[wday], month_abbr[month], day,
-               hours, mins, secs, year)
-
-# UNIX-style ctime (except it doesn't append '\n'!)
-def ctime(secs):
-       return asctime(localtime(secs))
-
-######################
-# Non-UNIX additions #
-######################
-
-# Calendar printing etc.
-
 # Note when comparing these calendars to the ones printed by cal(1):
 # My calendars have Monday as the first day of the week, and Sunday as
 # the last!  (I believe this is the European convention.)
@@ -48,10 +27,12 @@ day_name = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', \
            'Friday', 'Saturday', 'Sunday']
 day_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
 
-# Full names of months (1-based arrays!!!)
+# Full and abbreviated names of months (1-based arrays!!!)
 month_name =          ['', 'January',   'February', 'March',    'April', \
                           'May',       'June',     'July',     'August', \
                           'September', 'October',  'November', 'December']
+month_abbr =       ['   ', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \
+                          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
 
 # Return 1 for leap years, 0 for non-leap years
 def isleap(year):
index 063bfe82ce55753bc20bee0140dba8a819981641..62518b5f36c9b9400d75364483c1da9dd0650996 100644 (file)
@@ -81,6 +81,12 @@ def test_xbm(h, f):
 
 tests.append(test_xbm)
 
+def test_jpeg(h, f):
+       # JPEG data in JFIF format
+       if h[6:10] == 'JFIF':
+               return 'jpeg'
+
+tests.append(test_jpeg)
 
 #--------------------#
 # Small test program #
index e46aca33cef4813d6c494e240c0a29350dcbdb19..2e340d1751977af61566fc299fd0dbb84c6d0e49 100755 (executable)
@@ -40,6 +40,12 @@ t.append('pnmtoppm', '--')
 t.append('fromppm $IN $OUT', 'ff')
 table['rast'] = t
 
+t = pipes.Template().init()
+t.append('djpeg', '--')
+t.append('pnmtoppm', '--')
+t.append('fromppm $IN $OUT', 'ff')
+table['jpeg'] = t
+
 uncompress = pipes.Template().init()
 uncompress.append('uncompress', '--')
 
index a59323b1abc9cd4529d54c0b4ae6c08122344891..b7b349c5ba2cea2971218a94f5e52925f0ae2a39 100644 (file)
@@ -56,6 +56,7 @@ def whatraw(filename):
        from stat import ST_SIZE
        # XXX "whatsound" should be part of the distribution somehow...
        cmd = 'whatsound ' + filename + ' 2>/dev/null'
+       cmd = 'PATH=$PATH:/ufs/guido/bin/sgi\n' + cmd
        pipe = os.popen(cmd, 'r')
        data = pipe.read()
        sts = pipe.close()
index e46aca33cef4813d6c494e240c0a29350dcbdb19..2e340d1751977af61566fc299fd0dbb84c6d0e49 100755 (executable)
@@ -40,6 +40,12 @@ t.append('pnmtoppm', '--')
 t.append('fromppm $IN $OUT', 'ff')
 table['rast'] = t
 
+t = pipes.Template().init()
+t.append('djpeg', '--')
+t.append('pnmtoppm', '--')
+t.append('fromppm $IN $OUT', 'ff')
+table['jpeg'] = t
+
 uncompress = pipes.Template().init()
 uncompress.append('uncompress', '--')
 
index 370d46b91238ade4f44bc071e12a6e2f589ca1ca..26824ab929720bfcc5e8eb2b5f9a040de9cd33e4 100644 (file)
@@ -24,11 +24,11 @@ def tzparse(tzstr):
        [tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs
        return (tzname, delta, dstname, daystart, hourstart, dayend, hourend)
 
-def tzlocaltime(time, params):
-       import calendar
+def tzlocaltime(secs, params):
+       import time
        (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = params
-       year, month, days, hours, mins, secs, yday, wday = \
-               calendar.gmtime(time - delta*3600)
+       year, month, days, hours, mins, secs, yday, wday, isdst = \
+               time.gmtime(secs - delta*3600)
        if (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend):
                tzname = dstname
                hours = hours + 1
@@ -44,33 +44,39 @@ def tzset():
        daylight = 1
        tzname = tzparams[0], tzparams[2]
 
-def isdst(time):
-       import calendar
+def isdst(secs):
+       import time
        (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = \
                tzparams
        year, month, days, hours, mins, secs, yday, wday, isdst = \
-               calendar.gmtime(time - delta*3600)
+               time.gmtime(secs - delta*3600)
        return (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend)
 
 tzset()
 
-def localtime(time):
-       return tzlocaltime(time, tzparams)
+def localtime(secs):
+       return tzlocaltime(secs, tzparams)
 
 def test():
-       from calendar import asctime, gmtime
+       from time import asctime, gmtime
        import time, sys
        now = time.time()
        x = localtime(now)
-       print 'now =', now, '=', asctime(x[:-1]), x[-1]
+       tm = x[:-1] + (0,)
+       print 'now =', now, '=', asctime(tm), x[-1]
        now = now - now % (24*3600)
        if sys.argv[1:]: now = now + eval(sys.argv[1])
        x = gmtime(now)
-       print 'gmtime =', now, '=', asctime(x), 'yday =', x[-2]
+       tm = x[:-1] + (0,)
+       print 'gmtime =', now, '=', asctime(tm), 'yday =', x[-2]
        jan1 = now - x[-2]*24*3600
        x = localtime(jan1)
-       print 'jan1 =', jan1, '=', asctime(x[:-1]), x[-1]
+       tm = x[:-1] + (0,)
+       print 'jan1 =', jan1, '=', asctime(tm), x[-1]
        for d in range(85, 95) + range(265, 275):
                t = jan1 + d*24*3600
                x = localtime(t)
-               print 'd =', d, 't =', t, '=', asctime(x[:-1]), x[-1]
+               tm = x[:-1] + (0,)
+               print 'd =', d, 't =', t, '=', asctime(tm), x[-1]
+
+test()
index a59323b1abc9cd4529d54c0b4ae6c08122344891..b7b349c5ba2cea2971218a94f5e52925f0ae2a39 100644 (file)
@@ -56,6 +56,7 @@ def whatraw(filename):
        from stat import ST_SIZE
        # XXX "whatsound" should be part of the distribution somehow...
        cmd = 'whatsound ' + filename + ' 2>/dev/null'
+       cmd = 'PATH=$PATH:/ufs/guido/bin/sgi\n' + cmd
        pipe = os.popen(cmd, 'r')
        data = pipe.read()
        sts = pipe.close()