Modules implementing WWW and URL suite, and a module to control netscape.
diff --git a/Mac/Lib/toolbox/Standard_URL_suite.py b/Mac/Lib/toolbox/Standard_URL_suite.py
new file mode 100644
index 0000000..d8bac0c
--- /dev/null
+++ b/Mac/Lib/toolbox/Standard_URL_suite.py
@@ -0,0 +1,52 @@
+"""Suite Standard URL suite: Mac URL standard, supported by many apps
+
+
+
+Level 1, version 1
+
+Generated from flap:Programma's:Netscape 2.0b5 Folder:Netscape 2.0b5
+AETE/AEUT resource version 1/0, language 0, script 0
+"""
+
+import addpack
+addpack.addpack('Tools')
+addpack.addpack('bgen')
+addpack.addpack('ae')
+
+import aetools
+import MacOS
+
+_code = 'GURL'
+
+class Standard_URL_suite:
+
+ _argmap_GetURL = {
+ 'to' : 'dest',
+ 'inside' : 'HWIN',
+ '_from' : 'refe',
+ }
+
+ def GetURL(self, _object, _attributes={}, **_arguments):
+ """GetURL: Loads the URL (optionaly to disk)
+
+ Required argument: The url
+ Keyword argument to: file the URL should be loaded into
+ Keyword argument inside: Window the URL should be loaded to
+ Keyword argument _from: Refererer, to be sent with the HTTP request
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ """
+ _code = 'GURL'
+ _subcode = 'GURL'
+
+ aetools.keysubst(_arguments, self._argmap_GetURL)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
diff --git a/Mac/Lib/toolbox/WWW_Suite.py b/Mac/Lib/toolbox/WWW_Suite.py
new file mode 100644
index 0000000..437243c
--- /dev/null
+++ b/Mac/Lib/toolbox/WWW_Suite.py
@@ -0,0 +1,416 @@
+"""Suite WorldWideWeb suite, as defined in Spyglass spec.:
+Level 1, version 1
+
+Generated from flap:Programma's:Netscape 2.0b5 Folder:Netscape 2.0b5
+AETE/AEUT resource version 1/0, language 0, script 0
+"""
+
+import addpack
+addpack.addpack('Tools')
+addpack.addpack('bgen')
+addpack.addpack('ae')
+
+import aetools
+import MacOS
+
+_code = 'WWW!'
+
+class WWW_Suite:
+
+ _argmap_OpenURL = {
+ 'to' : 'INTO',
+ 'toWindow' : 'WIND',
+ 'flags' : 'FLGS',
+ 'post_data' : 'POST',
+ 'post_type' : 'MIME',
+ 'progressApp' : 'PROG',
+ }
+
+ def OpenURL(self, _object, _attributes={}, **_arguments):
+ """OpenURL: Opens a URL. Allows for more options than GetURL event
+ Required argument: URL
+ Keyword argument to: file destination
+ Keyword argument toWindow: window iD
+ Keyword argument flags: Binary: any combination of 1, 2 and 4 is allowed: 1 and 2 mean force reload the document. 4 is ignored
+ Keyword argument post_data: Form posting data
+ Keyword argument post_type: MIME type of the posting data. Defaults to application/x-www-form-urlencoded
+ Keyword argument progressApp: Application that will display progress
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: ID of the loading window
+ """
+ _code = 'WWW!'
+ _subcode = 'OURL'
+
+ aetools.keysubst(_arguments, self._argmap_OpenURL)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_ShowFile = {
+ 'MIME_type' : 'MIME',
+ 'Window_ID' : 'WIND',
+ 'URL' : 'URL ',
+ }
+
+ def ShowFile(self, _object, _attributes={}, **_arguments):
+ """ShowFile: Similar to OpenDocuments, except that it specifies the parent URL, and MIME type of the file
+ Required argument: File to open
+ Keyword argument MIME_type: MIME type
+ Keyword argument Window_ID: Window to open the file in
+ Keyword argument URL: Use this as a base URL
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: Window ID of the loaded window. 0 means ShowFile failed, FFFFFFF means that data was not appropriate type to display in the browser.
+ """
+ _code = 'WWW!'
+ _subcode = 'SHWF'
+
+ aetools.keysubst(_arguments, self._argmap_ShowFile)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_parse_anchor = {
+ 'relative_to' : 'RELA',
+ }
+
+ def parse_anchor(self, _object, _attributes={}, **_arguments):
+ """parse anchor: Resolves the relative URL
+ Required argument: Main URL
+ Keyword argument relative_to: Relative URL
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: Parsed URL
+ """
+ _code = 'WWW!'
+ _subcode = 'PRSA'
+
+ aetools.keysubst(_arguments, self._argmap_parse_anchor)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_cancel_progress = {
+ 'in_window' : 'WIND',
+ }
+
+ def cancel_progress(self, _object=None, _attributes={}, **_arguments):
+ """cancel progress: Interrupts the download of the document in the given window
+ Required argument: progress ID, obtained from the progress app
+ Keyword argument in_window: window ID of the progress to cancel
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ """
+ _code = 'WWW!'
+ _subcode = 'CNCL'
+
+ aetools.keysubst(_arguments, self._argmap_cancel_progress)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ def find_URL(self, _object, _attributes={}, **_arguments):
+ """find URL: If the file was downloaded by Netscape, you can call FindURL to find out the URL used to download the file.
+ Required argument: File spec
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: The URL
+ """
+ _code = 'WWW!'
+ _subcode = 'FURL'
+
+ if _arguments: raise TypeError, 'No optional args expected'
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ def webActivate(self, _object=None, _attributes={}, **_arguments):
+ """webActivate: Makes Netscape the frontmost application, and selects a given window. This event is here for suite completeness/ cross-platform compatibility only, you should use standard AppleEvents instead.
+ Required argument: window to bring to front
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ """
+ _code = 'WWW!'
+ _subcode = 'ACTV'
+
+ if _arguments: raise TypeError, 'No optional args expected'
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ def list_windows(self, _no_object=None, _attributes={}, **_arguments):
+ """list windows: Lists the IDs of all the hypertext windows
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: List of unique IDs of all the hypertext windows
+ """
+ _code = 'WWW!'
+ _subcode = 'LSTW'
+
+ if _arguments: raise TypeError, 'No optional args expected'
+ if _no_object != None: raise TypeError, 'No direct arg expected'
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ def get_window_info(self, _object=None, _attributes={}, **_arguments):
+ """get window info: Returns the information about the window as a list. Currently the list contains the window title and the URL. You can get the same information using standard Apple Event GetProperty.
+ Required argument: window ID
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: undocumented, typecode 'list'
+ """
+ _code = 'WWW!'
+ _subcode = 'WNFO'
+
+ if _arguments: raise TypeError, 'No optional args expected'
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ def register_URL_echo(self, _object=None, _attributes={}, **_arguments):
+ """register URL echo: Registers the ³echo² application. Each download from now on will be echoed to this application.
+ Required argument: Application signature
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ """
+ _code = 'WWW!'
+ _subcode = 'RGUE'
+
+ if _arguments: raise TypeError, 'No optional args expected'
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ def unregister_URL_echo(self, _object, _attributes={}, **_arguments):
+ """unregister URL echo: cancels URL echo
+ Required argument: application signature
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ """
+ _code = 'WWW!'
+ _subcode = 'UNRU'
+
+ if _arguments: raise TypeError, 'No optional args expected'
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_register_viewer = {
+ 'MIME_type' : 'MIME',
+ 'with_file_type' : 'FTYP',
+ }
+
+ def register_viewer(self, _object, _attributes={}, **_arguments):
+ """register viewer: Registers an application as a special¹ viewer for this MIME type. The application will be launched with ViewDoc events
+ Required argument: Application sig
+ Keyword argument MIME_type: MIME type viewer is registering for
+ Keyword argument with_file_type: Mac file type for the downloaded files
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: TRUE if registration has been successful
+ """
+ _code = 'WWW!'
+ _subcode = 'RGVW'
+
+ aetools.keysubst(_arguments, self._argmap_register_viewer)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_unregister_viewer = {
+ 'MIME_type' : 'MIME',
+ }
+
+ def unregister_viewer(self, _object, _attributes={}, **_arguments):
+ """unregister viewer: Revert to the old way of handling this MIME type
+ Required argument: Application sig
+ Keyword argument MIME_type: MIME type to be unregistered
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: TRUE if the event was successful
+ """
+ _code = 'WWW!'
+ _subcode = 'UNRV'
+
+ aetools.keysubst(_arguments, self._argmap_unregister_viewer)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_register_protocol = {
+ 'for_protocol' : 'PROT',
+ }
+
+ def register_protocol(self, _object=None, _attributes={}, **_arguments):
+ """register protocol: Registers application as a ³handler² for this protocol with a given prefix. The handler will receive ³OpenURL², or if that fails, ³GetURL² event.
+ Required argument: Application sig
+ Keyword argument for_protocol: protocol prefix: ³finger:², ³file²,
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: TRUE if registration has been successful
+ """
+ _code = 'WWW!'
+ _subcode = 'RGPR'
+
+ aetools.keysubst(_arguments, self._argmap_register_protocol)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_unregister_protocol = {
+ 'for_protocol' : 'PROT',
+ }
+
+ def unregister_protocol(self, _object=None, _attributes={}, **_arguments):
+ """unregister protocol: reverses the effects of ³register protocol²
+ Required argument: Application sig.
+ Keyword argument for_protocol: protocol prefix. If none, unregister for all protocols
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: TRUE if successful
+ """
+ _code = 'WWW!'
+ _subcode = 'UNRP'
+
+ aetools.keysubst(_arguments, self._argmap_unregister_protocol)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_register_window_close = {
+ 'for_window' : 'WIND',
+ }
+
+ def register_window_close(self, _object=None, _attributes={}, **_arguments):
+ """register window close: Netscape will notify registered application when this window closes
+ Required argument: Application signature
+ Keyword argument for_window: window ID
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: true if successful
+ """
+ _code = 'WWW!'
+ _subcode = 'RGWC'
+
+ aetools.keysubst(_arguments, self._argmap_register_window_close)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
+ _argmap_unregister_window_close = {
+ 'for_window' : 'WIND',
+ }
+
+ def unregister_window_close(self, _object=None, _attributes={}, **_arguments):
+ """unregister window close: Undo for register window close
+ Required argument: Application signature
+ Keyword argument for_window: window ID
+ Keyword argument _attributes: AppleEvent attribute dictionary
+ Returns: true if successful
+ """
+ _code = 'WWW!'
+ _subcode = 'UNRC'
+
+ aetools.keysubst(_arguments, self._argmap_unregister_window_close)
+ _arguments['----'] = _object
+
+
+ _reply, _arguments, _attributes = self.send(_code, _subcode,
+ _arguments, _attributes)
+ if _arguments.has_key('errn'):
+ raise MacOS.Error, aetools.decodeerror(_arguments)
+ # XXXX Optionally decode result
+ if _arguments.has_key('----'):
+ return _arguments['----']
+
diff --git a/Mac/Modules/ae/nsremote.py b/Mac/Modules/ae/nsremote.py
new file mode 100644
index 0000000..cace374
--- /dev/null
+++ b/Mac/Modules/ae/nsremote.py
@@ -0,0 +1,76 @@
+"""nsremote - Control Netscape from python.
+
+Interface modelled after unix-interface done
+by hassan@cs.stanford.edu.
+
+Jack Jansen, CWI, January 1996.
+"""
+#
+# Note: this module currently uses the funny SpyGlass AppleEvents, since
+# these seem to be the only way to get the info from Netscape. It would
+# be nicer to use the more "object oriented" standard OSA stuff, when it
+# is implemented in Netscape.
+#
+import addpack
+import sys
+
+addpack.addpack('Tools')
+addpack.addpack('bgen')
+addpack.addpack('ae')
+
+import aetools
+import Standard_Suite
+import WWW_Suite
+import MacOS
+
+class Netscape(aetools.TalkTo, Standard_Suite.Standard_Suite, WWW_Suite.WWW_Suite):
+ pass
+
+SIGNATURE='MOSS'
+
+Error = 'nsremote.Error'
+
+_talker = None
+
+def _init():
+ global _talker
+ if _talker == None:
+ _talker = Netscape(SIGNATURE)
+
+def list(dpyinfo=""):
+ _init()
+ list = _talker.list_windows()
+ return map(lambda x: (x, 'version unknown'), list)
+
+def geturl(windowid=0, dpyinfo=""):
+ _init()
+ if windowid == 0:
+ ids = _talker.list_windows()
+ if not ids:
+ raise Error, 'No netscape windows open'
+ windowid = ids[0]
+ info = _talker.get_window_info(windowid)
+ return info
+
+def openurl(url, windowid=0, dpyinfo=""):
+ _init()
+ if windowid == 0:
+ _talker.OpenURL(url)
+ else:
+ _talker.OpenURL(url, toWindow=windowid)
+
+def _test():
+ """Test program: Open www.python.org in all windows, then revert"""
+ import sys
+ windows_and_versions = list()
+ windows_and_urls = map(lambda x: (x[0], geturl(x[0])[0]), windows_and_versions)
+ for id, version in windows_and_versions:
+ openurl('http://www.python.org/', windowid=id)
+ print 'Type return to revert to old contents-'
+ sys.stdin.readline()
+ for id, url in windows_and_urls:
+ openurl(url, id)
+
+if __name__ == '__main__':
+ _test()
+