.. include:: headings.inc .. _FileSystemHandler: ========================================================================================================================================== |phoenix_title| **FileSystemHandler** ========================================================================================================================================== Classes derived from :ref:`FileSystemHandler` are used to access virtual file systems. Its public interface consists of two methods: :meth:`FileSystemHandler.CanOpen` and :meth:`FileSystemHandler.OpenFile` . It provides additional protected methods to simplify the process of opening the file: :meth:`~FileSystemHandler.GetProtocol`, :meth:`~FileSystemHandler.GetLeftLocation`, :meth:`~FileSystemHandler.GetRightLocation`, :meth:`~FileSystemHandler.GetAnchor`, :meth:`~FileSystemHandler.GetMimeTypeFromExt`. Please have a look at overview (see :ref:`FileSystem`) if you don't know how locations are constructed. Also consult the :ref:`list of available handlers `. Note that the handlers are shared by all instances of :ref:`FileSystem`. .. note:: ``HTML`` library provides handlers for local files and ``HTTP`` or ``FTP`` protocol. .. note:: The location parameter passed to :meth:`OpenFile` or :meth:`CanOpen` methods is always an absolute path. You don't need to check the FS's current path. .. seealso:: :ref:`FileSystem`, :ref:`FSFile`, :ref:`FileSystem Overview ` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **FileSystemHandler** .. raw:: html

Inheritance diagram of FileSystemHandler

| |sub_classes| Known Subclasses ============================== :ref:`ArchiveFSHandler`, :ref:`FilterFSHandler`, :ref:`InternetFSHandler`, :ref:`MemoryFSHandler` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~FileSystemHandler.__init__` Constructor. :meth:`~FileSystemHandler.CanOpen` Returns ``True`` if the handler is able to open this file. :meth:`~FileSystemHandler.FindFirst` Works like :func:`FindFirstFile`. :meth:`~FileSystemHandler.FindNext` Returns next filename that matches parameters passed to :meth:`FileSystem.FindFirst` . :meth:`~FileSystemHandler.GetMimeTypeFromExt` Returns the ``MIME`` type based on **extension** of `location`. :meth:`~FileSystemHandler.OpenFile` Opens the file and returns :ref:`FSFile` pointer or ``None`` if failed. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: FileSystemHandler(Object) Classes derived from FileSystemHandler are used to access virtual file systems. **Possible constructors**:: FileSystemHandler() .. method:: __init__(self) Constructor. .. method:: CanOpen(self, location) Returns ``True`` if the handler is able to open this file. This function doesn't check whether the file exists or not, it only checks if it knows the protocol. Example: :: def CanOpen(self, location): return self.GetProtocol(location) == "http" Must be overridden in derived handlers. :param `location`: :type `location`: string :rtype: `bool` .. method:: FindFirst(self, wildcard, flags=0) Works like :func:`FindFirstFile`. Returns the name of the first filename (within filesystem's current path) that matches `wildcard`. `flags` may be one of ``FILE`` (only files), ``DIR`` (only directories) or 0 (both). This method is only called if :meth:`CanOpen` returns ``True``. :param `wildcard`: :type `wildcard`: string :param `flags`: :type `flags`: int :rtype: `string` .. method:: FindNext(self) Returns next filename that matches parameters passed to :meth:`FileSystem.FindFirst` . This method is only called if :meth:`CanOpen` returns ``True`` and :meth:`FindFirst` returned a non-empty string. :rtype: `string` .. staticmethod:: GetMimeTypeFromExt(location) Returns the ``MIME`` type based on **extension** of `location`. (While :meth:`FSFile.GetMimeType` returns real ``MIME`` type - either extension-based or queried from ``HTTP``.) Example: :: if GetMimeTypeFromExt("index.htm") == "text/html": wx.MessageBox("Is HTML!") :param `location`: :type `location`: string :rtype: `string` .. method:: OpenFile(self, fs, location) Opens the file and returns :ref:`FSFile` pointer or ``None`` if failed. Must be overridden in derived handlers. :param `fs`: Parent ``FS`` (the ``FS`` from that OpenFile was called). See the ``ZIP`` handler for details of how to use it. :type `fs`: FileSystem :param `location`: The absolute location of file. :type `location`: string :rtype: :ref:`FSFile`