PyXWF.utils – Miscellaneous


Converts the given ETree tree from XHTML to HTML in-place. Raises ValueError if a non-XHTML namespace is encountered.

PyXWF.utils.add_class(node, cls)[source]

Take the @class attribute of node, split it at spaces, put it into a set, add cls to the set and re-join the set with spaces.

PyXWF.utils.file_last_modified(fileref, float_times=False)[source]

If fileref is a file name or a file like with associated fileno which points to an actual file, return the date of last modification stored in the filesystem, None otherwise.

By default, the times are truncated to full seconds. If you need the floating point part of the times (if supported by the platform), pass True to float_times.


Return a tuple (useragent, version), where useragent is one of:

  • ie for Internet Explorer™
  • firefox for firefox
  • mozilla for mozilla
  • opera for opera
  • safari for safari
  • links for links
  • lynx for lynx
  • wget for wget
  • chrome for chrome
  • yahoo-slurp for yahoo slurp bot
  • konqueror for konqueror
  • googlebot for googlebot
  • None for each unknown user agent

version will be either the version number of the user agent or None if the version could not be determined reliably. The version number is represented as a floating point value.


Parse a date like returned with isoformat(), but with a trailing Z to indicate the UTC timezone.


Split an ElementTree tag into its namespace and XML local-name and return these as a tuple (namespace, localname). If the tag has no namespace associated, None is returned for namespace.

Previous topic

Various utilities

Next topic

PyXWF.HTTPUtils – Utility functions for HTTP

This Page