]> granicus.if.org Git - python/commitdiff
Separate the script portion from the library portion; everything that
authorFred Drake <fdrake@acm.org>
Wed, 5 Dec 2001 15:58:29 +0000 (15:58 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 5 Dec 2001 15:58:29 +0000 (15:58 +0000)
pertains to the script is now in the if __name__ == "__main__" block.
This is in response to a commenton python-dev from Neal Norwitz.

Lib/mimetypes.py

index 1cd424acb05d54bae4d8d6ef399ddaf207c9fb2c..5a708e32381295e02b5ad3188c53d266a25e036f 100644 (file)
@@ -20,17 +20,6 @@ Functions:
 
 init([files]) -- parse a list of files, default knownfiles
 read_mime_types(file) -- parse one file, return a dictionary or None
-
-When run as a script, the following command line options are recognized:
-
-Usage: mimetypes.py [options] type
-Options:
-    --help / -h       -- print this message and exit
-    --lenient / -l    -- additionally search of some common, but non-standard
-                         types.
-    --extension / -e  -- guess extension instead of type
-
-More than one type argument may be given.
 """
 
 import os
@@ -399,16 +388,27 @@ common_types = {
     }
 
 
-def usage(code, msg=''):
-    print __doc__
-    if msg: print msg
-    sys.exit(code)
-
-
 if __name__ == '__main__':
     import sys
     import getopt
 
+    USAGE = """\
+Usage: mimetypes.py [options] type
+
+Options:
+    --help / -h       -- print this message and exit
+    --lenient / -l    -- additionally search of some common, but non-standard
+                         types.
+    --extension / -e  -- guess extension instead of type
+
+More than one type argument may be given.
+"""
+
+    def usage(code, msg=''):
+        print USAGE
+        if msg: print msg
+        sys.exit(code)
+
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'hle',
                                    ['help', 'lenient', 'extension'])