/usr/lib/python2.7/dist-packages/mutagen/_tags.py is in python-mutagen 1.36-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | # -*- coding: utf-8 -*-
# Copyright (C) 2005 Michael Urman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
from ._util import loadfile
class PaddingInfo(object):
"""PaddingInfo()
Abstract padding information object.
This will be passed to the callback function that can be used
for saving tags.
::
def my_callback(info: PaddingInfo):
return info.get_default_padding()
The callback should return the amount of padding to use (>= 0) based on
the content size and the padding of the file after saving. The actual used
amount of padding might vary depending on the file format (due to
alignment etc.)
The default implementation can be accessed using the
:meth:`get_default_padding` method in the callback.
Attributes:
padding (`int`): The amount of padding left after saving in bytes
(can be negative if more data needs to be added as padding is
available)
size (`int`): The amount of data following the padding
"""
def __init__(self, padding, size):
self.padding = padding
self.size = size
def get_default_padding(self):
"""The default implementation which tries to select a reasonable
amount of padding and which might change in future versions.
Returns:
int: Amount of padding after saving
"""
high = 1024 * 10 + self.size // 100 # 10 KiB + 1% of trailing data
low = 1024 + self.size // 1000 # 1 KiB + 0.1% of trailing data
if self.padding >= 0:
# enough padding left
if self.padding > high:
# padding too large, reduce
return low
# just use existing padding as is
return self.padding
else:
# not enough padding, add some
return low
def _get_padding(self, user_func):
if user_func is None:
return self.get_default_padding()
else:
return user_func(self)
def __repr__(self):
return "<%s size=%d padding=%d>" % (
type(self).__name__, self.size, self.padding)
class Tags(object):
"""`Tags` is the base class for many of the tag objects in Mutagen.
In many cases it has a dict like interface.
"""
__module__ = "mutagen"
def pprint(self):
"""
Returns:
text: tag information
"""
raise NotImplementedError
class Metadata(Tags):
"""Metadata(filething=None, **kwargs)
Args:
filething (filething): a filename or a file-like object or `None`
to create an empty instance (like ``ID3()``)
Like :class:`Tags` but for standalone tagging formats that are not
solely managed by a container format.
Provides methods to load, save and delete tags.
"""
__module__ = "mutagen"
def __init__(self, *args, **kwargs):
if args or kwargs:
self.load(*args, **kwargs)
@loadfile()
def load(self, filething, **kwargs):
raise NotImplementedError
@loadfile(writable=False)
def save(self, filething, **kwargs):
"""save(filething=None, **kwargs)
Save changes to a file.
Args:
filething (filething): or `None`
Raises:
MutagenError: if saving wasn't possible
"""
raise NotImplementedError
@loadfile(writable=False)
def delete(self, filething):
"""delete(filething=None)
Remove tags from a file.
In most cases this means any traces of the tag will be removed
from the file.
Args:
filething (filething): or `None`
Raises:
MutagenError: if deleting wasn't possible
"""
raise NotImplementedError
|