Back to index

plone3  3.1.7
Classes | Functions
five.customerize.browser Namespace Reference

Classes

class  CustomizationView
class  RegistrationsView

Functions

def mangleAbsoluteFilename

Function Documentation

Mangle an absolute filename when the file happens to be in a
package.  The mangled name will then be of the form::

  <dotted package name>/<base filename>.

For example, let's take Five's configure.zcml as an example.  We
assemble it in an OS-independent way so this test works on all
platforms:

  >>> def filesystemPath(*elements):
  ...     return sep.join(elements)

We see that the filename is now mangled:

  >>> mangleAbsoluteFilename(filesystemPath(
  ...     '', 'path', 'to', 'Products', 'Five', 'configure.zcml'))
  'Products.Five/configure.zcml'

The name of a file that's not in a package is returned unchanged:

  >>> not_in_a_package = filesystemPath('', 'path', 'to', 'configure.zcml')
  >>> mangleAbsoluteFilename(not_in_a_package) == not_in_a_package
  True

Definition at line 22 of file browser.py.

00022 
00023 def mangleAbsoluteFilename(filename):
00024     """
00025     Mangle an absolute filename when the file happens to be in a
00026     package.  The mangled name will then be of the form::
00027 
00028       <dotted package name>/<base filename>.
00029 
00030     For example, let's take Five's configure.zcml as an example.  We
00031     assemble it in an OS-independent way so this test works on all
00032     platforms:
00033     
00034       >>> def filesystemPath(*elements):
00035       ...     return sep.join(elements)
00036 
00037     We see that the filename is now mangled:
00038 
00039       >>> mangleAbsoluteFilename(filesystemPath(
00040       ...     '', 'path', 'to', 'Products', 'Five', 'configure.zcml'))
00041       'Products.Five/configure.zcml'
00042 
00043     The name of a file that's not in a package is returned unchanged:
00044 
00045       >>> not_in_a_package = filesystemPath('', 'path', 'to', 'configure.zcml')
00046       >>> mangleAbsoluteFilename(not_in_a_package) == not_in_a_package
00047       True
00048     """
00049     if not isabs(filename):
00050         raise ValueError("Can only determine package for absolute filenames")
00051     dir, base = split(filename)
00052     pieces = dir.split(sep)
00053     if pieces[0] == '':
00054         pieces = pieces[1:]
00055     while pieces:
00056         try:
00057             resolve('.'.join(pieces))
00058             break
00059         except (ImportError, ValueError):
00060             pieces = pieces[1:]
00061     if not pieces:
00062         return filename
00063     return '.'.join(pieces) + '/' + base

Here is the call graph for this function:

Here is the caller graph for this function: