<s> """<STR_LIT>""" <EOL> import re <EOL> from xml . sax . saxutils import quoteattr <EOL> from jinja2 import Markup <EOL> from . helpers import local , to_unicode , url_for <EOL> __all__ = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ) <EOL> def dumb_plural ( num , plural = '<STR_LIT:s>' , singular = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return plural if num != <NUM_LIT:1> else singular <EOL> def html_attrs ( classes = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> attrs = [ ] <EOL> props = [ ] <EOL> classes = classes . strip ( ) <EOL> if classes : <EOL> classes = to_unicode ( quoteattr ( classes ) ) <EOL> attrs . append ( '<STR_LIT>' % classes ) <EOL> for key , value in kwargs . iteritems ( ) : <EOL> key = key . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> key = to_unicode ( key ) <EOL> if isinstance ( value , bool ) : <EOL> if value is True : <EOL> props . append ( key ) <EOL> else : <EOL> value = quoteattr ( to_unicode ( value ) ) <EOL> attrs . append ( u'<STR_LIT>' % ( key , value ) ) <EOL> attrs . sort ( ) <EOL> props . sort ( ) <EOL> attrs . extend ( props ) <EOL> return u'<STR_LIT:U+0020>' . join ( attrs ) <EOL> URL_RE = ur '<STR_LIT>' <EOL> def link_to ( text = '<STR_LIT>' , endpoint = '<STR_LIT>' , classes = '<STR_LIT>' , wrapper = None , partial = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> request = local . request <EOL> path = request . path . rstrip ( '<STR_LIT:/>' ) <EOL> patterns = endpoint if isinstance ( endpoint , ( list , tuple ) ) else [ endpoint ] <EOL> patterns = [ p <EOL> if p . startswith ( '<STR_LIT:/>' ) or re . match ( URL_RE , p ) else url_for ( p ) <EOL> for p in patterns ] <EOL> for url in patterns : <EOL> url = url . rstrip ( '<STR_LIT:/>' ) <EOL> if path == url or ( partial and path . startswith ( url ) ) : <EOL> classes += '<STR_LIT>' <EOL> break <EOL> data = { <EOL> '<STR_LIT:url>' : patterns [ <NUM_LIT:0> ] , <EOL> '<STR_LIT:text>' : text , <EOL> '<STR_LIT>' : html_attrs ( classes , ** kwargs ) , <EOL> } <EOL> data [ '<STR_LIT>' ] = '<STR_LIT:U+0020>' + data [ '<STR_LIT>' ] if data [ '<STR_LIT>' ] else '<STR_LIT>' <EOL> if wrapper : <EOL> data [ '<STR_LIT>' ] = str ( wrapper ) . lower ( ) <EOL> tmpl = u'<STR_LIT>' <EOL> else : <EOL> tmpl = u'<STR_LIT>' <EOL> return Markup ( tmpl % data ) </s>
