Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lookup(self):
pdf1 = Mime.lookup("application/pdf")
pdf2 = Mime.lookup("application", "pdf")
self.assertEqual(pdf1, pdf2)
self.check_mimetype(pdf1, 'application', 'pdf')
def test_inheritance(self):
text_python = Mime.lookup('text/x-python')
self.check_mimetype(text_python, 'text', 'x-python')
text_plain = Mime.lookup('text/plain')
app_executable = Mime.lookup('application/x-executable')
self.assertEqual(text_python.inherits_from(), set([text_plain, app_executable]))
assert isinstance(jpeg, Mime.MagicMatchAny), type(jpeg)
self.assertEqual(len(jpeg.rules), 2)
self.assertEqual(jpeg.rules[0].value, b'\xff\xd8\xff')
prio, ora = self.magic.bytype[Mime.lookup('image', 'openraster')][0]
assert isinstance(ora, Mime.MagicRule), type(ora)
self.assertEqual(ora.value, b'PK\x03\x04')
ora1 = ora.also
assert ora1 is not None
self.assertEqual(ora1.start, 30)
ora2 = ora1.also
assert ora2 is not None
self.assertEqual(ora2.start, 38)
self.assertEqual(ora2.value, b'image/openraster')
prio, svg = self.magic.bytype[Mime.lookup('image', 'svg+xml')][0]
self.assertEqual(len(svg.rules), 2)
self.assertEqual(svg.rules[0].value, b'
assert isinstance(ora, Mime.MagicRule), type(ora)
self.assertEqual(ora.value, b'PK\x03\x04')
ora1 = ora.also
assert ora1 is not None
self.assertEqual(ora1.start, 30)
ora2 = ora1.also
assert ora2 is not None
self.assertEqual(ora2.start, 38)
self.assertEqual(ora2.value, b'image/openraster')
prio, svg = self.magic.bytype[Mime.lookup('image', 'svg+xml')][0]
self.assertEqual(len(svg.rules), 2)
self.assertEqual(svg.rules[0].value, b'
self.assertEqual(ora1.start, 30)
ora2 = ora1.also
assert ora2 is not None
self.assertEqual(ora2.start, 38)
self.assertEqual(ora2.value, b'image/openraster')
prio, svg = self.magic.bytype[Mime.lookup('image', 'svg+xml')][0]
self.assertEqual(len(svg.rules), 2)
self.assertEqual(svg.rules[0].value, b'
def test_match_data(self):
res = self.magic.match_data(resources.png_data)
self.check_mimetype(res, 'image', 'png')
# Denied by min or max priority
notpng_max40 = self.magic.match_data(resources.png_data, max_pri=40)
assert notpng_max40 is None, notpng_max40
notpng_min60 = self.magic.match_data(resources.png_data, min_pri=60)
assert notpng_min60 is None, notpng_min60
# With list of options
options = [Mime.lookup('image', 'nonexistant'), # Missing MIMEtype should be dropped
Mime.lookup('image','png'), Mime.lookup('image', 'jpeg')]
res = self.magic.match_data(resources.png_data, possible=options)
self.check_mimetype(res, 'image', 'png')
# Non matching
res = self.magic.match_data(b'oiejgoethetrkjgnwefergoijekngjekg')
assert res is None, res
def test_parsing(self):
self.assertEqual(len(self.magic.bytype), 9)
# Check repr() doesn't throw an error
repr(self.magic)
prio, png = self.magic.bytype[Mime.lookup('image', 'png')][0]
self.assertEqual(prio, 50)
assert isinstance(png, Mime.MagicRule), type(png)
repr(png) # Check this doesn't throw an error.
self.assertEqual(png.start, 0)
self.assertEqual(png.value, b'\x89PNG')
self.assertEqual(png.mask, None)
self.assertEqual(png.also, None)
prio, jpeg = self.magic.bytype[Mime.lookup('image', 'jpeg')][0]
assert isinstance(jpeg, Mime.MagicMatchAny), type(jpeg)
self.assertEqual(len(jpeg.rules), 2)
self.assertEqual(jpeg.rules[0].value, b'\xff\xd8\xff')
prio, ora = self.magic.bytype[Mime.lookup('image', 'openraster')][0]
assert isinstance(ora, Mime.MagicRule), type(ora)
self.assertEqual(ora.value, b'PK\x03\x04')
def test_parsing(self):
self.assertEqual(len(self.magic.bytype), 9)
# Check repr() doesn't throw an error
repr(self.magic)
prio, png = self.magic.bytype[Mime.lookup('image', 'png')][0]
self.assertEqual(prio, 50)
assert isinstance(png, Mime.MagicRule), type(png)
repr(png) # Check this doesn't throw an error.
self.assertEqual(png.start, 0)
self.assertEqual(png.value, b'\x89PNG')
self.assertEqual(png.mask, None)
self.assertEqual(png.also, None)
prio, jpeg = self.magic.bytype[Mime.lookup('image', 'jpeg')][0]
assert isinstance(jpeg, Mime.MagicMatchAny), type(jpeg)
self.assertEqual(len(jpeg.rules), 2)
self.assertEqual(jpeg.rules[0].value, b'\xff\xd8\xff')
prio, ora = self.magic.bytype[Mime.lookup('image', 'openraster')][0]
assert isinstance(ora, Mime.MagicRule), type(ora)
self.assertEqual(ora.value, b'PK\x03\x04')
ora1 = ora.also
assert ora1 is not None
self.assertEqual(ora1.start, 30)
ora2 = ora1.also
assert ora2 is not None
self.assertEqual(ora2.start, 38)
self.assertEqual(ora2.value, b'image/openraster')
prio, svg = self.magic.bytype[Mime.lookup('image', 'svg+xml')][0]
def modifyUserInterface(self, app):
import xdg.Mime
import os.path
import gtk
mime = xdg.Mime.lookup(self._string)
SearchActivationStyle.modifyUserInterface(self, app)
app.label_progress.set_markup("<big><b>%s</b></big>\n\n%s" %
(_("Searching for appropriate "
"applications"),
_("A list of applications that can "
"handle documents of the type '%s' "
"will be created") % mime.get_comment()))
app.button_ok.set_label(_("_Install"))
if self._uri:
#TRANSLATORS: %s represents a file path
app.window_main.set_title(_("Install applications to open \"%s\"")\
% os.path.basename(self._duri))
else:
app.window_main.set_title(_("Install applications"))
app.window_main.set_property("default_width", 500)
model = app.treeview_packages.get_model()