Back to index

plone3  3.1.7
Public Member Functions
plone.i18n.normalizer.FileNameNormalizer Class Reference

List of all members.

Public Member Functions

def normalize

Detailed Description

This normalizer can normalize any unicode string and returns a version
that only contains of ASCII characters allowed in a file name.

Let's make sure that this implementation actually fulfills the API.

  >>> from zope.interface.verify import verifyClass
  >>> verifyClass(IFileNameNormalizer, FileNameNormalizer)
  True

Definition at line 97 of file __init__.py.


Member Function Documentation

def plone.i18n.normalizer.FileNameNormalizer.normalize (   self,
  text,
  locale = None,
  max_length = MAX_FILENAME_LENGTH 
)
Returns a normalized text. text has to be a unicode string and locale
should be a normal locale, for example: 'pt_BR', 'sr@Latn' or 'de'

Definition at line 110 of file __init__.py.

00110 
00111     def normalize(self, text, locale=None, max_length=MAX_FILENAME_LENGTH):
00112         """
00113         Returns a normalized text. text has to be a unicode string and locale
00114         should be a normal locale, for example: 'pt_BR', 'sr@Latn' or 'de'
00115         """
00116         if locale is not None:
00117             # Try to get a normalizer for the locale
00118             util = queryUtility(IFileNameNormalizer, name=locale)
00119             parts = locale.split('_')
00120             if util is None and len(parts) > 1:
00121                 # Try to get a normalizer for the base language if we asked
00122                 # for one for a language/country combination and found none
00123                 util = queryUtility(IFileNameNormalizer, name=parts[0])
00124             if util is not None:
00125                 text = util.normalize(text, locale=locale)
00126 
00127         # Preserve filename extensions
00128         base = text = baseNormalize(text)
00129         ext  = ''
00130 
00131         m = FILENAME_REGEX.match(text)
00132         if m is not None:
00133             base = m.groups()[0]
00134             ext  = m.groups()[1]
00135 
00136         base = IGNORE_REGEX.sub('', base)
00137         base = DANGEROUS_CHARS_REGEX.sub('-', base)
00138         base = EXTRA_DASHES_REGEX.sub('', base)
00139         base = MULTIPLE_DASHES_REGEX.sub('-', base)
00140 
00141         base = cropName(base, maxLength=max_length)
00142 
00143         if ext != '':
00144             base = base + '.' + ext
00145 
00146         return base
00147 

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: