<s> from django_seo_js import settings <EOL> from base import SEOBackendBase , RequestsBasedBackend <EOL> class PrerenderIO ( SEOBackendBase , RequestsBasedBackend ) : <EOL> """<STR_LIT>""" <EOL> BASE_URL = "<STR_LIT>" <EOL> RECACHE_URL = "<STR_LIT>" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SEOBackendBase , self ) . __init__ ( * args , ** kwargs ) <EOL> self . token = self . _get_token ( ) <EOL> def _get_token ( self ) : <EOL> if settings . PRERENDER_TOKEN is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return settings . PRERENDER_TOKEN <EOL> def get_response_for_url ( self , url ) : <EOL> """<STR_LIT>""" <EOL> if not url or "<STR_LIT>" not in url : <EOL> raise ValueError ( "<STR_LIT>" % url ) <EOL> render_url = self . BASE_URL + url <EOL> headers = { <EOL> '<STR_LIT>' : self . token , <EOL> } <EOL> r = self . session . get ( render_url , headers = headers , allow_redirects = False ) <EOL> assert r . status_code < <NUM_LIT> <EOL> return self . build_django_response_from_requests_response ( r ) <EOL> def update_url ( self , url = None , regex = None ) : <EOL> """<STR_LIT>""" <EOL> if not url and not regex : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> headers = { <EOL> '<STR_LIT>' : self . token , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> } <EOL> data = { <EOL> '<STR_LIT>' : settings . PRERENDER_TOKEN , <EOL> } <EOL> if url : <EOL> data [ "<STR_LIT:url>" ] = url <EOL> if regex : <EOL> data [ "<STR_LIT>" ] = regex <EOL> r = self . session . post ( self . RECACHE_URL , headers = headers , data = data ) <EOL> return r . status_code < <NUM_LIT> <EOL> class PrerenderHosted ( PrerenderIO ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SEOBackendBase , self ) . __init__ ( * args , ** kwargs ) <EOL> self . token = "<STR_LIT>" <EOL> if not settings . PRERENDER_URL : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not settings . PRERENDER_RECACHE_URL : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . BASE_URL = settings . PRERENDER_URL <EOL> self . RECACHE_URL = settings . PRERENDER_RECACHE_URL <EOL> def _get_token ( self ) : <EOL> pass <EOL> def update_url ( self , url = None ) : <EOL> """<STR_LIT>""" <EOL> if not url : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> post_url = "<STR_LIT>" % ( self . BASE_URL , url ) <EOL> r = self . session . post ( post_url ) <EOL> return int ( r . status_code ) < <NUM_LIT> </s>
