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

22 statements  

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/ 

5 

6__all__ = ["Blob"] 

7 

8from mimetypes import guess_type 

9import os 

10import sys 

11 

12if sys.version_info >= (3, 8): 

13 from typing import Literal 

14else: 

15 from typing_extensions import Literal 

16 

17from . import base 

18 

19 

20class Blob(base.IndexObject): 

21 """A Blob encapsulates a git blob object. 

22 

23 See :manpage:`gitglossary(7)` on "blob": 

24 https://git-scm.com/docs/gitglossary#def_blob_object 

25 """ 

26 

27 DEFAULT_MIME_TYPE = "text/plain" 

28 type: Literal["blob"] = "blob" 

29 

30 # Valid blob modes 

31 executable_mode = 0o100755 

32 file_mode = 0o100644 

33 link_mode = 0o120000 

34 

35 __slots__ = () 

36 

37 @property 

38 def mime_type(self) -> str: 

39 """ 

40 :return: 

41 String describing the mime type of this file (based on the filename) 

42 

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