Anonymous avatar Anonymous committed 34eee68

[svn] Moved escape function into util with partial

Comments (0)

Files changed (7)

webhelpers/escapes.py

-# $Id: escapes.py 2013 2005-12-31 03:19:39Z zzzeek $
-# escapes.py - string escaping functions for Myghty
-# Copyright (C) 2004, 2005 Michael Bayer mike_mp@zzzcomputing.com
-# Original Perl code and documentation copyright (c) 1998-2003 by Jonathan Swartz. 
-#
-# This module is part of Myghty and is released under
-# the MIT License: http://www.opensource.org/licenses/mit-license.php
-#
-
-
-import cgi
-
-def html_escape(s):
-    """HTML-escape a string or object
-
-    This converts any non-string objects passed into it to strings
-    (actually, using ``unicode()``).  All values returned are
-    non-unicode strings (using ``&#num;`` entities for all non-ASCII
-    characters).
-
-    None is treated specially, and returns the empty string.
-    """
-    if s is None:
-        return ''
-    if not isinstance(s, basestring):
-        s = unicode(s)
-    s = cgi.escape(s, True)
-    if isinstance(s, unicode):
-        s = s.encode('ascii', 'xmlcharrefreplace')
-    return s

webhelpers/htmlgen.py

    happen in webhelpers.
 """
 
-from escapes import html_escape
+from util import html_escape
 
 __all__ = ['html']
 

webhelpers/rails/form_options.py

 Form Options Helpers
 """
 
-from webhelpers.escapes import html_escape
+from webhelpers.util import html_escape
 
 def options_for_select(container, selected = None):
     """

webhelpers/rails/form_tag.py

 """
 
 from tags import *
-from webhelpers.escapes import html_escape
+from webhelpers.util import html_escape
 
 def form(url, **options):
     """

webhelpers/rails/tags.py

 """
 Tag Helpers
 """
-from webhelpers.escapes import html_escape
+from webhelpers.util import html_escape
 import re
 
 def camelize(name):

webhelpers/rails/urls.py

 """
 import cgi
 
-from webhelpers.escapes import html_escape
+from webhelpers.util import html_escape
 
 from routes import url_for, request_config
 from javascript import *

webhelpers/util.py

+"""Utility functions used by various web helpers"""
+import cgi
+
+def html_escape(s):
+    """HTML-escape a string or object
+    
+    This converts any non-string objects passed into it to strings
+    (actually, using ``unicode()``).  All values returned are
+    non-unicode strings (using ``&#num;`` entities for all non-ASCII
+    characters).
+    
+    None is treated specially, and returns the empty string.
+    """
+    if s is None:
+        return ''
+    if not isinstance(s, basestring):
+        s = unicode(s)
+    s = cgi.escape(s, True)
+    if isinstance(s, unicode):
+        s = s.encode('ascii', 'xmlcharrefreplace')
+    return s
+
+class Partial(object):
+    """partial object, which will be in Python 2.5"""
+    def __init__(*args, **kw):
+        self = args[0]
+        self.fn, self.args, self.kw = (args[1], args[2:], kw)
+    
+    def __call__(self, *args, **kw):
+        if kw and self.kw:
+            d = self.kw.copy()
+            d.update(kw)
+        else:
+            d = kw or self.kw
+        return self.fn(*(self.args + args), **d)
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.