5     'application/mathml+xml': 'librarian.embeds.mathml.MathML',
 
   6     'application/x-latex': 'librarian.embeds.latex.LaTeX',
 
  11     def transforms_to(cls, mime_types, downgrade=False):
 
  13         for name, method in cls.__dict__.iteritems():
 
  14             if hasattr(method, "embed_converts_to"):
 
  15                 conv_type, conv_downgrade = method.embed_converts_to
 
  16                 if downgrade == conv_downgrade and conv_type in mime_types:
 
  17                     matches.add(conv_type)
 
  20     def transform_to(self, mime_type, downgrade=False):
 
  21         for name, method in type(cls).__dict__.iteritems():
 
  22             if hasattr(method, "embed_converts_to"):
 
  23                 conv_type, conv_downgrade = method.embed_converts_to
 
  24                 if downgrade == conv_downgrade and conv_type == mime_type:
 
  28 class DataEmbed(Embed):
 
  29     def __init__(self, data=None):
 
  32 class TreeEmbed(Embed):
 
  33     def __init__(self, tree=None):
 
  34         if isinstance(tree, etree._Element):
 
  35             tree = etree.ElementTree(tree)
 
  38 def converts_to(mime_type, downgrade=False):
 
  39     def decorator(method):
 
  40         method.embed_converts_to = mime_type, downgrade
 
  44 def downgrades_to(mime_type):
 
  45     return converts_to(mime_type, True)
 
  47 def create_embed(mime_type, tree=None, data=None):
 
  48     embed = known_types.get(mime_type)
 
  50         embed = DataEmbed if tree is None else TreeEmbed
 
  52         mod_name, cls_name = embed.rsplit('.', 1)
 
  53         mod = importlib.import_module(mod_name)
 
  54         embed = getattr(mod, cls_name)
 
  56     return embed(data if tree is None else tree)