Back to index

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

List of all members.

Public Member Functions

def normalize

Detailed Description

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

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

  >>> from zope.interface.verify import verifyClass
  >>> verifyClass(IURLNormalizer, URLNormalizer)
  True

Definition at line 148 of file __init__.py.


Member Function Documentation

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

00161 
00162     def normalize(self, text, locale=None, max_length=MAX_URL_LENGTH):
00163         """
00164         Returns a normalized text. text has to be a unicode string and locale
00165         should be a normal locale, for example: 'pt_BR', 'sr@Latn' or 'de'
00166         """
00167         if locale is not None:
00168             # Try to get a normalizer for the locale
00169             util = queryUtility(IURLNormalizer, name=locale)
00170             parts = locale.split('_')
00171             if util is None and len(parts) > 1:
00172                 # Try to get a normalizer for the base language if we asked
00173                 # for one for a language/country combination and found none
00174                 util = queryUtility(IURLNormalizer, name=parts[0])
00175             if util is not None:
00176                 text = util.normalize(text, locale=locale)
00177 
00178         text = baseNormalize(text)
00179 
00180         # lowercase text
00181         base = text.lower()
00182         ext  = ''
00183 
00184         m = FILENAME_REGEX.match(base)
00185         if m is not None:
00186             base = m.groups()[0]
00187             ext  = m.groups()[1]
00188 
00189         base = base.replace(' ', '-')
00190         base = IGNORE_REGEX.sub('', base)
00191         base = URL_DANGEROUS_CHARS_REGEX.sub('-', base)
00192         base = EXTRA_DASHES_REGEX.sub('', base)
00193         base = MULTIPLE_DASHES_REGEX.sub('-', base)
00194 
00195         base = cropName(base, maxLength=max_length)
00196 
00197         if ext != '':
00198             base = base + '.' + ext
00199 
00200         return base

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: