Back to index

plone3  3.1.7
Public Member Functions
plone.i18n.normalizer.IDNormalizer 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 typical
scripting or programming language id, such as CSS class names or Python
variable names for example.

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

  >>> from zope.interface.verify import verifyClass
  >>> verifyClass(IIDNormalizer, IDNormalizer)
  True

Definition at line 41 of file __init__.py.


Member Function Documentation

def plone.i18n.normalizer.IDNormalizer.normalize (   self,
  text,
  locale = None,
  max_length = MAX_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 56 of file __init__.py.

00056 
00057     def normalize(self, text, locale=None, max_length=MAX_LENGTH):
00058         """
00059         Returns a normalized text. text has to be a unicode string and locale
00060         should be a normal locale, for example: 'pt_BR', 'sr@Latn' or 'de'
00061         """
00062         if locale is not None:
00063             # Try to get a normalizer for the locale
00064             util = queryUtility(IIDNormalizer, name=locale)
00065             parts = locale.split('_')
00066             if util is None and len(parts) > 1:
00067                 # Try to get a normalizer for the base language if we asked
00068                 # for one for a language/country combination and found none
00069                 util = queryUtility(IIDNormalizer, name=parts[0])
00070             if util is not None:
00071                 text = util.normalize(text, locale=locale)
00072 
00073         text = baseNormalize(text)
00074 
00075         # lowercase text
00076         base = text.lower()
00077         ext  = ''
00078 
00079         # replace whitespace and punctuation, but preserve filename extensions
00080         m = FILENAME_REGEX.match(text)
00081         if m is not None:
00082             base = m.groups()[0]
00083             ext  = m.groups()[1]
00084 
00085         base = IGNORE_REGEX.sub('', base)
00086         base = NON_WORD_REGEX.sub('-', base)
00087         base = MULTIPLE_DASHES_REGEX.sub('-', base)
00088         base = EXTRA_DASHES_REGEX.sub('', base)
00089 
00090         base = cropName(base, maxLength=max_length)
00091         
00092         if ext != '':
00093             base = base + '.' + ext
00094 
00095         return base
00096 

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: