Deleted Added
full compact
magic.py (302408) magic.py (309847)
1# coding: utf-8
2
3'''
4Python bindings for libmagic
5'''
6
7import ctypes
8

--- 120 unchanged lines hidden (view full) ---

129 try: # keep Python 2 compatibility
130 bi = bytes(filename, 'utf-8')
131 except TypeError:
132 bi = bytes(filename)
133 r = _file(self._magic_t, bi)
134 if isinstance(r, str):
135 return r
136 else:
1# coding: utf-8
2
3'''
4Python bindings for libmagic
5'''
6
7import ctypes
8

--- 120 unchanged lines hidden (view full) ---

129 try: # keep Python 2 compatibility
130 bi = bytes(filename, 'utf-8')
131 except TypeError:
132 bi = bytes(filename)
133 r = _file(self._magic_t, bi)
134 if isinstance(r, str):
135 return r
136 else:
137 return str(r).encode('utf-8')
137 return str(r, 'utf-8')
138
139 def descriptor(self, fd):
140 """
141 Like the file method, but the argument is a file descriptor.
142 """
143 return _descriptor(self._magic_t, fd)
144
145 def buffer(self, buf):
146 """
147 Returns a textual description of the contents of the argument passed
148 as a buffer or None if an error occurred and the MAGIC_ERROR flag
149 is set. A call to errno() will return the numeric error code.
150 """
151 r = _buffer(self._magic_t, buf, len(buf))
152 if isinstance(r, str):
153 return r
154 else:
138
139 def descriptor(self, fd):
140 """
141 Like the file method, but the argument is a file descriptor.
142 """
143 return _descriptor(self._magic_t, fd)
144
145 def buffer(self, buf):
146 """
147 Returns a textual description of the contents of the argument passed
148 as a buffer or None if an error occurred and the MAGIC_ERROR flag
149 is set. A call to errno() will return the numeric error code.
150 """
151 r = _buffer(self._magic_t, buf, len(buf))
152 if isinstance(r, str):
153 return r
154 else:
155 return str(r).encode('utf-8')
155 return str(r, 'utf-8')
156
157 def error(self):
158 """
159 Returns a textual explanation of the last error or None
160 if there was no error.
161 """
162 e = _error(self._magic_t)
163 if isinstance(e, str):
164 return e
165 else:
156
157 def error(self):
158 """
159 Returns a textual explanation of the last error or None
160 if there was no error.
161 """
162 e = _error(self._magic_t)
163 if isinstance(e, str):
164 return e
165 else:
166 return str(e).encode('utf-8')
166 return str(e, 'utf-8')
167
168 def setflags(self, flags):
169 """
170 Set flags on the magic object which determine how magic checking
171 behaves; a bitwise OR of the flags described in libmagic(3), but
172 without the MAGIC_ prefix.
173
174 Returns -1 on systems that don't support utime(2) or utimes(2)

--- 103 unchanged lines hidden ---
167
168 def setflags(self, flags):
169 """
170 Set flags on the magic object which determine how magic checking
171 behaves; a bitwise OR of the flags described in libmagic(3), but
172 without the MAGIC_ prefix.
173
174 Returns -1 on systems that don't support utime(2) or utimes(2)

--- 103 unchanged lines hidden ---