MCPcopy Index your code
hub / github.com/ahupp/python-magic / from_buffer

Method from_buffer

magic/__init__.py:94–108  ·  view source on GitHub ↗

Identify the contents of `buf`

(self, buf)

Source from the content-addressed store, hash-verified

92 pass
93
94 def from_buffer(self, buf):
95 """
96 Identify the contents of `buf`
97 """
98 with self.lock:
99 try:
100 # if we're on python3, convert buf to bytes
101 # otherwise this string is passed as wchar*
102 # which is not what libmagic expects
103 # NEXTBREAK: only take bytes
104 if type(buf) == str and str != bytes:
105 buf = buf.encode('utf-8', errors='replace')
106 return maybe_decode(magic_buffer(self.cookie, buf))
107 except MagicException as e:
108 return self._handle509Bug(e)
109
110 def from_file(self, filename):
111 # raise FileNotFoundException or IOError if the file does not exist

Callers 5

test_name_countMethod · 0.95
assert_valuesMethod · 0.80
test_rethrowMethod · 0.80
from_bufferFunction · 0.80

Calls 3

_handle509BugMethod · 0.95
maybe_decodeFunction · 0.85
magic_bufferFunction · 0.85

Tested by 4

test_name_countMethod · 0.76
assert_valuesMethod · 0.64
test_rethrowMethod · 0.64