| 1 | n/a | """icopen patch |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | OVERVIEW |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | icopen patches MacOS Python to use the Internet Config file mappings to select |
|---|
| 6 | n/a | the type and creator for a file. |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | Version 1 released to the public domain 3 November 1999 |
|---|
| 9 | n/a | by Oliver Steele (steele@cs.brandeis.edu). |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | DETAILS |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | This patch causes files created by Python's open(filename, 'w') command (and |
|---|
| 14 | n/a | by functions and scripts that call it) to set the type and creator of the file |
|---|
| 15 | n/a | to the type and creator associated with filename's extension (the |
|---|
| 16 | n/a | portion of the filename after the last period), according to Internet Config. |
|---|
| 17 | n/a | Thus, a script that creates a file foo.html will create one that opens in whatever |
|---|
| 18 | n/a | browser you've set to handle *.html files, and so on. |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | Python IDE uses its own algorithm to select the type and creator for saved |
|---|
| 21 | n/a | editor windows, so this patch won't effect their types. |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | As of System 8.6 at least, Internet Config is built into the system, and the |
|---|
| 24 | n/a | file mappings are accessed from the Advanced pane of the Internet control |
|---|
| 25 | n/a | panel. User Mode (in the Edit menu) needs to be set to Advanced in order to |
|---|
| 26 | n/a | access this pane. |
|---|
| 27 | n/a | |
|---|
| 28 | n/a | INSTALLATION |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | Put this file in your Python path, and create a file named {Python}:sitecustomize.py |
|---|
| 31 | n/a | that contains: |
|---|
| 32 | n/a | import icopen |
|---|
| 33 | n/a | |
|---|
| 34 | n/a | (If {Python}:sitecustomizer.py already exists, just add the 'import' line to it.) |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | The next time you launch PythonInterpreter or Python IDE, the patch will take |
|---|
| 37 | n/a | effect. |
|---|
| 38 | n/a | """ |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | from warnings import warnpy3k |
|---|
| 41 | n/a | warnpy3k("In 3.x, the icopen module is removed.", stacklevel=2) |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | import __builtin__ |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | _builtin_open = globals().get('_builtin_open', __builtin__.open) |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | def _open_with_typer(*args): |
|---|
| 48 | n/a | file = _builtin_open(*args) |
|---|
| 49 | n/a | filename = args[0] |
|---|
| 50 | n/a | mode = 'r' |
|---|
| 51 | n/a | if args[1:]: |
|---|
| 52 | n/a | mode = args[1] |
|---|
| 53 | n/a | if mode[0] == 'w': |
|---|
| 54 | n/a | from ic import error, settypecreator |
|---|
| 55 | n/a | try: |
|---|
| 56 | n/a | settypecreator(filename) |
|---|
| 57 | n/a | except error: |
|---|
| 58 | n/a | pass |
|---|
| 59 | n/a | return file |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | __builtin__.open = _open_with_typer |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | """ |
|---|
| 64 | n/a | open('test.py') |
|---|
| 65 | n/a | _open_with_typer('test.py', 'w') |
|---|
| 66 | n/a | _open_with_typer('test.txt', 'w') |
|---|
| 67 | n/a | _open_with_typer('test.html', 'w') |
|---|
| 68 | n/a | _open_with_typer('test.foo', 'w') |
|---|
| 69 | n/a | """ |
|---|