Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/git/objects/blob.py: 73%
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 os
10import sys
12if sys.version_info >= (3, 8):
13 from typing import Literal
14else:
15 from typing_extensions import Literal
17from . import base
20class Blob(base.IndexObject):
21 """A Blob encapsulates a git blob object.
23 See :manpage:`gitglossary(7)` on "blob":
24 https://git-scm.com/docs/gitglossary#def_blob_object
25 """
27 DEFAULT_MIME_TYPE = "text/plain"
28 type: Literal["blob"] = "blob"
30 # Valid blob modes
31 executable_mode = 0o100755
32 file_mode = 0o100644
33 link_mode = 0o120000
35 __slots__ = ()
37 @property
38 def mime_type(self) -> str:
39 """
40 :return:
41 String describing the mime type of this file (based on the filename)
43 :note:
44 Defaults to ``text/plain`` in case the actual file type is unknown.
45 """
46 guesses = None
47 if self.path:
48 guesses = guess_type(os.fspath(self.path))
49 return guesses and guesses[0] or self.DEFAULT_MIME_TYPE