[Zope3-checkins] SVN: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/ reproduce the good parts of previous real-testbrowser branch with improvements

Benji York benji at zope.com
Sat Jul 29 22:22:14 EDT 2006


Log message for revision 69294:
  reproduce the good parts of previous real-testbrowser branch with improvements
  

Changed:
  U   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/LICENSES.txt
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/BeautifulSoup.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/__init__.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/decoder.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/encoder.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/jsonfilter.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/scanner.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/__init__.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_fail.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass1.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass2.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass3.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_recursion.py
  U   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/browser.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__init__.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Async.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Base.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Color.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DOM.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DateTime.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Format.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Iter.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Logging.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/LoggingPane.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MochiKit.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MockDOM.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Signal.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Test.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Visual.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/__package__.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/shim.js
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/start.html
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/tests.py
  A   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/utilities.py

-=-
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/LICENSES.txt
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/LICENSES.txt	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/LICENSES.txt	2006-07-30 02:22:10 UTC (rev 69294)
@@ -104,3 +104,17 @@
 Software Foundation (PSF) and is covered by the PSF license agreement
 for Python 2.4.  We will no-longer distribute this module with Zope at
 some point on the future.
+
+----------------------------------------------------------------------
+
+The simplejson library is covered by the MIT license.
+
+----------------------------------------------------------------------
+
+The Beautiful Soup module is covered by the Python license.
+
+----------------------------------------------------------------------
+
+MochiKit is covered by the MIT license.
+
+----------------------------------------------------------------------

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/BeautifulSoup.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/BeautifulSoup.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/BeautifulSoup.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,1080 @@
+"""Beautiful Soup
+Elixir and Tonic
+"The Screen-Scraper's Friend"
+v2.1.1
+http://www.crummy.com/software/BeautifulSoup/
+
+Beautiful Soup parses arbitrarily invalid XML- or HTML-like substance
+into a tree representation. It provides methods and Pythonic idioms
+that make it easy to search and modify the tree.
+
+A well-formed XML/HTML document will yield a well-formed data
+structure. An ill-formed XML/HTML document will yield a
+correspondingly ill-formed data structure. If your document is only
+locally well-formed, you can use this library to find and process the
+well-formed part of it. The BeautifulSoup class has heuristics for
+obtaining a sensible parse tree in the face of common HTML errors.
+
+Beautiful Soup has no external dependencies. It works with Python 2.2
+and up.
+
+Beautiful Soup defines classes for four different parsing strategies:
+
+ * BeautifulStoneSoup, for parsing XML, SGML, or your domain-specific
+   language that kind of looks like XML.
+
+ * BeautifulSoup, for parsing run-of-the-mill HTML code, be it valid
+   or invalid.
+
+ * ICantBelieveItsBeautifulSoup, for parsing valid but bizarre HTML
+   that trips up BeautifulSoup.
+
+ * BeautifulSOAP, for making it easier to parse XML documents that use
+   lots of subelements containing a single string, where you'd prefer
+   they put that string into an attribute (such as SOAP messages).
+
+You can subclass BeautifulStoneSoup or BeautifulSoup to create a
+parsing strategy specific to an XML schema or a particular bizarre
+HTML document. Typically your subclass would just override
+SELF_CLOSING_TAGS and/or NESTABLE_TAGS.
+"""
+from __future__ import generators
+
+__author__ = "Leonard Richardson (leonardr at segfault.org)"
+__version__ = "2.1.1"
+__date__ = "$Date: 2004/10/18 00:14:20 $"
+__copyright__ = "Copyright (c) 2004-2005 Leonard Richardson"
+__license__ = "PSF"
+
+from sgmllib import SGMLParser, SGMLParseError
+import types
+import re
+import sgmllib
+
+#This code makes Beautiful Soup able to parse XML with namespaces
+sgmllib.tagfind = re.compile('[a-zA-Z][-_.:a-zA-Z0-9]*')
+
+class NullType(object):
+
+    """Similar to NoneType with a corresponding singleton instance
+    'Null' that, unlike None, accepts any message and returns itself.
+
+    Examples:
+    >>> Null("send", "a", "message")("and one more",
+    ...      "and what you get still") is Null
+    True
+    """
+
+    def __new__(cls):                    return Null
+    def __call__(self, *args, **kwargs): return Null
+##    def __getstate__(self, *args):       return Null
+    def __getattr__(self, attr):         return Null
+    def __getitem__(self, item):         return Null
+    def __setattr__(self, attr, value):  pass
+    def __setitem__(self, item, value):  pass
+    def __len__(self):                   return 0
+    # FIXME: is this a python bug? otherwise ``for x in Null: pass``
+    #        never terminates...
+    def __iter__(self):                  return iter([])
+    def __contains__(self, item):        return False
+    def __repr__(self):                  return "Null"
+Null = object.__new__(NullType)
+
+class PageElement:
+    """Contains the navigational information for some part of the page
+    (either a tag or a piece of text)"""
+
+    def setup(self, parent=Null, previous=Null):
+        """Sets up the initial relations between this element and
+        other elements."""
+        self.parent = parent
+        self.previous = previous
+        self.next = Null
+        self.previousSibling = Null
+        self.nextSibling = Null
+        if self.parent and self.parent.contents:
+            self.previousSibling = self.parent.contents[-1]
+            self.previousSibling.nextSibling = self
+
+    def findNext(self, name=None, attrs={}, text=None):
+        """Returns the first item that matches the given criteria and
+        appears after this Tag in the document."""
+        return self._first(self.fetchNext, name, attrs, text)
+    firstNext = findNext
+
+    def fetchNext(self, name=None, attrs={}, text=None, limit=None):
+        """Returns all items that match the given criteria and appear
+        before after Tag in the document."""
+        return self._fetch(name, attrs, text, limit, self.nextGenerator)
+
+    def findNextSibling(self, name=None, attrs={}, text=None):
+        """Returns the closest sibling to this Tag that matches the
+        given criteria and appears after this Tag in the document."""
+        return self._first(self.fetchNextSiblings, name, attrs, text)
+    firstNextSibling = findNextSibling
+
+    def fetchNextSiblings(self, name=None, attrs={}, text=None, limit=None):
+        """Returns the siblings of this Tag that match the given
+        criteria and appear after this Tag in the document."""
+        return self._fetch(name, attrs, text, limit, self.nextSiblingGenerator)
+
+    def findPrevious(self, name=None, attrs={}, text=None):
+        """Returns the first item that matches the given criteria and
+        appears before this Tag in the document."""
+        return self._first(self.fetchPrevious, name, attrs, text)
+
+    def fetchPrevious(self, name=None, attrs={}, text=None, limit=None):
+        """Returns all items that match the given criteria and appear
+        before this Tag in the document."""
+        return self._fetch(name, attrs, text, limit, self.previousGenerator)
+    firstPrevious = findPrevious
+
+    def findPreviousSibling(self, name=None, attrs={}, text=None):
+        """Returns the closest sibling to this Tag that matches the
+        given criteria and appears before this Tag in the document."""
+        return self._first(self.fetchPreviousSiblings, name, attrs, text)
+    firstPreviousSibling = findPreviousSibling
+
+    def fetchPreviousSiblings(self, name=None, attrs={}, text=None,
+                              limit=None):
+        """Returns the siblings of this Tag that match the given
+        criteria and appear before this Tag in the document."""
+        return self._fetch(name, attrs, text, limit,
+                           self.previousSiblingGenerator)
+
+    def findParent(self, name=None, attrs={}):
+        """Returns the closest parent of this Tag that matches the given
+        criteria."""
+        r = Null
+        l = self.fetchParents(name, attrs, 1)
+        if l:
+            r = l[0]
+        return r
+    firstParent = findParent
+
+    def fetchParents(self, name=None, attrs={}, limit=None):
+        """Returns the parents of this Tag that match the given
+        criteria."""
+        return self._fetch(name, attrs, None, limit, self.parentGenerator)
+
+    #These methods do the real heavy lifting.
+
+    def _first(self, method, name, attrs, text):
+        r = Null
+        l = method(name, attrs, text, 1)
+        if l:
+            r = l[0]
+        return r
+    
+    def _fetch(self, name, attrs, text, limit, generator):
+        "Iterates over a generator looking for things that match."
+        if not hasattr(attrs, 'items'):
+            attrs = {'class' : attrs}
+
+        results = []
+        g = generator()
+        while True:
+            try:
+                i = g.next()
+            except StopIteration:
+                break
+            found = None
+            if isinstance(i, Tag):
+                if not text:
+                    if not name or self._matches(i, name):
+                        match = True
+                        for attr, matchAgainst in attrs.items():
+                            check = i.get(attr)
+                            if not self._matches(check, matchAgainst):
+                                match = False
+                                break
+                        if match:
+                            found = i
+            elif text:
+                if self._matches(i, text):
+                    found = i                    
+            if found:
+                results.append(found)
+                if limit and len(results) >= limit:
+                    break
+        return results
+
+    #Generators that can be used to navigate starting from both
+    #NavigableTexts and Tags.                
+    def nextGenerator(self):
+        i = self
+        while i:
+            i = i.next
+            yield i
+
+    def nextSiblingGenerator(self):
+        i = self
+        while i:
+            i = i.nextSibling
+            yield i
+
+    def previousGenerator(self):
+        i = self
+        while i:
+            i = i.previous
+            yield i
+
+    def previousSiblingGenerator(self):
+        i = self
+        while i:
+            i = i.previousSibling
+            yield i
+
+    def parentGenerator(self):
+        i = self
+        while i:
+            i = i.parent
+            yield i
+
+    def _matches(self, chunk, howToMatch):
+        #print 'looking for %s in %s' % (howToMatch, chunk)
+        #
+        # If given a list of items, return true if the list contains a
+        # text element that matches.
+        if isList(chunk) and not isinstance(chunk, Tag):
+            for tag in chunk:
+                if isinstance(tag, NavigableText) and self._matches(tag, howToMatch):
+                    return True
+            return False
+        if callable(howToMatch):
+            return howToMatch(chunk)
+        if isinstance(chunk, Tag):
+            #Custom match methods take the tag as an argument, but all other
+            #ways of matching match the tag name as a string
+            chunk = chunk.name
+        #Now we know that chunk is a string
+        if not isinstance(chunk, basestring):
+            chunk = str(chunk)
+        if hasattr(howToMatch, 'match'):
+            # It's a regexp object.
+            return howToMatch.search(chunk)
+        if isList(howToMatch):
+            return chunk in howToMatch
+        if hasattr(howToMatch, 'items'):
+            return howToMatch.has_key(chunk)
+        #It's just a string
+        return str(howToMatch) == chunk
+
+class NavigableText(PageElement):
+
+    def __getattr__(self, attr):
+        "For backwards compatibility, text.string gives you text"
+        if attr == 'string':
+            return self
+        else:
+            raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)
+        
+class NavigableString(str, NavigableText):
+    pass
+
+class NavigableUnicodeString(unicode, NavigableText):
+    pass
+
+class Tag(PageElement):
+
+    """Represents a found HTML tag with its attributes and contents."""
+
+    def __init__(self, name, attrs=None, parent=Null, previous=Null):
+        "Basic constructor."
+        self.name = name
+        if attrs == None:
+            attrs = []
+        self.attrs = attrs
+        self.contents = []
+        self.setup(parent, previous)
+        self.hidden = False
+
+    def get(self, key, default=None):
+        """Returns the value of the 'key' attribute for the tag, or
+        the value given for 'default' if it doesn't have that
+        attribute."""
+        return self._getAttrMap().get(key, default)    
+
+    def __getitem__(self, key):
+        """tag[key] returns the value of the 'key' attribute for the tag,
+        and throws an exception if it's not there."""
+        return self._getAttrMap()[key]
+
+    def __iter__(self):
+        "Iterating over a tag iterates over its contents."
+        return iter(self.contents)
+
+    def __len__(self):
+        "The length of a tag is the length of its list of contents."
+        return len(self.contents)
+
+    def __contains__(self, x):
+        return x in self.contents
+
+    def __nonzero__(self):
+        "A tag is non-None even if it has no contents."
+        return True
+
+    def __setitem__(self, key, value):        
+        """Setting tag[key] sets the value of the 'key' attribute for the
+        tag."""
+        self._getAttrMap()
+        self.attrMap[key] = value
+        found = False
+        for i in range(0, len(self.attrs)):
+            if self.attrs[i][0] == key:
+                self.attrs[i] = (key, value)
+                found = True
+        if not found:
+            self.attrs.append((key, value))
+        self._getAttrMap()[key] = value
+
+    def __delitem__(self, key):
+        "Deleting tag[key] deletes all 'key' attributes for the tag."
+        for item in self.attrs:
+            if item[0] == key:
+                self.attrs.remove(item)
+                #We don't break because bad HTML can define the same
+                #attribute multiple times.
+            self._getAttrMap()
+            if self.attrMap.has_key(key):
+                del self.attrMap[key]
+
+    def __call__(self, *args, **kwargs):
+        """Calling a tag like a function is the same as calling its
+        fetch() method. Eg. tag('a') returns a list of all the A tags
+        found within this tag."""
+        return apply(self.fetch, args, kwargs)
+
+    def __getattr__(self, tag):
+        if len(tag) > 3 and tag.rfind('Tag') == len(tag)-3:
+            return self.first(tag[:-3])
+        elif tag.find('__') != 0:
+            return self.first(tag)
+
+    def __eq__(self, other):
+        """Returns true iff this tag has the same name, the same attributes,
+        and the same contents (recursively) as the given tag.
+
+        NOTE: right now this will return false if two tags have the
+        same attributes in a different order. Should this be fixed?"""
+        if not hasattr(other, 'name') or not hasattr(other, 'attrs') or not hasattr(other, 'contents') or self.name != other.name or self.attrs != other.attrs or len(self) != len(other):
+            return False
+        for i in range(0, len(self.contents)):
+            if self.contents[i] != other.contents[i]:
+                return False
+        return True
+
+    def __ne__(self, other):
+        """Returns true iff this tag is not identical to the other tag,
+        as defined in __eq__."""
+        return not self == other
+
+    def __repr__(self):
+        """Renders this tag as a string."""
+        return str(self)
+
+    def __unicode__(self):
+        return self.__str__(1)
+
+    def __str__(self, needUnicode=None, showStructureIndent=None):
+        """Returns a string or Unicode representation of this tag and
+        its contents.
+
+        NOTE: since Python's HTML parser consumes whitespace, this
+        method is not certain to reproduce the whitespace present in
+        the original string."""
+        
+        attrs = []
+        if self.attrs:
+            for key, val in self.attrs:
+                attrs.append('%s="%s"' % (key, val))
+        close = ''
+        closeTag = ''
+        if self.isSelfClosing():
+            close = ' /'
+        else:
+            closeTag = '</%s>' % self.name
+        indentIncrement = None        
+        if showStructureIndent != None:
+            indentIncrement = showStructureIndent
+            if not self.hidden:
+                indentIncrement += 1
+        contents = self.renderContents(indentIncrement, needUnicode=needUnicode)        
+        if showStructureIndent:
+            space = '\n%s' % (' ' * showStructureIndent)
+        if self.hidden:
+            s = contents
+        else:
+            s = []
+            attributeString = ''
+            if attrs:
+                attributeString = ' ' + ' '.join(attrs)            
+            if showStructureIndent:
+                s.append(space)
+            s.append('<%s%s%s>' % (self.name, attributeString, close))
+            s.append(contents)
+            if closeTag and showStructureIndent != None:
+                s.append(space)
+            s.append(closeTag)
+            s = ''.join(s)
+        isUnicode = type(s) == types.UnicodeType
+        if needUnicode and not isUnicode:
+            s = unicode(s)
+        elif isUnicode and needUnicode==False:
+            s = str(s)
+        return s
+
+    def prettify(self, needUnicode=None):
+        return self.__str__(needUnicode, showStructureIndent=True)
+
+    def renderContents(self, showStructureIndent=None, needUnicode=None):
+        """Renders the contents of this tag as a (possibly Unicode) 
+        string."""
+        s=[]
+        for c in self:
+            text = None
+            if isinstance(c, NavigableUnicodeString) or type(c) == types.UnicodeType:
+                text = unicode(c)
+            elif isinstance(c, Tag):
+                s.append(c.__str__(needUnicode, showStructureIndent))
+            elif needUnicode:
+                text = unicode(c)
+            else:
+                text = str(c)
+            if text:
+                if showStructureIndent != None:
+                    if text[-1] == '\n':
+                        text = text[:-1]
+                s.append(text)
+        return ''.join(s)    
+
+    #Soup methods
+
+    def firstText(self, text, recursive=True):
+        """Convenience method to retrieve the first piece of text matching the
+        given criteria. 'text' can be a string, a regular expression object,
+        a callable that takes a string and returns whether or not the
+        string 'matches', etc."""
+        return self.first(recursive=recursive, text=text)
+
+    def fetchText(self, text, recursive=True, limit=None):
+        """Convenience method to retrieve all pieces of text matching the
+        given criteria. 'text' can be a string, a regular expression object,
+        a callable that takes a string and returns whether or not the
+        string 'matches', etc."""
+        return self.fetch(recursive=recursive, text=text, limit=limit)
+
+    def first(self, name=None, attrs={}, recursive=True, text=None):
+        """Return only the first child of this
+        Tag matching the given criteria."""
+        r = Null
+        l = self.fetch(name, attrs, recursive, text, 1)
+        if l:
+            r = l[0]
+        return r
+    findChild = first
+
+    def fetch(self, name=None, attrs={}, recursive=True, text=None,
+              limit=None):
+        """Extracts a list of Tag objects that match the given
+        criteria.  You can specify the name of the Tag and any
+        attributes you want the Tag to have.
+
+        The value of a key-value pair in the 'attrs' map can be a
+        string, a list of strings, a regular expression object, or a
+        callable that takes a string and returns whether or not the
+        string matches for some custom definition of 'matches'. The
+        same is true of the tag name."""
+        generator = self.recursiveChildGenerator
+        if not recursive:
+            generator = self.childGenerator
+        return self._fetch(name, attrs, text, limit, generator)
+    fetchChildren = fetch
+    
+    #Utility methods
+
+    def isSelfClosing(self):
+        """Returns true iff this is a self-closing tag as defined in the HTML
+        standard.
+
+        TODO: This is specific to BeautifulSoup and its subclasses, but it's
+        used by __str__"""
+        return self.name in BeautifulSoup.SELF_CLOSING_TAGS
+
+    def append(self, tag):
+        """Appends the given tag to the contents of this tag."""
+        self.contents.append(tag)
+
+    #Private methods
+
+    def _getAttrMap(self):
+        """Initializes a map representation of this tag's attributes,
+        if not already initialized."""
+        if not getattr(self, 'attrMap'):
+            self.attrMap = {}
+            for (key, value) in self.attrs:
+                self.attrMap[key] = value 
+        return self.attrMap
+
+    #Generator methods
+    def childGenerator(self):
+        for i in range(0, len(self.contents)):
+            yield self.contents[i]
+        raise StopIteration
+    
+    def recursiveChildGenerator(self):
+        stack = [(self, 0)]
+        while stack:
+            tag, start = stack.pop()
+            if isinstance(tag, Tag):            
+                for i in range(start, len(tag.contents)):
+                    a = tag.contents[i]
+                    yield a
+                    if isinstance(a, Tag) and tag.contents:
+                        if i < len(tag.contents) - 1:
+                            stack.append((tag, i+1))
+                        stack.append((a, 0))
+                        break
+        raise StopIteration
+
+
+def isList(l):
+    """Convenience method that works with all 2.x versions of Python
+    to determine whether or not something is listlike."""
+    return hasattr(l, '__iter__') \
+           or (type(l) in (types.ListType, types.TupleType))
+
+def buildTagMap(default, *args):
+    """Turns a list of maps, lists, or scalars into a single map.
+    Used to build the SELF_CLOSING_TAGS and NESTABLE_TAGS maps out
+    of lists and partial maps."""
+    built = {}
+    for portion in args:
+        if hasattr(portion, 'items'):
+            #It's a map. Merge it.
+            for k,v in portion.items():
+                built[k] = v
+        elif isList(portion):
+            #It's a list. Map each item to the default.
+            for k in portion:
+                built[k] = default
+        else:
+            #It's a scalar. Map it to the default.
+            built[portion] = default
+    return built
+
+class BeautifulStoneSoup(Tag, SGMLParser):
+
+    """This class contains the basic parser and fetch code. It defines
+    a parser that knows nothing about tag behavior except for the
+    following:
+   
+      You can't close a tag without closing all the tags it encloses.
+      That is, "<foo><bar></foo>" actually means
+      "<foo><bar></bar></foo>".
+
+    [Another possible explanation is "<foo><bar /></foo>", but since
+    this class defines no SELF_CLOSING_TAGS, it will never use that
+    explanation.]
+
+    This class is useful for parsing XML or made-up markup languages,
+    or when BeautifulSoup makes an assumption counter to what you were
+    expecting."""
+
+    SELF_CLOSING_TAGS = {}
+    NESTABLE_TAGS = {}
+    RESET_NESTING_TAGS = {}
+    QUOTE_TAGS = {}
+
+    #As a public service we will by default silently replace MS smart quotes
+    #and similar characters with their HTML or ASCII equivalents.
+    MS_CHARS = { '\x80' : '&euro;',
+                 '\x81' : ' ',
+                 '\x82' : '&sbquo;',
+                 '\x83' : '&fnof;',
+                 '\x84' : '&bdquo;',
+                 '\x85' : '&hellip;',
+                 '\x86' : '&dagger;',
+                 '\x87' : '&Dagger;',
+                 '\x88' : '&caret;',
+                 '\x89' : '%',
+                 '\x8A' : '&Scaron;',
+                 '\x8B' : '&lt;',
+                 '\x8C' : '&OElig;',
+                 '\x8D' : '?',
+                 '\x8E' : 'Z',
+                 '\x8F' : '?',
+                 '\x90' : '?',
+                 '\x91' : '&lsquo;',
+                 '\x92' : '&rsquo;',
+                 '\x93' : '&ldquo;',
+                 '\x94' : '&rdquo;',
+                 '\x95' : '&bull;',
+                 '\x96' : '&ndash;',
+                 '\x97' : '&mdash;',
+                 '\x98' : '&tilde;',
+                 '\x99' : '&trade;',
+                 '\x9a' : '&scaron;',
+                 '\x9b' : '&gt;',
+                 '\x9c' : '&oelig;',
+                 '\x9d' : '?',
+                 '\x9e' : 'z',
+                 '\x9f' : '&Yuml;',}
+
+    PARSER_MASSAGE = [(re.compile('(<[^<>]*)/>'),
+                       lambda(x):x.group(1) + ' />'),
+                      (re.compile('<!\s+([^<>]*)>'),
+                       lambda(x):'<!' + x.group(1) + '>'),
+                      (re.compile("([\x80-\x9f])"),
+                       lambda(x): BeautifulStoneSoup.MS_CHARS.get(x.group(1)))
+                      ]
+
+    ROOT_TAG_NAME = '[document]'
+
+    def __init__(self, text=None, avoidParserProblems=True,
+                 initialTextIsEverything=True):
+        """Initialize this as the 'root tag' and feed in any text to
+        the parser.
+
+        NOTE about avoidParserProblems: sgmllib will process most bad
+        HTML, and BeautifulSoup has tricks for dealing with some HTML
+        that kills sgmllib, but Beautiful Soup can nonetheless choke
+        or lose data if your data uses self-closing tags or
+        declarations incorrectly. By default, Beautiful Soup sanitizes
+        its input to avoid the vast majority of these problems. The
+        problems are relatively rare, even in bad HTML, so feel free
+        to pass in False to avoidParserProblems if they don't apply to
+        you, and you'll get better performance. The only reason I have
+        this turned on by default is so I don't get so many tech
+        support questions.
+
+        The two most common instances of invalid HTML that will choke
+        sgmllib are fixed by the default parser massage techniques:
+
+         <br/> (No space between name of closing tag and tag close)
+         <! --Comment--> (Extraneous whitespace in declaration)
+
+        You can pass in a custom list of (RE object, replace method)
+        tuples to get Beautiful Soup to scrub your input the way you
+        want."""
+        Tag.__init__(self, self.ROOT_TAG_NAME)
+        if avoidParserProblems \
+           and not isList(avoidParserProblems):
+            avoidParserProblems = self.PARSER_MASSAGE            
+        self.avoidParserProblems = avoidParserProblems
+        SGMLParser.__init__(self)
+        self.quoteStack = []
+        self.hidden = 1
+        self.reset()
+        if hasattr(text, 'read'):
+            #It's a file-type object.
+            text = text.read()
+        if text:
+            self.feed(text)
+        if initialTextIsEverything:
+            self.done()
+
+    def __getattr__(self, methodName):
+        """This method routes method call requests to either the SGMLParser
+        superclass or the Tag superclass, depending on the method name."""
+        if methodName.find('start_') == 0 or methodName.find('end_') == 0 \
+               or methodName.find('do_') == 0:
+            return SGMLParser.__getattr__(self, methodName)
+        elif methodName.find('__') != 0:
+            return Tag.__getattr__(self, methodName)
+        else:
+            raise AttributeError
+
+    def feed(self, text):
+        if self.avoidParserProblems:
+            for fix, m in self.avoidParserProblems:
+                text = fix.sub(m, text)
+        SGMLParser.feed(self, text)
+
+    def done(self):
+        """Called when you're done parsing, so that the unclosed tags can be
+        correctly processed."""
+        self.endData() #NEW
+        while self.currentTag.name != self.ROOT_TAG_NAME:
+            self.popTag()
+            
+    def reset(self):
+        SGMLParser.reset(self)
+        self.currentData = []
+        self.currentTag = None
+        self.tagStack = []
+        self.pushTag(self)        
+    
+    def popTag(self):
+        tag = self.tagStack.pop()
+        # Tags with just one string-owning child get the child as a
+        # 'string' property, so that soup.tag.string is shorthand for
+        # soup.tag.contents[0]
+        if len(self.currentTag.contents) == 1 and \
+           isinstance(self.currentTag.contents[0], NavigableText):
+            self.currentTag.string = self.currentTag.contents[0]
+
+        #print "Pop", tag.name
+        if self.tagStack:
+            self.currentTag = self.tagStack[-1]
+        return self.currentTag
+
+    def pushTag(self, tag):
+        #print "Push", tag.name
+        if self.currentTag:
+            self.currentTag.append(tag)
+        self.tagStack.append(tag)
+        self.currentTag = self.tagStack[-1]
+
+    def endData(self):
+        currentData = ''.join(self.currentData)
+        if currentData:
+            if not currentData.strip():
+                if '\n' in currentData:
+                    currentData = '\n'
+                else:
+                    currentData = ' '
+            c = NavigableString
+            if type(currentData) == types.UnicodeType:
+                c = NavigableUnicodeString
+            o = c(currentData)
+            o.setup(self.currentTag, self.previous)
+            if self.previous:
+                self.previous.next = o
+            self.previous = o
+            self.currentTag.contents.append(o)
+        self.currentData = []
+
+    def _popToTag(self, name, inclusivePop=True):
+        """Pops the tag stack up to and including the most recent
+        instance of the given tag. If inclusivePop is false, pops the tag
+        stack up to but *not* including the most recent instqance of
+        the given tag."""
+        if name == self.ROOT_TAG_NAME:
+            return            
+
+        numPops = 0
+        mostRecentTag = None
+        for i in range(len(self.tagStack)-1, 0, -1):
+            if name == self.tagStack[i].name:
+                numPops = len(self.tagStack)-i
+                break
+        if not inclusivePop:
+            numPops = numPops - 1
+
+        for i in range(0, numPops):
+            mostRecentTag = self.popTag()
+        return mostRecentTag    
+
+    def _smartPop(self, name):
+
+        """We need to pop up to the previous tag of this type, unless
+        one of this tag's nesting reset triggers comes between this
+        tag and the previous tag of this type, OR unless this tag is a
+        generic nesting trigger and another generic nesting trigger
+        comes between this tag and the previous tag of this type.
+
+        Examples:
+         <p>Foo<b>Bar<p> should pop to 'p', not 'b'.
+         <p>Foo<table>Bar<p> should pop to 'table', not 'p'.
+         <p>Foo<table><tr>Bar<p> should pop to 'tr', not 'p'.
+         <p>Foo<b>Bar<p> should pop to 'p', not 'b'.
+
+         <li><ul><li> *<li>* should pop to 'ul', not the first 'li'.
+         <tr><table><tr> *<tr>* should pop to 'table', not the first 'tr'
+         <td><tr><td> *<td>* should pop to 'tr', not the first 'td'
+        """
+
+        nestingResetTriggers = self.NESTABLE_TAGS.get(name)
+        isNestable = nestingResetTriggers != None
+        isResetNesting = self.RESET_NESTING_TAGS.has_key(name)
+        popTo = None
+        inclusive = True
+        for i in range(len(self.tagStack)-1, 0, -1):
+            p = self.tagStack[i]
+            if (not p or p.name == name) and not isNestable:
+                #Non-nestable tags get popped to the top or to their
+                #last occurance.
+                popTo = name
+                break
+            if (nestingResetTriggers != None
+                and p.name in nestingResetTriggers) \
+                or (nestingResetTriggers == None and isResetNesting
+                    and self.RESET_NESTING_TAGS.has_key(p.name)):
+                
+                #If we encounter one of the nesting reset triggers
+                #peculiar to this tag, or we encounter another tag
+                #that causes nesting to reset, pop up to but not
+                #including that tag.
+
+                popTo = p.name
+                inclusive = False
+                break
+            p = p.parent
+        if popTo:
+            self._popToTag(popTo, inclusive)
+
+    def unknown_starttag(self, name, attrs, selfClosing=0):
+        #print "Start tag %s" % name
+        if self.quoteStack:
+            #This is not a real tag.
+            #print "<%s> is not real!" % name
+            attrs = ''.join(map(lambda(x, y): ' %s="%s"' % (x, y), attrs))
+            self.handle_data('<%s%s>' % (name, attrs))
+            return
+        self.endData()
+        if not name in self.SELF_CLOSING_TAGS and not selfClosing:
+            self._smartPop(name)
+        tag = Tag(name, attrs, self.currentTag, self.previous)        
+        if self.previous:
+            self.previous.next = tag
+        self.previous = tag
+        self.pushTag(tag)
+        if selfClosing or name in self.SELF_CLOSING_TAGS:
+            self.popTag()                
+        if name in self.QUOTE_TAGS:
+            #print "Beginning quote (%s)" % name
+            self.quoteStack.append(name)
+            self.literal = 1
+
+    def unknown_endtag(self, name):
+        if self.quoteStack and self.quoteStack[-1] != name:
+            #This is not a real end tag.
+            #print "</%s> is not real!" % name
+            self.handle_data('</%s>' % name)
+            return
+        self.endData()
+        self._popToTag(name)
+        if self.quoteStack and self.quoteStack[-1] == name:
+            self.quoteStack.pop()
+            self.literal = (len(self.quoteStack) > 0)
+
+    def handle_data(self, data):
+        self.currentData.append(data)
+
+    def handle_pi(self, text):
+        "Propagate processing instructions right through."
+        self.handle_data("<?%s>" % text)
+
+    def handle_comment(self, text):
+        "Propagate comments right through."
+        self.handle_data("<!--%s-->" % text)
+
+    def handle_charref(self, ref):
+        "Propagate char refs right through."
+        self.handle_data('&#%s;' % ref)
+
+    def handle_entityref(self, ref):
+        "Propagate entity refs right through."
+        self.handle_data('&%s;' % ref)
+        
+    def handle_decl(self, data):
+        "Propagate DOCTYPEs and the like right through."
+        self.handle_data('<!%s>' % data)
+
+    def parse_declaration(self, i):
+        """Treat a bogus SGML declaration as raw data. Treat a CDATA
+        declaration as regular data."""
+        j = None
+        if self.rawdata[i:i+9] == '<![CDATA[':
+             k = self.rawdata.find(']]>', i)
+             if k == -1:
+                 k = len(self.rawdata)
+             self.handle_data(self.rawdata[i+9:k])
+             j = k+3
+        else:
+            try:
+                j = SGMLParser.parse_declaration(self, i)
+            except SGMLParseError:
+                toHandle = self.rawdata[i:]
+                self.handle_data(toHandle)
+                j = i + len(toHandle)
+        return j
+
+class BeautifulSoup(BeautifulStoneSoup):
+
+    """This parser knows the following facts about HTML:
+
+    * Some tags have no closing tag and should be interpreted as being
+      closed as soon as they are encountered.
+
+    * The text inside some tags (ie. 'script') may contain tags which
+      are not really part of the document and which should be parsed
+      as text, not tags. If you want to parse the text as tags, you can
+      always fetch it and parse it explicitly.
+
+    * Tag nesting rules:
+
+      Most tags can't be nested at all. For instance, the occurance of
+      a <p> tag should implicitly close the previous <p> tag.
+
+       <p>Para1<p>Para2
+        should be transformed into:
+       <p>Para1</p><p>Para2
+
+      Some tags can be nested arbitrarily. For instance, the occurance
+      of a <blockquote> tag should _not_ implicitly close the previous
+      <blockquote> tag.
+
+       Alice said: <blockquote>Bob said: <blockquote>Blah
+        should NOT be transformed into:
+       Alice said: <blockquote>Bob said: </blockquote><blockquote>Blah
+
+      Some tags can be nested, but the nesting is reset by the
+      interposition of other tags. For instance, a <tr> tag should
+      implicitly close the previous <tr> tag within the same <table>,
+      but not close a <tr> tag in another table.
+
+       <table><tr>Blah<tr>Blah
+        should be transformed into:
+       <table><tr>Blah</tr><tr>Blah
+        but,
+       <tr>Blah<table><tr>Blah
+        should NOT be transformed into
+       <tr>Blah<table></tr><tr>Blah
+
+    Differing assumptions about tag nesting rules are a major source
+    of problems with the BeautifulSoup class. If BeautifulSoup is not
+    treating as nestable a tag your page author treats as nestable,
+    try ICantBelieveItsBeautifulSoup before writing your own
+    subclass."""
+
+    SELF_CLOSING_TAGS = buildTagMap(None, ['br' , 'hr', 'input', 'img', 'meta',
+                                           'spacer', 'link', 'frame', 'base'])
+
+    QUOTE_TAGS = {'script': None}
+    
+    #According to the HTML standard, each of these inline tags can
+    #contain another tag of the same type. Furthermore, it's common
+    #to actually use these tags this way.
+    NESTABLE_INLINE_TAGS = ['span', 'font', 'q', 'object', 'bdo', 'sub', 'sup',
+                            'center']
+
+    #According to the HTML standard, these block tags can contain
+    #another tag of the same type. Furthermore, it's common
+    #to actually use these tags this way.
+    NESTABLE_BLOCK_TAGS = ['blockquote', 'div', 'fieldset', 'ins', 'del']
+
+    #Lists can contain other lists, but there are restrictions.    
+    NESTABLE_LIST_TAGS = { 'ol' : [],
+                           'ul' : [],
+                           'li' : ['ul', 'ol'],
+                           'dl' : [],
+                           'dd' : ['dl'],
+                           'dt' : ['dl'] }
+
+    #Tables can contain other tables, but there are restrictions.    
+    NESTABLE_TABLE_TAGS = {'table' : [], 
+                           'tr' : ['table', 'tbody', 'tfoot', 'thead'],
+                           'td' : ['tr'],
+                           'th' : ['tr'],
+                           }
+
+    NON_NESTABLE_BLOCK_TAGS = ['address', 'form', 'p', 'pre']
+
+    #If one of these tags is encountered, all tags up to the next tag of
+    #this type are popped.
+    RESET_NESTING_TAGS = buildTagMap(None, NESTABLE_BLOCK_TAGS, 'noscript',
+                                     NON_NESTABLE_BLOCK_TAGS,
+                                     NESTABLE_LIST_TAGS,
+                                     NESTABLE_TABLE_TAGS)
+
+    NESTABLE_TAGS = buildTagMap([], NESTABLE_INLINE_TAGS, NESTABLE_BLOCK_TAGS,
+                                NESTABLE_LIST_TAGS, NESTABLE_TABLE_TAGS)
+    
+class ICantBelieveItsBeautifulSoup(BeautifulSoup):
+
+    """The BeautifulSoup class is oriented towards skipping over
+    common HTML errors like unclosed tags. However, sometimes it makes
+    errors of its own. For instance, consider this fragment:
+
+     <b>Foo<b>Bar</b></b>
+
+    This is perfectly valid (if bizarre) HTML. However, the
+    BeautifulSoup class will implicitly close the first b tag when it
+    encounters the second 'b'. It will think the author wrote
+    "<b>Foo<b>Bar", and didn't close the first 'b' tag, because
+    there's no real-world reason to bold something that's already
+    bold. When it encounters '</b></b>' it will close two more 'b'
+    tags, for a grand total of three tags closed instead of two. This
+    can throw off the rest of your document structure. The same is
+    true of a number of other tags, listed below.
+
+    It's much more common for someone to forget to close (eg.) a 'b'
+    tag than to actually use nested 'b' tags, and the BeautifulSoup
+    class handles the common case. This class handles the
+    not-co-common case: where you can't believe someone wrote what
+    they did, but it's valid HTML and BeautifulSoup screwed up by
+    assuming it wouldn't be.
+
+    If this doesn't do what you need, try subclassing this class or
+    BeautifulSoup, and providing your own list of NESTABLE_TAGS."""
+
+    I_CANT_BELIEVE_THEYRE_NESTABLE_INLINE_TAGS = \
+     ['em', 'big', 'i', 'small', 'tt', 'abbr', 'acronym', 'strong',
+      'cite', 'code', 'dfn', 'kbd', 'samp', 'strong', 'var', 'b',
+      'big']
+
+    I_CANT_BELIEVE_THEYRE_NESTABLE_BLOCK_TAGS = ['noscript']
+
+    NESTABLE_TAGS = buildTagMap([], BeautifulSoup.NESTABLE_TAGS,
+                                I_CANT_BELIEVE_THEYRE_NESTABLE_BLOCK_TAGS,
+                                I_CANT_BELIEVE_THEYRE_NESTABLE_INLINE_TAGS)
+
+class BeautifulSOAP(BeautifulStoneSoup):
+    """This class will push a tag with only a single string child into
+    the tag's parent as an attribute. The attribute's name is the tag
+    name, and the value is the string child. An example should give
+    the flavor of the change:
+
+    <foo><bar>baz</bar></foo>
+     =>
+    <foo bar="baz"><bar>baz</bar></foo>
+
+    You can then access fooTag['bar'] instead of fooTag.barTag.string.
+
+    This is, of course, useful for scraping structures that tend to
+    use subelements instead of attributes, such as SOAP messages. Note
+    that it modifies its input, so don't print the modified version
+    out.
+
+    I'm not sure how many people really want to use this class; let me
+    know if you do. Mainly I like the name."""
+
+    def popTag(self):
+        if len(self.tagStack) > 1:
+            tag = self.tagStack[-1]
+            parent = self.tagStack[-2]
+            parent._getAttrMap()
+            if (isinstance(tag, Tag) and len(tag.contents) == 1 and
+                isinstance(tag.contents[0], NavigableText) and 
+                not parent.attrMap.has_key(tag.name)):
+                parent[tag.name] = tag.contents[0]
+        BeautifulStoneSoup.popTag(self)
+
+#Enterprise class names! It has come to our attention that some people
+#think the names of the Beautiful Soup parser classes are too silly
+#and "unprofessional" for use in enterprise screen-scraping. We feel
+#your pain! For such-minded folk, the Beautiful Soup Consortium And
+#All-Night Kosher Bakery recommends renaming this file to
+#"RobustParser.py" (or, in cases of extreme enterprisitude,
+#"RobustParserBeanInterface.class") and using the following
+#enterprise-friendly class aliases:
+class RobustXMLParser(BeautifulStoneSoup):
+    pass
+class RobustHTMLParser(BeautifulSoup):
+    pass
+class RobustWackAssHTMLParser(ICantBelieveItsBeautifulSoup):
+    pass
+class SimplifyingSOAPParser(BeautifulSOAP):
+    pass
+
+###
+
+
+#By default, act as an HTML pretty-printer.
+if __name__ == '__main__':
+    import sys
+    soup = BeautifulStoneSoup(sys.stdin.read())
+    print soup.prettify()


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/BeautifulSoup.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/__init__.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/__init__.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/__init__.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,221 @@
+r"""
+A simple, fast, extensible JSON encoder and decoder
+
+JSON (JavaScript Object Notation) <http://json.org> is a subset of
+JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
+interchange format.
+
+simplejson exposes an API familiar to uses of the standard library
+marshal and pickle modules.
+
+Encoding basic Python object hierarchies::
+    
+    >>> import simplejson
+    >>> simplejson.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
+    '["foo", {"bar": ["baz", null, 1.0, 2]}]'
+    >>> print simplejson.dumps("\"foo\bar")
+    "\"foo\bar"
+    >>> print simplejson.dumps(u'\u1234')
+    "\u1234"
+    >>> print simplejson.dumps('\\')
+    "\\"
+    >>> print simplejson.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
+    {"a": 0, "b": 0, "c": 0}
+    >>> from StringIO import StringIO
+    >>> io = StringIO()
+    >>> simplejson.dump(['streaming API'], io)
+    >>> io.getvalue()
+    '["streaming API"]'
+
+Decoding JSON::
+    
+    >>> import simplejson
+    >>> simplejson.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
+    [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
+    >>> simplejson.loads('"\\"foo\\bar"')
+    u'"foo\x08ar'
+    >>> from StringIO import StringIO
+    >>> io = StringIO('["streaming API"]')
+    >>> simplejson.load(io)
+    [u'streaming API']
+
+Specializing JSON object decoding::
+
+    >>> import simplejson
+    >>> def as_complex(dct):
+    ...     if '__complex__' in dct:
+    ...         return complex(dct['real'], dct['imag'])
+    ...     return dct
+    ... 
+    >>> simplejson.loads('{"__complex__": true, "real": 1, "imag": 2}',
+    ...     object_hook=as_complex)
+    (1+2j)
+
+Extending JSONEncoder::
+    
+    >>> import simplejson
+    >>> class ComplexEncoder(simplejson.JSONEncoder):
+    ...     def default(self, obj):
+    ...         if isinstance(obj, complex):
+    ...             return [obj.real, obj.imag]
+    ...         return simplejson.JSONEncoder.default(self, obj)
+    ... 
+    >>> dumps(2 + 1j, cls=ComplexEncoder)
+    '[2.0, 1.0]'
+    >>> ComplexEncoder().encode(2 + 1j)
+    '[2.0, 1.0]'
+    >>> list(ComplexEncoder().iterencode(2 + 1j))
+    ['[', '2.0', ', ', '1.0', ']']
+    
+
+Note that the JSON produced by this module is a subset of YAML,
+so it may be used as a serializer for that as well.
+"""
+__version__ = '1.3'
+__all__ = [
+    'dump', 'dumps', 'load', 'loads',
+    'JSONDecoder', 'JSONEncoder',
+]
+
+from decoder import JSONDecoder
+from encoder import JSONEncoder
+
+def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
+        allow_nan=True, cls=None, **kw):
+    """
+    Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
+    ``.write()``-supporting file-like object).
+
+    If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
+    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) 
+    will be skipped instead of raising a ``TypeError``.
+
+    If ``ensure_ascii`` is ``False``, then the some chunks written to ``fp``
+    may be ``unicode`` instances, subject to normal Python ``str`` to
+    ``unicode`` coercion rules.  Unless ``fp.write()`` explicitly
+    understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
+    to cause an error.
+
+    If ``check_circular`` is ``False``, then the circular reference check
+    for container types will be skipped and a circular reference will
+    result in an ``OverflowError`` (or worse).
+
+    If ``allow_nan`` is ``False``, then it will be a ``ValueError`` to
+    serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
+    in strict compliance of the JSON specification, instead of using the
+    JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+
+    To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
+    ``.default()`` method to serialize additional types), specify it with
+    the ``cls`` kwarg.
+    """
+    if cls is None:
+        cls = JSONEncoder
+    iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
+        check_circular=check_circular, allow_nan=allow_nan,
+        **kw).iterencode(obj)
+    # could accelerate with writelines in some versions of Python, at
+    # a debuggability cost
+    for chunk in iterable:
+        fp.write(chunk)
+
+def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
+        allow_nan=True, cls=None, **kw):
+    """
+    Serialize ``obj`` to a JSON formatted ``str``.
+
+    If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
+    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) 
+    will be skipped instead of raising a ``TypeError``.
+
+    If ``ensure_ascii`` is ``False``, then the return value will be a
+    ``unicode`` instance subject to normal Python ``str`` to ``unicode``
+    coercion rules instead of being escaped to an ASCII ``str``.
+
+    If ``check_circular`` is ``False``, then the circular reference check
+    for container types will be skipped and a circular reference will
+    result in an ``OverflowError`` (or worse).
+
+    If ``allow_nan`` is ``False``, then it will be a ``ValueError`` to
+    serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
+    strict compliance of the JSON specification, instead of using the
+    JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+
+    To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
+    ``.default()`` method to serialize additional types), specify it with
+    the ``cls`` kwarg.
+    """
+    if cls is None:
+        cls = JSONEncoder
+    return cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
+        check_circular=check_circular, allow_nan=allow_nan, **kw).encode(obj)
+
+def load(fp, encoding=None, cls=None, object_hook=None, **kw):
+    """
+    Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
+    a JSON document) to a Python object.
+
+    If the contents of ``fp`` is encoded with an ASCII based encoding other
+    than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
+    be specified.  Encodings that are not ASCII based (such as UCS-2) are
+    not allowed, and should be wrapped with
+    ``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
+    object and passed to ``loads()``
+
+    ``object_hook`` is an optional function that will be called with the
+    result of any object literal decode (a ``dict``).  The return value of
+    ``object_hook`` will be used instead of the ``dict``.  This feature
+    can be used to implement custom decoders (e.g. JSON-RPC class hinting).
+    
+    To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
+    kwarg.
+    """
+    if cls is None:
+        cls = JSONDecoder
+    if object_hook is not None:
+        kw['object_hook'] = object_hook
+    return cls(encoding=encoding, **kw).decode(fp.read())
+
+def loads(s, encoding=None, cls=None, object_hook=None, **kw):
+    """
+    Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
+    document) to a Python object.
+
+    If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
+    other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
+    must be specified.  Encodings that are not ASCII based (such as UCS-2)
+    are not allowed and should be decoded to ``unicode`` first.
+
+    ``object_hook`` is an optional function that will be called with the
+    result of any object literal decode (a ``dict``).  The return value of
+    ``object_hook`` will be used instead of the ``dict``.  This feature
+    can be used to implement custom decoders (e.g. JSON-RPC class hinting).
+
+    To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
+    kwarg.
+    """
+    if cls is None:
+        cls = JSONDecoder
+    if object_hook is not None:
+        kw['object_hook'] = object_hook
+    return cls(encoding=encoding, **kw).decode(s)
+
+def read(s):
+    """
+    json-py API compatibility hook.  Use loads(s) instead.
+    """
+    import warnings
+    warnings.warn("simplejson.loads(s) should be used instead of read(s)",
+        DeprecationWarning)
+    return loads(s)
+
+def write(obj):
+    """
+    json-py API compatibility hook.  Use dumps(s) instead.
+    """
+    import warnings
+    warnings.warn("simplejson.dumps(s) should be used instead of write(s)",
+        DeprecationWarning)
+    return dumps(obj)
+
+


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/decoder.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/decoder.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/decoder.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,271 @@
+"""
+Implementation of JSONDecoder
+"""
+import re
+
+from simplejson.scanner import Scanner, pattern
+
+FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
+
+def _floatconstants():
+    import struct
+    import sys
+    _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
+    if sys.byteorder != 'big':
+        _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
+    nan, inf = struct.unpack('dd', _BYTES)
+    return nan, inf, -inf
+
+NaN, PosInf, NegInf = _floatconstants()
+
+def linecol(doc, pos):
+    lineno = doc.count('\n', 0, pos) + 1
+    if lineno == 1:
+        colno = pos
+    else:
+        colno = pos - doc.rindex('\n', 0, pos)
+    return lineno, colno
+
+def errmsg(msg, doc, pos, end=None):
+    lineno, colno = linecol(doc, pos)
+    if end is None:
+        return '%s: line %d column %d (char %d)' % (msg, lineno, colno, pos)
+    endlineno, endcolno = linecol(doc, end)
+    return '%s: line %d column %d - line %d column %d (char %d - %d)' % (
+        msg, lineno, colno, endlineno, endcolno, pos, end)
+
+_CONSTANTS = {
+    '-Infinity': NegInf,
+    'Infinity': PosInf,
+    'NaN': NaN,
+    'true': True,
+    'false': False,
+    'null': None,
+}
+
+def JSONConstant(match, context, c=_CONSTANTS):
+    return c[match.group(0)], None
+pattern('(-?Infinity|NaN|true|false|null)')(JSONConstant)
+
+def JSONNumber(match, context):
+    match = JSONNumber.regex.match(match.string, *match.span())
+    integer, frac, exp = match.groups()
+    if frac or exp:
+        res = float(integer + (frac or '') + (exp or ''))
+    else:
+        res = int(integer)
+    return res, None
+pattern(r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?')(JSONNumber)
+
+STRINGCHUNK = re.compile(r'(.*?)(["\\])', FLAGS)
+BACKSLASH = {
+    '"': u'"', '\\': u'\\', '/': u'/',
+    'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t',
+}
+
+DEFAULT_ENCODING = "utf-8"
+
+def scanstring(s, end, encoding=None, _b=BACKSLASH, _m=STRINGCHUNK.match):
+    if encoding is None:
+        encoding = DEFAULT_ENCODING
+    chunks = []
+    _append = chunks.append
+    begin = end - 1
+    while 1:
+        chunk = _m(s, end)
+        if chunk is None:
+            raise ValueError(
+                errmsg("Unterminated string starting at", s, begin))
+        end = chunk.end()
+        content, terminator = chunk.groups()
+        if content:
+            if not isinstance(content, unicode):
+                content = unicode(content, encoding)
+            _append(content)
+        if terminator == '"':
+            break
+        try:
+            esc = s[end]
+        except IndexError:
+            raise ValueError(
+                errmsg("Unterminated string starting at", s, begin))
+        if esc != 'u':
+            try:
+                m = _b[esc]
+            except KeyError:
+                raise ValueError(
+                    errmsg("Invalid \\escape: %r" % (esc,), s, end))
+            end += 1
+        else:
+            esc = s[end + 1:end + 5]
+            try:
+                m = unichr(int(esc, 16))
+                if len(esc) != 4 or not esc.isalnum():
+                    raise ValueError
+            except ValueError:
+                raise ValueError(errmsg("Invalid \\uXXXX escape", s, end))
+            end += 5
+        _append(m)
+    return u''.join(chunks), end
+
+def JSONString(match, context):
+    encoding = getattr(context, 'encoding', None)
+    return scanstring(match.string, match.end(), encoding)
+pattern(r'"')(JSONString)
+
+WHITESPACE = re.compile(r'\s*', FLAGS)
+
+def JSONObject(match, context, _w=WHITESPACE.match):
+    pairs = {}
+    s = match.string
+    end = _w(s, match.end()).end()
+    nextchar = s[end:end + 1]
+    # trivial empty object
+    if nextchar == '}':
+        return pairs, end + 1
+    if nextchar != '"':
+        raise ValueError(errmsg("Expecting property name", s, end))
+    end += 1
+    encoding = getattr(context, 'encoding', None)
+    while True:
+        key, end = scanstring(s, end, encoding)
+        end = _w(s, end).end()
+        if s[end:end + 1] != ':':
+            raise ValueError(errmsg("Expecting : delimiter", s, end))
+        end = _w(s, end + 1).end()
+        try:
+            value, end = JSONScanner.iterscan(s, idx=end).next()
+        except StopIteration:
+            raise ValueError(errmsg("Expecting object", s, end))
+        pairs[key] = value
+        end = _w(s, end).end()
+        nextchar = s[end:end + 1]
+        end += 1
+        if nextchar == '}':
+            break
+        if nextchar != ',':
+            raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
+        end = _w(s, end).end()
+        nextchar = s[end:end + 1]
+        end += 1
+        if nextchar != '"':
+            raise ValueError(errmsg("Expecting property name", s, end - 1))
+    object_hook = getattr(context, 'object_hook', None)
+    if object_hook is not None:
+        pairs = object_hook(pairs)
+    return pairs, end
+pattern(r'{')(JSONObject)
+            
+def JSONArray(match, context, _w=WHITESPACE.match):
+    values = []
+    s = match.string
+    end = _w(s, match.end()).end()
+    # look-ahead for trivial empty array
+    nextchar = s[end:end + 1]
+    if nextchar == ']':
+        return values, end + 1
+    while True:
+        try:
+            value, end = JSONScanner.iterscan(s, idx=end).next()
+        except StopIteration:
+            raise ValueError(errmsg("Expecting object", s, end))
+        values.append(value)
+        end = _w(s, end).end()
+        nextchar = s[end:end + 1]
+        end += 1
+        if nextchar == ']':
+            break
+        if nextchar != ',':
+            raise ValueError(errmsg("Expecting , delimiter", s, end))
+        end = _w(s, end).end()
+    return values, end
+pattern(r'\[')(JSONArray)
+ 
+ANYTHING = [
+    JSONObject,
+    JSONArray,
+    JSONString,
+    JSONConstant,
+    JSONNumber,
+]
+
+JSONScanner = Scanner(ANYTHING)
+
+class JSONDecoder(object):
+    """
+    Simple JSON <http://json.org> decoder
+
+    Performs the following translations in decoding:
+    
+    +---------------+-------------------+
+    | JSON          | Python            |
+    +===============+===================+
+    | object        | dict              |
+    +---------------+-------------------+
+    | array         | list              |
+    +---------------+-------------------+
+    | string        | unicode           |
+    +---------------+-------------------+
+    | number (int)  | int, long         |
+    +---------------+-------------------+
+    | number (real) | float             |
+    +---------------+-------------------+
+    | true          | True              |
+    +---------------+-------------------+
+    | false         | False             |
+    +---------------+-------------------+
+    | null          | None              |
+    +---------------+-------------------+
+
+    It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as
+    their corresponding ``float`` values, which is outside the JSON spec.
+    """
+
+    _scanner = Scanner(ANYTHING)
+    __all__ = ['__init__', 'decode', 'raw_decode']
+
+    def __init__(self, encoding=None, object_hook=None):
+        """
+        ``encoding`` determines the encoding used to interpret any ``str``
+        objects decoded by this instance (utf-8 by default).  It has no
+        effect when decoding ``unicode`` objects.
+        
+        Note that currently only encodings that are a superset of ASCII work,
+        strings of other encodings should be passed in as ``unicode``.
+
+        ``object_hook``, if specified, will be called with the result
+        of every JSON object decoded and its return value will be used in
+        place of the given ``dict``.  This can be used to provide custom
+        deserializations (e.g. to support JSON-RPC class hinting).
+        """
+        self.encoding = encoding
+        self.object_hook = object_hook
+
+    def decode(self, s, _w=WHITESPACE.match):
+        """
+        Return the Python representation of ``s`` (a ``str`` or ``unicode``
+        instance containing a JSON document)
+        """
+        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
+        end = _w(s, end).end()
+        if end != len(s):
+            raise ValueError(errmsg("Extra data", s, end, len(s)))
+        return obj
+
+    def raw_decode(self, s, **kw):
+        """
+        Decode a JSON document from ``s`` (a ``str`` or ``unicode`` beginning
+        with a JSON document) and return a 2-tuple of the Python
+        representation and the index in ``s`` where the document ended.
+
+        This can be used to decode a JSON document from a string that may
+        have extraneous data at the end.
+        """
+        kw.setdefault('context', self)
+        try:
+            obj, end = self._scanner.iterscan(s, **kw).next()
+        except StopIteration:
+            raise ValueError("No JSON object could be decoded")
+        return obj, end
+
+__all__ = ['JSONDecoder']


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/decoder.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/encoder.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/encoder.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/encoder.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,289 @@
+"""
+Implementation of JSONEncoder
+"""
+import re
+
+# this should match any kind of infinity
+INFCHARS = re.compile(r'[infINF]')
+ESCAPE = re.compile(r'[\x00-\x19\\"\b\f\n\r\t]')
+ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])')
+ESCAPE_DCT = {
+    '\\': '\\\\',
+    '"': '\\"',
+    '\b': '\\b',
+    '\f': '\\f',
+    '\n': '\\n',
+    '\r': '\\r',
+    '\t': '\\t',
+}
+for i in range(20):
+    ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
+
+def floatstr(o, allow_nan=True):
+    s = str(o)
+    # If the first non-sign is a digit then it's not a special value
+    if (o < 0.0 and s[1].isdigit()) or s[0].isdigit():
+        return s
+    elif not allow_nan:
+        raise ValueError("Out of range float values are not JSON compliant: %r"
+            % (o,))
+    # These are the string representations on the platforms I've tried
+    if s == 'nan':
+        return 'NaN'
+    if s == 'inf':
+        return 'Infinity'
+    if s == '-inf':
+        return '-Infinity'
+    # NaN should either be inequal to itself, or equal to everything
+    if o != o or o == 0.0:
+        return 'NaN'
+    # Last ditch effort, assume inf
+    if o < 0:
+        return '-Infinity'
+    return 'Infinity'
+
+def encode_basestring(s):
+    """
+    Return a JSON representation of a Python string
+    """
+    def replace(match):
+        return ESCAPE_DCT[match.group(0)]
+    return '"' + ESCAPE.sub(replace, s) + '"'
+
+def encode_basestring_ascii(s):
+    def replace(match):
+        s = match.group(0)
+        try:
+            return ESCAPE_DCT[s]
+        except KeyError:
+            return '\\u%04x' % (ord(s),)
+    return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
+        
+
+class JSONEncoder(object):
+    """
+    Extensible JSON <http://json.org> encoder for Python data structures.
+
+    Supports the following objects and types by default:
+    
+    +-------------------+---------------+
+    | Python            | JSON          |
+    +===================+===============+
+    | dict              | object        |
+    +-------------------+---------------+
+    | list, tuple       | array         |
+    +-------------------+---------------+
+    | str, unicode      | string        |
+    +-------------------+---------------+
+    | int, long, float  | number        |
+    +-------------------+---------------+
+    | True              | true          |
+    +-------------------+---------------+
+    | False             | false         |
+    +-------------------+---------------+
+    | None              | null          |
+    +-------------------+---------------+
+
+    To extend this to recognize other objects, subclass and implement a
+    ``.default()`` method with another method that returns a serializable
+    object for ``o`` if possible, otherwise it should call the superclass
+    implementation (to raise ``TypeError``).
+    """
+    __all__ = ['__init__', 'default', 'encode', 'iterencode']
+    def __init__(self, skipkeys=False, ensure_ascii=True,
+            check_circular=True, allow_nan=True, sort_keys=False):
+        """
+        Constructor for JSONEncoder, with sensible defaults.
+
+        If skipkeys is False, then it is a TypeError to attempt
+        encoding of keys that are not str, int, long, float or None.  If
+        skipkeys is True, such items are simply skipped.
+
+        If ensure_ascii is True, the output is guaranteed to be str
+        objects with all incoming unicode characters escaped.  If
+        ensure_ascii is false, the output will be unicode object.
+
+        If check_circular is True, then lists, dicts, and custom encoded
+        objects will be checked for circular references during encoding to
+        prevent an infinite recursion (which would cause an OverflowError).
+        Otherwise, no such check takes place.
+
+        If allow_nan is True, then NaN, Infinity, and -Infinity will be
+        encoded as such.  This behavior is not JSON specification compliant,
+        but is consistent with most JavaScript based encoders and decoders.
+        Otherwise, it will be a ValueError to encode such floats.
+
+        If sort_keys is True, then the output of dictionaries will be
+        sorted by key; this is useful for regression tests to ensure
+        that JSON serializations can be compared on a day-to-day basis.
+        """
+
+        self.skipkeys = skipkeys
+        self.ensure_ascii = ensure_ascii
+        self.check_circular = check_circular
+        self.allow_nan = allow_nan
+        self.sort_keys = sort_keys
+
+    def _iterencode_list(self, lst, markers=None):
+        if not lst:
+            yield '[]'
+            return
+        if markers is not None:
+            markerid = id(lst)
+            if markerid in markers:
+                raise ValueError("Circular reference detected")
+            markers[markerid] = lst
+        yield '['
+        first = True
+        for value in lst:
+            if first:
+                first = False
+            else:
+                yield ', '
+            for chunk in self._iterencode(value, markers):
+                yield chunk
+        yield ']'
+        if markers is not None:
+            del markers[markerid]
+
+    def _iterencode_dict(self, dct, markers=None):
+        if not dct:
+            yield '{}'
+            return
+        if markers is not None:
+            markerid = id(dct)
+            if markerid in markers:
+                raise ValueError("Circular reference detected")
+            markers[markerid] = dct
+        yield '{'
+        first = True
+        if self.ensure_ascii:
+            encoder = encode_basestring_ascii
+        else:
+            encoder = encode_basestring
+        allow_nan = self.allow_nan
+        if self.sort_keys:
+            keys = dct.keys()
+            keys.sort()
+            items = [(k,dct[k]) for k in keys]
+        else:
+            items = dct.iteritems()
+        for key, value in items:
+            if isinstance(key, basestring):
+                pass
+            # JavaScript is weakly typed for these, so it makes sense to
+            # also allow them.  Many encoders seem to do something like this.
+            elif isinstance(key, float):
+                key = floatstr(key, allow_nan)
+            elif isinstance(key, (int, long)):
+                key = str(key)
+            elif key is True:
+                key = 'true'
+            elif key is False:
+                key = 'false'
+            elif key is None:
+                key = 'null'
+            elif self.skipkeys:
+                continue
+            else:
+                raise TypeError("key %r is not a string" % (key,))
+            if first:
+                first = False
+            else:
+                yield ', '
+            yield encoder(key)
+            yield ': '
+            for chunk in self._iterencode(value, markers):
+                yield chunk
+        yield '}'
+        if markers is not None:
+            del markers[markerid]
+
+    def _iterencode(self, o, markers=None):
+        if isinstance(o, basestring):
+            if self.ensure_ascii:
+                encoder = encode_basestring_ascii
+            else:
+                encoder = encode_basestring
+            yield encoder(o)
+        elif o is None:
+            yield 'null'
+        elif o is True:
+            yield 'true'
+        elif o is False:
+            yield 'false'
+        elif isinstance(o, (int, long)):
+            yield str(o)
+        elif isinstance(o, float):
+            yield floatstr(o, self.allow_nan)
+        elif isinstance(o, (list, tuple)):
+            for chunk in self._iterencode_list(o, markers):
+                yield chunk
+        elif isinstance(o, dict):
+            for chunk in self._iterencode_dict(o, markers):
+                yield chunk
+        else:
+            if markers is not None:
+                markerid = id(o)
+                if markerid in markers:
+                    raise ValueError("Circular reference detected")
+                markers[markerid] = o
+            for chunk in self._iterencode_default(o, markers):
+                yield chunk
+            if markers is not None:
+                del markers[markerid]
+
+    def _iterencode_default(self, o, markers=None):
+        newobj = self.default(o)
+        return self._iterencode(newobj, markers)
+
+    def default(self, o):
+        """
+        Implement this method in a subclass such that it returns
+        a serializable object for ``o``, or calls the base implementation
+        (to raise a ``TypeError``).
+
+        For example, to support arbitrary iterators, you could
+        implement default like this::
+            
+            def default(self, o):
+                try:
+                    iterable = iter(o)
+                except TypeError:
+                    pass
+                else:
+                    return list(iterable)
+                return JSONEncoder.default(self, o)
+        """
+        raise TypeError("%r is not JSON serializable" % (o,))
+
+    def encode(self, o):
+        """
+        Return a JSON string representation of a Python data structure.
+
+        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
+        '{"foo":["bar", "baz"]}'
+        """
+        # This doesn't pass the iterator directly to ''.join() because it
+        # sucks at reporting exceptions.  It's going to do this internally
+        # anyway because it uses PySequence_Fast or similar.
+        chunks = list(self.iterencode(o))
+        return ''.join(chunks)
+
+    def iterencode(self, o):
+        """
+        Encode the given object and yield each string
+        representation as available.
+        
+        For example::
+            
+            for chunk in JSONEncoder().iterencode(bigobject):
+                mysocket.write(chunk)
+        """
+        if self.check_circular:
+            markers = {}
+        else:
+            markers = None
+        return self._iterencode(o, markers)
+
+__all__ = ['JSONEncoder']


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/encoder.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/jsonfilter.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/jsonfilter.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/jsonfilter.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,40 @@
+import simplejson
+import cgi
+
+class JSONFilter(object):
+    def __init__(self, app, mime_type='text/x-json'):
+        self.app = app
+        self.mime_type = mime_type
+
+    def __call__(self, environ, start_response):
+        # Read JSON POST input to jsonfilter.json if matching mime type
+        response = {'status': '200 OK', 'headers': []}
+        def json_start_response(status, headers):
+            response['status'] = status
+            response['headers'].extend(headers)
+        environ['jsonfilter.mime_type'] = self.mime_type
+        if environ.get('REQUEST_METHOD', '') == 'POST':
+            if environ.get('CONTENT_TYPE', '') == self.mime_type:
+                args = [_ for _ in [environ.get('CONTENT_LENGTH')] if _]
+                data = environ['wsgi.input'].read(*map(int, args))
+                environ['jsonfilter.json'] = simplejson.loads(data)
+        res = simplejson.dumps(self.app(environ, json_start_response))
+        jsonp = cgi.parse_qs(environ.get('QUERY_STRING', '')).get('jsonp')
+        if jsonp:
+            content_type = 'text/javascript'
+            res = ''.join(jsonp + ['(', res, ')'])
+        elif 'Opera' in environ.get('HTTP_USER_AGENT', ''):
+            # Opera has bunk XMLHttpRequest support for most mime types
+            content_type = 'text/plain'
+        else:
+            content_type = self.mime_type
+        headers = [
+            ('Content-type', content_type),
+            ('Content-length', len(res)),
+        ]
+        headers.extend(response['headers'])
+        start_response(response['status'], headers)
+        return [res]
+
+def factory(app, global_conf, **kw):
+    return JSONFilter(app, **kw)


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/jsonfilter.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/scanner.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/scanner.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/scanner.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,63 @@
+"""
+Iterator based sre token scanner
+"""
+import sre_parse, sre_compile, sre_constants
+from sre_constants import BRANCH, SUBPATTERN
+from sre import VERBOSE, MULTILINE, DOTALL
+import re
+
+__all__ = ['Scanner', 'pattern']
+
+FLAGS = (VERBOSE | MULTILINE | DOTALL)
+class Scanner(object):
+    def __init__(self, lexicon, flags=FLAGS):
+        self.actions = [None]
+        # combine phrases into a compound pattern
+        s = sre_parse.Pattern()
+        s.flags = flags
+        p = []
+        for idx, token in enumerate(lexicon):
+            phrase = token.pattern
+            try:
+                subpattern = sre_parse.SubPattern(s,
+                    [(SUBPATTERN, (idx + 1, sre_parse.parse(phrase, flags)))])
+            except sre_constants.error:
+                raise
+            p.append(subpattern)
+            self.actions.append(token)
+
+        p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
+        self.scanner = sre_compile.compile(p)
+
+
+    def iterscan(self, string, idx=0, context=None):
+        """
+        Yield match, end_idx for each match
+        """
+        match = self.scanner.scanner(string, idx).match
+        actions = self.actions
+        lastend = idx
+        end = len(string)
+        while True:
+            m = match()
+            if m is None:
+                break
+            matchbegin, matchend = m.span()
+            if lastend == matchend:
+                break
+            action = actions[m.lastindex]
+            if action is not None:
+                rval, next_pos = action(m, context)
+                if next_pos is not None and next_pos != matchend:
+                    # "fast forward" the scanner
+                    matchend = next_pos
+                    match = self.scanner.scanner(string, matchend).match
+                yield rval, matchend
+            lastend = matchend
+            
+def pattern(pattern, flags=FLAGS):
+    def decorator(fn):
+        fn.pattern = pattern
+        fn.regex = re.compile(pattern, flags)
+        return fn
+    return decorator


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/scanner.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/__init__.py
===================================================================


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_fail.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_fail.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_fail.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,70 @@
+# Fri Dec 30 18:57:26 2005
+JSONDOCS = [
+    # http://json.org/JSON_checker/test/fail1.json
+    '"A JSON payload should be an object or array, not a string."',
+    # http://json.org/JSON_checker/test/fail2.json
+    '["Unclosed array"',
+    # http://json.org/JSON_checker/test/fail3.json
+    '{unquoted_key: "keys must be quoted}',
+    # http://json.org/JSON_checker/test/fail4.json
+    '["extra comma",]',
+    # http://json.org/JSON_checker/test/fail5.json
+    '["double extra comma",,]',
+    # http://json.org/JSON_checker/test/fail6.json
+    '[   , "<-- missing value"]',
+    # http://json.org/JSON_checker/test/fail7.json
+    '["Comma after the close"],',
+    # http://json.org/JSON_checker/test/fail8.json
+    '["Extra close"]]',
+    # http://json.org/JSON_checker/test/fail9.json
+    '{"Extra comma": true,}',
+    # http://json.org/JSON_checker/test/fail10.json
+    '{"Extra value after close": true} "misplaced quoted value"',
+    # http://json.org/JSON_checker/test/fail11.json
+    '{"Illegal expression": 1 + 2}',
+    # http://json.org/JSON_checker/test/fail12.json
+    '{"Illegal invocation": alert()}',
+    # http://json.org/JSON_checker/test/fail13.json
+    '{"Numbers cannot have leading zeroes": 013}',
+    # http://json.org/JSON_checker/test/fail14.json
+    '{"Numbers cannot be hex": 0x14}',
+    # http://json.org/JSON_checker/test/fail15.json
+    '["Illegal backslash escape: \\x15"]',
+    # http://json.org/JSON_checker/test/fail16.json
+    '["Illegal backslash escape: \\\'"]',
+    # http://json.org/JSON_checker/test/fail17.json
+    '["Illegal backslash escape: \\017"]',
+    # http://json.org/JSON_checker/test/fail18.json
+    '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]',
+    # http://json.org/JSON_checker/test/fail19.json
+    '{"Missing colon" null}',
+    # http://json.org/JSON_checker/test/fail20.json
+    '{"Double colon":: null}',
+    # http://json.org/JSON_checker/test/fail21.json
+    '{"Comma instead of colon", null}',
+    # http://json.org/JSON_checker/test/fail22.json
+    '["Colon instead of comma": false]',
+    # http://json.org/JSON_checker/test/fail23.json
+    '["Bad value", truth]',
+    # http://json.org/JSON_checker/test/fail24.json
+    "['single quote']",
+]
+
+SKIPS = {
+    1: "why not have a string payload?",
+    18: "spec doesn't specify any nesting limitations",
+}
+
+def test_failures():
+    import simplejson
+    for idx, doc in enumerate(JSONDOCS):
+        idx = idx + 1
+        if idx in SKIPS:
+            simplejson.loads(doc)
+            continue
+        try:
+            simplejson.loads(doc)
+        except ValueError:
+            pass
+        else:
+            assert False, "Expected failure for fail%d.json: %r" % (idx, doc)


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_fail.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass1.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass1.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass1.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,72 @@
+# from http://json.org/JSON_checker/test/pass1.json
+JSON = r'''
+[
+    "JSON Test Pattern pass1",
+    {"object with 1 member":["array with 1 element"]},
+    {},
+    [],
+    -42,
+    true,
+    false,
+    null,
+    {
+        "integer": 1234567890,
+        "real": -9876.543210,
+        "e": 0.123456789e-12,
+        "E": 1.234567890E+34,
+        "":  23456789012E666,
+        "zero": 0,
+        "one": 1,
+        "space": " ",
+        "quote": "\"",
+        "backslash": "\\",
+        "controls": "\b\f\n\r\t",
+        "slash": "/ & \/",
+        "alpha": "abcdefghijklmnopqrstuvwyz",
+        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
+        "digit": "0123456789",
+        "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
+        "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
+        "true": true,
+        "false": false,
+        "null": null,
+        "array":[  ],
+        "object":{  },
+        "address": "50 St. James Street",
+        "url": "http://www.JSON.org/",
+        "comment": "// /* <!-- --",
+        "# -- --> */": " ",
+        " s p a c e d " :[1,2 , 3
+
+,
+
+4 , 5        ,          6           ,7        ],
+        "compact": [1,2,3,4,5,6,7],
+        "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
+        "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
+        "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
+: "A key can be any string"
+    },
+    0.5 ,98.6
+,
+99.44
+,
+
+1066
+
+
+,"rosebud"]
+'''
+
+def test_parse():
+    # test in/out equivalence and parsing
+    import simplejson
+    res = simplejson.loads(JSON)
+    out = simplejson.dumps(res)
+    assert res == simplejson.loads(out)
+    try:
+        simplejson.dumps(res, allow_nan=False)
+    except ValueError:
+        pass
+    else:
+        assert False, "23456789012E666 should be out of range"


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass1.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass2.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass2.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass2.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,11 @@
+# from http://json.org/JSON_checker/test/pass2.json
+JSON = r'''
+[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
+'''
+
+def test_parse():
+    # test in/out equivalence and parsing
+    import simplejson
+    res = simplejson.loads(JSON)
+    out = simplejson.dumps(res)
+    assert res == simplejson.loads(out)


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass2.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass3.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass3.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass3.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,16 @@
+# from http://json.org/JSON_checker/test/pass3.json
+JSON = r'''
+{
+    "JSON Test Pattern pass3": {
+        "The outermost value": "must be an object or array.",
+        "In this test": "It is an object."
+    }
+}
+'''
+
+def test_parse():
+    # test in/out equivalence and parsing
+    import simplejson
+    res = simplejson.loads(JSON)
+    out = simplejson.dumps(res)
+    assert res == simplejson.loads(out)


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_pass3.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_recursion.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_recursion.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_recursion.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,62 @@
+import simplejson
+
+def test_listrecursion():
+    x = []
+    x.append(x)
+    try:
+        simplejson.dumps(x)
+    except ValueError:
+        pass
+    else:
+        assert False, "didn't raise ValueError on list recursion"
+    x = []
+    y = [x]
+    x.append(y)
+    try:
+        simplejson.dumps(x)
+    except ValueError:
+        pass
+    else:
+        assert False, "didn't raise ValueError on alternating list recursion"
+    y = []
+    x = [y, y]
+    # ensure that the marker is cleared
+    simplejson.dumps(x)
+
+def test_dictrecursion():
+    x = {}
+    x["test"] = x
+    try:
+        simplejson.dumps(x)
+    except ValueError:
+        pass
+    else:
+        assert False, "didn't raise ValueError on dict recursion"
+    x = {}
+    y = {"a": x, "b": x}
+    # ensure that the marker is cleared
+    simplejson.dumps(x)
+
+class TestObject:
+    pass
+
+class RecursiveJSONEncoder(simplejson.JSONEncoder):
+    recurse = False
+    def default(self, o):
+        if o is TestObject:
+            if self.recurse:
+                return [TestObject]
+            else:
+                return 'TestObject'
+        simplejson.JSONEncoder.default(o)
+
+def test_defaultrecursion():
+    enc = RecursiveJSONEncoder()
+    assert enc.encode(TestObject) == '"TestObject"'
+    enc.recurse = True
+    try:
+        enc.encode(TestObject)
+    except ValueError:
+        pass
+    else:
+        assert False, "didn't raise ValueError on default recursion"


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/simplejson/tests/test_recursion.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/browser.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/browser.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/browser.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -16,10 +16,12 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
+from cStringIO import StringIO
 from test import pystone
 from zope.testbrowser import interfaces
+from zope.testbrowser.utilities import disambiguate, any, onlyOne, zeroOrOne, \
+    SetattrErrorsMixin, PystoneTimer, compressText, RegexType
 import ClientForm
-from cStringIO import StringIO
 import mechanize
 import operator
 import re
@@ -32,24 +34,6 @@
 except ImportError:
     from dummymodules import interface
 
-RegexType = type(re.compile(''))
-_compress_re = re.compile(r"\s+")
-compressText = lambda text: _compress_re.sub(' ', text.strip())
-
-def disambiguate(intermediate, msg, index):
-    if intermediate:
-        if index is None:
-            if len(intermediate) > 1:
-                raise ClientForm.AmbiguityError(msg)
-            else:
-                return intermediate[0]
-        else:
-            try:
-                return intermediate[index]
-            except KeyError:
-                msg = '%s index %d' % (msg, index)
-    raise LookupError(msg)
-
 def controlFactory(control, form, browser):
     if isinstance(control, ClientForm.Item):
         # it is a subcontrol
@@ -65,84 +49,7 @@
         else:
             return Control(control, form, browser)
 
-def any(items):
-    return bool(sum([bool(i) for i in items]))
 
-def onlyOne(items, description):
-    total = sum([bool(i) for i in items])
-    if total == 0 or total > 1:
-        raise ValueError(
-            "Supply one and only one of %s as arguments" % description)
-
-def zeroOrOne(items, description):
-    if sum([bool(i) for i in items]) > 1:
-        raise ValueError(
-            "Supply no more than one of %s as arguments" % description)
-
-
-class SetattrErrorsMixin(object):
-    _enable_setattr_errors = False
-
-    def __setattr__(self, name, value):
-        if self._enable_setattr_errors:
-            # cause an attribute error if the attribute doesn't already exist
-            getattr(self, name)
-
-        # set the value
-        object.__setattr__(self, name, value)
-
-
-class PystoneTimer(object):
-    start_time = 0
-    end_time = 0
-    _pystones_per_second = None
-
-    @property
-    def pystonesPerSecond(self):
-        """How many pystones are equivalent to one second on this machine"""
-        if self._pystones_per_second == None:
-            self._pystones_per_second = pystone.pystones(pystone.LOOPS/10)[1]
-        return self._pystones_per_second
-
-    def _getTime(self):
-        if sys.platform.startswith('win'):
-            # Windows' time.clock gives us high-resolution wall-time
-            return time.clock()
-        else:
-            # everyone else uses time.time
-            return time.time()
-
-    def start(self):
-        """Begin a timing period"""
-        self.start_time = self._getTime()
-        self.end_time = None
-
-    def stop(self):
-        """End a timing period"""
-        self.end_time = self._getTime()
-
-    @property
-    def elapsedSeconds(self):
-        """Elapsed time from calling `start` to calling `stop` or present time
-
-        If `stop` has been called, the timing period stopped then, otherwise
-        the end is the current time.
-        """
-        if self.end_time is None:
-            end_time = self._getTime()
-        else:
-            end_time = self.end_time
-        return end_time - self.start_time
-
-    @property
-    def elapsedPystones(self):
-        """Elapsed pystones in timing period
-
-        See elapsed_seconds for definition of timing period.
-        """
-        return self.elapsedSeconds * self.pystonesPerSecond
-
-
 class Browser(SetattrErrorsMixin):
     """A web user agent."""
     interface.implements(interfaces.IBrowser)

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__init__.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__init__.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__init__.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1 @@
+#


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Async.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Async.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Async.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,637 @@
+/***
+
+MochiKit.Async 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide("MochiKit.Async");
+    dojo.require("MochiKit.Base");
+}
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Base", []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.Async depends on MochiKit.Base!";
+}
+
+if (typeof(MochiKit.Async) == 'undefined') {
+    MochiKit.Async = {};
+}
+
+MochiKit.Async.NAME = "MochiKit.Async";
+MochiKit.Async.VERSION = "1.3.1";
+MochiKit.Async.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+MochiKit.Async.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.Async.Deferred = function (/* optional */ canceller) {
+    this.chain = [];
+    this.id = this._nextId();
+    this.fired = -1;
+    this.paused = 0;
+    this.results = [null, null];
+    this.canceller = canceller;
+    this.silentlyCancelled = false;
+    this.chained = false;
+};
+
+MochiKit.Async.Deferred.prototype = {
+    repr: function () {
+        var state;
+        if (this.fired == -1) {
+            state = 'unfired';
+        } else if (this.fired === 0) {
+            state = 'success';
+        } else {
+            state = 'error';
+        }
+        return 'Deferred(' + this.id + ', ' + state + ')';
+    },
+
+    toString: MochiKit.Base.forwardCall("repr"),
+
+    _nextId: MochiKit.Base.counter(),
+
+    cancel: function () {
+        var self = MochiKit.Async;
+        if (this.fired == -1) {
+            if (this.canceller) {
+                this.canceller(this);
+            } else {
+                this.silentlyCancelled = true;
+            }
+            if (this.fired == -1) {
+                this.errback(new self.CancelledError(this));
+            }
+        } else if ((this.fired === 0) && (this.results[0] instanceof self.Deferred)) {
+            this.results[0].cancel();
+        }
+    },
+            
+
+    _pause: function () {
+        /***
+
+        Used internally to signal that it's waiting on another Deferred
+
+        ***/
+        this.paused++;
+    },
+
+    _unpause: function () {
+        /***
+
+        Used internally to signal that it's no longer waiting on another
+        Deferred.
+
+        ***/
+        this.paused--;
+        if ((this.paused === 0) && (this.fired >= 0)) {
+            this._fire();
+        }
+    },
+
+    _continue: function (res) {
+        /***
+
+        Used internally when a dependent deferred fires.
+
+        ***/
+        this._resback(res);
+        this._unpause();
+    },
+
+    _resback: function (res) {
+        /***
+
+        The primitive that means either callback or errback
+
+        ***/
+        this.fired = ((res instanceof Error) ? 1 : 0);
+        this.results[this.fired] = res;
+        this._fire();
+    },
+
+    _check: function () {
+        if (this.fired != -1) {
+            if (!this.silentlyCancelled) {
+                throw new MochiKit.Async.AlreadyCalledError(this);
+            }
+            this.silentlyCancelled = false;
+            return;
+        }
+    },
+
+    callback: function (res) {
+        this._check();
+        if (res instanceof MochiKit.Async.Deferred) {
+            throw new Error("Deferred instances can only be chained if they are the result of a callback");
+        }
+        this._resback(res);
+    },
+
+    errback: function (res) {
+        this._check();
+        var self = MochiKit.Async;
+        if (res instanceof self.Deferred) {
+            throw new Error("Deferred instances can only be chained if they are the result of a callback");
+        }
+        if (!(res instanceof Error)) {
+            res = new self.GenericError(res);
+        }
+        this._resback(res);
+    },
+
+    addBoth: function (fn) {
+        if (arguments.length > 1) {
+            fn = MochiKit.Base.partial.apply(null, arguments);
+        }
+        return this.addCallbacks(fn, fn);
+    },
+
+    addCallback: function (fn) {
+        if (arguments.length > 1) {
+            fn = MochiKit.Base.partial.apply(null, arguments);
+        }
+        return this.addCallbacks(fn, null);
+    },
+
+    addErrback: function (fn) {
+        if (arguments.length > 1) {
+            fn = MochiKit.Base.partial.apply(null, arguments);
+        }
+        return this.addCallbacks(null, fn);
+    },
+
+    addCallbacks: function (cb, eb) {
+        if (this.chained) {
+            throw new Error("Chained Deferreds can not be re-used");
+        }
+        this.chain.push([cb, eb]);
+        if (this.fired >= 0) {
+            this._fire();
+        }
+        return this;
+    },
+
+    _fire: function () {
+        /***
+
+        Used internally to exhaust the callback sequence when a result
+        is available.
+
+        ***/
+        var chain = this.chain;
+        var fired = this.fired;
+        var res = this.results[fired];
+        var self = this;
+        var cb = null;
+        while (chain.length > 0 && this.paused === 0) {
+            // Array
+            var pair = chain.shift();
+            var f = pair[fired];
+            if (f === null) {
+                continue;
+            }
+            try {
+                res = f(res);
+                fired = ((res instanceof Error) ? 1 : 0);
+                if (res instanceof MochiKit.Async.Deferred) {
+                    cb = function (res) {
+                        self._continue(res);
+                    };
+                    this._pause();
+                }
+            } catch (err) {
+                fired = 1;
+                if (!(err instanceof Error)) {
+                    err = new MochiKit.Async.GenericError(err);
+                }
+                res = err;
+            }
+        }
+        this.fired = fired;
+        this.results[fired] = res;
+        if (cb && this.paused) {
+            // this is for "tail recursion" in case the dependent deferred
+            // is already fired
+            res.addBoth(cb);
+            res.chained = true;
+        }
+    }
+};
+
+MochiKit.Base.update(MochiKit.Async, {
+    evalJSONRequest: function (/* req */) {
+        return eval('(' + arguments[0].responseText + ')');
+    },
+
+    succeed: function (/* optional */result) {
+        var d = new MochiKit.Async.Deferred();
+        d.callback.apply(d, arguments);
+        return d;
+    },
+
+    fail: function (/* optional */result) {
+        var d = new MochiKit.Async.Deferred();
+        d.errback.apply(d, arguments);
+        return d;
+    },
+
+    getXMLHttpRequest: function () {
+        var self = arguments.callee;
+        if (!self.XMLHttpRequest) {
+            var tryThese = [
+                function () { return new XMLHttpRequest(); },
+                function () { return new ActiveXObject('Msxml2.XMLHTTP'); },
+                function () { return new ActiveXObject('Microsoft.XMLHTTP'); },
+                function () { return new ActiveXObject('Msxml2.XMLHTTP.4.0'); },
+                function () {
+                    throw new MochiKit.Async.BrowserComplianceError("Browser does not support XMLHttpRequest");
+                }
+            ];
+            for (var i = 0; i < tryThese.length; i++) {
+                var func = tryThese[i];
+                try {
+                    self.XMLHttpRequest = func;
+                    return func();
+                } catch (e) {
+                    // pass
+                }
+            }
+        }
+        return self.XMLHttpRequest();
+    },
+
+    _nothing: function () {},
+
+    _xhr_onreadystatechange: function (d) {
+        // MochiKit.Logging.logDebug('this.readyState', this.readyState);
+        if (this.readyState == 4) {
+            // IE SUCKS
+            try {
+                this.onreadystatechange = null;
+            } catch (e) {
+                try {
+                    this.onreadystatechange = MochiKit.Async._nothing;
+                } catch (e) {
+                }
+            }
+            var status = null;
+            try {
+                status = this.status;
+                if (!status && MochiKit.Base.isNotEmpty(this.responseText)) {
+                    // 0 or undefined seems to mean cached or local
+                    status = 304;
+                }
+            } catch (e) {
+                // pass
+                // MochiKit.Logging.logDebug('error getting status?', repr(items(e)));
+            }
+            //  200 is OK, 304 is NOT_MODIFIED
+            if (status == 200 || status == 304) { // OK
+                d.callback(this);
+            } else {
+                var err = new MochiKit.Async.XMLHttpRequestError(this, "Request failed");
+                if (err.number) {
+                    // XXX: This seems to happen on page change
+                    d.errback(err);
+                } else {
+                    // XXX: this seems to happen when the server is unreachable
+                    d.errback(err);
+                }
+            }
+        }
+    },
+
+    _xhr_canceller: function (req) {
+        // IE SUCKS
+        try {
+            req.onreadystatechange = null;
+        } catch (e) {
+            try {
+                req.onreadystatechange = MochiKit.Async._nothing;
+            } catch (e) {
+            }
+        }
+        req.abort();
+    },
+
+    
+    sendXMLHttpRequest: function (req, /* optional */ sendContent) {
+        if (typeof(sendContent) == "undefined" || sendContent === null) {
+            sendContent = "";
+        }
+
+        var m = MochiKit.Base;
+        var self = MochiKit.Async;
+        var d = new self.Deferred(m.partial(self._xhr_canceller, req));
+        
+        try {
+            req.onreadystatechange = m.bind(self._xhr_onreadystatechange,
+                req, d);
+            req.send(sendContent);
+        } catch (e) {
+            try {
+                req.onreadystatechange = null;
+            } catch (ignore) {
+                // pass
+            }
+            d.errback(e);
+        }
+
+        return d;
+
+    },
+
+    doSimpleXMLHttpRequest: function (url/*, ...*/) {
+        var self = MochiKit.Async;
+        var req = self.getXMLHttpRequest();
+        if (arguments.length > 1) {
+            var m = MochiKit.Base;
+            var qs = m.queryString.apply(null, m.extend(null, arguments, 1));
+            if (qs) {
+                url += "?" + qs;
+            }
+        }
+        req.open("GET", url, true);
+        return self.sendXMLHttpRequest(req);
+    },
+
+    loadJSONDoc: function (url) {
+        var self = MochiKit.Async;
+        var d = self.doSimpleXMLHttpRequest.apply(self, arguments);
+        d = d.addCallback(self.evalJSONRequest);
+        return d;
+    },
+
+    wait: function (seconds, /* optional */value) {
+        var d = new MochiKit.Async.Deferred();
+        var m = MochiKit.Base;
+        if (typeof(value) != 'undefined') {
+            d.addCallback(function () { return value; });
+        }
+        var timeout = setTimeout(
+            m.bind("callback", d),
+            Math.floor(seconds * 1000));
+        d.canceller = function () {
+            try {
+                clearTimeout(timeout);
+            } catch (e) {
+                // pass
+            }
+        };
+        return d;
+    },
+
+    callLater: function (seconds, func) {
+        var m = MochiKit.Base;
+        var pfunc = m.partial.apply(m, m.extend(null, arguments, 1));
+        return MochiKit.Async.wait(seconds).addCallback(
+            function (res) { return pfunc(); }
+        );
+    }
+});
+
+
+MochiKit.Async.DeferredLock = function () {
+    this.waiting = [];
+    this.locked = false;
+    this.id = this._nextId();
+};
+
+MochiKit.Async.DeferredLock.prototype = {
+    __class__: MochiKit.Async.DeferredLock,
+    acquire: function () {
+        d = new MochiKit.Async.Deferred();
+        if (this.locked) {
+            this.waiting.push(d);
+        } else {
+            this.locked = true;
+            d.callback(this);
+        }
+        return d;
+    },
+    release: function () {
+        if (!this.locked) {
+            throw TypeError("Tried to release an unlocked DeferredLock");
+        }
+        this.locked = false;
+        if (this.waiting.length > 0) {
+            this.locked = true;
+            this.waiting.shift().callback(this);
+        }
+    },
+    _nextId: MochiKit.Base.counter(),
+    repr: function () {
+        var state;
+        if (this.locked) {
+            state = 'locked, ' + this.waiting.length + ' waiting';
+        } else {
+            state = 'unlocked';
+        }
+        return 'DeferredLock(' + this.id + ', ' + state + ')';
+    },
+    toString: MochiKit.Base.forwardCall("repr")
+
+};
+
+MochiKit.Async.DeferredList = function (list, /* optional */fireOnOneCallback, fireOnOneErrback, consumeErrors, canceller) {
+    this.list = list;
+    this.resultList = new Array(this.list.length);
+
+    // Deferred init
+    this.chain = [];
+    this.id = this._nextId();
+    this.fired = -1;
+    this.paused = 0;
+    this.results = [null, null];
+    this.canceller = canceller;
+    this.silentlyCancelled = false;
+    
+    if (this.list.length === 0 && !fireOnOneCallback) {
+        this.callback(this.resultList);
+    }
+    
+    this.finishedCount = 0;
+    this.fireOnOneCallback = fireOnOneCallback;
+    this.fireOnOneErrback = fireOnOneErrback;
+    this.consumeErrors = consumeErrors;
+
+    var index = 0;
+    MochiKit.Base.map(MochiKit.Base.bind(function (d) {
+        d.addCallback(MochiKit.Base.bind(this._cbDeferred, this), index, true);
+        d.addErrback(MochiKit.Base.bind(this._cbDeferred, this), index, false);
+        index += 1;
+    }, this), this.list);
+};
+
+MochiKit.Base.update(MochiKit.Async.DeferredList.prototype,
+                     MochiKit.Async.Deferred.prototype);
+
+MochiKit.Base.update(MochiKit.Async.DeferredList.prototype, {
+    _cbDeferred: function (index, succeeded, result) {
+        this.resultList[index] = [succeeded, result];
+        this.finishedCount += 1;
+        if (this.fired !== 0) {
+            if (succeeded && this.fireOnOneCallback) {
+                this.callback([index, result]);
+            } else if (!succeeded && this.fireOnOneErrback) {
+                this.errback(result);
+            } else if (this.finishedCount == this.list.length) {
+                this.callback(this.resultList);
+            }
+        }
+        if (!succeeded && this.consumeErrors) {
+            result = null;
+        }
+        return result;
+    }
+});
+
+MochiKit.Async.gatherResults = function (deferredList) {
+    var d = new MochiKit.Async.DeferredList(deferredList, false, true, false);
+    d.addCallback(function (results) {
+        var ret = [];
+        for (var i = 0; i < results.length; i++) {
+            ret.push(results[i][1]);
+        }
+        return ret;
+    });
+    return d;
+};
+
+MochiKit.Async.maybeDeferred = function (func) {
+    var self = MochiKit.Async;
+    var result;
+    try {
+        var r = func.apply(null, MochiKit.Base.extend([], arguments, 1));
+        if (r instanceof self.Deferred) {
+            result = r;
+        } else if (r instanceof Error) {
+            result = self.fail(r);
+        } else {
+            result = self.succeed(r);
+        }
+    } catch (e) {
+        result = self.fail(e);
+    }
+    return result;
+};
+
+
+MochiKit.Async.EXPORT = [
+    "AlreadyCalledError",
+    "CancelledError",
+    "BrowserComplianceError",
+    "GenericError",
+    "XMLHttpRequestError",
+    "Deferred",
+    "succeed",
+    "fail",
+    "getXMLHttpRequest",
+    "doSimpleXMLHttpRequest",
+    "loadJSONDoc",
+    "wait",
+    "callLater",
+    "sendXMLHttpRequest",
+    "DeferredLock",
+    "DeferredList",
+    "gatherResults",
+    "maybeDeferred"
+];
+    
+MochiKit.Async.EXPORT_OK = [
+    "evalJSONRequest"
+];
+
+MochiKit.Async.__new__ = function () {
+    var m = MochiKit.Base;
+    var ne = m.partial(m._newNamedError, this);
+    ne("AlreadyCalledError", 
+        function (deferred) {
+            /***
+
+            Raised by the Deferred if callback or errback happens
+            after it was already fired.
+
+            ***/
+            this.deferred = deferred;
+        }
+    );
+
+    ne("CancelledError",
+        function (deferred) {
+            /***
+
+            Raised by the Deferred cancellation mechanism.
+
+            ***/
+            this.deferred = deferred;
+        }
+    );
+
+    ne("BrowserComplianceError",
+        function (msg) {
+            /***
+
+            Raised when the JavaScript runtime is not capable of performing
+            the given function.  Technically, this should really never be
+            raised because a non-conforming JavaScript runtime probably
+            isn't going to support exceptions in the first place.
+
+            ***/
+            this.message = msg;
+        }
+    );
+
+    ne("GenericError", 
+        function (msg) {
+            this.message = msg;
+        }
+    );
+
+    ne("XMLHttpRequestError",
+        function (req, msg) {
+            /***
+
+            Raised when an XMLHttpRequest does not complete for any reason.
+
+            ***/
+            this.req = req;
+            this.message = msg;
+            try {
+                // Strange but true that this can raise in some cases.
+                this.number = req.status;
+            } catch (e) {
+                // pass
+            }
+        }
+    );
+
+
+    this.EXPORT_TAGS = {
+        ":common": this.EXPORT,
+        ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+    };
+
+    m.nameFunctions(this);
+
+};
+
+MochiKit.Async.__new__();
+
+MochiKit.Base._exportSymbols(this, MochiKit.Async);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Base.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Base.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Base.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,1131 @@
+/***
+
+MochiKit.Base 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide("MochiKit.Base");
+}
+
+if (typeof(MochiKit) == 'undefined') {
+    MochiKit = {};
+}
+if (typeof(MochiKit.Base) == 'undefined') {
+    MochiKit.Base = {};
+}
+
+MochiKit.Base.VERSION = "1.3.1";
+MochiKit.Base.NAME = "MochiKit.Base";
+MochiKit.Base.update = function (self, obj/*, ... */) {
+    if (self === null) {
+        self = {};
+    }
+    for (var i = 1; i < arguments.length; i++) {
+        var o = arguments[i];
+        if (typeof(o) != 'undefined' && o !== null) {
+            for (var k in o) {
+                self[k] = o[k];
+            }
+        }
+    }
+    return self;
+};
+
+MochiKit.Base.update(MochiKit.Base, {
+    __repr__: function () {
+        return "[" + this.NAME + " " + this.VERSION + "]";
+    },
+
+    toString: function () {
+        return this.__repr__();
+    },
+
+    counter: function (n/* = 1 */) {
+        if (arguments.length === 0) {
+            n = 1;
+        }
+        return function () {
+            return n++;
+        };
+    },
+        
+    clone: function (obj) {
+        var me = arguments.callee;
+        if (arguments.length == 1) {
+            me.prototype = obj;
+            return new me();
+        }
+    },
+            
+    flattenArguments: function (lst/* ...*/) {
+        var res = [];
+        var m = MochiKit.Base;
+        var args = m.extend(null, arguments);
+        while (args.length) {
+            var o = args.shift();
+            if (o && typeof(o) == "object" && typeof(o.length) == "number") {
+                for (var i = o.length - 1; i >= 0; i--) {
+                    args.unshift(o[i]);
+                }
+            } else {
+                res.push(o);
+            }
+        }
+        return res;
+    },
+
+    extend: function (self, obj, /* optional */skip) {        
+        // Extend an array with an array-like object starting
+        // from the skip index
+        if (!skip) {
+            skip = 0;
+        }
+        if (obj) {
+            // allow iterable fall-through, but skip the full isArrayLike
+            // check for speed, this is called often.
+            var l = obj.length;
+            if (typeof(l) != 'number' /* !isArrayLike(obj) */) {
+                if (typeof(MochiKit.Iter) != "undefined") {
+                    obj = MochiKit.Iter.list(obj);
+                    l = obj.length;
+                } else {
+                    throw new TypeError("Argument not an array-like and MochiKit.Iter not present");
+                }
+            }
+            if (!self) {
+                self = [];
+            }
+            for (var i = skip; i < l; i++) {
+                self.push(obj[i]);
+            }
+        }
+        // This mutates, but it's convenient to return because
+        // it's often used like a constructor when turning some
+        // ghetto array-like to a real array
+        return self;
+    },
+
+
+    updatetree: function (self, obj/*, ...*/) {
+        if (self === null) {
+            self = {};
+        }
+        for (var i = 1; i < arguments.length; i++) {
+            var o = arguments[i];
+            if (typeof(o) != 'undefined' && o !== null) {
+                for (var k in o) {
+                    var v = o[k];
+                    if (typeof(self[k]) == 'object' && typeof(v) == 'object') {
+                        arguments.callee(self[k], v);
+                    } else {
+                        self[k] = v;
+                    }
+                }
+            }
+        }
+        return self;
+    },
+
+    setdefault: function (self, obj/*, ...*/) {
+        if (self === null) {
+            self = {};
+        }
+        for (var i = 1; i < arguments.length; i++) {
+            var o = arguments[i];
+            for (var k in o) {
+                if (!(k in self)) {
+                    self[k] = o[k];
+                }
+            }
+        }
+        return self;
+    },
+
+    keys: function (obj) {
+        var rval = [];
+        for (var prop in obj) {
+            rval.push(prop);
+        }
+        return rval;
+    },
+        
+    items: function (obj) {
+        var rval = [];
+        var e;
+        for (var prop in obj) {
+            var v;
+            try {
+                v = obj[prop];
+            } catch (e) {
+                continue;
+            }
+            rval.push([prop, v]);
+        }
+        return rval;
+    },
+
+
+    _newNamedError: function (module, name, func) {
+        func.prototype = new MochiKit.Base.NamedError(module.NAME + "." + name);
+        module[name] = func;
+    },
+
+
+    operator: {
+        // unary logic operators
+        truth: function (a) { return !!a; }, 
+        lognot: function (a) { return !a; },
+        identity: function (a) { return a; },
+
+        // bitwise unary operators
+        not: function (a) { return ~a; },
+        neg: function (a) { return -a; },
+
+        // binary operators
+        add: function (a, b) { return a + b; },
+        sub: function (a, b) { return a - b; },
+        div: function (a, b) { return a / b; },
+        mod: function (a, b) { return a % b; },
+        mul: function (a, b) { return a * b; },
+
+        // bitwise binary operators
+        and: function (a, b) { return a & b; },
+        or: function (a, b) { return a | b; },
+        xor: function (a, b) { return a ^ b; },
+        lshift: function (a, b) { return a << b; },
+        rshift: function (a, b) { return a >> b; },
+        zrshift: function (a, b) { return a >>> b; },
+
+        // near-worthless built-in comparators
+        eq: function (a, b) { return a == b; },
+        ne: function (a, b) { return a != b; },
+        gt: function (a, b) { return a > b; },
+        ge: function (a, b) { return a >= b; },
+        lt: function (a, b) { return a < b; },
+        le: function (a, b) { return a <= b; },
+
+        // compare comparators
+        ceq: function (a, b) { return MochiKit.Base.compare(a, b) === 0; },
+        cne: function (a, b) { return MochiKit.Base.compare(a, b) !== 0; },
+        cgt: function (a, b) { return MochiKit.Base.compare(a, b) == 1; },
+        cge: function (a, b) { return MochiKit.Base.compare(a, b) != -1; },
+        clt: function (a, b) { return MochiKit.Base.compare(a, b) == -1; },
+        cle: function (a, b) { return MochiKit.Base.compare(a, b) != 1; },
+
+        // binary logical operators
+        logand: function (a, b) { return a && b; },
+        logor: function (a, b) { return a || b; },
+        contains: function (a, b) { return b in a; }
+    },
+
+    forwardCall: function (func) {
+        return function () {
+            return this[func].apply(this, arguments);
+        };
+    },
+
+    itemgetter: function (func) {
+        return function (arg) {
+            return arg[func];
+        };
+    },
+
+    typeMatcher: function (/* typ */) {
+        var types = {};
+        for (var i = 0; i < arguments.length; i++) {
+            var typ = arguments[i];
+            types[typ] = typ;
+        }
+        return function () { 
+            for (var i = 0; i < arguments.length; i++) {
+                if (!(typeof(arguments[i]) in types)) {
+                    return false;
+                }
+            }
+            return true;
+        };
+    },
+
+    isNull: function (/* ... */) {
+        for (var i = 0; i < arguments.length; i++) {
+            if (arguments[i] !== null) {
+                return false;
+            }
+        }
+        return true;
+    },
+
+    isUndefinedOrNull: function (/* ... */) {
+        for (var i = 0; i < arguments.length; i++) {
+            var o = arguments[i];
+            if (!(typeof(o) == 'undefined' || o === null)) {
+                return false;
+            }
+        }
+        return true;
+    },
+
+    isEmpty: function (obj) {
+        return !MochiKit.Base.isNotEmpty.apply(this, arguments);
+    },
+
+    isNotEmpty: function (obj) {
+        for (var i = 0; i < arguments.length; i++) {
+            var o = arguments[i];
+            if (!(o && o.length)) {
+                return false;
+            }
+        }
+        return true;
+    },
+
+    isArrayLike: function () {
+        for (var i = 0; i < arguments.length; i++) {
+            var o = arguments[i];
+            var typ = typeof(o);
+            if (
+                (typ != 'object' && !(typ == 'function' && typeof(o.item) == 'function')) ||
+                o === null ||
+                typeof(o.length) != 'number'
+            ) {
+                return false;
+            }
+        }
+        return true;
+    },
+
+    isDateLike: function () {
+        for (var i = 0; i < arguments.length; i++) {
+            var o = arguments[i];
+            if (typeof(o) != "object" || o === null
+                    || typeof(o.getTime) != 'function') {
+                return false;
+            }
+        }
+        return true;
+    },
+
+
+    xmap: function (fn/*, obj... */) {
+        if (fn === null) {
+            return MochiKit.Base.extend(null, arguments, 1);
+        }
+        var rval = [];
+        for (var i = 1; i < arguments.length; i++) {
+            rval.push(fn(arguments[i]));
+        }
+        return rval;
+    },
+
+    map: function (fn, lst/*, lst... */) {
+        var m = MochiKit.Base;
+        var itr = MochiKit.Iter;
+        var isArrayLike = m.isArrayLike;
+        if (arguments.length <= 2) {
+            // allow an iterable to be passed
+            if (!isArrayLike(lst)) {
+                if (itr) {
+                    // fast path for map(null, iterable)
+                    lst = itr.list(lst);
+                    if (fn === null) {
+                        return lst;
+                    }
+                } else {
+                    throw new TypeError("Argument not an array-like and MochiKit.Iter not present");
+                }
+            }
+            // fast path for map(null, lst)
+            if (fn === null) {
+                return m.extend(null, lst);
+            }
+            // disabled fast path for map(fn, lst)
+            /*
+            if (false && typeof(Array.prototype.map) == 'function') {
+                // Mozilla fast-path
+                return Array.prototype.map.call(lst, fn);
+            }
+            */
+            var rval = [];
+            for (var i = 0; i < lst.length; i++) {
+                rval.push(fn(lst[i]));
+            }
+            return rval;
+        } else {
+            // default for map(null, ...) is zip(...)
+            if (fn === null) {
+                fn = Array;
+            }
+            var length = null;
+            for (i = 1; i < arguments.length; i++) {
+                // allow iterables to be passed
+                if (!isArrayLike(arguments[i])) {
+                    if (itr) {
+                        return itr.list(itr.imap.apply(null, arguments));
+                    } else {
+                        throw new TypeError("Argument not an array-like and MochiKit.Iter not present");
+                    }
+                }
+                // find the minimum length
+                var l = arguments[i].length;
+                if (length === null || length > l) {
+                    length = l;
+                }
+            }
+            rval = [];
+            for (i = 0; i < length; i++) {
+                var args = [];
+                for (var j = 1; j < arguments.length; j++) {
+                    args.push(arguments[j][i]);
+                }
+                rval.push(fn.apply(this, args));
+            }
+            return rval;
+        }
+    },
+
+    xfilter: function (fn/*, obj... */) {
+        var rval = [];
+        if (fn === null) {
+            fn = MochiKit.Base.operator.truth;
+        }
+        for (var i = 1; i < arguments.length; i++) {
+            var o = arguments[i];
+            if (fn(o)) {
+                rval.push(o);
+            }
+        }
+        return rval;
+    },
+
+    filter: function (fn, lst, self) {
+        var rval = [];
+        // allow an iterable to be passed
+        var m = MochiKit.Base;
+        if (!m.isArrayLike(lst)) {
+            if (MochiKit.Iter) {
+                lst = MochiKit.Iter.list(lst);
+            } else {
+                throw new TypeError("Argument not an array-like and MochiKit.Iter not present");
+            }
+        }
+        if (fn === null) {
+            fn = m.operator.truth;
+        }
+        if (typeof(Array.prototype.filter) == 'function') {
+            // Mozilla fast-path
+            return Array.prototype.filter.call(lst, fn, self);
+        } else if (typeof(self) == 'undefined' || self === null) {
+            for (var i = 0; i < lst.length; i++) {
+                var o = lst[i];
+                if (fn(o)) {
+                    rval.push(o);
+                }
+            }
+        } else {
+            for (i = 0; i < lst.length; i++) {
+                o = lst[i];
+                if (fn.call(self, o)) {
+                    rval.push(o);
+                }
+            }
+        }
+        return rval;
+    },
+
+
+    _wrapDumbFunction: function (func) {
+        return function () {
+            // fast path!
+            switch (arguments.length) {
+                case 0: return func();
+                case 1: return func(arguments[0]);
+                case 2: return func(arguments[0], arguments[1]);
+                case 3: return func(arguments[0], arguments[1], arguments[2]);
+            }
+            var args = [];
+            for (var i = 0; i < arguments.length; i++) {
+                args.push("arguments[" + i + "]");
+            }
+            return eval("(func(" + args.join(",") + "))");
+        };
+    },
+            
+    method: function (self, func) {
+        var m = MochiKit.Base;
+        return m.bind.apply(this, m.extend([func, self], arguments, 2));
+    },
+
+    bind: function (func, self/* args... */) {
+        if (typeof(func) == "string") {
+            func = self[func];
+        }
+        var im_func = func.im_func;
+        var im_preargs = func.im_preargs;
+        var im_self = func.im_self;
+        var m = MochiKit.Base;
+        if (typeof(func) == "function" && typeof(func.apply) == "undefined") {
+            // this is for cases where JavaScript sucks ass and gives you a
+            // really dumb built-in function like alert() that doesn't have
+            // an apply
+            func = m._wrapDumbFunction(func);
+        }
+        if (typeof(im_func) != 'function') {
+            im_func = func;
+        }
+        if (typeof(self) != 'undefined') {
+            im_self = self;
+        }
+        if (typeof(im_preargs) == 'undefined') {
+            im_preargs = [];
+        } else  {
+            im_preargs = im_preargs.slice();
+        }
+        m.extend(im_preargs, arguments, 2);
+        var newfunc = function () {
+            var args = arguments;
+            var me = arguments.callee;
+            if (me.im_preargs.length > 0) {
+                args = m.concat(me.im_preargs, args);
+            }
+            var self = me.im_self;
+            if (!self) {
+                self = this;
+            }
+            return me.im_func.apply(self, args);
+        };
+        newfunc.im_self = im_self;
+        newfunc.im_func = im_func;
+        newfunc.im_preargs = im_preargs;
+        return newfunc;
+    },
+
+    bindMethods: function (self) {
+        var bind = MochiKit.Base.bind;
+        for (var k in self) {
+            var func = self[k];
+            if (typeof(func) == 'function') {
+                self[k] = bind(func, self);
+            }
+        }
+    },
+
+    registerComparator: function (name, check, comparator, /* optional */ override) {
+        MochiKit.Base.comparatorRegistry.register(name, check, comparator, override);
+    },
+
+    _primitives: {'boolean': true, 'string': true, 'number': true},
+
+    compare: function (a, b) {
+        if (a == b) {
+            return 0;
+        }
+        var aIsNull = (typeof(a) == 'undefined' || a === null);
+        var bIsNull = (typeof(b) == 'undefined' || b === null);
+        if (aIsNull && bIsNull) {
+            return 0;
+        } else if (aIsNull) {
+            return -1;
+        } else if (bIsNull) {
+            return 1;
+        }
+        var m = MochiKit.Base;
+        // bool, number, string have meaningful comparisons
+        var prim = m._primitives;
+        if (!(typeof(a) in prim && typeof(b) in prim)) {
+            try {
+                return m.comparatorRegistry.match(a, b);
+            } catch (e) {
+                if (e != m.NotFound) {
+                    throw e;
+                }
+            }
+        }
+        if (a < b) {
+            return -1;
+        } else if (a > b) {
+            return 1;
+        }
+        // These types can't be compared
+        var repr = m.repr;
+        throw new TypeError(repr(a) + " and " + repr(b) + " can not be compared");
+    },
+
+    compareDateLike: function (a, b) {
+        return MochiKit.Base.compare(a.getTime(), b.getTime());
+    },
+
+    compareArrayLike: function (a, b) {
+        var compare = MochiKit.Base.compare;
+        var count = a.length;
+        var rval = 0;
+        if (count > b.length) {
+            rval = 1;
+            count = b.length;
+        } else if (count < b.length) {
+            rval = -1;
+        }
+        for (var i = 0; i < count; i++) {
+            var cmp = compare(a[i], b[i]);
+            if (cmp) {
+                return cmp;
+            }
+        }
+        return rval;
+    },
+
+    registerRepr: function (name, check, wrap, /* optional */override) {
+        MochiKit.Base.reprRegistry.register(name, check, wrap, override);
+    },
+
+    repr: function (o) {
+        if (typeof(o) == "undefined") {
+            return "undefined";
+        } else if (o === null) {
+            return "null";
+        }
+        try {
+            if (typeof(o.__repr__) == 'function') {
+                return o.__repr__();
+            } else if (typeof(o.repr) == 'function' && o.repr != arguments.callee) {
+                return o.repr();
+            }
+            return MochiKit.Base.reprRegistry.match(o);
+        } catch (e) {
+            if (typeof(o.NAME) == 'string' && (
+                    o.toString == Function.prototype.toString ||
+                    o.toString == Object.prototype.toString
+                )) {
+                return o.NAME;
+            }
+        }
+        try {
+            var ostring = (o + "");
+        } catch (e) {
+            return "[" + typeof(o) + "]";
+        }
+        if (typeof(o) == "function") {
+            o = ostring.replace(/^\s+/, "");
+            var idx = o.indexOf("{");
+            if (idx != -1) {
+                o = o.substr(0, idx) + "{...}";
+            }
+        }
+        return ostring;
+    },
+
+    reprArrayLike: function (o) {
+        var m = MochiKit.Base;
+        return "[" + m.map(m.repr, o).join(", ") + "]";
+    },
+
+    reprString: function (o) { 
+        return ('"' + o.replace(/(["\\])/g, '\\$1') + '"'
+            ).replace(/[\f]/g, "\\f"
+            ).replace(/[\b]/g, "\\b"
+            ).replace(/[\n]/g, "\\n"
+            ).replace(/[\t]/g, "\\t"
+            ).replace(/[\r]/g, "\\r");
+    },
+
+    reprNumber: function (o) {
+        return o + "";
+    },
+
+    registerJSON: function (name, check, wrap, /* optional */override) {
+        MochiKit.Base.jsonRegistry.register(name, check, wrap, override);
+    },
+
+
+    evalJSON: function () {
+        return eval("(" + arguments[0] + ")");
+    },
+
+    serializeJSON: function (o) {
+        var objtype = typeof(o);
+        if (objtype == "undefined") {
+            return "undefined";
+        } else if (objtype == "number" || objtype == "boolean") {
+            return o + "";
+        } else if (o === null) {
+            return "null";
+        }
+        var m = MochiKit.Base;
+        var reprString = m.reprString;
+        if (objtype == "string") {
+            return reprString(o);
+        }
+        // recurse
+        var me = arguments.callee;
+        // short-circuit for objects that support "json" serialization
+        // if they return "self" then just pass-through...
+        var newObj;
+        if (typeof(o.__json__) == "function") {
+            newObj = o.__json__();
+            if (o !== newObj) {
+                return me(newObj);
+            }
+        }
+        if (typeof(o.json) == "function") {
+            newObj = o.json();
+            if (o !== newObj) {
+                return me(newObj);
+            }
+        }
+        // array
+        if (objtype != "function" && typeof(o.length) == "number") {
+            var res = [];
+            for (var i = 0; i < o.length; i++) {
+                var val = me(o[i]);
+                if (typeof(val) != "string") {
+                    val = "undefined";
+                }
+                res.push(val);
+            }
+            return "[" + res.join(", ") + "]";
+        }
+        // look in the registry
+        try {
+            newObj = m.jsonRegistry.match(o);
+            return me(newObj);
+        } catch (e) {
+            if (e != m.NotFound) {
+                // something really bad happened
+                throw e;
+            }
+        }
+        // it's a function with no adapter, bad
+        if (objtype == "function") {
+            return null;
+        }
+        // generic object code path
+        res = [];
+        for (var k in o) {
+            var useKey;
+            if (typeof(k) == "number") {
+                useKey = '"' + k + '"';
+            } else if (typeof(k) == "string") {
+                useKey = reprString(k);
+            } else {
+                // skip non-string or number keys
+                continue;
+            }
+            val = me(o[k]);
+            if (typeof(val) != "string") {
+                // skip non-serializable values
+                continue;
+            }
+            res.push(useKey + ":" + val);
+        }
+        return "{" + res.join(", ") + "}";
+    },
+            
+
+    objEqual: function (a, b) {
+        return (MochiKit.Base.compare(a, b) === 0);
+    },
+
+    arrayEqual: function (self, arr) {
+        if (self.length != arr.length) {
+            return false;
+        }
+        return (MochiKit.Base.compare(self, arr) === 0);
+    },
+
+    concat: function (/* lst... */) {
+        var rval = [];
+        var extend = MochiKit.Base.extend;
+        for (var i = 0; i < arguments.length; i++) {
+            extend(rval, arguments[i]);
+        }
+        return rval;
+    },
+
+    keyComparator: function (key/* ... */) {
+        // fast-path for single key comparisons
+        var m = MochiKit.Base;
+        var compare = m.compare;
+        if (arguments.length == 1) {
+            return function (a, b) {
+                return compare(a[key], b[key]);
+            };
+        }
+        var compareKeys = m.extend(null, arguments);
+        return function (a, b) {
+            var rval = 0;
+            // keep comparing until something is inequal or we run out of
+            // keys to compare
+            for (var i = 0; (rval === 0) && (i < compareKeys.length); i++) {
+                var key = compareKeys[i];
+                rval = compare(a[key], b[key]);
+            }
+            return rval;
+        };
+    },
+
+    reverseKeyComparator: function (key) {
+        var comparator = MochiKit.Base.keyComparator.apply(this, arguments);
+        return function (a, b) {
+            return comparator(b, a);
+        };
+    },
+
+    partial: function (func) {
+        var m = MochiKit.Base;
+        return m.bind.apply(this, m.extend([func, undefined], arguments, 1));
+    },
+     
+    listMinMax: function (which, lst) {
+        if (lst.length === 0) {
+            return null;
+        }
+        var cur = lst[0];
+        var compare = MochiKit.Base.compare;
+        for (var i = 1; i < lst.length; i++) {
+            var o = lst[i];
+            if (compare(o, cur) == which) {
+                cur = o;
+            }
+        }
+        return cur;
+    },
+
+    objMax: function (/* obj... */) {
+        return MochiKit.Base.listMinMax(1, arguments);
+    },
+            
+    objMin: function (/* obj... */) {
+        return MochiKit.Base.listMinMax(-1, arguments);
+    },
+
+    findIdentical: function (lst, value, start/* = 0 */, /* optional */end) {
+        if (typeof(end) == "undefined" || end === null) {
+            end = lst.length;
+        }
+        for (var i = (start || 0); i < end; i++) {
+            if (lst[i] === value) {
+                return i;
+            }
+        }
+        return -1;
+    },
+
+    findValue: function (lst, value, start/* = 0 */, /* optional */end) {
+        if (typeof(end) == "undefined" || end === null) {
+            end = lst.length;
+        }
+        var cmp = MochiKit.Base.compare;
+        for (var i = (start || 0); i < end; i++) {
+            if (cmp(lst[i], value) === 0) {
+                return i;
+            }
+        }
+        return -1;
+    },
+    
+    nodeWalk: function (node, visitor) {
+        var nodes = [node];
+        var extend = MochiKit.Base.extend;
+        while (nodes.length) {
+            var res = visitor(nodes.shift());
+            if (res) {
+                extend(nodes, res);
+            }
+        }
+    },
+
+       
+    nameFunctions: function (namespace) {
+        var base = namespace.NAME;
+        if (typeof(base) == 'undefined') {
+            base = '';
+        } else {
+            base = base + '.';
+        }
+        for (var name in namespace) {
+            var o = namespace[name];
+            if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') {
+                try {
+                    o.NAME = base + name;
+                } catch (e) {
+                    // pass
+                }
+            }
+        }
+    },
+
+
+    queryString: function (names, values) {
+        // check to see if names is a string or a DOM element, and if
+        // MochiKit.DOM is available.  If so, drop it like it's a form
+        // Ugliest conditional in MochiKit?  Probably!
+        if (typeof(MochiKit.DOM) != "undefined" && arguments.length == 1
+            && (typeof(names) == "string" || (
+                typeof(names.nodeType) != "undefined" && names.nodeType > 0
+            ))
+        ) {
+            var kv = MochiKit.DOM.formContents(names);
+            names = kv[0];
+            values = kv[1];
+        } else if (arguments.length == 1) {
+            var o = names;
+            names = [];
+            values = [];
+            for (var k in o) {
+                var v = o[k];
+                if (typeof(v) != "function") {
+                    names.push(k);
+                    values.push(v);
+                }
+            }
+        }
+        var rval = [];
+        var len = Math.min(names.length, values.length);
+        var urlEncode = MochiKit.Base.urlEncode;
+        for (var i = 0; i < len; i++) {
+            v = values[i];
+            if (typeof(v) != 'undefined' && v !== null) {
+                rval.push(urlEncode(names[i]) + "=" + urlEncode(v));
+            }
+        }
+        return rval.join("&");
+    },
+
+
+    parseQueryString: function (encodedString, useArrays) {
+        var pairs = encodedString.replace(/\+/g, "%20").split("&");
+        var o = {};
+        var decode;
+        if (typeof(decodeURIComponent) != "undefined") {
+            decode = decodeURIComponent;
+        } else {
+            decode = unescape;
+        }
+        if (useArrays) {
+            for (var i = 0; i < pairs.length; i++) {
+                var pair = pairs[i].split("=");
+                var name = decode(pair[0]);
+                var arr = o[name];
+                if (!(arr instanceof Array)) {
+                    arr = [];
+                    o[name] = arr;
+                }
+                arr.push(decode(pair[1]));
+            }
+        } else {
+            for (i = 0; i < pairs.length; i++) {
+                pair = pairs[i].split("=");
+                o[decode(pair[0])] = decode(pair[1]);
+            }
+        }
+        return o;
+    }
+});
+    
+MochiKit.Base.AdapterRegistry = function () {
+    this.pairs = [];
+};
+
+MochiKit.Base.AdapterRegistry.prototype = {
+    register: function (name, check, wrap, /* optional */ override) {
+        if (override) {
+            this.pairs.unshift([name, check, wrap]);
+        } else {
+            this.pairs.push([name, check, wrap]);
+        }
+    },
+
+    match: function (/* ... */) {
+        for (var i = 0; i < this.pairs.length; i++) {
+            var pair = this.pairs[i];
+            if (pair[1].apply(this, arguments)) {
+                return pair[2].apply(this, arguments);
+            }
+        }
+        throw MochiKit.Base.NotFound;
+    },
+
+    unregister: function (name) {
+        for (var i = 0; i < this.pairs.length; i++) {
+            var pair = this.pairs[i];
+            if (pair[0] == name) {
+                this.pairs.splice(i, 1);
+                return true;
+            }
+        }
+        return false;
+    }
+};
+
+
+MochiKit.Base.EXPORT = [
+    "counter",
+    "clone",
+    "extend",
+    "update",
+    "updatetree",
+    "setdefault",
+    "keys",
+    "items",
+    "NamedError",
+    "operator",
+    "forwardCall",
+    "itemgetter",
+    "typeMatcher",
+    "isCallable",
+    "isUndefined",
+    "isUndefinedOrNull",
+    "isNull",
+    "isEmpty",
+    "isNotEmpty",
+    "isArrayLike",
+    "isDateLike",
+    "xmap",
+    "map",
+    "xfilter",
+    "filter",
+    "bind",
+    "bindMethods",
+    "NotFound",
+    "AdapterRegistry",
+    "registerComparator",
+    "compare",
+    "registerRepr",
+    "repr",
+    "objEqual",
+    "arrayEqual",
+    "concat",
+    "keyComparator",
+    "reverseKeyComparator",
+    "partial",
+    "merge",
+    "listMinMax",
+    "listMax",
+    "listMin",
+    "objMax",
+    "objMin",
+    "nodeWalk",
+    "zip",
+    "urlEncode",
+    "queryString",
+    "serializeJSON",
+    "registerJSON",
+    "evalJSON",
+    "parseQueryString",
+    "findValue",
+    "findIdentical",
+    "flattenArguments",
+    "method"
+];
+
+MochiKit.Base.EXPORT_OK = [
+    "nameFunctions",
+    "comparatorRegistry",
+    "reprRegistry",
+    "jsonRegistry",
+    "compareDateLike",
+    "compareArrayLike",
+    "reprArrayLike",
+    "reprString",
+    "reprNumber"
+];
+
+MochiKit.Base._exportSymbols = function (globals, module) {
+    if (typeof(MochiKit.__export__) == "undefined") {
+        MochiKit.__export__ = (MochiKit.__compat__  ||
+            (typeof(JSAN) == 'undefined' && typeof(dojo) == 'undefined')
+        );
+    }
+    if (!MochiKit.__export__) {
+        return;
+    }
+    var all = module.EXPORT_TAGS[":all"];
+    for (var i = 0; i < all.length; i++) {
+        globals[all[i]] = module[all[i]];
+    }
+};
+
+MochiKit.Base.__new__ = function () {
+    // A singleton raised when no suitable adapter is found
+    var m = this;
+
+    // Backwards compat
+    m.forward = m.forwardCall;
+    m.find = m.findValue;
+
+    if (typeof(encodeURIComponent) != "undefined") {
+        m.urlEncode = function (unencoded) {
+            return encodeURIComponent(unencoded).replace(/\'/g, '%27');
+        };
+    } else {
+        m.urlEncode = function (unencoded) {
+            return escape(unencoded
+                ).replace(/\+/g, '%2B'
+                ).replace(/\"/g,'%22'
+                ).rval.replace(/\'/g, '%27');
+        };
+    }
+
+    m.NamedError = function (name) {
+        this.message = name;
+        this.name = name;
+    };
+    m.NamedError.prototype = new Error();
+    m.update(m.NamedError.prototype, {
+        repr: function () {
+            if (this.message && this.message != this.name) {
+                return this.name + "(" + m.repr(this.message) + ")";
+            } else {
+                return this.name + "()";
+            }
+        },
+        toString: m.forwardCall("repr")
+    });
+
+    m.NotFound = new m.NamedError("MochiKit.Base.NotFound");
+
+
+    m.listMax = m.partial(m.listMinMax, 1);
+    m.listMin = m.partial(m.listMinMax, -1);
+
+    m.isCallable = m.typeMatcher('function');
+    m.isUndefined = m.typeMatcher('undefined');
+
+    m.merge = m.partial(m.update, null);
+    m.zip = m.partial(m.map, null);
+
+    m.comparatorRegistry = new m.AdapterRegistry();
+    m.registerComparator("dateLike", m.isDateLike, m.compareDateLike);
+    m.registerComparator("arrayLike", m.isArrayLike, m.compareArrayLike);
+
+    m.reprRegistry = new m.AdapterRegistry();
+    m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike);
+    m.registerRepr("string", m.typeMatcher("string"), m.reprString);
+    m.registerRepr("numbers", m.typeMatcher("number", "boolean"), m.reprNumber);
+
+    m.jsonRegistry = new m.AdapterRegistry();
+
+    var all = m.concat(m.EXPORT, m.EXPORT_OK);
+    m.EXPORT_TAGS = {
+        ":common": m.concat(m.EXPORT_OK),
+        ":all": all
+    };
+
+    m.nameFunctions(this);
+
+};
+
+MochiKit.Base.__new__();
+
+//
+// XXX: Internet Explorer blows
+//
+if (!MochiKit.__compat__) {
+    compare = MochiKit.Base.compare;
+}
+
+MochiKit.Base._exportSymbols(this, MochiKit.Base);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Color.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Color.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Color.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,825 @@
+/***
+
+MochiKit.Color 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito and others.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Color');
+    dojo.require('MochiKit.Base');
+}
+
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Base", []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.Color depends on MochiKit.Base";
+}
+
+if (typeof(MochiKit.Color) == "undefined") {
+    MochiKit.Color = {};
+}
+
+MochiKit.Color.NAME = "MochiKit.Color";
+MochiKit.Color.VERSION = "1.3.1";
+
+MochiKit.Color.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.Color.toString = function () {
+    return this.__repr__();
+};
+
+
+MochiKit.Color.Color = function (red, green, blue, alpha) {
+    if (typeof(alpha) == 'undefined' || alpha === null) {
+        alpha = 1.0;
+    }
+    this.rgb = {
+        r: red,
+        g: green,
+        b: blue,
+        a: alpha
+    };
+};
+
+
+// Prototype methods
+MochiKit.Color.Color.prototype = {
+
+    __class__: MochiKit.Color.Color,
+
+    colorWithAlpha: function (alpha) {
+        var rgb = this.rgb;
+        var m = MochiKit.Color;
+        return m.Color.fromRGB(rgb.r, rgb.g, rgb.b, alpha);
+    },
+
+    colorWithHue: function (hue) {
+        // get an HSL model, and set the new hue...
+        var hsl = this.asHSL();
+        hsl.h = hue;
+        var m = MochiKit.Color;
+        // convert back to RGB...
+        return m.Color.fromHSL(hsl);
+    },
+
+    colorWithSaturation: function (saturation) {
+        // get an HSL model, and set the new hue...
+        var hsl = this.asHSL();
+        hsl.s = saturation;
+        var m = MochiKit.Color;
+        // convert back to RGB...
+        return m.Color.fromHSL(hsl);
+    },
+
+    colorWithLightness: function (lightness) {
+        // get an HSL model, and set the new hue...
+        var hsl = this.asHSL();
+        hsl.l = lightness;
+        var m = MochiKit.Color;
+        // convert back to RGB...
+        return m.Color.fromHSL(hsl);
+    },
+
+    darkerColorWithLevel: function (level) {
+        var hsl  = this.asHSL();
+        hsl.l = Math.max(hsl.l - level, 0);
+        var m = MochiKit.Color;
+        return m.Color.fromHSL(hsl);
+    },
+
+    lighterColorWithLevel: function (level) {
+        var hsl  = this.asHSL();
+        hsl.l = Math.min(hsl.l + level, 1);
+        var m = MochiKit.Color;
+        return m.Color.fromHSL(hsl);
+    },
+
+    blendedColor: function (other, /* optional */ fraction) {
+        if (typeof(fraction) == 'undefined' || fraction === null) {
+            fraction = 0.5;
+        }
+        var sf = 1.0 - fraction;
+        var s = this.rgb;
+        var d = other.rgb;
+        var df = fraction;
+        return MochiKit.Color.Color.fromRGB(
+            (s.r * sf) + (d.r * df),
+            (s.g * sf) + (d.g * df),
+            (s.b * sf) + (d.b * df),
+            (s.a * sf) + (d.a * df)
+        );
+    },
+
+    compareRGB: function (other) {
+        var a = this.asRGB();
+        var b = other.asRGB();
+        return MochiKit.Base.compare(
+            [a.r, a.g, a.b, a.a],
+            [b.r, b.g, b.b, b.a]
+        );
+    },
+        
+    isLight: function () {
+        return this.asHSL().b > 0.5;
+    },
+
+    isDark: function () {
+        return (!this.isLight());
+    },
+
+    toHSLString: function () {
+        var c = this.asHSL();
+        var ccc = MochiKit.Color.clampColorComponent;
+        var rval = this._hslString;
+        if (!rval) {
+            var mid = (
+                ccc(c.h, 360).toFixed(0)
+                + "," + ccc(c.s, 100).toPrecision(4) + "%" 
+                + "," + ccc(c.l, 100).toPrecision(4) + "%"
+            );
+            var a = c.a;
+            if (a >= 1) {
+                a = 1;
+                rval = "hsl(" + mid + ")";
+            } else {
+                if (a <= 0) {
+                    a = 0;
+                }
+                rval = "hsla(" + mid + "," + a + ")";
+            }
+            this._hslString = rval;
+        }
+        return rval;
+    },
+
+    toRGBString: function () {
+        var c = this.rgb;
+        var ccc = MochiKit.Color.clampColorComponent;
+        var rval = this._rgbString;
+        if (!rval) {
+            var mid = (
+                ccc(c.r, 255).toFixed(0)
+                + "," + ccc(c.g, 255).toFixed(0)
+                + "," + ccc(c.b, 255).toFixed(0)
+            );
+            if (c.a != 1) {
+                rval = "rgba(" + mid + "," + c.a + ")";
+            } else {
+                rval = "rgb(" + mid + ")";
+            }
+            this._rgbString = rval;
+        }
+        return rval;
+    },
+
+    asRGB: function () {
+        return MochiKit.Base.clone(this.rgb);
+    },
+
+    toHexString: function () {
+        var m = MochiKit.Color;
+        var c = this.rgb;
+        var ccc = MochiKit.Color.clampColorComponent;
+        var rval = this._hexString;
+        if (!rval) {
+            rval = ("#" + 
+                m.toColorPart(ccc(c.r, 255)) +
+                m.toColorPart(ccc(c.g, 255)) +
+                m.toColorPart(ccc(c.b, 255))
+            );
+            this._hexString = rval;
+        }
+        return rval;
+    },
+
+    asHSV: function () {
+        var hsv = this.hsv;
+        var c = this.rgb;
+        if (typeof(hsv) == 'undefined' || hsv === null) {
+            hsv = MochiKit.Color.rgbToHSV(this.rgb);
+            this.hsv = hsv;
+        }
+        return MochiKit.Base.clone(hsv);
+    },
+
+    asHSL: function () {
+        var hsl = this.hsl;
+        var c = this.rgb;
+        if (typeof(hsl) == 'undefined' || hsl === null) {
+            hsl = MochiKit.Color.rgbToHSL(this.rgb);
+            this.hsl = hsl;
+        }
+        return MochiKit.Base.clone(hsl);
+    },
+
+    toString: function () {
+        return this.toRGBString();
+    },
+
+    repr: function () {
+        var c = this.rgb;
+        var col = [c.r, c.g, c.b, c.a];
+        return this.__class__.NAME + "(" + col.join(", ") + ")";
+    }
+
+};
+
+// Constructor methods
+MochiKit.Base.update(MochiKit.Color.Color, {
+    fromRGB: function (red, green, blue, alpha) {
+        // designated initializer
+        var Color = MochiKit.Color.Color;
+        if (arguments.length == 1) {
+            var rgb = red;
+            red = rgb.r;
+            green = rgb.g;
+            blue = rgb.b;
+            if (typeof(rgb.a) == 'undefined') {
+                alpha = undefined;
+            } else {
+                alpha = rgb.a;
+            }
+        }
+        return new Color(red, green, blue, alpha);
+    },
+
+    fromHSL: function (hue, saturation, lightness, alpha) {
+        var m = MochiKit.Color;
+        return m.Color.fromRGB(m.hslToRGB.apply(m, arguments));
+    },
+
+    fromHSV: function (hue, saturation, value, alpha) {
+        var m = MochiKit.Color;
+        return m.Color.fromRGB(m.hsvToRGB.apply(m, arguments));
+    },
+
+    fromName: function (name) {
+        var Color = MochiKit.Color.Color;
+        // Opera 9 seems to "quote" named colors(?!)
+        if (name.charAt(0) == '"') {
+            name = name.substr(1, name.length - 2);
+        }
+        var htmlColor = Color._namedColors[name.toLowerCase()];
+        if (typeof(htmlColor) == 'string') {
+            return Color.fromHexString(htmlColor);
+        } else if (name == "transparent") {
+            return Color.transparentColor();
+        }
+        return null;
+    },
+
+    fromString: function (colorString) {
+        var self = MochiKit.Color.Color;
+        var three = colorString.substr(0, 3);
+        if (three == "rgb") {
+            return self.fromRGBString(colorString);
+        } else if (three == "hsl") {
+            return self.fromHSLString(colorString);
+        } else if (colorString.charAt(0) == "#") {
+            return self.fromHexString(colorString);
+        }
+        return self.fromName(colorString);
+    },
+
+
+    fromHexString: function (hexCode) {
+        if (hexCode.charAt(0) == '#') {
+            hexCode = hexCode.substring(1);
+        }
+        var components = [];
+        var i, hex;
+        if (hexCode.length == 3) {
+            for (i = 0; i < 3; i++) {
+                hex = hexCode.substr(i, 1);
+                components.push(parseInt(hex + hex, 16) / 255.0);
+            }
+        } else {
+            for (i = 0; i < 6; i += 2) {
+                hex = hexCode.substr(i, 2);
+                components.push(parseInt(hex, 16) / 255.0);
+            }
+        }
+        var Color = MochiKit.Color.Color;
+        return Color.fromRGB.apply(Color, components);
+    },
+        
+
+    _fromColorString: function (pre, method, scales, colorCode) {
+        // parses either HSL or RGB
+        if (colorCode.indexOf(pre) === 0) {
+            colorCode = colorCode.substring(colorCode.indexOf("(", 3) + 1, colorCode.length - 1);
+        } 
+        var colorChunks = colorCode.split(/\s*,\s*/);
+        var colorFloats = [];
+        for (var i = 0; i < colorChunks.length; i++) {
+            var c = colorChunks[i];
+            var val;
+            var three = c.substring(c.length - 3);
+            if (c.charAt(c.length - 1) == '%') {
+                val = 0.01 * parseFloat(c.substring(0, c.length - 1));
+            } else if (three == "deg") {
+                val = parseFloat(c) / 360.0;
+            } else if (three == "rad") {
+                val = parseFloat(c) / (Math.PI * 2);
+            } else {
+                val = scales[i] * parseFloat(c);
+            }
+            colorFloats.push(val);
+        }
+        return this[method].apply(this, colorFloats);
+    },
+    
+    fromComputedStyle: function (elem, style, mozillaEquivalentCSS) {
+        var d = MochiKit.DOM;
+        var cls = MochiKit.Color.Color;
+        for (elem = d.getElement(elem); elem; elem = elem.parentNode) {
+            var actualColor = d.computedStyle.apply(d, arguments);
+            if (!actualColor) {
+                continue;
+            }
+            var color = cls.fromString(actualColor);
+            if (!color) {
+                break;
+            }
+            if (color.asRGB().a > 0) {
+                return color;
+            }
+        }
+        return null;
+    },
+
+    fromBackground: function (elem) {
+        var cls = MochiKit.Color.Color;
+        return cls.fromComputedStyle(
+            elem, "backgroundColor", "background-color") || cls.whiteColor();
+    },
+
+    fromText: function (elem) {
+        var cls = MochiKit.Color.Color;
+        return cls.fromComputedStyle(
+            elem, "color", "color") || cls.blackColor();
+    },
+
+    namedColors: function () {
+        return MochiKit.Base.clone(MochiKit.Color.Color._namedColors);
+    }
+});
+
+// Module level functions
+MochiKit.Base.update(MochiKit.Color, {
+    clampColorComponent: function (v, scale) {
+        v *= scale;
+        if (v < 0) {
+            return 0;
+        } else if (v > scale) {
+            return scale;
+        } else {
+            return v;
+        }
+    },
+
+    _hslValue: function (n1, n2, hue) {
+        if (hue > 6.0) {
+            hue -= 6.0;
+        } else if (hue < 0.0) {
+            hue += 6.0;
+        }
+        var val;
+        if (hue < 1.0) {
+            val = n1 + (n2 - n1) * hue;
+        } else if (hue < 3.0) {
+            val = n2;
+        } else if (hue < 4.0) {
+            val = n1 + (n2 - n1) * (4.0 - hue);
+        } else {
+            val = n1;
+        }
+        return val;
+    },
+        
+    hsvToRGB: function (hue, saturation, value, alpha) {
+        if (arguments.length == 1) {
+            var hsv = hue;
+            hue = hsv.h;
+            saturation = hsv.s;
+            value = hsv.v;
+            alpha = hsv.a;
+        }
+        var red;
+        var green;
+        var blue;
+        if (saturation === 0) {
+            red = 0;
+            green = 0;
+            blue = 0;
+        } else {
+            var i = Math.floor(hue * 6);
+            var f = (hue * 6) - i;
+            var p = value * (1 - saturation);
+            var q = value * (1 - (saturation * f));
+            var t = value * (1 - (saturation * (1 - f)));
+            switch (i) {
+                case 1: red = q; green = value; blue = p; break;
+                case 2: red = p; green = value; blue = t; break;
+                case 3: red = p; green = q; blue = value; break;
+                case 4: red = t; green = p; blue = value; break;
+                case 5: red = value; green = p; blue = q; break;
+                case 6: // fall through
+                case 0: red = value; green = t; blue = p; break;
+            }
+        }
+        return {
+            r: red,
+            g: green,
+            b: blue,
+            a: alpha
+        };
+    },
+
+    hslToRGB: function (hue, saturation, lightness, alpha) {
+        if (arguments.length == 1) {
+            var hsl = hue;
+            hue = hsl.h;
+            saturation = hsl.s;
+            lightness = hsl.l;
+            alpha = hsl.a;
+        }
+        var red;
+        var green;
+        var blue;
+        if (saturation === 0) {
+            red = lightness;
+            green = lightness;
+            blue = lightness;
+        } else {
+            var m2;
+            if (lightness <= 0.5) {
+                m2 = lightness * (1.0 + saturation);
+            } else {
+                m2 = lightness + saturation - (lightness * saturation);
+            }
+            var m1 = (2.0 * lightness) - m2;
+            var f = MochiKit.Color._hslValue;
+            var h6 = hue * 6.0;
+            red = f(m1, m2, h6 + 2);
+            green = f(m1, m2, h6);
+            blue = f(m1, m2, h6 - 2);
+        }
+        return {
+            r: red,
+            g: green,
+            b: blue,
+            a: alpha
+        };
+    },
+
+    rgbToHSV: function (red, green, blue, alpha) {
+        if (arguments.length == 1) {
+            var rgb = red;
+            red = rgb.r;
+            green = rgb.g;
+            blue = rgb.b;
+            alpha = rgb.a;
+        }
+        var max = Math.max(Math.max(red, green), blue);
+        var min = Math.min(Math.min(red, green), blue);
+        var hue;
+        var saturation;
+        var value = max;
+        if (min == max) {
+            hue = 0;
+            saturation = 0;
+        } else {
+            var delta = (max - min);
+            saturation = delta / max;
+
+            if (red == max) {
+                hue = (green - blue) / delta;
+            } else if (green == max) {
+                hue = 2 + ((blue - red) / delta);
+            } else {
+                hue = 4 + ((red - green) / delta);
+            }
+            hue /= 6;
+            if (hue < 0) {
+                hue += 1;
+            }
+            if (hue > 1) {
+                hue -= 1;
+            }
+        }
+        return {
+            h: hue,
+            s: saturation,
+            v: value,
+            a: alpha
+        };
+    },
+            
+    rgbToHSL: function (red, green, blue, alpha) {
+        if (arguments.length == 1) {
+            var rgb = red;
+            red = rgb.r;
+            green = rgb.g;
+            blue = rgb.b;
+            alpha = rgb.a;
+        }
+        var max = Math.max(red, Math.max(green, blue));
+        var min = Math.min(red, Math.min(green, blue));
+        var hue;
+        var saturation;
+        var lightness = (max + min) / 2.0;
+        var delta = max - min;
+        if (delta === 0) {
+            hue = 0;
+            saturation = 0;
+        } else {
+            if (lightness <= 0.5) {
+                saturation = delta / (max + min);
+            } else {
+                saturation = delta / (2 - max - min);
+            }
+            if (red == max) {
+                hue = (green - blue) / delta;
+            } else if (green == max) {
+                hue = 2 + ((blue - red) / delta);
+            } else {
+                hue = 4 + ((red - green) / delta);
+            }
+            hue /= 6;
+            if (hue < 0) {
+                hue += 1;
+            }
+            if (hue > 1) {
+                hue -= 1;
+            }
+            
+        }
+        return {
+            h: hue,
+            s: saturation,
+            l: lightness,
+            a: alpha
+        };
+    },
+
+    toColorPart: function (num) {
+        num = Math.round(num);
+        var digits = num.toString(16);
+        if (num < 16) {
+            return '0' + digits;
+        }
+        return digits;
+    },
+
+    __new__: function () {
+        var m = MochiKit.Base;
+        this.Color.fromRGBString = m.bind(
+            this.Color._fromColorString, this.Color, "rgb", "fromRGB",
+            [1.0/255.0, 1.0/255.0, 1.0/255.0, 1]
+        );
+        this.Color.fromHSLString = m.bind(
+            this.Color._fromColorString, this.Color, "hsl", "fromHSL",
+            [1.0/360.0, 0.01, 0.01, 1]
+        );
+        
+        var third = 1.0 / 3.0;
+        var colors = {
+            // NSColor colors plus transparent
+            black: [0, 0, 0],
+            blue: [0, 0, 1],
+            brown: [0.6, 0.4, 0.2],
+            cyan: [0, 1, 1],
+            darkGray: [third, third, third],
+            gray: [0.5, 0.5, 0.5],
+            green: [0, 1, 0],
+            lightGray: [2 * third, 2 * third, 2 * third],
+            magenta: [1, 0, 1],
+            orange: [1, 0.5, 0],
+            purple: [0.5, 0, 0.5],
+            red: [1, 0, 0],
+            transparent: [0, 0, 0, 0],
+            white: [1, 1, 1],
+            yellow: [1, 1, 0]
+        };
+
+        var makeColor = function (name, r, g, b, a) {
+            var rval = this.fromRGB(r, g, b, a);
+            this[name] = function () { return rval; };
+            return rval;
+        };
+
+        for (var k in colors) {
+            var name = k + "Color";
+            var bindArgs = m.concat(
+                [makeColor, this.Color, name],
+                colors[k]
+            );
+            this.Color[name] = m.bind.apply(null, bindArgs);
+        }
+
+        var isColor = function () {
+            for (var i = 0; i < arguments.length; i++) {
+                if (!(arguments[i] instanceof Color)) {
+                    return false;
+                }
+            }
+            return true;
+        };
+
+        var compareColor = function (a, b) {
+            return a.compareRGB(b);
+        };
+
+        m.nameFunctions(this);
+
+        m.registerComparator(this.Color.NAME, isColor, compareColor);
+            
+        this.EXPORT_TAGS = {
+            ":common": this.EXPORT,
+            ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+        };
+
+    }
+});
+
+MochiKit.Color.EXPORT = [
+    "Color"
+];
+
+MochiKit.Color.EXPORT_OK = [
+    "clampColorComponent",
+    "rgbToHSL",
+    "hslToRGB",
+    "rgbToHSV",
+    "hsvToRGB",
+    "toColorPart"
+];
+
+MochiKit.Color.__new__();
+
+MochiKit.Base._exportSymbols(this, MochiKit.Color);
+
+// Full table of css3 X11 colors <http://www.w3.org/TR/css3-color/#X11COLORS>
+
+MochiKit.Color.Color._namedColors = {
+    aliceblue: "#f0f8ff",
+    antiquewhite: "#faebd7",
+    aqua: "#00ffff",
+    aquamarine: "#7fffd4",
+    azure: "#f0ffff",
+    beige: "#f5f5dc",
+    bisque: "#ffe4c4",
+    black: "#000000",
+    blanchedalmond: "#ffebcd",
+    blue: "#0000ff",
+    blueviolet: "#8a2be2",
+    brown: "#a52a2a",
+    burlywood: "#deb887",
+    cadetblue: "#5f9ea0",
+    chartreuse: "#7fff00",
+    chocolate: "#d2691e",
+    coral: "#ff7f50",
+    cornflowerblue: "#6495ed",
+    cornsilk: "#fff8dc",
+    crimson: "#dc143c",
+    cyan: "#00ffff",
+    darkblue: "#00008b",
+    darkcyan: "#008b8b",
+    darkgoldenrod: "#b8860b",
+    darkgray: "#a9a9a9",
+    darkgreen: "#006400",
+    darkgrey: "#a9a9a9",
+    darkkhaki: "#bdb76b",
+    darkmagenta: "#8b008b",
+    darkolivegreen: "#556b2f",
+    darkorange: "#ff8c00",
+    darkorchid: "#9932cc",
+    darkred: "#8b0000",
+    darksalmon: "#e9967a",
+    darkseagreen: "#8fbc8f",
+    darkslateblue: "#483d8b",
+    darkslategray: "#2f4f4f",
+    darkslategrey: "#2f4f4f",
+    darkturquoise: "#00ced1",
+    darkviolet: "#9400d3",
+    deeppink: "#ff1493",
+    deepskyblue: "#00bfff",
+    dimgray: "#696969",
+    dimgrey: "#696969",
+    dodgerblue: "#1e90ff",
+    firebrick: "#b22222",
+    floralwhite: "#fffaf0",
+    forestgreen: "#228b22",
+    fuchsia: "#ff00ff",
+    gainsboro: "#dcdcdc",
+    ghostwhite: "#f8f8ff",
+    gold: "#ffd700",
+    goldenrod: "#daa520",
+    gray: "#808080",
+    green: "#008000",
+    greenyellow: "#adff2f",
+    grey: "#808080",
+    honeydew: "#f0fff0",
+    hotpink: "#ff69b4",
+    indianred: "#cd5c5c",
+    indigo: "#4b0082",
+    ivory: "#fffff0",
+    khaki: "#f0e68c",
+    lavender: "#e6e6fa",
+    lavenderblush: "#fff0f5",
+    lawngreen: "#7cfc00",
+    lemonchiffon: "#fffacd",
+    lightblue: "#add8e6",
+    lightcoral: "#f08080",
+    lightcyan: "#e0ffff",
+    lightgoldenrodyellow: "#fafad2",
+    lightgray: "#d3d3d3",
+    lightgreen: "#90ee90",
+    lightgrey: "#d3d3d3",
+    lightpink: "#ffb6c1",
+    lightsalmon: "#ffa07a",
+    lightseagreen: "#20b2aa",
+    lightskyblue: "#87cefa",
+    lightslategray: "#778899",
+    lightslategrey: "#778899",
+    lightsteelblue: "#b0c4de",
+    lightyellow: "#ffffe0",
+    lime: "#00ff00",
+    limegreen: "#32cd32",
+    linen: "#faf0e6",
+    magenta: "#ff00ff",
+    maroon: "#800000",
+    mediumaquamarine: "#66cdaa",
+    mediumblue: "#0000cd",
+    mediumorchid: "#ba55d3",
+    mediumpurple: "#9370db",
+    mediumseagreen: "#3cb371",
+    mediumslateblue: "#7b68ee",
+    mediumspringgreen: "#00fa9a",
+    mediumturquoise: "#48d1cc",
+    mediumvioletred: "#c71585",
+    midnightblue: "#191970",
+    mintcream: "#f5fffa",
+    mistyrose: "#ffe4e1",
+    moccasin: "#ffe4b5",
+    navajowhite: "#ffdead",
+    navy: "#000080",
+    oldlace: "#fdf5e6",
+    olive: "#808000",
+    olivedrab: "#6b8e23",
+    orange: "#ffa500",
+    orangered: "#ff4500",
+    orchid: "#da70d6",
+    palegoldenrod: "#eee8aa",
+    palegreen: "#98fb98",
+    paleturquoise: "#afeeee",
+    palevioletred: "#db7093",
+    papayawhip: "#ffefd5",
+    peachpuff: "#ffdab9",
+    peru: "#cd853f",
+    pink: "#ffc0cb",
+    plum: "#dda0dd",
+    powderblue: "#b0e0e6",
+    purple: "#800080",
+    red: "#ff0000",
+    rosybrown: "#bc8f8f",
+    royalblue: "#4169e1",
+    saddlebrown: "#8b4513",
+    salmon: "#fa8072",
+    sandybrown: "#f4a460",
+    seagreen: "#2e8b57",
+    seashell: "#fff5ee",
+    sienna: "#a0522d",
+    silver: "#c0c0c0",
+    skyblue: "#87ceeb",
+    slateblue: "#6a5acd",
+    slategray: "#708090",
+    slategrey: "#708090",
+    snow: "#fffafa",
+    springgreen: "#00ff7f",
+    steelblue: "#4682b4",
+    tan: "#d2b48c",
+    teal: "#008080",
+    thistle: "#d8bfd8",
+    tomato: "#ff6347",
+    turquoise: "#40e0d0",
+    violet: "#ee82ee",
+    wheat: "#f5deb3",
+    white: "#ffffff",
+    whitesmoke: "#f5f5f5",
+    yellow: "#ffff00",
+    yellowgreen: "#9acd32"
+};

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DOM.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DOM.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DOM.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,1106 @@
+/***
+
+MochiKit.DOM 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide("MochiKit.DOM");
+    dojo.require("MochiKit.Iter");
+}
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Iter", []);
+}
+
+try {
+    if (typeof(MochiKit.Iter) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.DOM depends on MochiKit.Iter!";
+}
+
+if (typeof(MochiKit.DOM) == 'undefined') {
+    MochiKit.DOM = {};
+}
+
+MochiKit.DOM.NAME = "MochiKit.DOM";
+MochiKit.DOM.VERSION = "1.3.1";
+MochiKit.DOM.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+MochiKit.DOM.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.DOM.EXPORT = [
+    "formContents",
+    "currentWindow",
+    "currentDocument",
+    "withWindow",
+    "withDocument",
+    "registerDOMConverter",
+    "coerceToDOM",
+    "createDOM",
+    "createDOMFunc",
+    "getNodeAttribute",
+    "setNodeAttribute",
+    "updateNodeAttributes",
+    "appendChildNodes",
+    "replaceChildNodes",
+    "removeElement",
+    "swapDOM",
+    "BUTTON",
+    "TT",
+    "PRE",
+    "H1",
+    "H2",
+    "H3",
+    "BR",
+    "CANVAS",
+    "HR",
+    "LABEL",
+    "TEXTAREA",
+    "FORM",
+    "STRONG",
+    "SELECT",
+    "OPTION",
+    "OPTGROUP",
+    "LEGEND",
+    "FIELDSET",
+    "P",
+    "UL",
+    "OL",
+    "LI",
+    "TD",
+    "TR",
+    "THEAD",
+    "TBODY",
+    "TFOOT",
+    "TABLE",
+    "TH",
+    "INPUT",
+    "SPAN",
+    "A",
+    "DIV",
+    "IMG",
+    "getElement",
+    "$",
+    "computedStyle",
+    "getElementsByTagAndClassName",
+    "addToCallStack",
+    "addLoadEvent",
+    "focusOnLoad",
+    "setElementClass",
+    "toggleElementClass",
+    "addElementClass",
+    "removeElementClass",
+    "swapElementClass",
+    "hasElementClass",
+    "escapeHTML",
+    "toHTML",
+    "emitHTML",
+    "setDisplayForElement",
+    "hideElement",
+    "showElement",
+    "scrapeText",
+    "elementDimensions",
+    "elementPosition",
+    "setElementDimensions",
+    "setElementPosition",
+    "getViewportDimensions",
+    "setOpacity"
+];
+
+MochiKit.DOM.EXPORT_OK = [
+    "domConverters"
+];
+
+MochiKit.DOM.Dimensions = function (w, h) {
+    this.w = w;
+    this.h = h;
+};
+
+MochiKit.DOM.Dimensions.prototype.repr = function () {
+    var repr = MochiKit.Base.repr;
+    return "{w: "  + repr(this.w) + ", h: " + repr(this.h) + "}";
+};
+
+MochiKit.DOM.Coordinates = function (x, y) {
+    this.x = x;
+    this.y = y;
+};
+
+MochiKit.DOM.Coordinates.prototype.repr = function () {
+    var repr = MochiKit.Base.repr;
+    return "{x: "  + repr(this.x) + ", y: " + repr(this.y) + "}";
+};
+
+MochiKit.DOM.Coordinates.prototype.toString = function () {
+    return this.repr();
+};
+
+MochiKit.Base.update(MochiKit.DOM, {
+
+    setOpacity: function(elem, o) {
+        elem = MochiKit.DOM.getElement(elem);
+        MochiKit.DOM.updateNodeAttributes(elem, {'style': {
+                'opacity': o, 
+                '-moz-opacity': o,
+                '-khtml-opacity': o,
+                'filter':' alpha(opacity=' + (o * 100) + ')'
+            }});
+    },
+    
+    getViewportDimensions: function() {
+        var d = new MochiKit.DOM.Dimensions();
+        
+        var w = MochiKit.DOM._window;
+        var b = MochiKit.DOM._document.body;
+        
+        if (w.innerWidth) {
+            d.w = w.innerWidth;
+            d.h = w.innerHeight;
+        } else if (b.parentElement.clientWidth) {
+            d.w = b.parentElement.clientWidth;
+            d.h = b.parentElement.clientHeight;
+        } else if (b && b.clientWidth) {
+            d.w = b.clientWidth;
+            d.h = b.clientHeight;
+        }
+        return d;
+    },
+
+    elementDimensions: function (elem) {
+        var self = MochiKit.DOM;
+        if (typeof(elem.w) == 'number' || typeof(elem.h) == 'number') {
+            return new self.Dimensions(elem.w || 0, elem.h || 0);
+        }
+        elem = self.getElement(elem);
+        if (!elem) {
+            return undefined;
+        }
+        if (self.computedStyle(elem, 'display') != 'none') {
+            return new self.Dimensions(elem.offsetWidth || 0, 
+                elem.offsetHeight || 0);
+        }
+        var s = elem.style;
+        var originalVisibility = s.visibility;
+        var originalPosition = s.position;
+        s.visibility = 'hidden';
+        s.position = 'absolute';
+        s.display = '';
+        var originalWidth = elem.offsetWidth;
+        var originalHeight = elem.offsetHeight;
+        s.display = 'none';
+        s.position = originalPosition;
+        s.visibility = originalVisibility;
+        return new self.Dimensions(originalWidth, originalHeight);
+    },
+
+    /* 
+
+        elementPosition is adapted from YAHOO.util.Dom.getXY, version 0.9.0.
+        Copyright: Copyright (c) 2006, Yahoo! Inc. All rights reserved.
+        License: BSD, http://developer.yahoo.net/yui/license.txt
+
+    */
+    elementPosition: function (elem, /* optional */relativeTo) {
+        var self = MochiKit.DOM;        
+        elem = self.getElement(elem);
+        
+        if (!elem) { 
+            return undefined;
+        }
+
+        var c = new self.Coordinates(0, 0);
+        
+        if (elem.x && elem.y) {
+            /* it's just a MochiKit.DOM.Coordinates object */
+            c.x += elem.x || 0;
+            c.y += elem.y || 0;
+            return c;
+        } else if (elem.parentNode === null || self.computedStyle(elem, 'display') == 'none') {
+            return undefined;
+        }
+        
+        var box = null;
+        var parent = null;
+        
+        var d = MochiKit.DOM._document;
+        var de = d.documentElement;
+        var b = d.body;            
+    
+        if (elem.getBoundingClientRect) { // IE shortcut
+            
+            /*
+            
+                The IE shortcut is off by two:
+                http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp
+                
+            */
+            box = elem.getBoundingClientRect();
+                        
+            c.x += box.left + 
+                (de.scrollLeft || b.scrollLeft) - 
+                (de.clientLeft || b.clientLeft);
+            
+            c.y += box.top + 
+                (de.scrollTop || b.scrollTop) - 
+                (de.clientTop || b.clientTop);
+            
+        } else if (d.getBoxObjectFor) { // Gecko shortcut
+            box = d.getBoxObjectFor(elem);
+            c.x += box.x;
+            c.y += box.y;
+        } else if (elem.offsetParent) {
+            c.x += elem.offsetLeft;
+            c.y += elem.offsetTop;
+            parent = elem.offsetParent;
+            
+            if (parent != elem) {
+                while (parent) {
+                    c.x += parent.offsetLeft;
+                    c.y += parent.offsetTop;
+                    parent = parent.offsetParent;
+                }
+            }
+
+            /*
+                
+                Opera < 9 and old Safari (absolute) incorrectly account for 
+                body offsetTop and offsetLeft.
+                
+            */            
+            var ua = navigator.userAgent.toLowerCase();
+            if ((typeof(opera) != "undefined" && 
+                parseFloat(opera.version()) < 9) || 
+                (ua.indexOf('safari') != -1 && 
+                self.computedStyle(elem, 'position') == 'absolute')) {
+                                
+                c.x -= b.offsetLeft;
+                c.y -= b.offsetTop;
+                
+            }
+        }
+        
+        if (typeof(relativeTo) != 'undefined') {
+            relativeTo = arguments.callee(relativeTo);
+            if (relativeTo) {
+                c.x -= (relativeTo.x || 0);
+                c.y -= (relativeTo.y || 0);
+            }
+        }
+        
+        if (elem.parentNode) {
+            parent = elem.parentNode;
+        } else {
+            parent = null;
+        }
+        
+        while (parent && parent.tagName != 'BODY' && 
+            parent.tagName != 'HTML') {
+            c.x -= parent.scrollLeft;
+            c.y -= parent.scrollTop;        
+            if (parent.parentNode) {
+                parent = parent.parentNode;
+            } else {
+                parent = null;
+            }
+        }
+        
+        return c;
+    },
+    
+    setElementDimensions: function (elem, newSize/* optional */, units) {
+        elem = MochiKit.DOM.getElement(elem);
+        if (typeof(units) == 'undefined') {
+            units = 'px';
+        }
+        MochiKit.DOM.updateNodeAttributes(elem, {'style': {
+            'width': newSize.w + units, 
+            'height': newSize.h + units
+        }});
+    },
+    
+    setElementPosition: function (elem, newPos/* optional */, units) {
+        elem = MochiKit.DOM.getElement(elem);
+        if (typeof(units) == 'undefined') {
+            units = 'px';
+        }
+        MochiKit.DOM.updateNodeAttributes(elem, {'style': {
+            'left': newPos.x + units,
+            'top': newPos.y + units
+        }});
+    },
+    
+    currentWindow: function () {
+        return MochiKit.DOM._window;
+    },
+
+    currentDocument: function () {
+        return MochiKit.DOM._document;
+    },
+
+    withWindow: function (win, func) {
+        var self = MochiKit.DOM;
+        var oldDoc = self._document;
+        var oldWin = self._win;
+        var rval;
+        try {
+            self._window = win;
+            self._document = win.document;
+            rval = func();
+        } catch (e) {
+            self._window = oldWin;
+            self._document = oldDoc;
+            throw e;
+        }
+        self._window = oldWin;
+        self._document = oldDoc;
+        return rval;
+    },
+
+    formContents: function (elem/* = document */) {
+        var names = [];
+        var values = [];
+        var m = MochiKit.Base;
+        var self = MochiKit.DOM;
+        if (typeof(elem) == "undefined" || elem === null) {
+            elem = self._document;
+        } else {
+            elem = self.getElement(elem);
+        }
+        m.nodeWalk(elem, function (elem) {
+            var name = elem.name;
+            if (m.isNotEmpty(name)) {
+                var tagName = elem.nodeName;
+                if (tagName == "INPUT"
+                    && (elem.type == "radio" || elem.type == "checkbox")
+                    && !elem.checked
+                ) {
+                    return null;
+                }
+                if (tagName == "SELECT") {
+                    if (elem.selectedIndex >= 0) {
+                        var opt = elem.options[elem.selectedIndex];
+                        names.push(name);
+                        values.push((opt.value) ? opt.value : opt.text);
+                        return null;
+                    }
+                    // no form elements?
+                    names.push(name);
+                    values.push("");
+                    return null;
+                }
+                if (tagName == "FORM" || tagName == "P" || tagName == "SPAN"
+                    || tagName == "DIV"
+                ) {
+                    return elem.childNodes;
+                }
+                names.push(name);
+                values.push(elem.value || '');
+                return null;
+            }
+            return elem.childNodes;
+        });
+        return [names, values];
+    },
+
+    withDocument: function (doc, func) {
+        var self = MochiKit.DOM;
+        var oldDoc = self._document;
+        var rval;
+        try {
+            self._document = doc;
+            rval = func();
+        } catch (e) {
+            self._document = oldDoc;
+            throw e;
+        }
+        self._document = oldDoc;
+        return rval;
+    },
+
+    registerDOMConverter: function (name, check, wrap, /* optional */override) {
+        MochiKit.DOM.domConverters.register(name, check, wrap, override);
+    },
+
+    coerceToDOM: function (node, ctx) {
+        var im = MochiKit.Iter;
+        var self = MochiKit.DOM;
+        var iter = im.iter;
+        var repeat = im.repeat;
+        var imap = im.imap;
+        var domConverters = self.domConverters;
+        var coerceToDOM = self.coerceToDOM;
+        var NotFound = MochiKit.Base.NotFound;
+        while (true) {
+            if (typeof(node) == 'undefined' || node === null) {
+                return null;
+            }
+            if (typeof(node.nodeType) != 'undefined' && node.nodeType > 0) {
+                return node;
+            }
+            if (typeof(node) == 'number' || typeof(node) == 'boolean') {
+                node = node.toString();
+                // FALL THROUGH
+            }
+            if (typeof(node) == 'string') {
+                return self._document.createTextNode(node);
+            }
+            if (typeof(node.toDOM) == 'function') {
+                node = node.toDOM(ctx);
+                continue;
+            }
+            if (typeof(node) == 'function') {
+                node = node(ctx);
+                continue;
+            }
+
+            // iterable
+            var iterNodes = null;
+            try {
+                iterNodes = iter(node);
+            } catch (e) {
+                // pass
+            }
+            if (iterNodes) {
+                return imap(
+                    coerceToDOM,
+                    iterNodes,
+                    repeat(ctx)
+                );
+            }
+
+            // adapter
+            try {
+                node = domConverters.match(node, ctx);
+                continue;
+            } catch (e) {
+                if (e != NotFound) {
+                    throw e;
+                }
+            }
+
+            // fallback
+            return self._document.createTextNode(node.toString());
+        }
+        // mozilla warnings aren't too bright
+        return undefined;
+    },
+        
+    setNodeAttribute: function (node, attr, value) {
+        var o = {};
+        o[attr] = value;
+        try {
+            return MochiKit.DOM.updateNodeAttributes(node, o);
+        } catch (e) {
+            // pass
+        }
+        return null;
+    },
+
+    getNodeAttribute: function (node, attr) {
+        var self = MochiKit.DOM;
+        var rename = self.attributeArray.renames[attr];
+        node = self.getElement(node);
+        try {
+            if (rename) {
+                return node[rename];
+            }
+            return node.getAttribute(attr);
+        } catch (e) {
+            // pass
+        }
+        return null;
+    },
+
+    updateNodeAttributes: function (node, attrs) {
+        var elem = node;
+        var self = MochiKit.DOM;
+        if (typeof(node) == 'string') {
+            elem = self.getElement(node);
+        }
+        if (attrs) {
+            var updatetree = MochiKit.Base.updatetree;
+            if (self.attributeArray.compliant) {
+                // not IE, good.
+                for (var k in attrs) {
+                    var v = attrs[k];
+                    if (typeof(v) == 'object' && typeof(elem[k]) == 'object') {
+                        updatetree(elem[k], v);
+                    } else if (k.substring(0, 2) == "on") {
+                        if (typeof(v) == "string") {
+                            v = new Function(v);
+                        }
+                        elem[k] = v;
+                    } else {
+                        elem.setAttribute(k, v);
+                    }
+                }
+            } else {
+                // IE is insane in the membrane
+                var renames = self.attributeArray.renames;
+                for (k in attrs) {
+                    v = attrs[k];
+                    var renamed = renames[k];
+                    if (k == "style" && typeof(v) == "string") {
+                        elem.style.cssText = v;
+                    } else if (typeof(renamed) == "string") {
+                        elem[renamed] = v;
+                    } else if (typeof(elem[k]) == 'object'
+                            && typeof(v) == 'object') {
+                        updatetree(elem[k], v);
+                    } else if (k.substring(0, 2) == "on") {
+                        if (typeof(v) == "string") {
+                            v = new Function(v);
+                        }
+                        elem[k] = v;
+                    } else {
+                        elem.setAttribute(k, v);
+                    }
+                }
+            }
+        }
+        return elem;
+    },
+
+    appendChildNodes: function (node/*, nodes...*/) {
+        var elem = node;
+        var self = MochiKit.DOM;
+        if (typeof(node) == 'string') {
+            elem = self.getElement(node);
+        }
+        var nodeStack = [
+            self.coerceToDOM(
+                MochiKit.Base.extend(null, arguments, 1),
+                elem
+            )
+        ];
+        var concat = MochiKit.Base.concat;
+        while (nodeStack.length) {
+            var n = nodeStack.shift();
+            if (typeof(n) == 'undefined' || n === null) {
+                // pass
+            } else if (typeof(n.nodeType) == 'number') {
+                elem.appendChild(n);
+            } else {
+                nodeStack = concat(n, nodeStack);
+            }
+        }
+        return elem;
+    },
+
+    replaceChildNodes: function (node/*, nodes...*/) {
+        var elem = node;
+        var self = MochiKit.DOM;
+        if (typeof(node) == 'string') {
+            elem = self.getElement(node);
+            arguments[0] = elem;
+        }
+        var child;
+        while ((child = elem.firstChild)) {
+            elem.removeChild(child);
+        }
+        if (arguments.length < 2) {
+            return elem;
+        } else {
+            return self.appendChildNodes.apply(this, arguments);
+        }
+    },
+
+    createDOM: function (name, attrs/*, nodes... */) {
+        /*
+
+            Create a DOM fragment in a really convenient manner, much like
+            Nevow's <http://nevow.com> stan.
+
+        */
+
+        var elem;
+        var self = MochiKit.DOM;
+        var m = MochiKit.Base;
+        if (typeof(attrs) == "string" || typeof(attrs) == "number") {
+            var args = m.extend([name, null], arguments, 1);
+            return arguments.callee.apply(this, args);
+        }
+        if (typeof(name) == 'string') {
+            // Internet Explorer is dumb
+            if (attrs && "name" in attrs && !self.attributeArray.compliant) {
+                // http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp
+                name = ('<' + name + ' name="' + self.escapeHTML(attrs.name)
+                    + '">');
+            }
+            elem = self._document.createElement(name);
+        } else {
+            elem = name;
+        }
+        if (attrs) {
+            self.updateNodeAttributes(elem, attrs);
+        }
+        if (arguments.length <= 2) {
+            return elem;
+        } else {
+            var args = m.extend([elem], arguments, 2);
+            return self.appendChildNodes.apply(this, args);
+        }
+    },
+
+    createDOMFunc: function (/* tag, attrs, *nodes */) {
+        var m = MochiKit.Base;
+        return m.partial.apply(
+            this,
+            m.extend([MochiKit.DOM.createDOM], arguments)
+        );
+    },
+
+    swapDOM: function (dest, src) {
+        var self = MochiKit.DOM;
+        dest = self.getElement(dest);
+        var parent = dest.parentNode;
+        if (src) {
+            src = self.getElement(src);
+            parent.replaceChild(src, dest);
+        } else {
+            parent.removeChild(dest);
+        }
+        return src;
+    },
+
+    getElement: function (id) {
+        var self = MochiKit.DOM;
+        if (arguments.length == 1) {
+            return ((typeof(id) == "string") ?
+                self._document.getElementById(id) : id);
+        } else {
+            return MochiKit.Base.map(self.getElement, arguments);
+        }
+    },
+
+    computedStyle: function (htmlElement, cssProperty, mozillaEquivalentCSS) {
+        if (arguments.length == 2) {
+            mozillaEquivalentCSS = cssProperty;
+        }   
+        var self = MochiKit.DOM;
+        var el = self.getElement(htmlElement);
+        var document = self._document;
+        if (!el || el == document) {
+            return undefined;
+        }
+        if (el.currentStyle) {
+            return el.currentStyle[cssProperty];
+        }
+        if (typeof(document.defaultView) == 'undefined') {
+            return undefined;
+        }
+        if (document.defaultView === null) {
+            return undefined;
+        }
+        var style = document.defaultView.getComputedStyle(el, null);
+        if (typeof(style) == "undefined" || style === null) {
+            return undefined;
+        }
+        return style.getPropertyValue(mozillaEquivalentCSS);
+    },
+
+    getElementsByTagAndClassName: function (tagName, className,
+            /* optional */parent) {
+        var self = MochiKit.DOM;
+        if (typeof(tagName) == 'undefined' || tagName === null) {
+            tagName = '*';
+        }
+        if (typeof(parent) == 'undefined' || parent === null) {
+            parent = self._document;
+        }
+        parent = self.getElement(parent);
+        var children = (parent.getElementsByTagName(tagName)
+            || self._document.all);
+        if (typeof(className) == 'undefined' || className === null) {
+            return MochiKit.Base.extend(null, children);
+        }
+
+        var elements = [];
+        for (var i = 0; i < children.length; i++) {
+            var child = children[i];
+            var classNames = child.className.split(' ');
+            for (var j = 0; j < classNames.length; j++) {
+                if (classNames[j] == className) {
+                    elements.push(child);
+                    break;
+                }
+            }
+        }
+
+        return elements;
+    },
+
+    _newCallStack: function (path, once) {
+        var rval = function () {
+            var callStack = arguments.callee.callStack;
+            for (var i = 0; i < callStack.length; i++) {
+                if (callStack[i].apply(this, arguments) === false) {
+                    break;
+                }
+            }
+            if (once) {
+                try {
+                    this[path] = null;
+                } catch (e) {
+                    // pass
+                }
+            }
+        };
+        rval.callStack = [];
+        return rval;
+    },
+
+    addToCallStack: function (target, path, func, once) {
+        var self = MochiKit.DOM;
+        var existing = target[path];
+        var regfunc = existing;
+        if (!(typeof(existing) == 'function'
+                && typeof(existing.callStack) == "object"
+                && existing.callStack !== null)) {
+            regfunc = self._newCallStack(path, once);
+            if (typeof(existing) == 'function') {
+                regfunc.callStack.push(existing);
+            }
+            target[path] = regfunc;
+        }
+        regfunc.callStack.push(func);
+    },
+
+    addLoadEvent: function (func) {
+        var self = MochiKit.DOM;
+        self.addToCallStack(self._window, "onload", func, true);
+        
+    },
+
+    focusOnLoad: function (element) {
+        var self = MochiKit.DOM;
+        self.addLoadEvent(function () {
+            element = self.getElement(element);
+            if (element) {
+                element.focus();
+            }
+        });
+    },
+            
+    setElementClass: function (element, className) {
+        var self = MochiKit.DOM;
+        var obj = self.getElement(element);
+        if (self.attributeArray.compliant) {
+            obj.setAttribute("class", className);
+        } else {
+            obj.setAttribute("className", className);
+        }
+    },
+            
+    toggleElementClass: function (className/*, element... */) {
+        var self = MochiKit.DOM;
+        for (var i = 1; i < arguments.length; i++) {
+            var obj = self.getElement(arguments[i]);
+            if (!self.addElementClass(obj, className)) {
+                self.removeElementClass(obj, className);
+            }
+        }
+    },
+
+    addElementClass: function (element, className) {
+        var self = MochiKit.DOM;
+        var obj = self.getElement(element);
+        var cls = obj.className;
+        // trivial case, no className yet
+        if (cls.length === 0) {
+            self.setElementClass(obj, className);
+            return true;
+        }
+        // the other trivial case, already set as the only class
+        if (cls == className) {
+            return false;
+        }
+        var classes = obj.className.split(" ");
+        for (var i = 0; i < classes.length; i++) {
+            // already present
+            if (classes[i] == className) {
+                return false;
+            }
+        }
+        // append class
+        self.setElementClass(obj, cls + " " + className);
+        return true;
+    },
+
+    removeElementClass: function (element, className) {
+        var self = MochiKit.DOM;
+        var obj = self.getElement(element);
+        var cls = obj.className;
+        // trivial case, no className yet
+        if (cls.length === 0) {
+            return false;
+        }
+        // other trivial case, set only to className
+        if (cls == className) {
+            self.setElementClass(obj, "");
+            return true;
+        }
+        var classes = obj.className.split(" ");
+        for (var i = 0; i < classes.length; i++) {
+            // already present
+            if (classes[i] == className) {
+                // only check sane case where the class is used once
+                classes.splice(i, 1);
+                self.setElementClass(obj, classes.join(" "));
+                return true;
+            }
+        }
+        // not found
+        return false;
+    },
+
+    swapElementClass: function (element, fromClass, toClass) {
+        var obj = MochiKit.DOM.getElement(element);
+        var res = MochiKit.DOM.removeElementClass(obj, fromClass);
+        if (res) {
+            MochiKit.DOM.addElementClass(obj, toClass);
+        }
+        return res;
+    },
+
+    hasElementClass: function (element, className/*...*/) {
+        var obj = MochiKit.DOM.getElement(element);
+        var classes = obj.className.split(" ");
+        for (var i = 1; i < arguments.length; i++) {
+            var good = false;
+            for (var j = 0; j < classes.length; j++) {
+                if (classes[j] == arguments[i]) {
+                    good = true;
+                    break;
+                }
+            }
+            if (!good) {
+                return false;
+            }
+        }
+        return true;
+    },
+
+    escapeHTML: function (s) {
+        return s.replace(/&/g, "&amp;"
+            ).replace(/"/g, "&quot;"
+            ).replace(/</g, "&lt;"
+            ).replace(/>/g, "&gt;");
+    },
+
+    toHTML: function (dom) {
+        return MochiKit.DOM.emitHTML(dom).join("");
+    },
+
+    emitHTML: function (dom, /* optional */lst) {
+        if (typeof(lst) == 'undefined' || lst === null) {
+            lst = [];
+        }
+        // queue is the call stack, we're doing this non-recursively
+        var queue = [dom];
+        var self = MochiKit.DOM;
+        var escapeHTML = self.escapeHTML;
+        var attributeArray = self.attributeArray;
+        while (queue.length) {
+            dom = queue.pop();
+            if (typeof(dom) == 'string') {
+                lst.push(dom);
+            } else if (dom.nodeType == 1) {
+                // we're not using higher order stuff here
+                // because safari has heisenbugs.. argh.
+                //
+                // I think it might have something to do with
+                // garbage collection and function calls.
+                lst.push('<' + dom.nodeName.toLowerCase());
+                var attributes = [];
+                var domAttr = attributeArray(dom);
+                for (var i = 0; i < domAttr.length; i++) {
+                    var a = domAttr[i];
+                    attributes.push([
+                        " ",
+                        a.name,
+                        '="',
+                        escapeHTML(a.value),
+                        '"'
+                    ]);
+                }
+                attributes.sort();
+                for (i = 0; i < attributes.length; i++) {
+                    var attrs = attributes[i];
+                    for (var j = 0; j < attrs.length; j++) {
+                        lst.push(attrs[j]);
+                    }
+                }
+                if (dom.hasChildNodes()) {
+                    lst.push(">");
+                    // queue is the FILO call stack, so we put the close tag
+                    // on first
+                    queue.push("</" + dom.nodeName.toLowerCase() + ">");
+                    var cnodes = dom.childNodes;
+                    for (i = cnodes.length - 1; i >= 0; i--) {
+                        queue.push(cnodes[i]);
+                    }
+                } else {
+                    lst.push('/>');
+                }
+            } else if (dom.nodeType == 3) {
+                lst.push(escapeHTML(dom.nodeValue));
+            }
+        }
+        return lst;
+    },
+
+    setDisplayForElement: function (display, element/*, ...*/) {
+        var m = MochiKit.Base;
+        var elements = m.extend(null, arguments, 1);
+        MochiKit.Iter.forEach(
+            m.filter(null, m.map(MochiKit.DOM.getElement, elements)),
+            function (element) {
+                element.style.display = display;
+            }
+        );
+    },
+
+    scrapeText: function (node, /* optional */asArray) {
+        var rval = [];
+        (function (node) {
+            var cn = node.childNodes;
+            if (cn) {
+                for (var i = 0; i < cn.length; i++) {
+                    arguments.callee.call(this, cn[i]);
+                }
+            }
+            var nodeValue = node.nodeValue;
+            if (typeof(nodeValue) == 'string') {
+                rval.push(nodeValue);
+            }
+        })(MochiKit.DOM.getElement(node));
+        if (asArray) {
+            return rval;
+        } else {
+            return rval.join("");
+        }
+    },
+
+
+    __new__: function (win) {
+
+        var m = MochiKit.Base;
+        this._document = document;
+        this._window = win;
+
+        this.domConverters = new m.AdapterRegistry(); 
+        
+        var __tmpElement = this._document.createElement("span");
+        var attributeArray;
+        if (__tmpElement && __tmpElement.attributes &&
+                __tmpElement.attributes.length > 0) {
+            // for braindead browsers (IE) that insert extra junk
+            var filter = m.filter;
+            attributeArray = function (node) {
+                return filter(attributeArray.ignoreAttrFilter, node.attributes);
+            };
+            attributeArray.ignoreAttr = {};
+            MochiKit.Iter.forEach(__tmpElement.attributes, function (a) {
+                attributeArray.ignoreAttr[a.name] = a.value;
+            });
+            attributeArray.ignoreAttrFilter = function (a) {
+                return (attributeArray.ignoreAttr[a.name] != a.value);
+            };
+            attributeArray.compliant = false;
+            attributeArray.renames = {
+                "class": "className",
+                "checked": "defaultChecked",
+                "usemap": "useMap",
+                "for": "htmlFor"
+            };
+        } else {
+            attributeArray = function (node) {
+                /***
+                    
+                    Return an array of attributes for a given node,
+                    filtering out attributes that don't belong for
+                    that are inserted by "Certain Browsers".
+
+                ***/
+                return node.attributes;
+            };
+            attributeArray.compliant = true;
+            attributeArray.renames = {};
+        }
+        this.attributeArray = attributeArray;
+
+
+        // shorthand for createDOM syntax
+        var createDOMFunc = this.createDOMFunc;
+        this.UL = createDOMFunc("ul");
+        this.OL = createDOMFunc("ol");
+        this.LI = createDOMFunc("li");
+        this.TD = createDOMFunc("td");
+        this.TR = createDOMFunc("tr");
+        this.TBODY = createDOMFunc("tbody");
+        this.THEAD = createDOMFunc("thead");
+        this.TFOOT = createDOMFunc("tfoot");
+        this.TABLE = createDOMFunc("table");
+        this.TH = createDOMFunc("th");
+        this.INPUT = createDOMFunc("input");
+        this.SPAN = createDOMFunc("span");
+        this.A = createDOMFunc("a");
+        this.DIV = createDOMFunc("div");
+        this.IMG = createDOMFunc("img");
+        this.BUTTON = createDOMFunc("button");
+        this.TT = createDOMFunc("tt");
+        this.PRE = createDOMFunc("pre");
+        this.H1 = createDOMFunc("h1");
+        this.H2 = createDOMFunc("h2");
+        this.H3 = createDOMFunc("h3");
+        this.BR = createDOMFunc("br");
+        this.HR = createDOMFunc("hr");
+        this.LABEL = createDOMFunc("label");
+        this.TEXTAREA = createDOMFunc("textarea");
+        this.FORM = createDOMFunc("form");
+        this.P = createDOMFunc("p");
+        this.SELECT = createDOMFunc("select");
+        this.OPTION = createDOMFunc("option");
+        this.OPTGROUP = createDOMFunc("optgroup");
+        this.LEGEND = createDOMFunc("legend");
+        this.FIELDSET = createDOMFunc("fieldset");
+        this.STRONG = createDOMFunc("strong");
+        this.CANVAS = createDOMFunc("canvas");
+
+        this.hideElement = m.partial(this.setDisplayForElement, "none");
+        this.showElement = m.partial(this.setDisplayForElement, "block");
+        this.removeElement = this.swapDOM;
+        
+        this.$ = this.getElement;
+
+        this.EXPORT_TAGS = {
+            ":common": this.EXPORT,
+            ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+        };
+
+        m.nameFunctions(this);
+
+    }
+});
+
+MochiKit.DOM.__new__(((typeof(window) == "undefined") ? this : window));
+
+//
+// XXX: Internet Explorer blows
+//
+if (!MochiKit.__compat__) {
+    withWindow = MochiKit.DOM.withWindow;
+    withDocument = MochiKit.DOM.withDocument;
+}
+
+MochiKit.Base._exportSymbols(this, MochiKit.DOM);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DateTime.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DateTime.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/DateTime.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,208 @@
+/***
+
+MochiKit.DateTime 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.DateTime');
+}
+
+if (typeof(MochiKit) == 'undefined') {
+    MochiKit = {};
+}
+       
+if (typeof(MochiKit.DateTime) == 'undefined') {
+    MochiKit.DateTime = {};
+}
+
+MochiKit.DateTime.NAME = "MochiKit.DateTime";
+MochiKit.DateTime.VERSION = "1.3.1";
+MochiKit.DateTime.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+MochiKit.DateTime.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.DateTime.isoDate = function (str) {
+    str = str + "";
+    if (typeof(str) != "string" || str.length === 0) {
+        return null;
+    }
+    var iso = str.split('-');
+    if (iso.length === 0) {
+        return null;
+    }
+    return new Date(iso[0], iso[1] - 1, iso[2]);
+};
+
+MochiKit.DateTime._isoRegexp = /(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/;
+
+MochiKit.DateTime.isoTimestamp = function (str) {
+    str = str + "";
+    if (typeof(str) != "string" || str.length === 0) {
+        return null;
+    }
+    var res = str.match(MochiKit.DateTime._isoRegexp);
+    if (typeof(res) == "undefined" || res === null) {
+        return null;
+    }
+    var year, month, day, hour, min, sec, msec;
+    year = parseInt(res[1], 10);
+    if (typeof(res[2]) == "undefined" || res[2] === '') {
+        return new Date(year);
+    }
+    month = parseInt(res[2], 10) - 1;
+    day = parseInt(res[3], 10);
+    if (typeof(res[4]) == "undefined" || res[4] === '') {
+        return new Date(year, month, day);
+    }
+    hour = parseInt(res[4], 10);
+    min = parseInt(res[5], 10);
+    sec = (typeof(res[6]) != "undefined" && res[6] !== '') ? parseInt(res[6], 10) : 0;
+    if (typeof(res[7]) != "undefined" && res[7] !== '') {
+        msec = Math.round(1000.0 * parseFloat("0." + res[7]));
+    } else {
+        msec = 0;
+    }
+    if ((typeof(res[8]) == "undefined" || res[8] === '') && (typeof(res[9]) == "undefined" || res[9] === '')) {
+        return new Date(year, month, day, hour, min, sec, msec);
+    }
+    var ofs;
+    if (typeof(res[9]) != "undefined" && res[9] !== '') {
+        ofs = parseInt(res[10], 10) * 3600000;
+        if (typeof(res[11]) != "undefined" && res[11] !== '') {
+            ofs += parseInt(res[11], 10) * 60000;
+        }
+        if (res[9] == "-") {
+            ofs = -ofs;
+        }
+    } else {
+        ofs = 0;
+    }
+    return new Date(Date.UTC(year, month, day, hour, min, sec, msec) - ofs);
+};
+
+MochiKit.DateTime.toISOTime = function (date, realISO/* = false */) {
+    if (typeof(date) == "undefined" || date === null) {
+        return null;
+    }
+    var hh = date.getHours();
+    var mm = date.getMinutes();
+    var ss = date.getSeconds();
+    var lst = [
+        ((realISO && (hh < 10)) ? "0" + hh : hh),
+        ((mm < 10) ? "0" + mm : mm),
+        ((ss < 10) ? "0" + ss : ss)
+    ];
+    return lst.join(":");
+};
+
+MochiKit.DateTime.toISOTimestamp = function (date, realISO/* = false*/) {
+    if (typeof(date) == "undefined" || date === null) {
+        return null;
+    }
+    var sep = realISO ? "T" : " ";
+    var foot = realISO ? "Z" : "";
+    if (realISO) {
+        date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
+    }
+    return MochiKit.DateTime.toISODate(date) + sep + MochiKit.DateTime.toISOTime(date, realISO) + foot;
+};
+
+MochiKit.DateTime.toISODate = function (date) {
+    if (typeof(date) == "undefined" || date === null) {
+        return null;
+    }
+    var _padTwo = MochiKit.DateTime._padTwo;
+    return [
+        date.getFullYear(),
+        _padTwo(date.getMonth() + 1),
+        _padTwo(date.getDate())
+    ].join("-");
+};
+
+MochiKit.DateTime.americanDate = function (d) {
+    d = d + "";
+    if (typeof(d) != "string" || d.length === 0) {
+        return null;
+    }
+    var a = d.split('/');
+    return new Date(a[2], a[0] - 1, a[1]);
+};
+
+MochiKit.DateTime._padTwo = function (n) {
+    return (n > 9) ? n : "0" + n;
+};
+
+MochiKit.DateTime.toPaddedAmericanDate = function (d) {
+    if (typeof(d) == "undefined" || d === null) {
+        return null;
+    }
+    var _padTwo = MochiKit.DateTime._padTwo;
+    return [
+        _padTwo(d.getMonth() + 1),
+        _padTwo(d.getDate()),
+        d.getFullYear()
+    ].join('/');
+};
+
+MochiKit.DateTime.toAmericanDate = function (d) {
+    if (typeof(d) == "undefined" || d === null) {
+        return null;
+    }
+    return [d.getMonth() + 1, d.getDate(), d.getFullYear()].join('/');
+};
+
+MochiKit.DateTime.EXPORT = [
+    "isoDate",
+    "isoTimestamp",
+    "toISOTime",
+    "toISOTimestamp",
+    "toISODate",
+    "americanDate",
+    "toPaddedAmericanDate",
+    "toAmericanDate"
+];
+
+MochiKit.DateTime.EXPORT_OK = [];
+MochiKit.DateTime.EXPORT_TAGS = {
+    ":common": MochiKit.DateTime.EXPORT,
+    ":all": MochiKit.DateTime.EXPORT
+};
+
+MochiKit.DateTime.__new__ = function () {
+    // MochiKit.Base.nameFunctions(this);
+    var base = this.NAME + ".";
+    for (var k in this) {
+        var o = this[k];
+        if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') {
+            try {
+                o.NAME = base + k;
+            } catch (e) {
+                // pass
+            }
+        }   
+    }
+};
+
+MochiKit.DateTime.__new__();
+
+if (typeof(MochiKit.Base) != "undefined") {
+    MochiKit.Base._exportSymbols(this, MochiKit.DateTime);
+} else {
+    (function (globals, module) {
+        if ((typeof(JSAN) == 'undefined' && typeof(dojo) == 'undefined')
+            || (typeof(MochiKit.__compat__) == 'boolean' && MochiKit.__compat__)) {
+            var all = module.EXPORT_TAGS[":all"];
+            for (var i = 0; i < all.length; i++) {
+                globals[all[i]] = module[all[i]]; 
+            }
+        }   
+    })(this, MochiKit.DateTime);  
+}

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Format.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Format.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Format.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,294 @@
+/***
+
+MochiKit.Format 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Format');
+}
+
+if (typeof(MochiKit) == 'undefined') {
+    MochiKit = {};
+}
+
+if (typeof(MochiKit.Format) == 'undefined') {
+    MochiKit.Format = {};
+}
+
+MochiKit.Format.NAME = "MochiKit.Format";
+MochiKit.Format.VERSION = "1.3.1";
+MochiKit.Format.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+MochiKit.Format.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.Format._numberFormatter = function (placeholder, header, footer, locale, isPercent, precision, leadingZeros, separatorAt, trailingZeros) {
+    return function (num) {
+        num = parseFloat(num);
+        if (typeof(num) == "undefined" || num === null || isNaN(num)) {
+            return placeholder;
+        }
+        var curheader = header;
+        var curfooter = footer;
+        if (num < 0) {
+            num = -num;
+        } else {
+            curheader = curheader.replace(/-/, "");
+        }
+        var me = arguments.callee;
+        var fmt = MochiKit.Format.formatLocale(locale);
+        if (isPercent) {
+            num = num * 100.0;
+            curfooter = fmt.percent + curfooter;
+        }
+        num = MochiKit.Format.roundToFixed(num, precision);
+        var parts = num.split(/\./);
+        var whole = parts[0];
+        var frac = (parts.length == 1) ? "" : parts[1];
+        var res = "";
+        while (whole.length < leadingZeros) {
+            whole = "0" + whole;
+        }
+        if (separatorAt) {
+            while (whole.length > separatorAt) {
+                var i = whole.length - separatorAt;
+                //res = res + fmt.separator + whole.substring(i, whole.length);
+                res = fmt.separator + whole.substring(i, whole.length) + res;
+                whole = whole.substring(0, i);
+            }
+        }
+        res = whole + res;
+        if (precision > 0) {
+            while (frac.length < trailingZeros) {
+                frac = frac + "0";
+            }
+            res = res + fmt.decimal + frac;
+        }
+        return curheader + res + curfooter;
+    };
+};
+
+MochiKit.Format.numberFormatter = function (pattern, placeholder/* = "" */, locale/* = "default" */) {
+    // http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html
+    // | 0 | leading or trailing zeros
+    // | # | just the number
+    // | , | separator
+    // | . | decimal separator
+    // | % | Multiply by 100 and format as percent
+    if (typeof(placeholder) == "undefined") {
+        placeholder = "";
+    }
+    var match = pattern.match(/((?:[0#]+,)?[0#]+)(?:\.([0#]+))?(%)?/);
+    if (!match) {
+        throw TypeError("Invalid pattern");
+    }
+    var header = pattern.substr(0, match.index);
+    var footer = pattern.substr(match.index + match[0].length);
+    if (header.search(/-/) == -1) {
+        header = header + "-";
+    }
+    var whole = match[1];
+    var frac = (typeof(match[2]) == "string" && match[2] != "") ? match[2] : "";
+    var isPercent = (typeof(match[3]) == "string" && match[3] != "");
+    var tmp = whole.split(/,/);
+    var separatorAt;
+    if (typeof(locale) == "undefined") {
+        locale = "default";
+    }
+    if (tmp.length == 1) {
+        separatorAt = null;
+    } else {
+        separatorAt = tmp[1].length;
+    }
+    var leadingZeros = whole.length - whole.replace(/0/g, "").length;
+    var trailingZeros = frac.length - frac.replace(/0/g, "").length;
+    var precision = frac.length;
+    var rval = MochiKit.Format._numberFormatter(
+        placeholder, header, footer, locale, isPercent, precision,
+        leadingZeros, separatorAt, trailingZeros
+    );
+    var m = MochiKit.Base;
+    if (m) {
+        var fn = arguments.callee;
+        var args = m.concat(arguments);
+        rval.repr = function () {
+            return [
+                self.NAME,
+                "(",
+                map(m.repr, args).join(", "),
+                ")"
+            ].join("");
+        };
+    }
+    return rval;
+};
+
+MochiKit.Format.formatLocale = function (locale) {
+    if (typeof(locale) == "undefined" || locale === null) {
+        locale = "default";
+    }
+    if (typeof(locale) == "string") {
+        var rval = MochiKit.Format.LOCALE[locale];
+        if (typeof(rval) == "string") {
+            rval = arguments.callee(rval);
+            MochiKit.Format.LOCALE[locale] = rval;
+        }
+        return rval;
+    } else {
+        return locale;
+    }
+};
+
+MochiKit.Format.twoDigitAverage = function (numerator, denominator) {
+    if (denominator) {
+        var res = numerator / denominator;
+        if (!isNaN(res)) {
+            return MochiKit.Format.twoDigitFloat(numerator / denominator);
+        }
+    }
+    return "0";
+};
+
+MochiKit.Format.twoDigitFloat = function (someFloat) {
+    var sign = (someFloat < 0 ? '-' : '');
+    var s = Math.floor(Math.abs(someFloat) * 100).toString();
+    if (s == '0') {
+        return s;
+    }
+    if (s.length < 3) {
+        while (s.charAt(s.length - 1) == '0') {
+            s = s.substring(0, s.length - 1);
+        }
+        return sign + '0.' + s;
+    }
+    var head = sign + s.substring(0, s.length - 2);
+    var tail = s.substring(s.length - 2, s.length);
+    if (tail == '00') {
+        return head;
+    } else if (tail.charAt(1) == '0') {
+        return head + '.' + tail.charAt(0);
+    } else {
+        return head + '.' + tail;
+    }
+};
+
+MochiKit.Format.lstrip = function (str, /* optional */chars) {
+    str = str + "";
+    if (typeof(str) != "string") {
+        return null;
+    }
+    if (!chars) {
+        return str.replace(/^\s+/, "");
+    } else {
+        return str.replace(new RegExp("^[" + chars + "]+"), "");
+    }
+};
+
+MochiKit.Format.rstrip = function (str, /* optional */chars) {
+    str = str + "";
+    if (typeof(str) != "string") {
+        return null;
+    }
+    if (!chars) {
+        return str.replace(/\s+$/, "");
+    } else {
+        return str.replace(new RegExp("[" + chars + "]+$"), "");
+    }
+};
+
+MochiKit.Format.strip = function (str, /* optional */chars) {
+    var self = MochiKit.Format;
+    return self.rstrip(self.lstrip(str, chars), chars);
+};
+
+MochiKit.Format.truncToFixed = function (aNumber, precision) {
+    aNumber = Math.floor(aNumber * Math.pow(10, precision));
+    var res = (aNumber * Math.pow(10, -precision)).toFixed(precision);
+    if (res.charAt(0) == ".") {
+        res = "0" + res;
+    }
+    return res;
+};
+
+MochiKit.Format.roundToFixed = function (aNumber, precision) {
+    return MochiKit.Format.truncToFixed(
+        aNumber + 0.5 * Math.pow(10, -precision),
+        precision
+    );
+};
+
+MochiKit.Format.percentFormat = function (someFloat) {
+    return MochiKit.Format.twoDigitFloat(100 * someFloat) + '%';
+};
+
+MochiKit.Format.EXPORT = [
+    "truncToFixed",
+    "roundToFixed",
+    "numberFormatter",
+    "formatLocale",
+    "twoDigitAverage",
+    "twoDigitFloat",
+    "percentFormat",
+    "lstrip",
+    "rstrip",
+    "strip"
+];
+
+MochiKit.Format.LOCALE = {
+    en_US: {separator: ",", decimal: ".", percent: "%"},
+    de_DE: {separator: ".", decimal: ",", percent: "%"},
+    fr_FR: {separator: " ", decimal: ",", percent: "%"},
+    "default": "en_US"
+};
+
+MochiKit.Format.EXPORT_OK = [];
+MochiKit.Format.EXPORT_TAGS = {
+    ':all': MochiKit.Format.EXPORT,
+    ':common': MochiKit.Format.EXPORT
+};
+
+MochiKit.Format.__new__ = function () {
+    // MochiKit.Base.nameFunctions(this);
+    var base = this.NAME + ".";
+    var k, v, o;
+    for (k in this.LOCALE) {
+        o = this.LOCALE[k];
+        if (typeof(o) == "object") {
+            o.repr = function () { return this.NAME; };
+            o.NAME = base + "LOCALE." + k;
+        }
+    }
+    for (k in this) {
+        o = this[k];
+        if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') {
+            try {
+                o.NAME = base + k;
+            } catch (e) {
+                // pass
+            }
+        }
+    }
+};
+
+MochiKit.Format.__new__();
+
+if (typeof(MochiKit.Base) != "undefined") {
+    MochiKit.Base._exportSymbols(this, MochiKit.Format);
+} else {
+    (function (globals, module) {
+        if ((typeof(JSAN) == 'undefined' && typeof(dojo) == 'undefined')
+            || (typeof(MochiKit.__compat__) == 'boolean' && MochiKit.__compat__)) {
+            var all = module.EXPORT_TAGS[":all"];
+            for (var i = 0; i < all.length; i++) {
+                globals[all[i]] = module[all[i]]; 
+            }
+        }   
+    })(this, MochiKit.Format);  
+}

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Iter.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Iter.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Iter.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,789 @@
+/***
+
+MochiKit.Iter 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Iter');
+    dojo.require('MochiKit.Base');
+}
+
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Base", []);
+}   
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.Iter depends on MochiKit.Base!";
+}  
+            
+if (typeof(MochiKit.Iter) == 'undefined') {
+    MochiKit.Iter = {};
+}           
+        
+MochiKit.Iter.NAME = "MochiKit.Iter";
+MochiKit.Iter.VERSION = "1.3.1";
+MochiKit.Base.update(MochiKit.Iter, {
+    __repr__: function () {
+        return "[" + this.NAME + " " + this.VERSION + "]";
+    },
+    toString: function () {
+        return this.__repr__();
+    },
+
+    registerIteratorFactory: function (name, check, iterfactory, /* optional */ override) {
+        MochiKit.Iter.iteratorRegistry.register(name, check, iterfactory, override);
+    },
+
+    iter: function (iterable, /* optional */ sentinel) {
+        var self = MochiKit.Iter;
+        if (arguments.length == 2) {
+            return self.takewhile(
+                function (a) { return a != sentinel; },
+                iterable
+            );
+        }
+        if (typeof(iterable.next) == 'function') {
+            return iterable;
+        } else if (typeof(iterable.iter) == 'function') {
+            return iterable.iter();
+        }
+        try {
+            return self.iteratorRegistry.match(iterable);
+        } catch (e) {
+            var m = MochiKit.Base;
+            if (e == m.NotFound) {
+                e = new TypeError(typeof(iterable) + ": " + m.repr(iterable) + " is not iterable");
+            }
+            throw e;
+        }
+    },
+
+    count: function (n) {
+        if (!n) {
+            n = 0;
+        }
+        var m = MochiKit.Base;
+        return {
+            repr: function () { return "count(" + n + ")"; },
+            toString: m.forwardCall("repr"),
+            next: m.counter(n)
+        };
+    },
+
+    cycle: function (p) {
+        var self = MochiKit.Iter;
+        var m = MochiKit.Base;
+        var lst = [];
+        var iterator = self.iter(p);
+        return {
+            repr: function () { return "cycle(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                try {
+                    var rval = iterator.next();
+                    lst.push(rval);
+                    return rval;
+                } catch (e) {
+                    if (e != self.StopIteration) {
+                        throw e;
+                    }
+                    if (lst.length === 0) {
+                        this.next = function () {
+                            throw self.StopIteration;
+                        };
+                    } else {
+                        var i = -1;
+                        this.next = function () {
+                            i = (i + 1) % lst.length;
+                            return lst[i];
+                        };
+                    }
+                    return this.next();
+                }
+            }
+        };
+    },
+
+    repeat: function (elem, /* optional */n) {
+        var m = MochiKit.Base;
+        if (typeof(n) == 'undefined') {
+            return {
+                repr: function () {
+                    return "repeat(" + m.repr(elem) + ")";
+                },
+                toString: m.forwardCall("repr"),
+                next: function () {
+                    return elem;
+                }
+            };
+        }
+        return {
+            repr: function () {
+                return "repeat(" + m.repr(elem) + ", " + n + ")";
+            },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                if (n <= 0) {
+                    throw MochiKit.Iter.StopIteration;
+                }
+                n -= 1;
+                return elem;
+            }
+        };
+    },
+            
+    next: function (iterator) {
+        return iterator.next();
+    },
+
+    izip: function (p, q/*, ...*/) {
+        var m = MochiKit.Base;
+        var next = MochiKit.Iter.next;
+        var iterables = m.map(iter, arguments);
+        return {
+            repr: function () { return "izip(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () { return m.map(next, iterables); }
+        };
+    },
+
+    ifilter: function (pred, seq) {
+        var m = MochiKit.Base;
+        seq = MochiKit.Iter.iter(seq);
+        if (pred === null) {
+            pred = m.operator.truth;
+        }
+        return {
+            repr: function () { return "ifilter(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                while (true) {
+                    var rval = seq.next();
+                    if (pred(rval)) {
+                        return rval;
+                    }
+                }
+                // mozilla warnings aren't too bright
+                return undefined;
+            }
+        };
+    },
+
+    ifilterfalse: function (pred, seq) {
+        var m = MochiKit.Base;
+        seq = MochiKit.Iter.iter(seq);
+        if (pred === null) {
+            pred = m.operator.truth;
+        }
+        return {
+            repr: function () { return "ifilterfalse(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                while (true) {
+                    var rval = seq.next();
+                    if (!pred(rval)) {
+                        return rval;
+                    }
+                }
+                // mozilla warnings aren't too bright
+                return undefined;
+            }
+        };
+    },
+     
+    islice: function (seq/*, [start,] stop[, step] */) {
+        var self = MochiKit.Iter;
+        var m = MochiKit.Base;
+        seq = self.iter(seq);
+        var start = 0;
+        var stop = 0;
+        var step = 1;
+        var i = -1;
+        if (arguments.length == 2) {
+            stop = arguments[1];
+        } else if (arguments.length == 3) {
+            start = arguments[1];
+            stop = arguments[2];
+        } else {
+            start = arguments[1];
+            stop = arguments[2];
+            step = arguments[3];
+        }
+        return {
+            repr: function () {
+                return "islice(" + ["...", start, stop, step].join(", ") + ")";
+            },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                var rval;
+                while (i < start) {
+                    rval = seq.next();
+                    i++;
+                }
+                if (start >= stop) {
+                    throw self.StopIteration;
+                }
+                start += step;
+                return rval;
+            }
+        };
+    },
+
+    imap: function (fun, p, q/*, ...*/) {
+        var m = MochiKit.Base;
+        var self = MochiKit.Iter;
+        var iterables = m.map(self.iter, m.extend(null, arguments, 1));
+        var map = m.map;
+        var next = self.next;
+        return {
+            repr: function () { return "imap(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                return fun.apply(this, map(next, iterables));
+            }
+        };
+    },
+        
+    applymap: function (fun, seq, self) {
+        seq = MochiKit.Iter.iter(seq);
+        var m = MochiKit.Base;
+        return {
+            repr: function () { return "applymap(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                return fun.apply(self, seq.next());
+            }
+        };
+    },
+
+    chain: function (p, q/*, ...*/) {
+        // dumb fast path
+        var self = MochiKit.Iter;
+        var m = MochiKit.Base;
+        if (arguments.length == 1) {
+            return self.iter(arguments[0]);
+        }
+        var argiter = m.map(self.iter, arguments);
+        return {
+            repr: function () { return "chain(...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                while (argiter.length > 1) {
+                    try {
+                        return argiter[0].next();
+                    } catch (e) {
+                        if (e != self.StopIteration) {
+                            throw e;
+                        }
+                        argiter.shift();
+                    }
+                }
+                if (argiter.length == 1) {
+                    // optimize last element
+                    var arg = argiter.shift();
+                    this.next = m.bind("next", arg);
+                    return this.next();
+                }
+                throw self.StopIteration;
+            }
+        };
+    },
+
+    takewhile: function (pred, seq) {
+        var self = MochiKit.Iter;
+        seq = self.iter(seq);
+        return {
+            repr: function () { return "takewhile(...)"; },
+            toString: MochiKit.Base.forwardCall("repr"),
+            next: function () {
+                var rval = seq.next();
+                if (!pred(rval)) {
+                    this.next = function () {
+                        throw self.StopIteration;
+                    };
+                    this.next();
+                }
+                return rval;
+            }
+        };
+    },
+
+    dropwhile: function (pred, seq) {
+        seq = MochiKit.Iter.iter(seq);
+        var m = MochiKit.Base;
+        var bind = m.bind;
+        return {
+            "repr": function () { return "dropwhile(...)"; },
+            "toString": m.forwardCall("repr"),
+            "next": function () {
+                while (true) {
+                    var rval = seq.next();
+                    if (!pred(rval)) {
+                        break;
+                    }
+                }
+                this.next = bind("next", seq);
+                return rval;
+            }
+        };
+    },
+
+    _tee: function (ident, sync, iterable) {
+        sync.pos[ident] = -1;
+        var m = MochiKit.Base;
+        var listMin = m.listMin;
+        return {
+            repr: function () { return "tee(" + ident + ", ...)"; },
+            toString: m.forwardCall("repr"),
+            next: function () {
+                var rval;
+                var i = sync.pos[ident];
+
+                if (i == sync.max) {
+                    rval = iterable.next();
+                    sync.deque.push(rval);
+                    sync.max += 1;
+                    sync.pos[ident] += 1;
+                } else {
+                    rval = sync.deque[i - sync.min];
+                    sync.pos[ident] += 1;
+                    if (i == sync.min && listMin(sync.pos) != sync.min) {
+                        sync.min += 1;
+                        sync.deque.shift();
+                    }
+                }
+                return rval;
+            }
+        };
+    },
+
+    tee: function (iterable, n/* = 2 */) {
+        var rval = [];
+        var sync = {
+            "pos": [],
+            "deque": [],
+            "max": -1,
+            "min": -1
+        };
+        if (arguments.length == 1) {
+            n = 2;
+        }
+        var self = MochiKit.Iter;
+        iterable = self.iter(iterable);
+        var _tee = self._tee;
+        for (var i = 0; i < n; i++) {
+            rval.push(_tee(i, sync, iterable));
+        }
+        return rval;
+    },
+
+    list: function (iterable) {
+        // Fast-path for Array and Array-like
+        var m = MochiKit.Base;
+        if (typeof(iterable.slice) == 'function') {
+            return iterable.slice();
+        } else if (m.isArrayLike(iterable)) {
+            return m.concat(iterable);
+        }
+
+        var self = MochiKit.Iter;
+        iterable = self.iter(iterable);
+        var rval = [];
+        try {
+            while (true) {
+                rval.push(iterable.next());
+            }
+        } catch (e) {
+            if (e != self.StopIteration) {
+                throw e;
+            }
+            return rval;
+        }
+        // mozilla warnings aren't too bright
+        return undefined;
+    },
+
+        
+    reduce: function (fn, iterable, /* optional */initial) {
+        var i = 0;
+        var x = initial;
+        var self = MochiKit.Iter;
+        iterable = self.iter(iterable);
+        if (arguments.length < 3) {
+            try {
+                x = iterable.next();
+            } catch (e) {
+                if (e == self.StopIteration) {
+                    e = new TypeError("reduce() of empty sequence with no initial value");
+                }
+                throw e;
+            }
+            i++;
+        }
+        try {
+            while (true) {
+                x = fn(x, iterable.next());
+            }
+        } catch (e) {
+            if (e != self.StopIteration) {
+                throw e;
+            }
+        }
+        return x;
+    },
+
+    range: function (/* [start,] stop[, step] */) {
+        var start = 0;
+        var stop = 0;
+        var step = 1;
+        if (arguments.length == 1) {
+            stop = arguments[0];
+        } else if (arguments.length == 2) {
+            start = arguments[0];
+            stop = arguments[1];
+        } else if (arguments.length == 3) {
+            start = arguments[0];
+            stop = arguments[1];
+            step = arguments[2];
+        } else {
+            throw new TypeError("range() takes 1, 2, or 3 arguments!");
+        }
+        if (step === 0) {
+            throw new TypeError("range() step must not be 0");
+        }
+        return {
+            next: function () {
+                if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
+                    throw MochiKit.Iter.StopIteration;
+                }
+                var rval = start;
+                start += step;
+                return rval;
+            },
+            repr: function () {
+                return "range(" + [start, stop, step].join(", ") + ")";
+            },
+            toString: MochiKit.Base.forwardCall("repr")
+        };
+    },
+            
+    sum: function (iterable, start/* = 0 */) {
+        var x = start || 0;
+        var self = MochiKit.Iter;
+        iterable = self.iter(iterable);
+        try {
+            while (true) {
+                x += iterable.next();
+            }
+        } catch (e) {
+            if (e != self.StopIteration) {
+                throw e;
+            }
+        }
+        return x;
+    },
+            
+    exhaust: function (iterable) {
+        var self = MochiKit.Iter;
+        iterable = self.iter(iterable);
+        try {
+            while (true) {
+                iterable.next();
+            }
+        } catch (e) {
+            if (e != self.StopIteration) {
+                throw e;
+            }
+        }
+    },
+
+    forEach: function (iterable, func, /* optional */self) {
+        var m = MochiKit.Base;
+        if (arguments.length > 2) {
+            func = m.bind(func, self);
+        }
+        // fast path for array
+        if (m.isArrayLike(iterable)) {
+            try {
+                for (var i = 0; i < iterable.length; i++) {
+                    func(iterable[i]);
+                }
+            } catch (e) {
+                if (e != MochiKit.Iter.StopIteration) {
+                    throw e;
+                }
+            }
+        } else {
+            self = MochiKit.Iter;
+            self.exhaust(self.imap(func, iterable));
+        }
+    },
+
+    every: function (iterable, func) {
+        var self = MochiKit.Iter;
+        try {
+            self.ifilterfalse(func, iterable).next();
+            return false;
+        } catch (e) {
+            if (e != self.StopIteration) {
+                throw e;
+            }
+            return true;
+        }
+    },
+
+    sorted: function (iterable, /* optional */cmp) {
+        var rval = MochiKit.Iter.list(iterable);
+        if (arguments.length == 1) {
+            cmp = MochiKit.Base.compare;
+        }
+        rval.sort(cmp);
+        return rval;
+    },
+
+    reversed: function (iterable) {
+        var rval = MochiKit.Iter.list(iterable);
+        rval.reverse();
+        return rval;
+    },
+
+    some: function (iterable, func) {
+        var self = MochiKit.Iter;
+        try {
+            self.ifilter(func, iterable).next();
+            return true;
+        } catch (e) {
+            if (e != self.StopIteration) {
+                throw e;
+            }
+            return false;
+        }
+    },
+
+    iextend: function (lst, iterable) {
+        if (MochiKit.Base.isArrayLike(iterable)) {
+            // fast-path for array-like
+            for (var i = 0; i < iterable.length; i++) {
+                lst.push(iterable[i]);
+            }
+        } else {
+            var self = MochiKit.Iter;
+            iterable = self.iter(iterable);
+            try {
+                while (true) {
+                    lst.push(iterable.next());
+                }
+            } catch (e) {
+                if (e != self.StopIteration) {
+                    throw e;
+                }
+            }
+        }
+        return lst;
+    },
+
+    groupby: function(iterable, /* optional */ keyfunc) {
+        var m = MochiKit.Base;
+        var self = MochiKit.Iter;
+        if (arguments.length < 2) {
+            keyfunc = m.operator.identity;
+        }
+        iterable = self.iter(iterable);
+
+        // shared
+        var pk = undefined;
+        var k = undefined;
+        var v;
+
+        function fetch() {
+            v = iterable.next();
+            k = keyfunc(v);
+        };
+
+        function eat() {
+            var ret = v;
+            v = undefined;
+            return ret;
+        };
+
+        var first = true;
+        return {
+            repr: function () { return "groupby(...)"; },
+            next: function() {
+                // iterator-next
+
+                // iterate until meet next group
+                while (k == pk) {
+                    fetch();
+                    if (first) {
+                        first = false;
+                        break;
+                    }
+                }
+                pk = k;
+                return [k, {
+                    next: function() {
+                        // subiterator-next
+                        if (v == undefined) { // Is there something to eat?
+                            fetch();
+                        }
+                        if (k != pk) {
+                            throw self.StopIteration;
+                        }
+                        return eat();
+                    }
+                }];
+            }
+        };
+    },
+
+    groupby_as_array: function (iterable, /* optional */ keyfunc) {
+        var m = MochiKit.Base;
+        var self = MochiKit.Iter;
+        if (arguments.length < 2) {
+            keyfunc = m.operator.identity;
+        }
+
+        iterable = self.iter(iterable);
+        var result = [];
+        var first = true;
+        var prev_key;
+        while (true) {
+            try {
+                var value = iterable.next();
+                var key = keyfunc(value);
+            } catch (e) {
+                if (e == self.StopIteration) {
+                    break;
+                }
+                throw e;
+            }
+            if (first || key != prev_key) {
+                var values = [];
+                result.push([key, values]);
+            }
+            values.push(value);
+            first = false;
+            prev_key = key;
+        }
+        return result;
+    },
+
+    arrayLikeIter: function (iterable) {
+        var i = 0;
+        return {
+            repr: function () { return "arrayLikeIter(...)"; },
+            toString: MochiKit.Base.forwardCall("repr"),
+            next: function () {
+                if (i >= iterable.length) {
+                    throw MochiKit.Iter.StopIteration;
+                }
+                return iterable[i++];
+            }
+        };
+    },
+
+    hasIterateNext: function (iterable) {
+        return (iterable && typeof(iterable.iterateNext) == "function");
+    },
+
+    iterateNextIter: function (iterable) {
+        return {
+            repr: function () { return "iterateNextIter(...)"; },
+            toString: MochiKit.Base.forwardCall("repr"),
+            next: function () {
+                var rval = iterable.iterateNext();
+                if (rval === null || rval === undefined) {
+                    throw MochiKit.Iter.StopIteration;
+                }
+                return rval;
+            }
+        };
+    }
+});
+
+
+MochiKit.Iter.EXPORT_OK = [
+    "iteratorRegistry",
+    "arrayLikeIter",
+    "hasIterateNext",
+    "iterateNextIter",
+];
+
+MochiKit.Iter.EXPORT = [
+    "StopIteration",
+    "registerIteratorFactory",
+    "iter",
+    "count",
+    "cycle",
+    "repeat",
+    "next",
+    "izip",
+    "ifilter",
+    "ifilterfalse",
+    "islice",
+    "imap",
+    "applymap",
+    "chain",
+    "takewhile",
+    "dropwhile",
+    "tee",
+    "list",
+    "reduce",
+    "range",
+    "sum",
+    "exhaust",
+    "forEach",
+    "every",
+    "sorted",
+    "reversed",
+    "some",
+    "iextend",
+    "groupby",
+    "groupby_as_array"
+];
+
+MochiKit.Iter.__new__ = function () {
+    var m = MochiKit.Base;
+    this.StopIteration = new m.NamedError("StopIteration");
+    this.iteratorRegistry = new m.AdapterRegistry();
+    // Register the iterator factory for arrays
+    this.registerIteratorFactory(
+        "arrayLike",
+        m.isArrayLike,
+        this.arrayLikeIter
+    );
+
+    this.registerIteratorFactory(
+        "iterateNext",
+        this.hasIterateNext,
+        this.iterateNextIter
+    );
+
+    this.EXPORT_TAGS = {
+        ":common": this.EXPORT,
+        ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+    };
+
+    m.nameFunctions(this);
+        
+};
+
+MochiKit.Iter.__new__();
+
+//
+// XXX: Internet Explorer blows
+//
+if (!MochiKit.__compat__) {
+    reduce = MochiKit.Iter.reduce;
+}
+
+MochiKit.Base._exportSymbols(this, MochiKit.Iter);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Logging.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Logging.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Logging.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,290 @@
+/***
+
+MochiKit.Logging 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Logging');
+    dojo.require('MochiKit.Base');
+}
+
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Base", []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.Logging depends on MochiKit.Base!";
+}
+
+if (typeof(MochiKit.Logging) == 'undefined') {
+    MochiKit.Logging = {};
+}
+
+MochiKit.Logging.NAME = "MochiKit.Logging";
+MochiKit.Logging.VERSION = "1.3.1";
+MochiKit.Logging.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.Logging.toString = function () {
+    return this.__repr__();
+};
+
+
+MochiKit.Logging.EXPORT = [
+    "LogLevel",
+    "LogMessage",
+    "Logger",
+    "alertListener",
+    "logger",
+    "log",
+    "logError",
+    "logDebug",
+    "logFatal",
+    "logWarning"
+];
+
+
+MochiKit.Logging.EXPORT_OK = [
+    "logLevelAtLeast",
+    "isLogMessage",
+    "compareLogMessage"
+];
+
+
+MochiKit.Logging.LogMessage = function (num, level, info) {
+    this.num = num;
+    this.level = level;
+    this.info = info;
+    this.timestamp = new Date();
+};
+
+MochiKit.Logging.LogMessage.prototype = {
+    repr: function () {
+        var m = MochiKit.Base;
+        return 'LogMessage(' + 
+            m.map(
+                m.repr,
+                [this.num, this.level, this.info]
+            ).join(', ') + ')';
+    },
+    toString: MochiKit.Base.forwardCall("repr")
+};
+
+MochiKit.Base.update(MochiKit.Logging, {
+    logLevelAtLeast: function (minLevel) {
+        var self = MochiKit.Logging;
+        if (typeof(minLevel) == 'string') {
+            minLevel = self.LogLevel[minLevel];
+        }
+        return function (msg) {
+            var msgLevel = msg.level;
+            if (typeof(msgLevel) == 'string') {
+                msgLevel = self.LogLevel[msgLevel];
+            }
+            return msgLevel >= minLevel;
+        };
+    },
+
+    isLogMessage: function (/* ... */) {
+        var LogMessage = MochiKit.Logging.LogMessage;
+        for (var i = 0; i < arguments.length; i++) {
+            if (!(arguments[i] instanceof LogMessage)) {
+                return false;
+            }
+        }
+        return true;
+    },
+
+    compareLogMessage: function (a, b) {
+        return MochiKit.Base.compare([a.level, a.info], [b.level, b.info]);
+    },
+
+    alertListener: function (msg) {
+        alert(
+            "num: " + msg.num +
+            "\nlevel: " +  msg.level +
+            "\ninfo: " + msg.info.join(" ")
+        );
+    }
+
+});
+
+MochiKit.Logging.Logger = function (/* optional */maxSize) {
+    this.counter = 0;
+    if (typeof(maxSize) == 'undefined' || maxSize === null) {
+        maxSize = -1;
+    }
+    this.maxSize = maxSize;
+    this._messages = [];
+    this.listeners = {};
+    this.useNativeConsole = false;
+};
+
+MochiKit.Logging.Logger.prototype = {
+    clear: function () {
+        this._messages.splice(0, this._messages.length);
+    },
+
+    logToConsole: function (msg) {
+        if (typeof(window) != "undefined" && window.console
+                && window.console.log) {
+            // Safari
+            window.console.log(msg);
+        } else if (typeof(opera) != "undefined" && opera.postError) {
+            // Opera
+            opera.postError(msg);
+        } else if (typeof(printfire) == "function") {
+            // FireBug
+            printfire(msg);
+        }
+    },
+    
+    dispatchListeners: function (msg) {
+        for (var k in this.listeners) {
+            var pair = this.listeners[k];
+            if (pair.ident != k || (pair[0] && !pair[0](msg))) {
+                continue;
+            }
+            pair[1](msg);
+        }
+    },
+
+    addListener: function (ident, filter, listener) {
+        if (typeof(filter) == 'string') {
+            filter = MochiKit.Logging.logLevelAtLeast(filter);
+        }
+        var entry = [filter, listener];
+        entry.ident = ident;
+        this.listeners[ident] = entry;
+    },
+
+    removeListener: function (ident) {
+        delete this.listeners[ident];
+    },
+
+    baseLog: function (level, message/*, ...*/) {
+        var msg = new MochiKit.Logging.LogMessage(
+            this.counter,
+            level,
+            MochiKit.Base.extend(null, arguments, 1)
+        );
+        this._messages.push(msg);
+        this.dispatchListeners(msg);
+        if (this.useNativeConsole) {
+            this.logToConsole(msg.level + ": " + msg.info.join(" "));
+        }
+        this.counter += 1;
+        while (this.maxSize >= 0 && this._messages.length > this.maxSize) {
+            this._messages.shift();
+        }
+    },
+
+    getMessages: function (howMany) {
+        var firstMsg = 0;
+        if (!(typeof(howMany) == 'undefined' || howMany === null)) {
+            firstMsg = Math.max(0, this._messages.length - howMany);
+        }
+        return this._messages.slice(firstMsg);
+    },
+
+    getMessageText: function (howMany) {
+        if (typeof(howMany) == 'undefined' || howMany === null) {
+            howMany = 30;
+        }
+        var messages = this.getMessages(howMany);
+        if (messages.length) {
+            var lst = map(function (m) {
+                return '\n  [' + m.num + '] ' + m.level + ': ' + m.info.join(' '); 
+            }, messages);
+            lst.unshift('LAST ' + messages.length + ' MESSAGES:');
+            return lst.join('');
+        }
+        return '';
+    },
+
+    debuggingBookmarklet: function (inline) {
+        if (typeof(MochiKit.LoggingPane) == "undefined") {
+            alert(this.getMessageText());
+        } else {
+            MochiKit.LoggingPane.createLoggingPane(inline || false);
+        }
+    }
+};
+
+
+MochiKit.Logging.__new__ = function () {
+    this.LogLevel = {
+        ERROR: 40,
+        FATAL: 50,
+        WARNING: 30,
+        INFO: 20,
+        DEBUG: 10
+    };
+
+    var m = MochiKit.Base;
+    m.registerComparator("LogMessage",
+        this.isLogMessage,
+        this.compareLogMessage
+    );
+
+    var partial = m.partial;
+
+    var Logger = this.Logger;
+    var baseLog = Logger.prototype.baseLog;
+    m.update(this.Logger.prototype, {
+        debug: partial(baseLog, 'DEBUG'),
+        log: partial(baseLog, 'INFO'),
+        error: partial(baseLog, 'ERROR'),
+        fatal: partial(baseLog, 'FATAL'),
+        warning: partial(baseLog, 'WARNING')
+    });
+
+    // indirectly find logger so it can be replaced
+    var self = this;
+    var connectLog = function (name) {
+        return function () {
+            self.logger[name].apply(self.logger, arguments);
+        };
+    };
+
+    this.log = connectLog('log');
+    this.logError = connectLog('error');
+    this.logDebug = connectLog('debug');
+    this.logFatal = connectLog('fatal');
+    this.logWarning = connectLog('warning');
+    this.logger = new Logger();
+    this.logger.useNativeConsole = true;
+
+    this.EXPORT_TAGS = {
+        ":common": this.EXPORT,
+        ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+    };
+
+    m.nameFunctions(this);
+
+};
+
+if (typeof(printfire) == "undefined" &&
+        typeof(document) != "undefined" && document.createEvent &&
+        typeof(dispatchEvent) != "undefined") {
+    // FireBug really should be less lame about this global function
+    printfire  = function () {
+        printfire.args = arguments;
+        var ev = document.createEvent("Events");
+        ev.initEvent("printfire", false, true);
+        dispatchEvent(ev);
+    };
+}
+
+MochiKit.Logging.__new__();
+
+MochiKit.Base._exportSymbols(this, MochiKit.Logging);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/LoggingPane.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/LoggingPane.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/LoggingPane.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,356 @@
+/***
+
+MochiKit.LoggingPane 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.LoggingPane');
+    dojo.require('MochiKit.Logging');
+    dojo.require('MochiKit.Base');
+}
+
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Logging", []);
+    JSAN.use("MochiKit.Base", []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined' || typeof(MochiKit.Logging) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.LoggingPane depends on MochiKit.Base and MochiKit.Logging!";
+}
+
+if (typeof(MochiKit.LoggingPane) == 'undefined') {
+    MochiKit.LoggingPane = {};
+}
+
+MochiKit.LoggingPane.NAME = "MochiKit.LoggingPane";
+MochiKit.LoggingPane.VERSION = "1.3.1";
+MochiKit.LoggingPane.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.LoggingPane.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.LoggingPane.createLoggingPane = function (inline/* = false */) {
+    var m = MochiKit.LoggingPane;
+    inline = !(!inline);
+    if (m._loggingPane && m._loggingPane.inline != inline) {
+        m._loggingPane.closePane();
+        m._loggingPane = null;
+    }
+    if (!m._loggingPane || m._loggingPane.closed) {
+        m._loggingPane = new m.LoggingPane(inline, MochiKit.Logging.logger);
+    }
+    return m._loggingPane;
+};
+
+MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = MochiKit.Logging.logger */) {
+    /* Use a div if inline, pop up a window if not */
+    /* Create the elements */
+    if (typeof(logger) == "undefined" || logger === null) {
+        logger = MochiKit.Logging.logger;
+    }
+    this.logger = logger;
+    var update = MochiKit.Base.update;
+    var updatetree = MochiKit.Base.updatetree;
+    var bind = MochiKit.Base.bind;
+    var clone = MochiKit.Base.clone;
+    var win = window;
+    var uid = "_MochiKit_LoggingPane";
+    if (typeof(MochiKit.DOM) != "undefined") {
+        win = MochiKit.DOM.currentWindow();
+    }
+    if (!inline) {
+        // name the popup with the base URL for uniqueness
+        var url = win.location.href.split("?")[0].replace(/[:\/.><&]/g, "_");
+        var name = uid + "_" + url;
+        var nwin = win.open("", name, "dependent,resizable,height=200");
+        if (!nwin) {
+            alert("Not able to open debugging window due to pop-up blocking.");
+            return undefined;
+        }
+        nwin.document.write(
+            '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
+            + '"http://www.w3.org/TR/html4/loose.dtd">'
+            + '<html><head><title>[MochiKit.LoggingPane]</title></head>'
+            + '<body></body></html>'
+        );
+        nwin.document.close();
+        nwin.document.title += ' ' + win.document.title;
+        win = nwin;
+    }
+    var doc = win.document;
+    this.doc = doc;
+    
+    // Connect to the debug pane if it already exists (i.e. in a window orphaned by the page being refreshed)
+    var debugPane = doc.getElementById(uid);
+    var existing_pane = !!debugPane;
+    if (debugPane && typeof(debugPane.loggingPane) != "undefined") {
+        debugPane.loggingPane.logger = this.logger;
+        debugPane.loggingPane.buildAndApplyFilter();
+        return debugPane.loggingPane;
+    }
+    
+    if (existing_pane) {
+        // clear any existing contents
+        var child;
+        while ((child = debugPane.firstChild)) {
+            debugPane.removeChild(child);
+        }
+    } else {
+        debugPane = doc.createElement("div");
+        debugPane.id = uid;
+    }
+    debugPane.loggingPane = this;
+    var levelFilterField = doc.createElement("input");
+    var infoFilterField = doc.createElement("input");
+    var filterButton = doc.createElement("button");
+    var loadButton = doc.createElement("button");
+    var clearButton = doc.createElement("button");
+    var closeButton = doc.createElement("button");
+    var logPaneArea = doc.createElement("div");
+    var logPane = doc.createElement("div");
+
+    /* Set up the functions */
+    var listenerId = uid + "_Listener";
+    this.colorTable = clone(this.colorTable);
+    var messages = [];
+    var messageFilter = null;
+
+    var messageLevel = function (msg) {
+        var level = msg.level;
+        if (typeof(level) == "number") {
+            level = MochiKit.Logging.LogLevel[level];
+        }
+        return level;
+    };
+
+    var messageText = function (msg) {
+        return msg.info.join(" ");
+    };
+
+    var addMessageText = bind(function (msg) {
+        var level = messageLevel(msg);
+        var text = messageText(msg);
+        var c = this.colorTable[level];
+        var p = doc.createElement("span");
+        p.className = "MochiKit-LogMessage MochiKit-LogLevel-" + level;
+        p.style.cssText = "margin: 0px; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; white-space: pre-line; word-wrap: break-word; wrap-option: emergency; color: " + c;
+        p.appendChild(doc.createTextNode(level + ": " + text));
+        logPane.appendChild(p);
+        logPane.appendChild(doc.createElement("br"));
+        if (logPaneArea.offsetHeight > logPaneArea.scrollHeight) {
+            logPaneArea.scrollTop = 0;
+        } else {
+            logPaneArea.scrollTop = logPaneArea.scrollHeight;
+        }
+    }, this);
+
+    var addMessage = function (msg) {
+        messages[messages.length] = msg;
+        addMessageText(msg);
+    };
+
+    var buildMessageFilter = function () {
+        var levelre, infore;
+        try {
+            /* Catch any exceptions that might arise due to invalid regexes */
+            levelre = new RegExp(levelFilterField.value);
+            infore = new RegExp(infoFilterField.value);
+        } catch(e) {
+            /* If there was an error with the regexes, do no filtering */
+            logDebug("Error in filter regex: " + e.message);
+            return null;
+        }
+
+        return function (msg) {
+            return (
+                levelre.test(messageLevel(msg)) &&
+                infore.test(messageText(msg))
+            );
+        };
+    };
+
+    var clearMessagePane = function () {
+        while (logPane.firstChild) {
+            logPane.removeChild(logPane.firstChild);
+        }
+    };
+
+    var clearMessages = function () {
+        messages = [];
+        clearMessagePane();
+    };
+
+    var closePane = bind(function () {
+        if (this.closed) {
+            return;
+        }
+        this.closed = true;
+        if (MochiKit.LoggingPane._loggingPane == this) {
+            MochiKit.LoggingPane._loggingPane = null;
+        }
+        this.logger.removeListener(listenerId);
+
+        debugPane.loggingPane = null;
+
+        if (inline) {
+            debugPane.parentNode.removeChild(debugPane);
+        } else {
+            this.win.close();
+        }
+    }, this);
+
+    var filterMessages = function () {
+        clearMessagePane();
+
+        for (var i = 0; i < messages.length; i++) {
+            var msg = messages[i];
+            if (messageFilter === null || messageFilter(msg)) {
+                addMessageText(msg);
+            }
+        }
+    };
+
+    this.buildAndApplyFilter = function () {
+        messageFilter = buildMessageFilter();
+
+        filterMessages();
+
+        this.logger.removeListener(listenerId);
+        this.logger.addListener(listenerId, messageFilter, addMessage);
+    };
+
+
+    var loadMessages = bind(function () {
+        messages = this.logger.getMessages();
+        filterMessages();
+    }, this);
+
+    var filterOnEnter = bind(function (event) {
+        event = event || window.event;
+        key = event.which || event.keyCode;
+        if (key == 13) {
+            this.buildAndApplyFilter();
+        }
+    }, this);
+
+    /* Create the debug pane */
+    var style = "display: block; z-index: 1000; left: 0px; bottom: 0px; position: fixed; width: 100%; background-color: white; font: " + this.logFont;
+    if (inline) {
+        style += "; height: 10em; border-top: 2px solid black";
+    } else {
+        style += "; height: 100%;";
+    }
+    debugPane.style.cssText = style;
+
+    if (!existing_pane) {
+        doc.body.appendChild(debugPane);
+    }
+
+    /* Create the filter fields */
+    style = {"cssText": "width: 33%; display: inline; font: " + this.logFont};
+
+    updatetree(levelFilterField, {
+        "value": "FATAL|ERROR|WARNING|INFO|DEBUG",
+        "onkeypress": filterOnEnter,
+        "style": style
+    });
+    debugPane.appendChild(levelFilterField);
+
+    updatetree(infoFilterField, {
+        "value": ".*",
+        "onkeypress": filterOnEnter,
+        "style": style
+    });
+    debugPane.appendChild(infoFilterField);
+
+    /* Create the buttons */
+    style = "width: 8%; display:inline; font: " + this.logFont;
+
+    filterButton.appendChild(doc.createTextNode("Filter"));
+    filterButton.onclick = bind("buildAndApplyFilter", this);
+    filterButton.style.cssText = style;
+    debugPane.appendChild(filterButton);
+
+    loadButton.appendChild(doc.createTextNode("Load"));
+    loadButton.onclick = loadMessages;
+    loadButton.style.cssText = style;
+    debugPane.appendChild(loadButton);
+
+    clearButton.appendChild(doc.createTextNode("Clear"));
+    clearButton.onclick = clearMessages;
+    clearButton.style.cssText = style;
+    debugPane.appendChild(clearButton);
+
+    closeButton.appendChild(doc.createTextNode("Close"));
+    closeButton.onclick = closePane;
+    closeButton.style.cssText = style;
+    debugPane.appendChild(closeButton);
+
+    /* Create the logging pane */
+    logPaneArea.style.cssText = "overflow: auto; width: 100%";
+    logPane.style.cssText = "width: 100%; height: " + (inline ? "8em" : "100%");
+
+    logPaneArea.appendChild(logPane);
+    debugPane.appendChild(logPaneArea);
+
+    this.buildAndApplyFilter();
+    loadMessages();
+
+    if (inline) {
+        this.win = undefined;
+    } else {
+        this.win = win;
+    }
+    this.inline = inline;
+    this.closePane = closePane;
+    this.closed = false;
+
+    return this;
+};
+
+MochiKit.LoggingPane.LoggingPane.prototype = {
+    "logFont": "8pt Verdana,sans-serif",
+    "colorTable": {
+        "ERROR": "red",
+        "FATAL": "darkred",
+        "WARNING": "blue",
+        "INFO": "black",
+        "DEBUG": "green"
+    }
+};
+
+
+MochiKit.LoggingPane.EXPORT_OK = [
+    "LoggingPane"
+];
+
+MochiKit.LoggingPane.EXPORT = [
+    "createLoggingPane"
+];
+
+MochiKit.LoggingPane.__new__ = function () {
+    this.EXPORT_TAGS = {
+        ":common": this.EXPORT,
+        ":all": MochiKit.Base.concat(this.EXPORT, this.EXPORT_OK)
+    };
+    
+    MochiKit.Base.nameFunctions(this);
+
+    MochiKit.LoggingPane._loggingPane = null;
+  
+};
+
+MochiKit.LoggingPane.__new__();
+
+MochiKit.Base._exportSymbols(this, MochiKit.LoggingPane);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MochiKit.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MochiKit.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MochiKit.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,152 @@
+/***
+
+MochiKit.MochiKit 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(MochiKit) == 'undefined') {
+    MochiKit = {};
+}
+
+if (typeof(MochiKit.MochiKit) == 'undefined') {
+    MochiKit.MochiKit = {};
+}
+
+MochiKit.MochiKit.NAME = "MochiKit.MochiKit";
+MochiKit.MochiKit.VERSION = "1.3.1";
+MochiKit.MochiKit.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.MochiKit.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.MochiKit.SUBMODULES = [
+    "Base",
+    "Iter",
+    "Logging",
+    "DateTime",
+    "Format",
+    "Async",
+    "DOM",
+    "LoggingPane",
+    "Color",
+    "Signal",
+    "Visual"
+];
+
+if (typeof(JSAN) != 'undefined' || typeof(dojo) != 'undefined') {
+    if (typeof(dojo) != 'undefined') {
+        dojo.provide('MochiKit.MochiKit');
+        dojo.require("MochiKit.*");
+    }
+    if (typeof(JSAN) != 'undefined') {
+        // hopefully this makes it easier for static analysis?
+        JSAN.use("MochiKit.Base", []);
+        JSAN.use("MochiKit.Iter", []);
+        JSAN.use("MochiKit.Logging", []);
+        JSAN.use("MochiKit.DateTime", []);
+        JSAN.use("MochiKit.Format", []);
+        JSAN.use("MochiKit.Async", []);
+        JSAN.use("MochiKit.DOM", []);
+        JSAN.use("MochiKit.LoggingPane", []);
+        JSAN.use("MochiKit.Color", []);
+        JSAN.use("MochiKit.Signal", []);
+        JSAN.use("MochiKit.Visual", []);
+    }
+    (function () {
+        var extend = MochiKit.Base.extend;
+        var self = MochiKit.MochiKit;
+        var modules = self.SUBMODULES;
+        var EXPORT = [];
+        var EXPORT_OK = [];
+        var EXPORT_TAGS = {};
+        var i, k, m, all;
+        for (i = 0; i < modules.length; i++) {
+            m = MochiKit[modules[i]];
+            extend(EXPORT, m.EXPORT);
+            extend(EXPORT_OK, m.EXPORT_OK);
+            for (k in m.EXPORT_TAGS) {
+                EXPORT_TAGS[k] = extend(EXPORT_TAGS[k], m.EXPORT_TAGS[k]);
+            }
+            all = m.EXPORT_TAGS[":all"];
+            if (!all) {
+                all = extend(null, m.EXPORT, m.EXPORT_OK);
+            }
+            var j;
+            for (j = 0; j < all.length; j++) {
+                k = all[j];
+                self[k] = m[k];
+            }
+        }
+        self.EXPORT = EXPORT;
+        self.EXPORT_OK = EXPORT_OK;
+        self.EXPORT_TAGS = EXPORT_TAGS;
+    }());
+    
+} else {
+    if (typeof(MochiKit.__compat__) == 'undefined') {
+        MochiKit.__compat__ = true;
+    }
+    (function () {
+        var scripts = document.getElementsByTagName("script");
+        var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+        var base = null;
+        var baseElem = null;
+        var allScripts = {};
+        var i;
+        for (i = 0; i < scripts.length; i++) {
+            var src = scripts[i].getAttribute("src");
+            if (!src) {
+                continue;
+            }
+            allScripts[src] = true;
+            if (src.match(/MochiKit.js$/)) {
+                base = src.substring(0, src.lastIndexOf('MochiKit.js'));
+                baseElem = scripts[i];
+            }
+        }
+        if (base === null) {
+            return;
+        }
+        var modules = MochiKit.MochiKit.SUBMODULES;
+        for (var i = 0; i < modules.length; i++) {
+            if (MochiKit[modules[i]]) {
+                continue;
+            }
+            var uri = base + modules[i] + '.js';
+            if (uri in allScripts) {
+                continue;
+            }
+            if (document.documentElement &&
+                document.documentElement.namespaceURI == kXULNSURI) {
+                // XUL
+                var s = document.createElementNS(kXULNSURI, 'script');
+                s.setAttribute("id", "MochiKit_" + base + modules[i]);
+                s.setAttribute("src", uri);
+                s.setAttribute("type", "application/x-javascript");
+                baseElem.parentNode.appendChild(s);
+            } else {
+                // HTML
+                /*
+                    DOM can not be used here because Safari does
+                    deferred loading of scripts unless they are
+                    in the document or inserted with document.write
+
+                    This is not XHTML compliant.  If you want XHTML
+                    compliance then you must use the packed version of MochiKit
+                    or include each script individually (basically unroll
+                    these document.write calls into your XHTML source)
+
+                */
+                document.write('<script src="' + uri +
+                    '" type="text/javascript"></script>');
+            }
+        };
+    })();
+}

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MockDOM.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MockDOM.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/MockDOM.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,73 @@
+/***
+    
+MochiKit.MockDOM 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+    
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+if (typeof(MochiKit) == "undefined") {
+    var MochiKit = {};
+}
+
+if (typeof(MochiKit.MockDOM) == "undefined") {
+    MochiKit.MockDOM = {};
+}
+
+MochiKit.MockDOM.NAME = "MochiKit.MockDOM";
+MochiKit.MockDOM.VERSION = "1.3.1";
+
+MochiKit.MockDOM.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.MockDOM.toString = function () {
+    return this.__repr__();
+};
+
+MochiKit.MockDOM.createDocument = function () {
+    var doc = new MochiKit.MockDOM.MockElement("DOCUMENT");
+    doc.body = doc.createElement("BODY");
+    doc.appendChild(doc.body);
+    return doc;
+};
+
+MochiKit.MockDOM.MockElement = function (name, data) {
+    this.nodeName = name.toUpperCase();
+    if (typeof(data) == "string") {
+        this.nodeValue = data;
+        this.nodeType = 3;
+    } else {
+        this.nodeType = 1;
+        this.childNodes = [];
+    }
+    if (name.substring(0, 1) == "<") {
+        var nameattr = name.substring(
+            name.indexOf('"') + 1, name.lastIndexOf('"'));
+        name = name.substring(1, name.indexOf(" "));
+        this.nodeName = name.toUpperCase();
+        this.setAttribute("name", nameattr);
+    }
+};
+
+MochiKit.MockDOM.MockElement.prototype = {
+    createElement: function (nodeName) {
+        return new MochiKit.MockDOM.MockElement(nodeName);
+    },
+    createTextNode: function (text) {
+        return new MochiKit.MockDOM.MockElement("text", text);
+    },
+    setAttribute: function (name, value) {
+        this[name] = value;
+    },
+    getAttribute: function (name) {
+        return this[name];
+    },
+    appendChild: function (child) {
+        this.childNodes.push(child);
+    },
+    toString: function () {
+        return "MockElement(" + this.nodeName + ")";
+    }
+};

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Signal.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Signal.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Signal.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,680 @@
+/***
+
+MochiKit.Signal 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2006 Jonathan Gardner, Beau Hartshorne, Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Signal');
+    dojo.require('MochiKit.Base');
+    dojo.require('MochiKit.DOM');
+}
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use('MochiKit.Base', []);
+    JSAN.use('MochiKit.DOM', []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined') {
+        throw '';
+    }
+} catch (e) {
+    throw 'MochiKit.Signal depends on MochiKit.Base!';
+}
+
+try {
+    if (typeof(MochiKit.DOM) == 'undefined') {
+        throw '';
+    }
+} catch (e) {
+    throw 'MochiKit.Signal depends on MochiKit.DOM!';
+}
+
+if (typeof(MochiKit.Signal) == 'undefined') {
+    MochiKit.Signal = {};
+}
+
+MochiKit.Signal.NAME = 'MochiKit.Signal';
+MochiKit.Signal.VERSION = '1.3.1';
+
+MochiKit.Signal._observers = [];
+
+MochiKit.Signal.Event = function (src, e) {
+    this._event = e || window.event;
+    this._src = src;
+};
+
+MochiKit.Base.update(MochiKit.Signal.Event.prototype, {
+
+    __repr__: function() {
+        var repr = MochiKit.Base.repr;
+        var str = '{event(): ' + repr(this.event()) +
+            ', src(): ' + repr(this.src()) + 
+            ', type(): ' + repr(this.type()) +
+            ', target(): ' + repr(this.target()) +
+            ', modifier(): ' + '{alt: ' + repr(this.modifier().alt) +
+            ', ctrl: ' + repr(this.modifier().ctrl) +
+            ', meta: ' + repr(this.modifier().meta) +
+            ', shift: ' + repr(this.modifier().shift) + 
+            ', any: ' + repr(this.modifier().any) + '}';
+        
+        if (this.type() && this.type().indexOf('key') === 0) {
+            str += ', key(): {code: ' + repr(this.key().code) +
+                ', string: ' + repr(this.key().string) + '}';
+        }
+
+        if (this.type() && (
+            this.type().indexOf('mouse') === 0 ||
+            this.type().indexOf('click') != -1 ||
+            this.type() == 'contextmenu')) {
+
+            str += ', mouse(): {page: ' + repr(this.mouse().page) +
+                ', client: ' + repr(this.mouse().client);
+
+            if (this.type() != 'mousemove') {
+                str += ', button: {left: ' + repr(this.mouse().button.left) +
+                    ', middle: ' + repr(this.mouse().button.middle) +
+                    ', right: ' + repr(this.mouse().button.right) + '}}';
+            } else {
+                str += '}';
+            }
+        }
+        if (this.type() == 'mouseover' || this.type() == 'mouseout') {
+            str += ', relatedTarget(): ' + repr(this.relatedTarget());
+        }
+        str += '}';
+        return str;
+    },
+
+    toString: function () {
+        return this.__repr__();
+    },
+
+    src: function () {
+        return this._src;
+    },
+
+    event: function () {
+        return this._event;
+    },
+
+    type: function () {
+        return this._event.type || undefined;
+    },
+
+    target: function () {
+        return this._event.target || this._event.srcElement;
+    },
+
+    relatedTarget: function () {
+        if (this.type() == 'mouseover') {
+            return (this._event.relatedTarget ||
+                this._event.fromElement);
+        } else if (this.type() == 'mouseout') {
+            return (this._event.relatedTarget ||
+                this._event.toElement);
+        }
+        // throw new Error("relatedTarget only available for 'mouseover' and 'mouseout'");
+        return undefined;
+    },
+
+    modifier: function () {
+        var m = {};
+        m.alt = this._event.altKey;
+        m.ctrl = this._event.ctrlKey;
+        m.meta = this._event.metaKey || false; // IE and Opera punt here
+        m.shift = this._event.shiftKey;
+        m.any = m.alt || m.ctrl || m.shift || m.meta;
+        return m;
+    },
+
+    key: function () {
+        var k = {};
+        if (this.type() && this.type().indexOf('key') === 0) {
+
+            /*
+
+    			If you're looking for a special key, look for it in keydown or
+                keyup, but never keypress. If you're looking for a Unicode
+                chracter, look for it with keypress, but never keyup or
+                keydown.
+	
+    			Notes:
+	
+    			FF key event behavior:
+    			key     event   charCode    keyCode
+    			DOWN    ku,kd   0           40
+    			DOWN    kp      0           40
+    			ESC     ku,kd   0           27
+    			ESC     kp      0           27
+    			a       ku,kd   0           65
+    			a       kp      97          0
+    			shift+a ku,kd   0           65
+    			shift+a kp      65          0
+    			1       ku,kd   0           49
+    			1       kp      49          0
+    			shift+1 ku,kd   0           0
+    			shift+1 kp      33          0
+	
+    			IE key event behavior:
+    			(IE doesn't fire keypress events for special keys.)
+    			key     event   keyCode
+    			DOWN    ku,kd   40
+    			DOWN    kp      undefined
+    			ESC     ku,kd   27
+    			ESC     kp      27
+    			a       ku,kd   65
+    			a       kp      97
+    			shift+a ku,kd   65
+    			shift+a kp      65
+    			1       ku,kd   49
+    			1       kp      49
+    			shift+1 ku,kd   49
+    			shift+1 kp      33
+
+    			Safari key event behavior:
+    			(Safari sets charCode and keyCode to something crazy for
+    			special keys.)
+    			key     event   charCode    keyCode
+    			DOWN    ku,kd   63233       40
+    			DOWN    kp      63233       63233
+    			ESC     ku,kd   27          27
+    			ESC     kp      27          27
+    			a       ku,kd   97          65
+    			a       kp      97          97
+    			shift+a ku,kd   65          65
+    			shift+a kp      65          65
+    			1       ku,kd   49          49
+    			1       kp      49          49
+    			shift+1 ku,kd   33          49
+    			shift+1 kp      33          33
+
+            */
+
+            /* look for special keys here */
+            if (this.type() == 'keydown' || this.type() == 'keyup') {
+                k.code = this._event.keyCode;
+                k.string = (MochiKit.Signal._specialKeys[k.code] ||
+                    'KEY_UNKNOWN');
+                return k;
+        
+            /* look for characters here */
+            } else if (this.type() == 'keypress') {
+            
+                /*
+            
+                    Special key behavior:
+                
+                    IE: does not fire keypress events for special keys
+                    FF: sets charCode to 0, and sets the correct keyCode
+                    Safari: sets keyCode and charCode to something stupid
+            
+                */
+            
+                k.code = 0;
+                k.string = '';
+                        
+                if (typeof(this._event.charCode) != 'undefined' && 
+                    this._event.charCode !== 0 &&
+                    !MochiKit.Signal._specialMacKeys[this._event.charCode]) {
+                    k.code = this._event.charCode;
+                    k.string = String.fromCharCode(k.code);
+                } else if (this._event.keyCode && 
+                    typeof(this._event.charCode) == 'undefined') { // IE
+                    k.code = this._event.keyCode;
+                    k.string = String.fromCharCode(k.code);
+                }
+            
+                return k;
+            }
+        }
+        // throw new Error('This is not a key event');
+        return undefined;
+    },
+
+    mouse: function () {
+        var m = {};
+        var e = this._event;
+        
+        if (this.type() && (
+            this.type().indexOf('mouse') === 0 ||
+            this.type().indexOf('click') != -1 ||
+            this.type() == 'contextmenu')) {
+            
+            m.client = new MochiKit.DOM.Coordinates(0, 0);
+            if (e.clientX || e.clientY) {
+                m.client.x = (!e.clientX || e.clientX < 0) ? 0 : e.clientX;
+                m.client.y = (!e.clientY || e.clientY < 0) ? 0 : e.clientY;
+            }
+
+            m.page = new MochiKit.DOM.Coordinates(0, 0);
+            if (e.pageX || e.pageY) {
+                m.page.x = (!e.pageX || e.pageX < 0) ? 0 : e.pageX;
+                m.page.y = (!e.pageY || e.pageY < 0) ? 0 : e.pageY;
+            } else {
+                /*
+            
+    				IE keeps the document offset in:
+        				document.documentElement.clientTop ||
+        				document.body.clientTop
+				
+    				and:
+        				document.documentElement.clientLeft ||
+        				document.body.clientLeft
+
+                    see:
+    				http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp
+
+    				The offset is (2,2) in standards mode and (0,0) in quirks 
+    				mode.
+				
+                */
+            
+                var de = MochiKit.DOM._document.documentElement;
+                var b = MochiKit.DOM._document.body;
+            
+                m.page.x = e.clientX +
+                    (de.scrollLeft || b.scrollLeft) - 
+                    (de.clientLeft || b.clientLeft);
+            
+                m.page.y = e.clientY +
+                    (de.scrollTop || b.scrollTop) - 
+                    (de.clientTop || b.clientTop);
+            
+            }
+            if (this.type() != 'mousemove') {
+                m.button = {};
+                m.button.left = false;
+                m.button.right = false;
+                m.button.middle = false;
+
+                /* we could check e.button, but which is more consistent */
+                if (e.which) {
+                    m.button.left = (e.which == 1);
+                    m.button.middle = (e.which == 2);
+                    m.button.right = (e.which == 3);
+
+                    /*
+                
+    					Mac browsers and right click:
+					
+    						- Safari doesn't fire any click events on a right
+    						  click:
+    						  http://bugzilla.opendarwin.org/show_bug.cgi?id=6595
+						  
+    						- Firefox fires the event, and sets ctrlKey = true
+						  
+    						- Opera fires the event, and sets metaKey = true
+					
+    					oncontextmenu is fired on right clicks between 
+    					browsers and across platforms.
+					
+                    */
+                
+                } else {
+                    m.button.left = !!(e.button & 1);
+                    m.button.right = !!(e.button & 2);
+                    m.button.middle = !!(e.button & 4);
+                }
+            }
+            return m;
+        }
+        // throw new Error('This is not a mouse event');
+        return undefined;
+    },
+
+    stop: function () {
+        this.stopPropagation();
+        this.preventDefault();
+    },
+
+    stopPropagation: function () {
+        if (this._event.stopPropagation) {
+            this._event.stopPropagation();
+        } else {
+            this._event.cancelBubble = true;
+        }
+    },
+
+    preventDefault: function () {
+        if (this._event.preventDefault) {
+            this._event.preventDefault();
+        } else {
+            this._event.returnValue = false;
+        }
+    }
+
+});
+
+/* Safari sets keyCode to these special values onkeypress. */
+MochiKit.Signal._specialMacKeys = {
+    3: 'KEY_ENTER',
+    63289: 'KEY_NUM_PAD_CLEAR',
+    63276: 'KEY_PAGE_UP',
+    63277: 'KEY_PAGE_DOWN',
+    63275: 'KEY_END',
+    63273: 'KEY_HOME',
+    63234: 'KEY_ARROW_LEFT',
+    63232: 'KEY_ARROW_UP',
+    63235: 'KEY_ARROW_RIGHT',
+    63233: 'KEY_ARROW_DOWN',
+    63302: 'KEY_INSERT',
+    63272: 'KEY_DELETE'
+};
+
+/* for KEY_F1 - KEY_F12 */
+for (i = 63236; i <= 63242; i++) {
+    MochiKit.Signal._specialMacKeys[i] = 'KEY_F' + (i - 63236 + 1); // no F0
+}
+
+/* Standard keyboard key codes. */
+MochiKit.Signal._specialKeys = {
+    8: 'KEY_BACKSPACE',
+    9: 'KEY_TAB',
+    12: 'KEY_NUM_PAD_CLEAR', // weird, for Safari and Mac FF only
+    13: 'KEY_ENTER',
+    16: 'KEY_SHIFT',
+    17: 'KEY_CTRL',
+    18: 'KEY_ALT',
+    19: 'KEY_PAUSE',
+    20: 'KEY_CAPS_LOCK',
+    27: 'KEY_ESCAPE',
+    32: 'KEY_SPACEBAR',
+    33: 'KEY_PAGE_UP',
+    34: 'KEY_PAGE_DOWN',
+    35: 'KEY_END',
+    36: 'KEY_HOME',
+    37: 'KEY_ARROW_LEFT',
+    38: 'KEY_ARROW_UP',
+    39: 'KEY_ARROW_RIGHT',
+    40: 'KEY_ARROW_DOWN',
+    44: 'KEY_PRINT_SCREEN', 
+    45: 'KEY_INSERT',
+    46: 'KEY_DELETE',
+    59: 'KEY_SEMICOLON', // weird, for Safari and IE only
+    91: 'KEY_WINDOWS_LEFT', 
+    92: 'KEY_WINDOWS_RIGHT', 
+    93: 'KEY_SELECT', 
+    106: 'KEY_NUM_PAD_ASTERISK',
+    107: 'KEY_NUM_PAD_PLUS_SIGN',
+    109: 'KEY_NUM_PAD_HYPHEN-MINUS',
+    110: 'KEY_NUM_PAD_FULL_STOP',
+    111: 'KEY_NUM_PAD_SOLIDUS',
+    144: 'KEY_NUM_LOCK',
+    145: 'KEY_SCROLL_LOCK',
+    186: 'KEY_SEMICOLON',
+    187: 'KEY_EQUALS_SIGN',
+    188: 'KEY_COMMA',
+    189: 'KEY_HYPHEN-MINUS',
+    190: 'KEY_FULL_STOP',
+    191: 'KEY_SOLIDUS',
+    192: 'KEY_GRAVE_ACCENT',
+    219: 'KEY_LEFT_SQUARE_BRACKET',
+    220: 'KEY_REVERSE_SOLIDUS',
+    221: 'KEY_RIGHT_SQUARE_BRACKET',
+    222: 'KEY_APOSTROPHE'
+    // undefined: 'KEY_UNKNOWN'
+};
+
+/* for KEY_0 - KEY_9 */
+for (var i = 48; i <= 57; i++) {
+    MochiKit.Signal._specialKeys[i] = 'KEY_' + (i - 48);
+}
+
+/* for KEY_A - KEY_Z */
+for (i = 65; i <= 90; i++) {
+    MochiKit.Signal._specialKeys[i] = 'KEY_' + String.fromCharCode(i);
+}
+
+/* for KEY_NUM_PAD_0 - KEY_NUM_PAD_9 */
+for (i = 96; i <= 105; i++) {
+    MochiKit.Signal._specialKeys[i] = 'KEY_NUM_PAD_' + (i - 96);
+}
+
+/* for KEY_F1 - KEY_F12 */
+for (i = 112; i <= 123; i++) {
+    MochiKit.Signal._specialKeys[i] = 'KEY_F' + (i - 112 + 1); // no F0
+}
+
+MochiKit.Base.update(MochiKit.Signal, {
+
+    __repr__: function () {
+        return '[' + this.NAME + ' ' + this.VERSION + ']';
+    },
+
+    toString: function () {
+        return this.__repr__();
+    },
+
+    _unloadCache: function () {
+        var self = MochiKit.Signal;
+        var observers = self._observers;
+        
+        for (var i = 0; i < observers.length; i++) {
+            self._disconnect(observers[i]);
+        }
+        
+        delete self._observers;
+        
+        try {
+            window.onload = undefined;
+        } catch(e) {
+            // pass
+        }
+
+        try {
+            window.onunload = undefined;
+        } catch(e) {
+            // pass
+        }
+    },
+
+    _listener: function (src, func, obj, isDOM) {
+        var E = MochiKit.Signal.Event;
+        if (!isDOM) {
+            return MochiKit.Base.bind(func, obj);
+        } 
+        obj = obj || src;
+        if (typeof(func) == "string") {
+            return function (nativeEvent) {
+                obj[func].apply(obj, [new E(src, nativeEvent)]);
+            };
+        } else {
+            return function (nativeEvent) {
+                func.apply(obj, [new E(src, nativeEvent)]);
+            };
+        }
+    },
+    
+    connect: function (src, sig, objOrFunc/* optional */, funcOrStr) {
+        src = MochiKit.DOM.getElement(src);
+        var self = MochiKit.Signal;
+        
+        if (typeof(sig) != 'string') {
+            throw new Error("'sig' must be a string");
+        }
+        
+        var obj = null;
+        var func = null;
+        if (typeof(funcOrStr) != 'undefined') {
+            obj = objOrFunc;
+            func = funcOrStr;
+            if (typeof(funcOrStr) == 'string') {
+                if (typeof(objOrFunc[funcOrStr]) != "function") {
+                    throw new Error("'funcOrStr' must be a function on 'objOrFunc'");
+                }
+            } else if (typeof(funcOrStr) != 'function') {
+                throw new Error("'funcOrStr' must be a function or string");
+            }
+        } else if (typeof(objOrFunc) != "function") {
+            throw new Error("'objOrFunc' must be a function if 'funcOrStr' is not given");
+        } else {
+            func = objOrFunc;
+        }
+        if (typeof(obj) == 'undefined' || obj === null) {
+            obj = src;
+        }
+        
+        var isDOM = !!(src.addEventListener || src.attachEvent);
+        var listener = self._listener(src, func, obj, isDOM);
+        
+        if (src.addEventListener) {
+            src.addEventListener(sig.substr(2), listener, false);
+        } else if (src.attachEvent) {
+            src.attachEvent(sig, listener); // useCapture unsupported
+        }
+
+        var ident = [src, sig, listener, isDOM, objOrFunc, funcOrStr];
+        self._observers.push(ident);
+        
+       
+        return ident;
+    },
+    
+    _disconnect: function (ident) {
+        // check isDOM
+        if (!ident[3]) { return; }
+        var src = ident[0];
+        var sig = ident[1];
+        var listener = ident[2];
+        if (src.removeEventListener) {
+            src.removeEventListener(sig.substr(2), listener, false);
+        } else if (src.detachEvent) {
+            src.detachEvent(sig, listener); // useCapture unsupported
+        } else {
+            throw new Error("'src' must be a DOM element");
+        }
+    },
+    
+    disconnect: function (ident) {
+        var self = MochiKit.Signal;
+        var observers = self._observers;
+        var m = MochiKit.Base;
+        if (arguments.length > 1) {
+            // compatibility API
+            var src = MochiKit.DOM.getElement(arguments[0]);
+            var sig = arguments[1];
+            var obj = arguments[2];
+            var func = arguments[3];
+            for (var i = observers.length - 1; i >= 0; i--) {
+                var o = observers[i];
+                if (o[0] === src && o[1] === sig && o[4] === obj && o[5] === func) {
+                    self._disconnect(o);
+                    observers.splice(i, 1);
+                    return true;
+                }
+            }
+        } else {
+            var idx = m.findIdentical(observers, ident);
+            if (idx >= 0) {
+                self._disconnect(ident);
+                observers.splice(idx, 1);
+                return true;
+            }
+        }
+        return false;
+    },
+    
+    disconnectAll: function(src/* optional */, sig) {
+        src = MochiKit.DOM.getElement(src);
+        var m = MochiKit.Base;
+        var signals = m.flattenArguments(m.extend(null, arguments, 1));
+        var self = MochiKit.Signal;
+        var disconnect = self._disconnect;
+        var observers = self._observers;
+        if (signals.length === 0) {
+            // disconnect all
+            for (var i = observers.length - 1; i >= 0; i--) {
+                var ident = observers[i];
+                if (ident[0] === src) {
+                    disconnect(ident);
+                    observers.splice(i, 1);
+                }
+            }
+        } else {
+            var sigs = {};
+            for (var i = 0; i < signals.length; i++) {
+                sigs[signals[i]] = true;
+            }
+            for (var i = observers.length - 1; i >= 0; i--) {
+                var ident = observers[i];
+                if (ident[0] === src && ident[1] in sigs) {
+                    disconnect(ident);
+                    observers.splice(i, 1);
+                }
+            }
+        }
+        
+    },
+
+    signal: function (src, sig) {
+        var observers = MochiKit.Signal._observers;
+        src = MochiKit.DOM.getElement(src);
+        var args = MochiKit.Base.extend(null, arguments, 2);
+        var errors = [];
+        for (var i = 0; i < observers.length; i++) {
+            var ident = observers[i];
+            if (ident[0] === src && ident[1] === sig) {
+                try {
+                    ident[2].apply(src, args);
+                } catch (e) {
+                    errors.push(e);
+                }
+            }
+        }
+        if (errors.length == 1) {
+            throw errors[0];
+        } else if (errors.length > 1) {
+            var e = new Error("Multiple errors thrown in handling 'sig', see errors property");
+            e.errors = errors;
+            throw e;
+        }
+    }
+
+});
+
+MochiKit.Signal.EXPORT_OK = [];
+
+MochiKit.Signal.EXPORT = [
+    'connect',
+    'disconnect',
+    'signal',
+    'disconnectAll'
+];
+
+MochiKit.Signal.__new__ = function (win) {
+    var m = MochiKit.Base;
+    this._document = document;
+    this._window = win;
+
+    try {
+        this.connect(window, 'onunload', this._unloadCache);
+    } catch (e) {
+        // pass: might not be a browser
+    }
+
+    this.EXPORT_TAGS = {
+        ':common': this.EXPORT,
+        ':all': m.concat(this.EXPORT, this.EXPORT_OK)
+    };
+
+    m.nameFunctions(this);
+};
+
+MochiKit.Signal.__new__(this);
+
+//
+// XXX: Internet Explorer blows
+//
+if (!MochiKit.__compat__) {
+    connect = MochiKit.Signal.connect;
+    disconnect = MochiKit.Signal.disconnect;
+    disconnectAll = MochiKit.Signal.disconnectAll;
+    signal = MochiKit.Signal.signal;
+}
+
+MochiKit.Base._exportSymbols(this, MochiKit.Signal);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Test.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Test.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Test.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,181 @@
+/***
+
+MochiKit.Test 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Test');
+    dojo.require('MochiKit.Base');
+}
+
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Base", []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.Test depends on MochiKit.Base!";
+}
+
+if (typeof(MochiKit.Test) == 'undefined') {
+    MochiKit.Test = {};
+}
+
+MochiKit.Test.NAME = "MochiKit.Test";
+MochiKit.Test.VERSION = "1.3.1";
+MochiKit.Test.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.Test.toString = function () {
+    return this.__repr__();
+};
+
+
+MochiKit.Test.EXPORT = ["runTests"];
+MochiKit.Test.EXPORT_OK = [];
+
+MochiKit.Test.runTests = function (obj) {
+    if (typeof(obj) == "string") {
+        obj = JSAN.use(obj);
+    }
+    var suite = new MochiKit.Test.Suite();
+    suite.run(obj);
+};
+
+MochiKit.Test.Suite = function () {
+    this.testIndex = 0;
+    MochiKit.Base.bindMethods(this);
+};
+
+MochiKit.Test.Suite.prototype = {
+    run: function (obj) {
+        try {
+            obj(this);
+        } catch (e) {
+            this.traceback(e);
+        }
+    },
+    traceback: function (e) {
+        var items = MochiKit.Iter.sorted(MochiKit.Base.items(e));
+        print("not ok " + this.testIndex + " - Error thrown");
+        for (var i = 0; i < items.length; i++) {
+            var kv = items[i];
+            if (kv[0] == "stack") {
+                kv[1] = kv[1].split(/\n/)[0];
+            }
+            this.print("# " + kv.join(": "));
+        }
+    },
+    print: function (s) {
+        print(s);
+    },
+    is: function (got, expected, /* optional */message) {
+        var res = 1;
+        var msg = null;
+        try {
+            res = MochiKit.Base.compare(got, expected);
+        } catch (e) {
+            msg = "Can not compare " + typeof(got) + ":" + typeof(expected);
+        }
+        if (res) {
+            msg = "Expected value did not compare equal";
+        }
+        if (!res) {
+            return this.testResult(true, message);
+        }
+        return this.testResult(false, message,
+            [[msg], ["got:", got], ["expected:", expected]]);
+    },
+
+    testResult: function (pass, msg, failures) {
+        this.testIndex += 1;
+        if (pass) {
+            this.print("ok " + this.testIndex + " - " + msg); 
+            return;
+        }
+        this.print("not ok " + this.testIndex + " - " + msg);
+        if (failures) {
+            for (var i = 0; i < failures.length; i++) {
+                this.print("# " + failures[i].join(" "));
+            }
+        }
+    },
+            
+    isDeeply: function (got, expected, /* optional */message) {
+        var m = MochiKit.Base;
+        var res = 1;
+        try {
+            res = m.compare(got, expected);
+        } catch (e) { 
+            // pass
+        }
+        if (res === 0) {
+            return this.ok(true, message);
+        }
+        var gk = m.keys(got);
+        var ek = m.keys(expected);
+        gk.sort();
+        ek.sort();
+        if (m.compare(gk, ek)) {
+            // differing keys
+            var cmp = {};
+            var i;
+            for (i = 0; i < gk.length; i++) {
+                cmp[gk[i]] = "got";
+            }
+            for (i = 0; i < ek.length; i++) {
+                if (ek[i] in cmp) {
+                    delete cmp[ek[i]];
+                } else {
+                    cmp[ek[i]] = "expected";
+                }
+            }
+            var diffkeys = m.keys(cmp);
+            diffkeys.sort();
+            var gotkeys = [];
+            var expkeys = [];
+            while (diffkeys.length) {
+                var k = diffkeys.shift();
+                if (k in Object.prototype) {
+                    continue;
+                }
+                (cmp[k] == "got" ? gotkeys : expkeys).push(k);
+            }
+
+
+        }
+        
+        return this.testResult((!res), msg,
+            (msg ? [["got:", got], ["expected:", expected]] : undefined)
+        );
+    },
+    
+    ok: function (res, message) {
+        return this.testResult(res, message);
+    }
+};
+
+MochiKit.Test.__new__ = function () {
+    var m = MochiKit.Base;
+
+    this.EXPORT_TAGS = {
+        ":common": this.EXPORT,
+        ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+    };
+
+    m.nameFunctions(this);
+
+};
+
+MochiKit.Test.__new__();
+
+MochiKit.Base._exportSymbols(this, MochiKit.Test);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Visual.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Visual.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/Visual.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,402 @@
+/***
+
+MochiKit.Visual 1.3.1
+
+See <http://mochikit.com/> for documentation, downloads, license, etc.
+
+(c) 2005 Bob Ippolito and others.  All rights Reserved.
+
+***/
+
+if (typeof(dojo) != 'undefined') {
+    dojo.provide('MochiKit.Visual');
+    dojo.require('MochiKit.Base');
+    dojo.require('MochiKit.DOM');
+    dojo.require('MochiKit.Color');
+}
+
+if (typeof(JSAN) != 'undefined') {
+    JSAN.use("MochiKit.Base", []);
+    JSAN.use("MochiKit.DOM", []);
+    JSAN.use("MochiKit.Color", []);
+}
+
+try {
+    if (typeof(MochiKit.Base) == 'undefined' ||
+        typeof(MochiKit.DOM) == 'undefined' ||
+        typeof(MochiKit.Color) == 'undefined') {
+        throw "";
+    }
+} catch (e) {
+    throw "MochiKit.Visual depends on MochiKit.Base, MochiKit.DOM and MochiKit.Color!";
+}
+
+if (typeof(MochiKit.Visual) == "undefined") {
+    MochiKit.Visual = {};
+}
+
+MochiKit.Visual.NAME = "MochiKit.Visual";
+MochiKit.Visual.VERSION = "1.3.1";
+
+MochiKit.Visual.__repr__ = function () {
+    return "[" + this.NAME + " " + this.VERSION + "]";
+};
+
+MochiKit.Visual.toString = function () {
+    return this.__repr__();
+};
+
+
+MochiKit.Visual._RoundCorners = function (e, options) {
+    e = MochiKit.DOM.getElement(e);
+    this._setOptions(options);
+    if (this.options.__unstable__wrapElement) {
+        e = this._doWrap(e);
+    }
+
+    var color = this.options.color;
+    var C = MochiKit.Color.Color;
+    if (this.options.color == "fromElement") {
+        color = C.fromBackground(e);
+    } else if (!(color instanceof C)) {
+        color = C.fromString(color);
+    }
+    this.isTransparent = (color.asRGB().a <= 0);
+
+    var bgColor = this.options.bgColor;
+    if (this.options.bgColor == "fromParent") {
+        bgColor = C.fromBackground(e.offsetParent);
+    } else if (!(bgColor instanceof C)) {
+        bgColor = C.fromString(bgColor);
+    }
+
+    this._roundCornersImpl(e, color, bgColor);
+};
+
+MochiKit.Visual._RoundCorners.prototype = {
+    _doWrap: function (e) {
+        var parent = e.parentNode;
+        var doc = MochiKit.DOM.currentDocument();
+        if (typeof(doc.defaultView) == "undefined"
+            || doc.defaultView === null) {
+            return e;
+        }
+        var style = doc.defaultView.getComputedStyle(e, null);
+        if (typeof(style) == "undefined" || style === null) {
+            return e;
+        }
+        var wrapper = MochiKit.DOM.DIV({"style": {
+            display: "block",
+            // convert padding to margin
+            marginTop: style.getPropertyValue("padding-top"),
+            marginRight: style.getPropertyValue("padding-right"),
+            marginBottom: style.getPropertyValue("padding-bottom"),
+            marginLeft: style.getPropertyValue("padding-left"),
+            // remove padding so the rounding looks right
+            padding: "0px"
+            /*
+            paddingRight: "0px",
+            paddingLeft: "0px"
+            */
+        }});
+        wrapper.innerHTML = e.innerHTML;
+        e.innerHTML = "";
+        e.appendChild(wrapper);
+        return e;
+    },
+
+    _roundCornersImpl: function (e, color, bgColor) {
+        if (this.options.border) {
+            this._renderBorder(e, bgColor);
+        }
+        if (this._isTopRounded()) {
+            this._roundTopCorners(e, color, bgColor);
+        }
+        if (this._isBottomRounded()) {
+            this._roundBottomCorners(e, color, bgColor);
+        }
+    },
+
+    _renderBorder: function (el, bgColor) {
+        var borderValue = "1px solid " + this._borderColor(bgColor);
+        var borderL = "border-left: "  + borderValue;
+        var borderR = "border-right: " + borderValue;
+        var style   = "style='" + borderL + ";" + borderR +  "'";
+        el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>";
+    },
+
+    _roundTopCorners: function (el, color, bgColor) {
+        var corner = this._createCorner(bgColor);
+        for (var i = 0; i < this.options.numSlices; i++) {
+            corner.appendChild(
+                this._createCornerSlice(color, bgColor, i, "top")
+            );
+        }
+        el.style.paddingTop = 0;
+        el.insertBefore(corner, el.firstChild);
+    },
+
+    _roundBottomCorners: function (el, color, bgColor) {
+        var corner = this._createCorner(bgColor);
+        for (var i = (this.options.numSlices - 1); i >= 0; i--) {
+            corner.appendChild(
+                this._createCornerSlice(color, bgColor, i, "bottom")
+            );
+        }
+        el.style.paddingBottom = 0;
+        el.appendChild(corner);
+    },
+
+    _createCorner: function (bgColor) {
+        var dom = MochiKit.DOM;
+        return dom.DIV({style: {backgroundColor: bgColor.toString()}});
+    },
+
+    _createCornerSlice: function (color, bgColor, n, position) {
+        var slice = MochiKit.DOM.SPAN();
+
+        var inStyle = slice.style;
+        inStyle.backgroundColor = color.toString();
+        inStyle.display = "block";
+        inStyle.height = "1px";
+        inStyle.overflow = "hidden";
+        inStyle.fontSize = "1px";
+
+        var borderColor = this._borderColor(color, bgColor);
+        if (this.options.border && n === 0) {
+            inStyle.borderTopStyle = "solid";
+            inStyle.borderTopWidth = "1px";
+            inStyle.borderLeftWidth = "0px";
+            inStyle.borderRightWidth = "0px";
+            inStyle.borderBottomWidth = "0px";
+            // assumes css compliant box model
+            inStyle.height = "0px";
+            inStyle.borderColor = borderColor.toString();
+        } else if (borderColor) {
+            inStyle.borderColor = borderColor.toString();
+            inStyle.borderStyle = "solid";
+            inStyle.borderWidth = "0px 1px";
+        }
+
+        if (!this.options.compact && (n == (this.options.numSlices - 1))) {
+            inStyle.height = "2px";
+        }
+
+        this._setMargin(slice, n, position);
+        this._setBorder(slice, n, position);
+
+        return slice;
+    },
+
+    _setOptions: function (options) {
+        this.options = {
+            corners: "all",
+            color: "fromElement",
+            bgColor: "fromParent",
+            blend: true,
+            border: false,
+            compact: false,
+            __unstable__wrapElement: false
+        };
+        MochiKit.Base.update(this.options, options);
+
+        this.options.numSlices = (this.options.compact ? 2 : 4);
+    },
+
+    _whichSideTop: function () {
+        var corners = this.options.corners;
+        if (this._hasString(corners, "all", "top")) {
+            return "";
+        }
+
+        var has_tl = (corners.indexOf("tl") != -1);
+        var has_tr = (corners.indexOf("tr") != -1);
+        if (has_tl && has_tr) {
+            return "";
+        }
+        if (has_tl) {
+            return "left";
+        }
+        if (has_tr) {
+            return "right";
+        }
+        return "";
+    },
+
+    _whichSideBottom: function () {
+        var corners = this.options.corners;
+        if (this._hasString(corners, "all", "bottom")) {
+            return "";
+        }
+
+        var has_bl = (corners.indexOf('bl') != -1);
+        var has_br = (corners.indexOf('br') != -1);
+        if (has_bl && has_br) {
+            return "";
+        }
+        if (has_bl) {
+            return "left";
+        }
+        if (has_br) {
+            return "right";
+        }
+        return "";
+    },
+
+    _borderColor: function (color, bgColor) {
+        if (color == "transparent") {
+            return bgColor;
+        } else if (this.options.border) {
+            return this.options.border;
+        } else if (this.options.blend) {
+            return bgColor.blendedColor(color);
+        }
+        return "";
+    },
+
+
+    _setMargin: function (el, n, corners) {
+        var marginSize = this._marginSize(n) + "px";
+        var whichSide = (
+            corners == "top" ? this._whichSideTop() : this._whichSideBottom()
+        );
+        var style = el.style;
+
+        if (whichSide == "left") {
+            style.marginLeft = marginSize;
+            style.marginRight = "0px";
+        } else if (whichSide == "right") {
+            style.marginRight = marginSize;
+            style.marginLeft  = "0px";
+        } else {
+            style.marginLeft = marginSize;
+            style.marginRight = marginSize;
+        }
+    },
+
+    _setBorder: function (el, n, corners) {
+        var borderSize = this._borderSize(n) + "px";
+        var whichSide = (
+            corners == "top" ? this._whichSideTop() : this._whichSideBottom()
+        );
+
+        var style = el.style;
+        if (whichSide == "left") {
+            style.borderLeftWidth = borderSize;
+            style.borderRightWidth = "0px";
+        } else if (whichSide == "right") {
+            style.borderRightWidth = borderSize;
+            style.borderLeftWidth  = "0px";
+        } else {
+            style.borderLeftWidth = borderSize;
+            style.borderRightWidth = borderSize;
+        }
+    },
+
+    _marginSize: function (n) {
+        if (this.isTransparent) {
+            return 0;
+        }
+
+        var o = this.options;
+        if (o.compact && o.blend) {
+            var smBlendedMarginSizes = [1, 0];
+            return smBlendedMarginSizes[n];
+        } else if (o.compact) {
+            var compactMarginSizes = [2, 1];
+            return compactMarginSizes[n];
+        } else if (o.blend) {
+            var blendedMarginSizes = [3, 2, 1, 0];
+            return blendedMarginSizes[n];
+        } else {
+            var marginSizes = [5, 3, 2, 1];
+            return marginSizes[n];
+        }
+    },
+
+    _borderSize: function (n) {
+        var o = this.options;
+        var borderSizes;
+        if (o.compact && (o.blend || this.isTransparent)) {
+            return 1;
+        } else if (o.compact) {
+            borderSizes = [1, 0];
+        } else if (o.blend) {
+            borderSizes = [2, 1, 1, 1];
+        } else if (o.border) {
+            borderSizes = [0, 2, 0, 0];
+        } else if (this.isTransparent) {
+            borderSizes = [5, 3, 2, 1];
+        } else {
+            return 0;
+        }
+        return borderSizes[n];
+    },
+
+    _hasString: function (str) {
+        for (var i = 1; i< arguments.length; i++) {
+            if (str.indexOf(arguments[i]) != -1) {
+                return true;
+            }
+        }
+        return false;
+    },
+
+    _isTopRounded: function () {
+        return this._hasString(this.options.corners,
+            "all", "top", "tl", "tr"
+        );
+    },
+
+    _isBottomRounded: function () {
+        return this._hasString(this.options.corners,
+            "all", "bottom", "bl", "br"
+        );
+    },
+
+    _hasSingleTextChild: function (el) {
+        return (el.childNodes.length == 1 && el.childNodes[0].nodeType == 3);
+    }
+};
+
+MochiKit.Visual.roundElement = function (e, options) {
+    new MochiKit.Visual._RoundCorners(e, options);
+};
+
+MochiKit.Visual.roundClass = function (tagName, className, options) {
+    var elements = MochiKit.DOM.getElementsByTagAndClassName(
+        tagName, className
+    );
+    for (var i = 0; i < elements.length; i++) {
+        MochiKit.Visual.roundElement(elements[i], options);
+    }
+};
+
+// Compatibility with MochiKit 1.0
+MochiKit.Visual.Color = MochiKit.Color.Color;
+MochiKit.Visual.getElementsComputedStyle = MochiKit.DOM.computedStyle;
+
+/* end of Rico adaptation */
+
+MochiKit.Visual.__new__  = function () {
+    var m = MochiKit.Base;
+
+    m.nameFunctions(this);
+
+    this.EXPORT_TAGS = {
+        ":common": this.EXPORT,
+        ":all": m.concat(this.EXPORT, this.EXPORT_OK)
+    };
+
+};
+
+MochiKit.Visual.EXPORT = [
+    "roundElement",
+    "roundClass"
+];
+
+MochiKit.Visual.EXPORT_OK = [];
+
+MochiKit.Visual.__new__();
+
+MochiKit.Base._exportSymbols(this, MochiKit.Visual);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/__package__.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/__package__.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/MochiKit/__package__.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,17 @@
+dojo.hostenv.conditionalLoadModule({
+    "common": [
+        "MochiKit.Base",
+        "MochiKit.Iter",
+        "MochiKit.Logging",
+        "MochiKit.DateTime",
+        "MochiKit.Format",
+        "MochiKit.Async",
+        "MochiKit.Color"
+    ],
+    "browser": [
+        "MochiKit.DOM",
+        "MochiKit.LoggingPane",
+        "MochiKit.Visual"
+    ]
+});
+dojo.hostenv.moduleLoaded("MochiKit.*");

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,68 @@
+function log(msg) {
+    top.frames['log_frame'].document.write(msg + '<br />');
+}
+
+function _tb_open(info) {
+    log('open '+info[0]);
+    _tb_remembered_links = [];
+    top.frames[0].location = info[0];
+    return '_tb_WAIT_FOR_PAGE_LOAD';
+}
+
+function _tb_stop(info) {
+    should_stop = true;
+    top.frames['log_frame'].document.close();
+}
+
+function _tb_getContents(info) {
+    return top.frames[0].document.documentElement.innerHTML;
+}
+
+function _tb_getUrl(info) {
+    return top.frames[0].location.href;
+}
+
+function _tb_reload(info) {
+    top.frames[0].location = top.frames[0].location.href;
+}
+
+function _tb_goBack(info) {
+    top.frames[0].history.back();
+}
+
+function _tb_rememberLinkN(info) {
+    links = top.frames[0].document.getElementsByTagName('a');
+    var id = _tb_remembered_links.length
+    _tb_remembered_links[id] = links[info[0]];
+    return id;
+}
+
+function _tb_clickRememberedLink(info) {
+    var n = info[0];
+    var element = _tb_remembered_links[n];
+    _tb_click(element);
+    return '_tb_WAIT_FOR_PAGE_LOAD';
+}
+
+//function _tb_doEvent(element, type) {
+//    if (element.fireEvent) {
+//        element.fireEvent('on'+type);
+//    } else {
+//        var evt = document.createEvent('HTMLEvents');
+//        evt.initEvent(type, false, true);
+//        element.dispatchEvent(evt);
+//    }
+//}
+
+function _tb_click(e) {
+    if (e.onclick) {
+        log('using onclick');
+        e.onclick();
+    }
+    else {
+        log('using href');
+        log(e.href);
+        top.frames[0].location = e.href;
+    }
+}
+

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/shim.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/shim.js	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/shim.js	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,42 @@
+last_result = '__testbrowser__no_result_yet';
+should_stop = false;
+_tb_onloadFunc = function() {};
+
+function _tb_gotNextCommand(info) {
+    log('gotNextCommand');
+    var command = info[0];
+    last_result = eval(info[0] + '(' + info[1] + ')');
+    if (last_result == '_tb_WAIT_FOR_PAGE_LOAD') {
+        _tb_waitForLoad(eval(_tb_nextCommand));
+    } else if (!should_stop) {
+        _tb_nextCommand();
+    }
+}
+
+function _tb_waitForLoad(func) {
+    log('waiting');
+    _tb_onloadFunc = function() {
+        log('loaded');
+        setTimeout(func, 500);
+        _tb_onloadFunc = function() {};
+    }
+}
+
+function _tb_fetchNextCommandFailed(error) {
+    alert(error);
+}
+
+function _tb_nextCommand() {
+    if (should_stop) {
+        return
+    }
+    var req = getXMLHttpRequest();
+    req.open('POST', '/__api__/next');
+    var d = sendXMLHttpRequest(req, serializeJSON(last_result)+'\r\n');
+    last_result = undefined;
+    d.addCallback(evalJSONRequest);
+    d.addCallback(_tb_gotNextCommand);
+    d.addErrback(_tb_fetchNextCommandFailed);
+}
+
+connect(window, 'onload', _tb_nextCommand);

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/start.html
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/start.html	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/start.html	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,14 @@
+<!doctype html public "-//w3c//dtd html 4.01 fRAMESET//en"
+   "HTTP://WWW.W3.ORG/tr/HTML4/FRAMESET.DTD">
+<html>
+<head>
+  <title>zope.testbrowser Start Page</title>
+  <script type="text/javascript" src="/__resources__/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/__resources__/shim.js"></script>
+  <script type="text/javascript" src="/__resources__/commands.js"></script>
+</head>
+<frameset rows="80%, 20%" border="1">
+    <frame src="about:blank" onload="_tb_onloadFunc();" />
+    <frame src="about:blank" name="log_frame" />
+</frameset>
+</html>

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,191 @@
+import BaseHTTPServer
+import Queue
+import SocketServer
+import cgi
+import httplib
+import os
+import select
+import simplejson
+import socket
+import threading
+import urlparse
+from zope.app.testing import functional
+from StringIO import StringIO
+
+base_dir = os.path.dirname(__file__)
+allowed_resources = ['MochiKit', 'shim.js', 'commands.js', 'start.html']
+
+PROXY_PORT = 23123
+PROXY_HOST = '127.0.0.1'
+
+class Constant(object):
+    def __init__(self, name):
+        self.name = name
+
+    def __str__(self):
+        return self.name
+
+UNDEFINED = Constant('undefined')
+
+class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+#    server_version = "TinyHTTPProxy/" + __version__
+    rbufsize = 0
+
+    def __init__(self, request, client_address, server):
+        self.caller = functional.HTTPCaller()
+        self.command_queue = server.command_queue
+        self.result_queue = server.result_queue
+        BaseHTTPServer.BaseHTTPRequestHandler.__init__(
+            self, request, client_address, server)
+
+    def _connect(self, netloc, soc):
+        if ':' in netloc:
+            i = netloc.index(':')
+            host_and_port = netloc[:i], int(netloc[i+1:])
+        else:
+            host_and_port = netloc, 80
+        try:
+            soc.connect(host_and_port)
+        except socket.error, arg:
+            try:
+                msg = arg[1]
+            except:
+                msg = arg
+            self.send_error(404, msg)
+            return False
+        return True
+
+    def sendFile(self, path):
+        assert path.startswith('/')
+        path = path[1:]
+        assert path.split('/')[1] in allowed_resources
+        # XXX might use too much memory
+        self.wfile.write(open(os.path.join(base_dir, path)).read())
+
+    def handleRequest(self):
+        (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(
+            self.path, 'http')
+        assert netloc == ''
+#        print self.path
+        if scheme != 'http':
+            self.send_error(400, "unknown scheme %r" % scheme)
+            return
+        self.log_request()
+
+        if self.command in ('GET', 'POST'):
+            if path.startswith('/__resources__/'):
+                self.sendFile(path)
+                return
+            elif path.startswith('/__api__/'):
+                operation = urlparse.urlparse(self.path)[2].split('/')[-1]
+                raw_json = self.rfile.next()
+
+                if raw_json.strip() == 'undefined':
+                    last_result = UNDEFINED
+                else:
+                    last_result = simplejson.loads(raw_json)
+
+                if operation == 'next':
+                    # if no command has been processed yet, the last_result
+                    # value will be a placeholder
+                    if last_result != '__testbrowser__no_result_yet':
+                        self.result_queue.put(last_result)
+
+                    response = self.command_queue.get()
+                    if response[0] == '_tb_stop':
+                        self.server.stop = True
+                        self.result_queue.put('the server has stopped')
+                else:
+                    self.send_response(404)
+                    self.send_header('Content-Type', 'text/plain')
+                    self.end_headers()
+                    msg = 'unknown operation: %r' % operation
+                    self.wfile.write(msg)
+                    raise RuntimeError(msg)
+
+                self.send_response(200)
+                self.send_header('Content-Type', 'text/plain')
+                self.end_headers()
+                self.wfile.write(simplejson.dumps(response))
+                import time;time.sleep(1)
+                return
+
+        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        try:
+#            print 'sending', self.remote_host
+            request = StringIO()
+            request.write("%s %s %s\r\n" % (
+                self.command,
+                urlparse.urlunparse(('', '', path, params, query, '')),
+                self.request_version))
+            self.headers['Connection'] = 'close'
+            for key_val in self.headers.items():
+                request.write("%s: %s\r\n" % key_val)
+            request.write("\r\n")
+            response = self.caller(request.getvalue())
+            self.connection.send(response.getOutput())
+#            print 'done with', self.path
+        finally:
+            self.connection.close()
+
+    do_HEAD = do_POST = do_PUT = do_DELETE = do_GET = handleRequest
+
+    def do_NOOP(self):
+        self.send_response(200)
+        self.end_headers()
+
+    def log_message(self, format, *args):
+        pass
+
+
+class HttpServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
+
+    stop = False
+
+    def __init__(self, *args, **kws):
+        self.command_queue = Queue.Queue()
+        self.result_queue = Queue.Queue()
+        self.threads = []
+        BaseHTTPServer.HTTPServer.__init__(self, *args, **kws)
+
+    def serve_forever(self):
+        """Handle one request at a time until stopped."""
+        while not self.stop:
+            self.handle_request()
+
+    # This method comes from ThreadingMixIn
+    def process_request_thread(self, request, client_address):
+        my_thread = threading.currentThread()
+        self.threads.append(my_thread)
+        return SocketServer.ThreadingMixIn.process_request_thread(
+            self, request, client_address)
+
+
+class ServerManager(object):
+    def __init__(self):
+        self.host = PROXY_HOST
+        self.port = PROXY_PORT
+        self.server = HttpServer((self.host, self.port), RequestHandler)
+
+    def start(self):
+        self.server_thread = threading.Thread(
+                                target=self.server.serve_forever)
+        self.server_thread.setDaemon(True)
+        self.server_thread.start()
+
+    def stop(self):
+        self.executeCommand('stop')
+        conn = httplib.HTTPConnection('%s:%d' % (self.host, self.port))
+        conn.request('NOOP', '/')
+        conn.getresponse()
+
+        # we want to wait until all outstanding requests are finished before
+        # we return
+        for t in self.server.threads:
+            t.join()
+
+        self.server_thread.join()
+
+    def executeCommand(self, command, *args):
+        self.server.command_queue.put( ('_tb_'+command, simplejson.dumps(args)) )
+        return self.server.result_queue.get()


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,216 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Browser-based Functional Doctests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+from BeautifulSoup import BeautifulSoup
+from zope.testbrowser import interfaces
+from zope.testbrowser.real.proxy import ServerManager, PROXY_PORT
+from zope.testbrowser.utilities import disambiguate, zeroOrOne, \
+    SetattrErrorsMixin, PystoneTimer
+import re
+import urlparse
+
+
+try:
+    from zope import interface
+except ImportError:
+    from dummymodules import interface
+
+def getTagText(soup):
+    text = str(soup)
+    text = re.sub('<[^>]*>', '', text)
+    text = re.sub(' +', ' ', text)
+    return text
+
+class Browser(SetattrErrorsMixin):
+    """A web user agent."""
+    interface.implements(interfaces.IBrowser)
+
+    _contents = None
+    _counter = 0
+
+    def __init__(self, url=None):
+        self.serverManager = ServerManager()
+        self.serverManager.start()
+        self.timer = PystoneTimer()
+        self._enable_setattr_errors = True
+
+        if url is not None:
+            self.open(url)
+
+    def close(self):
+        self.serverManager.stop()
+
+    @property
+    def url(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        return self.executeCommand('getUrl')
+
+    @property
+    def isHtml(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    @property
+    def title(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    @property
+    def contents(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        # XXX see note in commands.js
+        return self.executeCommand('getContents')
+
+    @property
+    def headers(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    def handleErrors():
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    def open(self, url, data=None):
+        """See zope.testbrowser.interfaces.IBrowser"""
+
+        (scheme, netloc, path, params, query, frag) = urlparse.urlparse(url)
+
+        if scheme != 'http':
+            self.send_error(400, "unknown scheme %r" % scheme)
+
+        url = urlparse.urlunparse(
+            (scheme, 'localhost:%s' % PROXY_PORT, path, params, query, frag))
+
+        self._start_timer()
+        self.executeCommand('open', url, data)
+        self._stop_timer()
+        self._changed()
+
+    def executeCommand(self, command, *args):
+        """Execute a JavaScript routine on the client (not an official API)"""
+        return self.serverManager.executeCommand(command, *args)
+
+    def _start_timer(self):
+        self.timer.start()
+
+    def _stop_timer(self):
+        self.timer.stop()
+
+    @property
+    def lastRequestPystones(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        return self.timer.elapsedPystones
+
+    @property
+    def lastRequestSeconds(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        return self.timer.elapsedSeconds
+
+    def reload(self):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        self._start_timer()
+        self.executeCommand('reload')
+        self._stop_timer()
+        self._changed()
+
+    def goBack(self, count=1):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        self._start_timer()
+        self.executeCommand('goBack')
+        self._stop_timer()
+        self._changed()
+
+    def addHeader(self, key, value):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    def getLink(self, text=None, url=None, id=None, index=None):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        soup = BeautifulSoup(self.contents)('a')
+        links = []
+
+        # "msg" holds the disambiguation message
+        # the Link instance below needs to know the index of the a tag (n)
+        if text is not None:
+            msg = 'text %r' % text
+            links = []
+            for n, a in enumerate(soup):
+                # remove all tags from the text in order to search it
+                if text in getTagText(a):
+                    links.append((a, n))
+        elif url is not None:
+            msg = 'url %r' % text
+            for n, a in enumerate(soup):
+                if a['href'] == url:
+                    links.append((a, n))
+        elif id is not None:
+            msg = 'id %r' % id
+            for n, a in enumerate(soup):
+                if a['id'] == id:
+                    links.append((a, n))
+
+        link, n = disambiguate(links, msg, index)
+        return Link(link, n, self)
+
+    def getControl(self, label=None, name=None, index=None):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    def getForm(self, id=None, name=None, action=None, index=None):
+        """See zope.testbrowser.interfaces.IBrowser"""
+        raise NotImplemented
+
+    def _changed(self):
+        self._counter += 1
+        self._contents = None
+
+
+class Link(SetattrErrorsMixin):
+    interface.implements(interfaces.ILink)
+
+    def __init__(self, link, index, browser):
+        self.link = link
+        self.browser = browser
+        self.url = urlparse.urljoin(self.browser.url, link['href'])
+        self._remembered_id = browser.executeCommand('rememberLinkN', index)
+        self._browser_counter = self.browser._counter
+        self._enable_setattr_errors = True
+
+    def click(self):
+        if self._browser_counter != self.browser._counter:
+            raise interfaces.ExpiredError
+        self.browser._start_timer()
+        self.browser.executeCommand('clickRememberedLink', self._remembered_id)
+        self.browser._stop_timer()
+        self.browser._changed()
+
+    @property
+    def text(self):
+        return getTagText(self.link)
+
+    @property
+    def tag(self):
+        return self.link.name
+
+    @property
+    def attrs(self):
+        return dict(self.link.attrs)
+
+    def __repr__(self):
+        return "<%s text=%r url=%r>" % (
+            self.__class__.__name__, self.text, self.url)


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,57 @@
+===================
+Using Real Browsers
+===================
+
+Using the zope.testbrowser.real module, real browsers can be controlled via
+the testbrowser API.  First, instantiate a Browser object.
+
+    >>> from zope.testbrowser.real.real import Browser # XXX real.real should go
+    >>> browser = Browser()
+
+We can open pages and look at their contents.
+
+    >>> browser.open('http://localhost/')
+    >>> browser.contents
+    u'...</head>...'
+
+    >>> browser.contents
+    u'...[top]...'
+
+    >>> browser.getLink('[top]', index=0)
+    <Link text='[top]' url=u'http://localhost:23123/@@SelectedManagementView.html'>
+
+If a link doesn't exist, we get an exception.
+
+    >>> browser.getLink('does not exist')
+    Traceback (most recent call last):
+    ...
+    LookupError: text 'does not exist'
+
+Links can be clicked.
+
+    >>> browser.getLink('[top]', index=0).click()
+
+We can retrieve the current address.
+
+    >>> browser.url
+    u'http://localhost:23123/'
+
+Reload works.
+
+    >>> original_contents = browser.contents
+    >>> browser.reload()
+    >>> original_contents == browser.contents
+    True
+
+
+goBack doesn't work. XXX
+
+    >>> browser.getLink('[top]', index=0).click()
+    >>> browser.goBack()
+    >>> import time; time.sleep(1) # XXX race condition
+    >>> original_contents == browser.contents
+    False
+
+When we're done with the browser we have to close it.
+
+    >>> browser.close()


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/tests.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/tests.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/tests.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test Browser Tests
+
+$Id$
+"""
+import unittest
+import doctest
+from zope.app.testing.functional import FunctionalDocFileSuite
+
+def test_suite():
+    flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
+    real = FunctionalDocFileSuite('real.txt', optionflags=flags)
+    real.level = 2
+    return unittest.TestSuite((real))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/utilities.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/utilities.py	2006-07-29 18:26:06 UTC (rev 69293)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/utilities.py	2006-07-30 02:22:10 UTC (rev 69294)
@@ -0,0 +1,121 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Utilities used by the package
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import re
+import sys
+import time
+from test import pystone
+
+class AmbiguityError(KeyError):
+    pass
+
+RegexType = type(re.compile(''))
+_compress_re = re.compile(r"\s+")
+compressText = lambda text: _compress_re.sub(' ', text.strip())
+
+def disambiguate(intermediate, msg, index):
+    if intermediate:
+        if index is None:
+            if len(intermediate) > 1:
+                raise AmbiguityError(msg)
+            else:
+                return intermediate[0]
+        else:
+            try:
+                return intermediate[index]
+            except KeyError:
+                msg = '%s index %d' % (msg, index)
+    raise LookupError(msg)
+
+def any(items):
+    return bool(sum([bool(i) for i in items]))
+
+def onlyOne(items, description):
+    total = sum([bool(i) for i in items])
+    if total == 0 or total > 1:
+        raise ValueError(
+            "Supply one and only one of %s as arguments" % description)
+
+def zeroOrOne(items, description):
+    if sum([bool(i) for i in items]) > 1:
+        raise ValueError(
+            "Supply no more than one of %s as arguments" % description)
+
+
+class SetattrErrorsMixin(object):
+    _enable_setattr_errors = False
+
+    def __setattr__(self, name, value):
+        if self._enable_setattr_errors:
+            # cause an attribute error if the attribute doesn't already exist
+            getattr(self, name)
+
+        # set the value
+        object.__setattr__(self, name, value)
+
+
+class PystoneTimer(object):
+    start_time = 0
+    end_time = 0
+    _pystones_per_second = None
+
+    @property
+    def pystonesPerSecond(self):
+        """How many pystones are equivalent to one second on this machine"""
+        if self._pystones_per_second == None:
+            self._pystones_per_second = pystone.pystones(pystone.LOOPS/10)[1]
+        return self._pystones_per_second
+
+    def _getTime(self):
+        if sys.platform.startswith('win'):
+            # Windows' time.clock gives us high-resolution wall-time
+            return time.clock()
+        else:
+            # everyone else uses time.time
+            return time.time()
+
+    def start(self):
+        """Begin a timing period"""
+        self.start_time = self._getTime()
+        self.end_time = None
+
+    def stop(self):
+        """End a timing period"""
+        self.end_time = self._getTime()
+
+    @property
+    def elapsedSeconds(self):
+        """Elapsed time from calling `start` to calling `stop` or present time
+
+        If `stop` has been called, the timing period stopped then, otherwise
+        the end is the current time.
+        """
+        if self.end_time is None:
+            end_time = self._getTime()
+        else:
+            end_time = self.end_time
+        return end_time - self.start_time
+
+    @property
+    def elapsedPystones(self):
+        """Elapsed pystones in timing period
+
+        See elapsed_seconds for definition of timing period.
+        """
+        return self.elapsedSeconds * self.pystonesPerSecond


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/utilities.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list