MCPcopy Create free account
hub / github.com/EasyIME/PIME / get_content

Method get_content

python/python3/tornado/web.py:2819–2855  ·  view source on GitHub ↗

Retrieve the content of the requested resource which is located at the given absolute path. This class method may be overridden by subclasses. Note that its signature is different from other overridable class methods (no ``settings`` argument); this is deliberate to

(
        cls, abspath: str, start: Optional[int] = None, end: Optional[int] = None
    )

Source from the content-addressed store, hash-verified

2817
2818 @classmethod
2819 def get_content(
2820 cls, abspath: str, start: Optional[int] = None, end: Optional[int] = None
2821 ) -> Generator[bytes, None, None]:
2822 """Retrieve the content of the requested resource which is located
2823 at the given absolute path.
2824
2825 This class method may be overridden by subclasses. Note that its
2826 signature is different from other overridable class methods
2827 (no ``settings`` argument); this is deliberate to ensure that
2828 ``abspath`` is able to stand on its own as a cache key.
2829
2830 This method should either return a byte string or an iterator
2831 of byte strings. The latter is preferred for large files
2832 as it helps reduce memory fragmentation.
2833
2834 .. versionadded:: 3.1
2835 """
2836 with open(abspath, "rb") as file:
2837 if start is not None:
2838 file.seek(start)
2839 if end is not None:
2840 remaining = end - (start or 0) # type: Optional[int]
2841 else:
2842 remaining = None
2843 while True:
2844 chunk_size = 64 * 1024
2845 if remaining is not None and remaining < chunk_size:
2846 chunk_size = remaining
2847 chunk = file.read(chunk_size)
2848 if chunk:
2849 if remaining is not None:
2850 remaining -= len(chunk)
2851 yield chunk
2852 else:
2853 if remaining is not None:
2854 assert remaining == 0
2855 return
2856
2857 @classmethod
2858 def get_content_version(cls, abspath: str) -> str:

Callers 2

getMethod · 0.95
get_content_versionMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected