<s> """<STR_LIT>""" <EOL> import urlparse <EOL> from google . appengine . ext import db <EOL> from codereview . exceptions import FetchError <EOL> def make_url ( base , filename , rev ) : <EOL> """<STR_LIT>""" <EOL> scheme , netloc , path , _ , _ , _ = urlparse . urlparse ( base ) <EOL> if netloc . endswith ( "<STR_LIT>" ) : <EOL> if rev is None : <EOL> raise FetchError ( "<STR_LIT>" ) <EOL> if not path . startswith ( "<STR_LIT>" ) : <EOL> raise FetchError ( "<STR_LIT>" % base ) <EOL> path = path [ <NUM_LIT:5> : ] <EOL> url = "<STR_LIT>" % ( scheme , netloc , rev , <EOL> path , filename ) <EOL> return url <EOL> elif netloc . endswith ( "<STR_LIT>" ) and rev is not None : <EOL> if path . strip ( ) . endswith ( "<STR_LIT:/>" ) : <EOL> path = path . strip ( ) [ : - <NUM_LIT:1> ] <EOL> else : <EOL> path = path . strip ( ) <EOL> splitted_path = path . split ( "<STR_LIT:/>" ) <EOL> url = "<STR_LIT>" % ( scheme , netloc , <EOL> "<STR_LIT:/>" . join ( splitted_path [ <NUM_LIT:1> : <NUM_LIT:3> ] ) , rev , <EOL> "<STR_LIT:/>" . join ( splitted_path [ <NUM_LIT:3> : ] ) , <EOL> filename ) <EOL> return url <EOL> url = base <EOL> if not url . endswith ( '<STR_LIT:/>' ) : <EOL> url += '<STR_LIT:/>' <EOL> url += filename <EOL> if rev is not None : <EOL> url += '<STR_LIT>' % rev <EOL> return url <EOL> def to_dbtext ( text ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( text , unicode ) : <EOL> return db . Text ( text ) <EOL> else : <EOL> try : <EOL> return db . Text ( text , encoding = '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError : <EOL> return db . Text ( text , encoding = '<STR_LIT>' ) <EOL> def unify_linebreaks ( text ) : <EOL> """<STR_LIT>""" <EOL> return text . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) . replace ( '<STR_LIT:\r>' , '<STR_LIT:\n>' ) </s>
