<s> from django . core . cache import cache <EOL> import requests <EOL> import re <EOL> RX = re . compile ( r'<STR_LIT>' , flags = re . U + re . I ) <EOL> class Singleton ( type ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( cls , name , bases , dct ) : <EOL> cls . __instance = None <EOL> type . __init__ ( cls , name , bases , dct ) <EOL> def __call__ ( cls , * args , ** kw ) : <EOL> if cls . __instance is None : <EOL> cls . __instance = type . __call__ ( cls , * args , ** kw ) <EOL> return cls . __instance <EOL> def get_url_data ( url ) : <EOL> response = requests . get ( url ) <EOL> if response . status_code == <NUM_LIT:200> : <EOL> pos = RX . findall ( response . content ) <EOL> if len ( pos ) > <NUM_LIT:0> : <EOL> return pos [ <NUM_LIT:0> ] , url <EOL> return url , url <EOL> def cacheable ( cache_key , timeout = <NUM_LIT> ) : <EOL> def paramed_decorator ( func ) : <EOL> def decorated ( self , * args , ** kwargs ) : <EOL> key = cache_key % self . __dict__ <EOL> res = cache . get ( key ) <EOL> if res == None : <EOL> res = func ( self , * args , ** kwargs ) <EOL> cache . set ( key , res , timeout ) <EOL> return res <EOL> decorated . __doc__ = func . __doc__ <EOL> decorated . __dict__ = func . __dict__ <EOL> return decorated <EOL> return paramed_decorator </s>
