MCPcopy Index your code
hub / github.com/python/cpython / get_bytes

Method get_bytes

Lib/mailbox.py:1111–1130  ·  view source on GitHub ↗

Return a bytes representation or raise a KeyError.

(self, key)

Source from the content-addressed store, hash-verified

1109 return msg
1110
1111 def get_bytes(self, key):
1112 """Return a bytes representation or raise a KeyError."""
1113 try:
1114 if self._locked:
1115 f = open(os.path.join(self._path, str(key)), 'rb+')
1116 else:
1117 f = open(os.path.join(self._path, str(key)), 'rb')
1118 except OSError as e:
1119 if e.errno == errno.ENOENT:
1120 raise KeyError('No message with key: %s' % key)
1121 else:
1122 raise
1123 with f:
1124 if self._locked:
1125 _lock_file(f)
1126 try:
1127 return f.read().replace(linesep, b'\n')
1128 finally:
1129 if self._locked:
1130 _unlock_file(f)
1131
1132 def get_file(self, key):
1133 """Return a file-like representation or raise a KeyError."""

Callers 7

test_add_8bit_bodyMethod · 0.45
test_add_binary_fileMethod · 0.45
test_get_bytesMethod · 0.45
test_get_bytes_fromMethod · 0.45

Calls 7

strFunction · 0.85
_lock_fileFunction · 0.85
_unlock_fileFunction · 0.85
openFunction · 0.70
joinMethod · 0.45
replaceMethod · 0.45
readMethod · 0.45

Tested by 7

test_add_8bit_bodyMethod · 0.36
test_add_binary_fileMethod · 0.36
test_get_bytesMethod · 0.36
test_get_bytes_fromMethod · 0.36