diff --git a/pywb/framework/wbrequestresponse.py b/pywb/framework/wbrequestresponse.py index a234c76e..991f42a2 100644 --- a/pywb/framework/wbrequestresponse.py +++ b/pywb/framework/wbrequestresponse.py @@ -87,6 +87,17 @@ class WbRequest(object): self._parse_extra() + @property + def is_embed(self): + return (self.wb_url and + self.wb_url.mod and + self.wb_url.mod != 'id_') + + @property + def is_identity(self): + return (self.wb_url and + self.wb_url.mod == 'id_') + def _is_ajax(self): value = self.env.get('HTTP_X_REQUESTED_WITH') if not value: diff --git a/pywb/rewrite/regex_rewriters.py b/pywb/rewrite/regex_rewriters.py index 7970ab48..5f429339 100644 --- a/pywb/rewrite/regex_rewriters.py +++ b/pywb/rewrite/regex_rewriters.py @@ -25,7 +25,7 @@ class RegexRewriter(object): @staticmethod def archival_rewrite(rewriter): - return lambda string: rewriter.rewrite(string) + return lambda string: rewriter.rewrite(string, 'em_') #@staticmethod #def replacer(other): @@ -33,7 +33,7 @@ class RegexRewriter(object): HTTPX_MATCH_STR = r'https?:\\?/\\?/[A-Za-z0-9:_@.-]+' - DEFAULT_OP = add_prefix + #DEFAULT_OP = add_prefix def __init__(self, rules): #rules = self.create_rules(http_prefix) @@ -74,8 +74,8 @@ class RegexRewriter(object): return m.group(0) # Custom func - if not hasattr(op, '__call__'): - op = RegexRewriter.DEFAULT_OP(op) + #if not hasattr(op, '__call__'): + # op = RegexRewriter.DEFAULT_OP(op) result = op(m.group(i)) final_str = result @@ -124,8 +124,8 @@ class JSLinkAndLocationRewriter(JSLinkOnlyRewriter): def __init__(self, rewriter, rules=[], prefix='WB_wombat_'): rules = rules + [ - (r'(?>> parse('') - + # Unterminated script tag, handle and auto-terminate >>> parse(' + >>> parse('') - + >>> parse('
') -
+
>>> parse('') - + # Unterminated style tag, handle and auto-terminate >>> parse(' + # Head Insertion >>> parse('Test', head_insert = '') diff --git a/pywb/rewrite/test/test_lxml_html_rewriter.py b/pywb/rewrite/test/test_lxml_html_rewriter.py index 2a4c727f..acdebaf7 100644 --- a/pywb/rewrite/test/test_lxml_html_rewriter.py +++ b/pywb/rewrite/test/test_lxml_html_rewriter.py @@ -49,24 +49,24 @@ ur""" # Script tag >>> parse('') - + # Unterminated script tag, will auto-terminate >>> parse(' + >>> parse('') - + >>> parse('
') -
+
>>> parse('') - + # Unterminated style tag, handle but don't auto-terminate >>> parse(' + # Head Insertion >>> parse('Test', head_insert = '') diff --git a/pywb/rewrite/test/test_regex_rewriters.py b/pywb/rewrite/test/test_regex_rewriters.py index e4a104f2..fac38789 100644 --- a/pywb/rewrite/test/test_regex_rewriters.py +++ b/pywb/rewrite/test/test_regex_rewriters.py @@ -12,16 +12,16 @@ r""" #================================================================= >>> _test_js('location = "http://example.com/abc.html"') -'WB_wombat_location = "/web/20131010im_/http://example.com/abc.html"' +'WB_wombat_location = "/web/20131010em_/http://example.com/abc.html"' >>> _test_js(r'location = "http:\/\/example.com/abc.html"') -'WB_wombat_location = "/web/20131010im_/http:\\/\\/example.com/abc.html"' +'WB_wombat_location = "/web/20131010em_/http:\\/\\/example.com/abc.html"' >>> _test_js(r'location = "http:\\/\\/example.com/abc.html"') -'WB_wombat_location = "/web/20131010im_/http:\\\\/\\\\/example.com/abc.html"' +'WB_wombat_location = "/web/20131010em_/http:\\\\/\\\\/example.com/abc.html"' >>> _test_js(r"location = 'http://example.com/abc.html/'") -"WB_wombat_location = '/web/20131010im_/http://example.com/abc.html/'" +"WB_wombat_location = '/web/20131010em_/http://example.com/abc.html/'" >>> _test_js(r'location = http://example.com/abc.html/') 'WB_wombat_location = http://example.com/abc.html/' @@ -37,21 +37,21 @@ r""" '"/location" == some_location_val; locations = WB_wombat_location;' >>> _test_js('cool_Location = "http://example.com/abc.html"') -'cool_Location = "/web/20131010im_/http://example.com/abc.html"' +'cool_Location = "/web/20131010em_/http://example.com/abc.html"' >>> _test_js('window.location = "http://example.com/abc.html" document.domain = "anotherdomain.com"') -'window.WB_wombat_location = "/web/20131010im_/http://example.com/abc.html" document.WB_wombat_domain = "anotherdomain.com"' +'window.WB_wombat_location = "/web/20131010em_/http://example.com/abc.html" document.WB_wombat_domain = "anotherdomain.com"' >>> _test_js('document_domain = "anotherdomain.com"; window.document.domain = "example.com"') 'document_domain = "anotherdomain.com"; window.document.WB_wombat_domain = "example.com"' # custom rules added >>> _test_js('window.location = "http://example.com/abc.html"; some_func(); ', [('some_func\(\).*', RegexRewriter.format('/*{0}*/'), 0)]) -'window.WB_wombat_location = "/web/20131010im_/http://example.com/abc.html"; /*some_func(); */' +'window.WB_wombat_location = "/web/20131010em_/http://example.com/abc.html"; /*some_func(); */' # scheme-agnostic >>> _test_js('cool_Location = "//example.com/abc.html" //comment') -'cool_Location = "/web/20131010im_///example.com/abc.html" //comment' +'cool_Location = "/web/20131010em_///example.com/abc.html" //comment' #================================================================= @@ -59,62 +59,62 @@ r""" #================================================================= >>> _test_xml('') -'' +'' >>> _test_xml('') -'' +'' >>> _test_xml(' http://example.comabchttp://example.com') -' /web/20131010im_/http://example.comabchttp://example.com' +' /web/20131010em_/http://example.comabchttp://example.com' >>> _test_xml('
http://www.example.com/blah http://example.com
') -'
/web/20131010im_/http://www.example.com/blah /web/20131010im_/http://example.com
' +'
/web/20131010em_/http://www.example.com/blah /web/20131010em_/http://example.com
' #================================================================= # CSS Rewriting #================================================================= >>> _test_css("background: url('/some/path.html')") -"background: url('/web/20131010im_/http://example.com/some/path.html')" +"background: url('/web/20131010em_/http://example.com/some/path.html')" >>> _test_css("background: url('../path.html')") -"background: url('/web/20131010im_/http://example.com/path.html')" +"background: url('/web/20131010em_/http://example.com/path.html')" >>> _test_css("background: url(\"http://domain.com/path.html\")") -'background: url("/web/20131010im_/http://domain.com/path.html")' +'background: url("/web/20131010em_/http://domain.com/path.html")' >>> _test_css("background: url(file.jpeg)") -'background: url(/web/20131010im_/http://example.com/file.jpeg)' +'background: url(/web/20131010em_/http://example.com/file.jpeg)' >>> _test_css("background: url('')") "background: url('')" >>> _test_css("background: url (\"weirdpath\')") -'background: url ("/web/20131010im_/http://example.com/weirdpath\')' +'background: url ("/web/20131010em_/http://example.com/weirdpath\')' >>> _test_css("@import url ('path.css')") -"@import url ('/web/20131010im_/http://example.com/path.css')" +"@import url ('/web/20131010em_/http://example.com/path.css')" >>> _test_css("@import url('path.css')") -"@import url('/web/20131010im_/http://example.com/path.css')" +"@import url('/web/20131010em_/http://example.com/path.css')" >>> _test_css("@import ( 'path.css')") -"@import ( '/web/20131010im_/http://example.com/path.css')" +"@import ( '/web/20131010em_/http://example.com/path.css')" >>> _test_css("@import \"path.css\"") -'@import "/web/20131010im_/http://example.com/path.css"' +'@import "/web/20131010em_/http://example.com/path.css"' >>> _test_css("@import ('../path.css\"") -'@import (\'/web/20131010im_/http://example.com/path.css"' +'@import (\'/web/20131010em_/http://example.com/path.css"' >>> _test_css("@import ('../url.css\"") -'@import (\'/web/20131010im_/http://example.com/url.css"' +'@import (\'/web/20131010em_/http://example.com/url.css"' >>> _test_css("@import (\"url.css\")") -'@import ("/web/20131010im_/http://example.com/url.css")' +'@import ("/web/20131010em_/http://example.com/url.css")' >>> _test_css("@import url(/url.css)\n@import url(/anotherurl.css)\n @import url(/and_a_third.css)") -'@import url(/web/20131010im_/http://example.com/url.css)\n@import url(/web/20131010im_/http://example.com/anotherurl.css)\n @import url(/web/20131010im_/http://example.com/and_a_third.css)' +'@import url(/web/20131010em_/http://example.com/url.css)\n@import url(/web/20131010em_/http://example.com/anotherurl.css)\n @import url(/web/20131010em_/http://example.com/and_a_third.css)' #================================================================= HTTP Headers Rewriting @@ -134,7 +134,7 @@ HTTP Headers Rewriting {'charset': None, 'removed_header_dict': {}, 'status_headers': StatusAndHeaders(protocol = '', statusline = '302 Redirect', headers = [ ('X-Archive-Orig-Connection', 'close'), - ('Location', '/web/20131010im_/http://example.com/other.html')]), + ('Location', '/web/20131010/http://example.com/other.html')]), 'text_type': None} # gzip @@ -172,7 +172,7 @@ from pywb.utils.statusandheaders import StatusAndHeaders import pprint -urlrewriter = UrlRewriter('20131010im_/http://example.com/', '/web/') +urlrewriter = UrlRewriter('20131010/http://example.com/', '/web/') def _test_js(string, extra = []): diff --git a/pywb/static/wb.js b/pywb/static/wb.js index 8ca3971d..ae5b586c 100644 --- a/pywb/static/wb.js +++ b/pywb/static/wb.js @@ -22,6 +22,10 @@ function init_banner() { var banner = document.getElementById(BANNER_ID); + if (wbinfo.is_embed) { + return; + } + if (!banner) { banner = document.createElement("wb_div"); banner.setAttribute("id", BANNER_ID); diff --git a/pywb/ui/head_insert.html b/pywb/ui/head_insert.html index 88528357..07f1f0c0 100644 --- a/pywb/ui/head_insert.html +++ b/pywb/ui/head_insert.html @@ -11,7 +11,9 @@ + diff --git a/setup.py b/setup.py index 512f6cc0..b53aca9d 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ class PyTest(TestCommand): setup( name='pywb', - version='0.2.0', + version='0.2.2', url='https://github.com/ikreymer/pywb', author='Ilya Kreymer', author_email='ikreymer@gmail.com',