def _render_license_css_content(content_bytes, version, query, source_path): '''Render the CSS license content by rewriting all the URIs.''' unrendered_css_string = EosCompanionAppService.bytes_to_string( content_bytes) return EosCompanionAppService.string_to_bytes( _RE_CSS_URL_CAPTURE.sub( relative_css_url_rewriter(version, query, source_path), unrendered_css_string))
def _html_content_adjuster(content_bytes, version, query, metadata, content_db_conn, shards, cache, cancellable, callback): '''Adjust HTML content by rewriting all the embedded URLs. There will be images, video and links in the document, parse it and rewrite it so that the links all go to somewhere that can be resolved by the server. Right now the way that this is done is a total hack (regex), in future we might want to depend on beautifulsoup and use that instead. ''' def _on_rendered_wrapper(error, rendered_page): '''Called when rendering the wrapper is complete.''' if error is not None: callback(error, None) return try: response_bytes = EosCompanionAppService.string_to_bytes( pipeline( rendered_page, lambda content: _RE_EKN_URL_CAPTURE.sub( ekn_url_rewriter(version, query), content ), lambda content: _RE_RESOURCE_URL_CAPTURE.sub( resource_url_rewriter(version, query), content ), lambda content: _RE_LICENSE_URL_CAPTURE.sub( license_url_rewriter(version, query), content ) ) ) except GLib.Error as render_bytes_error: callback(render_bytes_error, None) return callback(None, response_bytes) unrendered_html_string = EosCompanionAppService.bytes_to_string(content_bytes) # We need the content_db_conn, shards and metadata # in order to render our mobile wrapper. if (metadata is not None and content_db_conn is not None and shards is not None): if not metadata.get('isServerTemplated', False): rendered_content = renderer.render_legacy_content( unrendered_html_string, metadata.get('source', ''), metadata.get('sourceName', ''), metadata.get('originalURI', ''), metadata.get('license', ''), metadata.get('title', ''), show_title=True, use_scroll_manager=False ) else: rendered_content = unrendered_html_string render_mobile_wrapper(renderer, query['applicationId'], rendered_content, metadata, content_db_conn, shards, version, query, cache, cancellable, _on_rendered_wrapper) else: # Put this on an idle timer, mixing async and sync code # is a bad idea GLib.idle_add(lambda: _on_rendered_wrapper(None, unrendered_html_string))