Working on python 3 compatibility.

Making changes throughout the code for compatibility with Python v3.3.
  - importing pickle and StringIO with try/except clauses.
  - changing xrange to range
  - adding iteritems, itervalues, and iterkeys methods to the namespace
    to be compatible with both python 2 and 3 via try/except statements.
  - switching to use of iteritems, itervalues, and iterkeys methods.
  - adding explicit int() around integer division to ensure the result
    is an int in either python 2 or 3.