<s> from BeautifulSoup import BeautifulSoup , BeautifulStoneSoup <EOL> from django . http import HttpResponse <EOL> from urllib2 import build_opener , URLError , urlopen <EOL> from urlparse import urljoin <EOL> from django . db . models import aggregates <EOL> from django . db . models . sql import aggregates as sql_aggregates <EOL> from django . utils import simplejson <EOL> client = build_opener ( ) <EOL> client . addheaders = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def get_info ( url ) : <EOL> """<STR_LIT>""" <EOL> def fix_url ( url ) : <EOL> if not url . startswith ( "<STR_LIT:http>" ) or not url . startswith ( "<STR_LIT>" ) : <EOL> return urljoin ( resp_dict [ '<STR_LIT:url>' ] , url ) <EOL> else : <EOL> return url <EOL> resp_dict = { } <EOL> if not url or not ( url . startswith ( '<STR_LIT>' ) or <EOL> url . startswith ( '<STR_LIT>' ) ) : <EOL> return resp_dict <EOL> try : <EOL> opener = client . open ( url , None , timeout = <NUM_LIT:15> ) <EOL> except URLError : <EOL> return resp_dict <EOL> resp_dict = { "<STR_LIT:url>" : url , "<STR_LIT>" : [ ] } <EOL> if "<STR_LIT>" in opener . info ( ) . getheaders ( '<STR_LIT>' ) [ <NUM_LIT:0> ] : <EOL> data = opener . read ( ) <EOL> opener . close ( ) <EOL> bs = BeautifulSoup ( data ) <EOL> if not bs : <EOL> return resp_dict <EOL> og_title_bs = bs . find ( "<STR_LIT>" , attrs = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> if og_title_bs : <EOL> resp_dict [ '<STR_LIT:title>' ] = og_title_bs [ '<STR_LIT:content>' ] <EOL> else : <EOL> del ( og_title_bs ) <EOL> try : <EOL> title_bs = bs . html . head . title <EOL> except AttributeError : <EOL> title_bs = None <EOL> if title_bs and title_bs . string : <EOL> resp_dict [ '<STR_LIT:title>' ] = title_bs . string <EOL> og_desc_bs = bs . find ( "<STR_LIT>" , attrs = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> if og_desc_bs : <EOL> resp_dict [ '<STR_LIT:description>' ] = og_desc_bs [ '<STR_LIT:content>' ] <EOL> else : <EOL> del ( og_desc_bs ) <EOL> try : <EOL> desc_bs = bs . find ( "<STR_LIT>" , attrs = { "<STR_LIT>" : "<STR_LIT:description>" } ) <EOL> except AttributeError : <EOL> desc_bs = None <EOL> if desc_bs and desc_bs . string : <EOL> resp_dict [ '<STR_LIT:description>' ] = desc_bs . string <EOL> img_bs = bs . find ( "<STR_LIT>" , attrs = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> if img_bs and img_bs . get ( "<STR_LIT:content>" ) : <EOL> resp_dict [ '<STR_LIT>' ] . append ( img_bs . get ( '<STR_LIT:content>' ) ) <EOL> del ( img_bs ) <EOL> img_src_bs = bs . find ( "<STR_LIT>" , attrs = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> if img_src_bs : <EOL> resp_dict [ '<STR_LIT>' ] . append ( img_src_bs . get ( '<STR_LIT>' ) ) <EOL> resp_dict [ '<STR_LIT>' ] = "<STR_LIT>" % img_src_bs [ '<STR_LIT>' ] <EOL> imgs_bs = bs . findAll ( "<STR_LIT>" ) <EOL> if imgs_bs : <EOL> resp_dict [ '<STR_LIT>' ] . extend ( [ img_bs . get ( '<STR_LIT:src>' ) for img_bs in imgs_bs ] ) <EOL> if '<STR_LIT:title>' in resp_dict : <EOL> resp_dict [ '<STR_LIT:title>' ] = resp_dict [ '<STR_LIT:title>' ] . strip ( ) <EOL> try : <EOL> resp_dict [ '<STR_LIT:title>' ] = BeautifulStoneSoup ( <EOL> resp_dict [ '<STR_LIT:title>' ] , <EOL> convertEntities = BeautifulStoneSoup . HTML_ENTITIES <EOL> ) . contents [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> pass <EOL> if '<STR_LIT:description>' in resp_dict : <EOL> resp_dict [ '<STR_LIT:description>' ] == resp_dict [ '<STR_LIT:description>' ] . strip ( ) <EOL> try : <EOL> resp_dict [ '<STR_LIT:description>' ] = BeautifulStoneSoup ( <EOL> resp_dict [ '<STR_LIT:description>' ] , <EOL> convertEntities = BeautifulStoneSoup . HTML_ENTITIES <EOL> ) . contents [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> pass <EOL> except IndexError : <EOL> pass <EOL> resp_dict [ '<STR_LIT>' ] = filter ( lambda x : x != None , resp_dict [ '<STR_LIT>' ] ) <EOL> resp_dict [ '<STR_LIT>' ] = map ( fix_url , resp_dict [ '<STR_LIT>' ] ) <EOL> resp_dict [ '<STR_LIT>' ] = list ( set ( resp_dict [ '<STR_LIT>' ] ) ) <EOL> embed_bs = bs . find ( '<STR_LIT>' , attrs = { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> if embed_bs : <EOL> try : <EOL> embed_link_opener = urlopen ( embed_bs [ '<STR_LIT>' ] , None , timeout = <NUM_LIT:15> ) <EOL> except URLError : <EOL> embed_link_opener = None <EOL> if embed_link_opener : <EOL> try : <EOL> embed_data = simplejson . loads ( embed_link_opener . read ( ) ) <EOL> except ValueError : <EOL> embed_data = None <EOL> if embed_data : <EOL> try : <EOL> resp_dict [ '<STR_LIT>' ] = embed_data [ '<STR_LIT:html>' ] <EOL> except IndexError : <EOL> exit <EOL> else : <EOL> og_video_bs = bs . find ( "<STR_LIT>" , attrs = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> if og_video_bs : <EOL> resp_dict [ '<STR_LIT>' ] = "<STR_LIT>" % og_video_bs [ '<STR_LIT:content>' ] <EOL> if "<STR_LIT:image>" in opener . info ( ) . getheaders ( '<STR_LIT>' ) [ <NUM_LIT:0> ] : <EOL> resp_dict [ '<STR_LIT>' ] = [ url , ] <EOL> resp_dict [ '<STR_LIT>' ] = "<STR_LIT>" % url <EOL> opener . close ( ) <EOL> return resp_dict <EOL> class SumWithDefault ( aggregates . Aggregate ) : <EOL> name = '<STR_LIT>' <EOL> class SQLSumWithDefault ( sql_aggregates . Sum ) : <EOL> sql_template = '<STR_LIT>' <EOL> setattr ( sql_aggregates , '<STR_LIT>' , SQLSumWithDefault ) <EOL> def reduced_markdown ( text , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from markdown import blockprocessors as bp <EOL> from markdown import util <EOL> from markdown import markdown <EOL> def run_with_prettify ( self , parent , blocks ) : <EOL> """<STR_LIT>""" <EOL> sibling = self . lastChild ( parent ) <EOL> block = blocks . pop ( <NUM_LIT:0> ) <EOL> theRest = '<STR_LIT>' <EOL> if sibling and sibling . tag == "<STR_LIT>" and len ( sibling ) and sibling [ <NUM_LIT:0> ] . tag == "<STR_LIT:code>" : <EOL> code = sibling [ <NUM_LIT:0> ] <EOL> block , theRest = self . detab ( block ) <EOL> code . text = util . AtomicString ( '<STR_LIT>' % <EOL> ( code . text , block . rstrip ( ) ) ) <EOL> else : <EOL> pre = util . etree . SubElement ( parent , '<STR_LIT>' ) <EOL> pre . attrib [ '<STR_LIT:class>' ] = '<STR_LIT>' <EOL> code = util . etree . SubElement ( pre , '<STR_LIT:code>' ) <EOL> block , theRest = self . detab ( block ) <EOL> code . text = util . AtomicString ( '<STR_LIT>' % block . rstrip ( ) ) <EOL> if theRest : <EOL> blocks . insert ( <NUM_LIT:0> , theRest ) <EOL> def build_block_parser ( md_instance , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> parser = bp . BlockParser ( md_instance ) <EOL> parser . blockprocessors [ '<STR_LIT>' ] = bp . EmptyBlockProcessor ( parser ) <EOL> parser . blockprocessors [ '<STR_LIT:code>' ] = bp . CodeBlockProcessor ( parser ) <EOL> parser . blockprocessors [ '<STR_LIT>' ] = bp . OListProcessor ( parser ) <EOL> parser . blockprocessors [ '<STR_LIT>' ] = bp . UListProcessor ( parser ) <EOL> parser . blockprocessors [ '<STR_LIT>' ] = bp . BlockQuoteProcessor ( parser ) <EOL> parser . blockprocessors [ '<STR_LIT>' ] = bp . ParagraphProcessor ( parser ) <EOL> return parser <EOL> bp . build_block_parser = build_block_parser <EOL> bp . CodeBlockProcessor . run = run_with_prettify <EOL> return markdown ( text , * args , ** kwargs ) <EOL> def get_object_or_403 ( klass , * args , ** kwargs ) : <EOL> from django . shortcuts import _get_queryset <EOL> queryset = _get_queryset ( klass ) <EOL> try : <EOL> return queryset . get ( * args , ** kwargs ) <EOL> except queryset . model . DoesNotExist : <EOL> return HttpResponse ( status = <NUM_LIT> ) </s>
