Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/git/objects/blob.py: 95%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
2#
3# This module is part of GitPython and is released under the
4# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
6__all__ = ["Blob"]
8from mimetypes import guess_type
9import sys
11if sys.version_info >= (3, 8):
12 from typing import Literal
13else:
14 from typing_extensions import Literal
16from . import base
19class Blob(base.IndexObject):
20 """A Blob encapsulates a git blob object.
22 See :manpage:`gitglossary(7)` on "blob":
23 https://git-scm.com/docs/gitglossary#def_blob_object
24 """
26 DEFAULT_MIME_TYPE = "text/plain"
27 type: Literal["blob"] = "blob"
29 # Valid blob modes
30 executable_mode = 0o100755
31 file_mode = 0o100644
32 link_mode = 0o120000
34 __slots__ = ()
36 @property
37 def mime_type(self) -> str:
38 """
39 :return:
40 String describing the mime type of this file (based on the filename)
42 :note:
43 Defaults to ``text/plain`` in case the actual file type is unknown.
44 """
45 guesses = None
46 if self.path:
47 guesses = guess_type(str(self.path))
48 return guesses and guesses[0] or self.DEFAULT_MIME_TYPE