mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-09 00:48:12 +08:00
blackened code
This commit is contained in:
@@ -19,6 +19,7 @@ from cellxgene_gateway.cellxgene_exception import CellxgeneException
|
|||||||
from cellxgene_gateway.util import current_time_stamp
|
from cellxgene_gateway.util import current_time_stamp
|
||||||
from cellxgene_gateway.flask_util import querystring
|
from cellxgene_gateway.flask_util import querystring
|
||||||
|
|
||||||
|
|
||||||
class CacheEntry:
|
class CacheEntry:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -99,13 +100,20 @@ class CacheEntry:
|
|||||||
|
|
||||||
def rewrite_text_content(self, cellxgene_content):
|
def rewrite_text_content(self, cellxgene_content):
|
||||||
# for v0.16.0 compatibility, see issue #24
|
# for v0.16.0 compatibility, see issue #24
|
||||||
gateway_content = re.sub('(="|\()/static/', f'\\1{self.gateway_basepath()}static/', cellxgene_content).replace(
|
gateway_content = (
|
||||||
"http://fonts.gstatic.com", "https://fonts.gstatic.com"
|
re.sub(
|
||||||
).replace(self.cellxgene_basepath(), self.gateway_basepath())
|
'(="|\()/static/',
|
||||||
|
f"\\1{self.gateway_basepath()}static/",
|
||||||
|
cellxgene_content,
|
||||||
|
)
|
||||||
|
.replace("http://fonts.gstatic.com", "https://fonts.gstatic.com")
|
||||||
|
.replace(self.cellxgene_basepath(), self.gateway_basepath())
|
||||||
|
)
|
||||||
return gateway_content
|
return gateway_content
|
||||||
|
|
||||||
def gateway_basepath(self):
|
def gateway_basepath(self):
|
||||||
return f"{env.external_protocol}://{env.external_host}/view/{self.key.pathpart}/"
|
return f"{env.external_protocol}://{env.external_host}/view/{self.key.pathpart}/"
|
||||||
|
|
||||||
def cellxgene_basepath(self):
|
def cellxgene_basepath(self):
|
||||||
return f"http://127.0.0.1:{self.port}"
|
return f"http://127.0.0.1:{self.port}"
|
||||||
|
|
||||||
@@ -165,7 +173,9 @@ class CacheEntry:
|
|||||||
)
|
)
|
||||||
content_type = cellxgene_response.headers["content-type"]
|
content_type = cellxgene_response.headers["content-type"]
|
||||||
if "text" in content_type:
|
if "text" in content_type:
|
||||||
gateway_content = self.rewrite_text_content(cellxgene_response.content.decode())
|
gateway_content = self.rewrite_text_content(
|
||||||
|
cellxgene_response.content.decode()
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
gateway_content = cellxgene_response.content
|
gateway_content = cellxgene_response.content
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,22 @@ import unittest
|
|||||||
from cellxgene_gateway.cache_entry import CacheEntry
|
from cellxgene_gateway.cache_entry import CacheEntry
|
||||||
from cellxgene_gateway.cache_key import CacheKey
|
from cellxgene_gateway.cache_key import CacheKey
|
||||||
|
|
||||||
key = CacheKey('czi/pbmc3k.h5ad', 'pbmc3k.h5ad', 'tmp.csv')
|
key = CacheKey("czi/pbmc3k.h5ad", "pbmc3k.h5ad", "tmp.csv")
|
||||||
|
|
||||||
|
|
||||||
class TestRenderEntry(unittest.TestCase):
|
class TestRenderEntry(unittest.TestCase):
|
||||||
def test_GIVEN_absolute_static_url_THEN_include_path(self):
|
def test_GIVEN_absolute_static_url_THEN_include_path(self):
|
||||||
actual = CacheEntry.for_key(key, 8000).rewrite_text_content("src:url(/static/assets/")
|
actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
|
||||||
expected = "src:url(http://localhost:5005/view/czi/pbmc3k.h5ad/static/assets/"
|
"src:url(/static/assets/"
|
||||||
self.assertEqual(actual, expected)
|
)
|
||||||
def test_GIVEN_absolute_src_THEN_include_path(self):
|
expected = (
|
||||||
actual = CacheEntry.for_key(key, 8000).rewrite_text_content('<link rel="shortcut icon" href="/static/assets/favicon.ico">')
|
"src:url(http://localhost:5005/view/czi/pbmc3k.h5ad/static/assets/"
|
||||||
expected = '<link rel="shortcut icon" href="http://localhost:5005/view/czi/pbmc3k.h5ad/static/assets/favicon.ico">'
|
)
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
def test_GIVEN_absolute_src_THEN_include_path(self):
|
||||||
|
actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
|
||||||
|
'<link rel="shortcut icon" href="/static/assets/favicon.ico">'
|
||||||
|
)
|
||||||
|
expected = '<link rel="shortcut icon" href="http://localhost:5005/view/czi/pbmc3k.h5ad/static/assets/favicon.ico">'
|
||||||
|
self.assertEqual(actual, expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user