Commits

Anonymous committed 4cb933f

Refactor external dependencies and add docstrings and tests.

Comments (0)

Files changed (1)

unfinished/stringex.py

 
 """
 import re
+from webhelpers.html.tools import strip_tags
 
-from unidecode import unidecode
-from webob.exc import strip_tags
-
+try:
+    from unidecode import unidecode
+except ImportError:
+    unidecode = None
 
 def urlify(string):
     """Create a URI-friendly representation of the string
     
     Can be called manually in order to generate an URI-friendly version
     of any string.
-    
+
+    If the ``unidecode`` package is installed, it will also convert 
+    non-ASCII Latin characters to intelligent ASCII equivalents.
+
+    Examples::
+        >>> urlify("Mighty Mighty Bosstones")
+        'mighty-mighty-bosstones'
     """
     s = remove_formatting(string).lower()
     s = replace_whitespace(s, '-')
 
 
 def remove_formatting(string):
-    """Performs multiple text manipulations.
+    """Simplify HTML text by removing tags and several kinds of formatting.
     
-    Essentially a shortcut for typing them all. View source below to
-    see which methods are run.
-    
+    If the ``unidecode`` package is installed, it will also convert 
+    non-ASCII Latin characters to intelligent ASCII equivalents.
     """
     s = strip_tags(string)
     s = convert_accented_entities(s)
     s = convert_misc_entities(s)
     s = convert_misc_characters(s)
-    return collapse(unidecode(s))
+    if unidecode:
+        s = unidecode(s)
+    return collapse(s)
 
 
 def convert_accented_entities(string):
       "ø".convert_accented_entities #: "o"
       "ü".convert_accented_entities #: "u"
     
-    Note: This does not do any conversion of Unicode/Ascii
+    Note: This does not do any conversion of Unicode/ASCII
     accented-characters. For that functionality please use unidecode.
     
     """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.