def css_in_json(s, localize=True, dir='', prefix=''): ''' Retrieve css package information from the DOM/src and download them. NOTE: if prefix is a dir, remember to replace '/' with '\/'! ''' m_csses = re_json_css.finditer(s) csses = set() for m_css in m_csses: url = m_css.group('url') download_url = dejsonify(url) if localize: file = url_to_file(url) s = s.replace(url, prefix + file, 1) save_resource(download_url, dir, file) csses.add(prefix + file) else: csses.add(url) return {'source': s, 'csses': csses}
def js_in_json(s, localize=True, dir='', prefix=''): ''' Retrieve js information from json strings and download them by default. At the mean time replace all js url references by refs to local file. NOTE: if prefix is a dir, remember to replace '/' with '\/'! ''' m_jssources = re_json_js.finditer(s) javascripts = set() for m_jssource in m_jssources: url = m_jssource.group('url') download_url = dejsonify(url) if localize: file = url_to_file(url) s = s.replace(url, prefix + file, 1) save_resource(download_url, dir, file) javascripts.add(prefix + file) else: javascripts.add(url) return {'source': s, 'javascripts': javascripts}