NOTE:
This project is no longer being maintained: it was developed for my masters thesis, which was completed in early 1997. I still, however, welcome any questions or comments that people may have.

[Home] [ToC] [Prev] [Next]


iHTML Python Language

Standard ihURL Module

The ihURL module provides a standard interface to the host browser's URL transactions and other network operations. Its primary interface is through a set of classes that provide various types of services based on standard URL strings. In addition, some global symbols common to many of the classes are also available.


Exported Values


URL Status

URL_FINISHED
The connection has closed and all data has been read.
URL_INCOMPLETE
The connection is open and has not finished transffering data.
URL_INTERACTIVE
This is an interactive connection that is open and ready.

These three symbols define the status codes which an existing URL class may be in. And, yes, there is no error state yet...


Exported Exceptions


URLClosedError

This exception is raised when an I/O operation is attempted on a URL that has been closed. (E.g., its Destroy() method has been called.)

ImplementationError

This exception is raised when a method in an abstract class (e.g., the LineURL class) is called, but the method must be implemented by a subclass and has not been.

SecurityError

This exception is raised when some kind of insecure URL access is attempted, for example trying to open a "file:" URL.


Exported Functions


GetHostName

Synopsis
GetHostName()
Arguments
none.
Result
A string representing the network name of the machine the program is running under.

GetHostByName

Synopsis
GeHostByName(name)
Arguments
name
The network name of the machine to look up.
Result
A string representing the network IP address (in the nnn.nnn.nnn.nnn numeric dot form) of the given machine name.

Exported Types


There are no global types defined by this module.


Exported Classes


RawURL

This is the base-class of all URL classes. It defines the basic operations which may be done on a URL, retrieval of URL data and status information, and the active methods that sub-classes may override to interact with a URL.

Hierarchy

Superclass
none.
Subclasses
LineURL.

Methods

__init__(self, doc, url, ...)

Summary
Initiate a new URL transaction.
Arguments
doc
The Document under which the program desiring to retrieve this URL is running.
url
A string representing the URL to be retrieved. This may be a partial URL (e.g. "graphic.gif"), which will be interpreted as being relative to the base URL of the given document. See below for details on how different URLs are handled.
Result
A new instance of the class.
Description
To instantiate a RawURL class, the caller must supply a standard URL identifier and the Document in which it is running. The appropriate action will then be performed to retrieve the given URL. Control is returned back to the caller while the retrieval is in progress, with appropriate methods within this class called when data is ready.

The primary determining factor for what happens when this class is instantiated is the given URL string; this may be most of the more popular URL identifiers, along with special types intended to be useful primarily for internal program use. See the class description below for more detailed information.

OnRead(self, data)

Summary
Handler called when some data from the requested URL is available.
Arguments
data
A string containing the available data.
Result
nothing.
Description
This method is called whenever some data from the requested URL has arrived and is available. There is absolutely no structure associated with this data, beyond it being a byte stream, so it is up to the subclass to organize the data into higher logical units -- likely buffering partial data between calls to this method.

Note that this base-class's OnRead() method must be called by any subclass that overrides it, in order for this class to maintain correct state information.

Warning: This method may be called at any time. In particular, any time an asynchronous URL request is not supported, it will likely be called with the complete URL data before the __init__ method has returned.

Write(self, data)

Summary
Send data to the URL.
Arguments
data
A string containing the data to send.
Result
nothing.
Description
For two-way transactions (i.e., interactive URLs), this method is called to send data to the remote end. It is not blocking; any error will be reported through the OnError() method.

OnError(self, error)

Summary
Handler called when an error occurs.
Arguments
error
The associated error code. None are currently defined.
Result
nothing.
Description
This method is called when any error related to the retrieval of a URL occurs. Currently, error reporting is severely lacking and this method basically does nothing.

GetStatus(self)

Summary
Retrieve status information about the URL.
Arguments
none.
Result
Current status code.
Description
Returns a status code, defined above, describing the current state of this class's URL transaction. This can be used to check for errors, determine when all data has been retrieved, etc.

GetURL(self)

Summary
Return a string representing the actual URL being requested. This is the URL as given to __init__(), expanded to a fully-qualified URL string.
Arguments
none.
Result
A string representing the URL of the object.

GetHeader(self, name)

Summary
Retrieve the text for a particular piece of header information.
Arguments
name
Which header to retrieve the value of.
Result
A string containing the value of this header.
Description
This method retrieves the meta-information associated with a URL. Its exact semantics depend on the type of the URL: for HTTP and other MIME-based protocols, the name is a particular header, e.g. Content-type, and the returned value is a string representing the returned header line, or None if it was not supplied.

Note: the current implementation of iHTML does not get this header information from HTTP requests; it just always supplies one header line of Content-type: application/ihtml;language=python.

Destroy(self)

Summary
Kill this URL transaction.
Arguments
none.
Result
nothing.
Description
Calling this method kills the class's low-level URL transaction, and releases all resources associated with it. This is called when a transaction is over, to clean up circular links; it also must be called to stop a transaction in progress.

Members

This class has no publically defined members.

Description

This is the core class used to retrieve URL data. Most of its specific handling of URLs is performed back in the browser itself, and thus depends on the browser's capabilities. In the case of the Mosaic implementation, this provides access to most of the expected types of URLs -- http:, ftp:, etc. For these types of URLs, the expected behavior of returning the data associated with the given URL is provided. The behavior for other URLs such as news: and gopher: has not yet been defined.

The TCP: URL

In addition to the standard URLs mentioned above, the iHTML library itself defines a new URL named "tcp:". This URL provides low-level interactive access to a network; it essentially encapsulates the basic socket implementation into the same interface as all other higher-level network operations.

The complete syntax of this URL is "tcp://machine:port/". Much like other similarly constructed URLs, most of these fields are optional. The meanings of them are as follows:

machine
The name of the remote machine. E.g., flapjack.cs.orst.edu or 128.193.38.74.
port The specific port address of the machine to connect to.

Currently, only the fully qualified form, including both the machine name and port, is understood. This construct results in an interactive session being created with a server at the specified remote machine; it is essentially the equivalent of a socket connect() call.

In the future, additional forms of this URL will be added. Some of these will include:

tcp://port/
Open a local port that will listen for connections from other machines.
tcp:port/
Open a connection to the remote machine from which this document came, on the given port.

LineURL

An abstract class which provides line-structured access to a URL.

Hierarchy

Superclass
RawURL
Subclasses
none.

Methods

OnLine(self, lines)

Summary
Handler called when one or more lines of data have been retrieved from the URL. This method must be defined by a sub-class.
Arguments
lines
A list of the lines which have arrived. Every element of the list is a string, containing one line. The strings are not terminated by a new-line or carriage return character.
Result
nothing.
Description
This method is called whenever there are new lines of data available from the URL. The OnRead() method is overridden by this class, and it is used to buffer data until one or more complete lines are available. At that point, this method is called to hand the lines off to the superclass.

Members

This class has no publically defined members.


[Home] [ToC] [Prev] [Next]

_________.oo_Q_Q_oo.____________________________________________
Dianne Kyra Hackborn <hackbod@angryredplanet.com>
Last modified: Fri Sep 13 06:13:27 PDT 1996

This web page and all material contained herein is Copyright (c) 1997 Dianne Hackborn, unless otherwise noted. All rights reserved.