Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/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 os
11from typing import Literal
13from . import base
16class Blob(base.IndexObject):
17 """A Blob encapsulates a git blob object.
19 See :manpage:`gitglossary(7)` on "blob":
20 https://git-scm.com/docs/gitglossary#def_blob_object
21 """
23 DEFAULT_MIME_TYPE = "text/plain"
24 type: Literal["blob"] = "blob"
26 # Valid blob modes
27 executable_mode = 0o100755
28 file_mode = 0o100644
29 link_mode = 0o120000
31 __slots__ = ()
33 @property
34 def mime_type(self) -> str:
35 """
36 :return:
37 String describing the mime type of this file (based on the filename)
39 :note:
40 Defaults to ``text/plain`` in case the actual file type is unknown.
41 """
42 guesses = None
43 if self.path:
44 guesses = guess_type(os.fspath(self.path))
45 return guesses and guesses[0] or self.DEFAULT_MIME_TYPE