You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
927B

  1. # blob.py
  2. # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
  3. #
  4. # This module is part of GitPython and is released under
  5. # the BSD License: http://www.opensource.org/licenses/bsd-license.php
  6. from mimetypes import guess_type
  7. from . import base
  8. __all__ = ('Blob', )
  9. class Blob(base.IndexObject):
  10. """A Blob encapsulates a git blob object"""
  11. DEFAULT_MIME_TYPE = "text/plain"
  12. type = "blob"
  13. # valid blob modes
  14. executable_mode = 0o100755
  15. file_mode = 0o100644
  16. link_mode = 0o120000
  17. __slots__ = ()
  18. @property
  19. def mime_type(self):
  20. """
  21. :return: String describing the mime type of this file (based on the filename)
  22. :note: Defaults to 'text/plain' in case the actual file type is unknown. """
  23. guesses = None
  24. if self.path:
  25. guesses = guess_type(self.path)
  26. return guesses and guesses[0] or self.DEFAULT_MIME_TYPE