Skip to content

Commit

Permalink
Convert additional instances of % to .format()
Browse files Browse the repository at this point in the history
  • Loading branch information
tuffy committed Nov 17, 2015
1 parent 640bef4 commit 9e09945
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 89 deletions.
27 changes: 13 additions & 14 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -7544,32 +7544,31 @@
- [ ] trackverify
*** TODO Update modules
- [ ] __init__.py
- [ ] accuraterip.py
- [ ] aiff.py
- [X] accuraterip.py
- [X] aiff.py
- [ ] ape.py
- [ ] au.py
- [ ] cdtoc.py
- [ ] coverartarchive.py
- [X] cdtoc.py
- [X] coverartarchive.py
- [ ] flac.py
- [ ] freedb.py
- [X] freedb.py
- [ ] id3.py
- [ ] id3v1.py
- [ ] image.py
- [ ] m4a.py
- [X] m4a.py
- [ ] m4a_atoms.py
- [ ] mp3.py
- [ ] mpc.py
- [ ] musicbrainz.py
- [ ] ogg.py
- [X] mp3.py
- [X] mpc.py
- [X] musicbrainz.py
- [X] ogg.py
- [ ] opus.py
- [ ] player.py
- [ ] text.py
- [X] player.py
- [ ] tta.py
- [ ] ui.py
- [ ] vorbis.py
- [ ] vorbiscomment.py
- [ ] wav.py
- [ ] wavpack.py
- [X] wav.py
- [X] wavpack.py
**** TODO cue
- [ ] __init__.py
- [ ] tokrules.py
Expand Down
26 changes: 13 additions & 13 deletions audiotools/accuraterip.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ def __str__(self):
return self.__unicode__().encode('utf-8')

def __unicode__(self):
return u"dBAR-%(tracks)3.3d-%(id1)8.8x-%(id2)8.8x-%(freedb)8.8x.bin" % \
{"tracks": len(self.__track_numbers__),
"id1": self.id1(),
"id2": self.id2(),
"freedb": int(self.__freedb_disc_id__)}
return u"dBAR-{tracks:03d}-{id1:08x}-{id2:08x}-{freedb:08x}.bin".format(
tracks=len(self.__track_numbers__),
id1=self.id1(),
id2=self.id2(),
freedb=int(self.__freedb_disc_id__))

def __repr__(self):
return "AccurateRipDiscID(%s)" % \
(", ".join(["%s=%s" % (key, repr(getattr(self, attr)))
return "AccurateRipDiscID({})".format(
", ".join(["{}={!r}".format(key, getattr(self, attr))
for (key, attr) in
[("track_numbers", "__track_numbers__"),
("track_offsets", "__track_offsets__"),
Expand Down Expand Up @@ -283,12 +283,12 @@ def perform_lookup(disc_id,

matches = {n: [] for n in disc_id.track_numbers()}

url = "http://%s:%s/accuraterip/%s/%s/%s/%s" % (accuraterip_server,
accuraterip_port,
str(disc_id)[16],
str(disc_id)[15],
str(disc_id)[14],
disc_id)
url = "http://{}:{}/accuraterip/{}/{}/{}/{}".format(accuraterip_server,
accuraterip_port,
str(disc_id)[16],
str(disc_id)[15],
str(disc_id)[14],
disc_id)

try:
response = BitstreamReader(urlopen(url), True)
Expand Down
4 changes: 2 additions & 2 deletions audiotools/aiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __init__(self, chunk_id, chunk_size, chunk_data):
self.__data__ = chunk_data

def __repr__(self):
return "AIFF_Chunk(%s)" % (repr(self.id))
return "AIFF_Chunk({!r})".format(self.id)

def size(self):
"""returns size of chunk in bytes
Expand Down Expand Up @@ -279,7 +279,7 @@ def __del__(self):
self.__aiff_file__.close()

def __repr__(self):
return "AIFF_File_Chunk(%s)" % (repr(self.id))
return "AIFF_File_Chunk({!r})".format(self.id)

def data(self):
"""returns chunk data as file-like object"""
Expand Down
31 changes: 15 additions & 16 deletions audiotools/cdtoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self, cdtoc_tracks, lead_out):
self.__lead_out__ = lead_out

def __repr__(self):
return "CDTOC(%s, %s)" % (repr(self.__cdtoc_tracks__),
repr(self.__lead_out__))
return "CDTOC({!r}, {!r})".format(self.__cdtoc_tracks__,
self.__lead_out__)

if PY3:
def __str__(self):
Expand All @@ -40,9 +40,10 @@ def __str__(self):
return self.__unicode__().encode('utf-8')

def __unicode__(self):
return u"+".join([u"%X" % (len([t for t in self if t.is_audio()]))] +
return u"+".join([u"{:X}".format(
len([t for t in self if t.is_audio()]))] +
[t.__unicode__() for t in self] +
[u"%X" % (self.__lead_out__)])
[u"{:X}".format(self.__lead_out__)])

@classmethod
def from_unicode(cls, u):
Expand Down Expand Up @@ -153,14 +154,14 @@ def __init__(self, cdtoc_tracks, lead_out):
CDTOC.__init__(self, cdtoc_tracks, lead_out)

def __unicode__(self):
return u"+".join([u"%X" % (len(self) - 1)] +
return u"+".join([u"{:X}".format(len(self) - 1)] +
[t.__unicode__() for t in self[1:]] +
[u"%X" % (self.__lead_out__),
u"X%s" % (self[0].__unicode__())])
[u"{:X}".format(self.__lead_out__),
u"X{}".format(self[0].__unicode__())])

def __repr__(self):
return "CDTOC_DataAudio(%s, %s)" % (repr(self.__cdtoc_tracks__),
repr(self.__lead_out__))
return "CDTOC_DataAudio({!r}, {!r})".format(self.__cdtoc_tracks__,
self.__lead_out__)


class CDTOC_Track(SheetTrack):
Expand Down Expand Up @@ -203,10 +204,8 @@ def __unicode__(self):
return self.index(1).__unicode__()

def __repr__(self):
return "CDTOC_Track(%s, %s, %s)" % \
(repr(self.__number__),
repr(self.__indexes__),
repr(self.__is_audio__))
return "CDTOC_Track({!r}, {!r}, {!r})".format(
self.__number__, self.__indexes__, self.__is_audio__)

def number(self):
"""return SheetTrack's number, starting from 1"""
Expand Down Expand Up @@ -252,11 +251,11 @@ def __str__(self):
return self.__unicode__().encode('utf-8')

def __unicode__(self):
return u"%X" % (self.__address__)
return u"{:X}".format(self.__address__)

def __repr__(self):
return "CDTOC_Index(number=%s, address=%s)" % \
(repr(self.__number__), repr(self.__address__))
return "CDTOC_Index(number={!r}, address={!r})".format(
self.__number__, self.__address__)

def number(self):
return self.__number__
Expand Down
34 changes: 15 additions & 19 deletions audiotools/freedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def from_sheet(cls, sheet, total_pcm_frames, sample_rate):
sample_rate))

def __repr__(self):
return "DiscID(%s)" % \
", ".join(["%s=%s" % (attr, getattr(self, attr))
return "DiscID({})".format(
", ".join(["{}={}".format(attr, getattr(self, attr))
for attr in ["offsets",
"total_length",
"track_count",
Expand All @@ -128,7 +128,7 @@ def __str__(self):
return self.__unicode__().encode('ascii')

def __unicode__(self):
return u"%8.8X" % (int(self))
return u"{:08X}".format(int(self))

def __int__(self):
digit_sum_ = sum([digit_sum(o // 75) for o in self.offsets])
Expand Down Expand Up @@ -159,9 +159,9 @@ def perform_lookup(disc_id, freedb_server, freedb_port):
freedb_port,
u"query",
*([disc_id.__unicode__(),
u"%d" % (disc_id.track_count)] +
[u"%d" % (o) for o in disc_id.offsets] +
[u"%d" % (disc_id.playable_length)]))
u"{:d}".format(disc_id.track_count)] +
[u"{:d}".format(o) for o in disc_id.offsets] +
[u"{:d}".format(disc_id.playable_length)]))

line = next(query)
response = RESPONSE.match(line)
Expand Down Expand Up @@ -257,26 +257,22 @@ def freedb_command(freedb_server, freedb_port, cmd, *args):

# generate query to post with arguments in specific order
if len(args) > 0:
POST.append((u"cmd", u"cddb %s %s" % (cmd, " ".join(args))))
POST.append((u"cmd", u"cddb {} {}".format(cmd, " ".join(args))))
else:
POST.append((u"cmd", u"cddb %s" % (cmd)))
POST.append((u"cmd", u"cddb {}".format(cmd)))

if PY3:
POST.append((u"hello",
u"user %s %s %s" % (getfqdn(),
u"audiotools",
VERSION)))
else:
POST.append((u"hello",
u"user %s %s %s" % (getfqdn().decode("UTF-8", "replace"),
u"audiotools",
VERSION.decode("ascii"))))
POST.append(
(u"hello",
u"user {} {} {}".format(
getfqdn() if PY3 else getfqdn().decode("UTF-8", "replace"),
u"audiotools",
VERSION if PY3 else VERSION.decode("ascii"))))

POST.append((u"proto", u"6"))

# get Request object from post
request = urlopen(
"http://%s:%d/~cddb/cddb.cgi" % (freedb_server, freedb_port),
"http://{}:{:d}/~cddb/cddb.cgi".format(freedb_server, freedb_port),
urlencode(POST).encode("UTF-8") if (version_info[0] >= 3) else
urlencode(POST))
try:
Expand Down
20 changes: 10 additions & 10 deletions audiotools/id3v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def __init__(self, track_name=u"",
MetaData.__setattr__(self, "__genre__", genre)

def __repr__(self):
return "ID3v1Comment(%s, %s, %s, %s, %s, %s, %s)" % \
(repr(self.__track_name__),
repr(self.__artist_name__),
repr(self.__album_name__),
repr(self.__year__),
repr(self.__comment__),
repr(self.__track_number__),
repr(self.__genre__))
return "ID3v1Comment({!r},{!r},{!r},{!r},{!r},{!r},{!r})".format(
self.__track_name__,
self.__artist_name__,
self.__album_name__,
self.__year__,
self.__comment__,
self.__track_number__,
self.__genre__)

def __getattr__(self, attr):
if attr == "track_number":
Expand Down Expand Up @@ -149,15 +149,15 @@ def raw_info(self):

return linesep.join(
[u"ID3v1.1:"] +
[u"%s = %s" % (label, getattr(self, attr))
[u"{} = {}".format(label, getattr(self, attr))
for (label, attr) in [(u" track name", "track_name"),
(u" artist name", "artist_name"),
(u" album name", "album_name"),
(u" year", "year"),
(u" comment", "comment"),
(u"track number", "track_number")]
if (getattr(self, attr) is not None)] +
[u" genre = %d" % (self.__genre__)])
[u" genre = {:d}".format(self.__genre__)])

@classmethod
def parse(cls, mp3_file):
Expand Down
2 changes: 1 addition & 1 deletion audiotools/mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, value, length):
self.__length__ = length

def __repr__(self):
return "MPC_Size(%d, %d)" % (self.__value__, self.__length__)
return "MPC_Size({!r}, {!r})".format(self.__value__, self.__length__)

def __int__(self):
return self.__value__
Expand Down
20 changes: 10 additions & 10 deletions audiotools/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def from_sheet(cls, sheet, total_pcm_frames, sample_rate):
offsets=[int(t.index(1).offset() * 75 + 150) for t in sheet])

def __repr__(self):
return "DiscID(%s)" % \
", ".join(["%s=%s" % (attr, getattr(self, attr))
return "DiscID({})".format(
", ".join(["{}={!r}".format(attr, getattr(self, attr))
for attr in ["first_track_number",
"last_track_number",
"lead_out_offset",
"offsets"]])
"offsets"]]))

if sys.version_info[0] >= 3:
def __str__(self):
Expand All @@ -105,10 +105,10 @@ def __unicode__(self):
from hashlib import sha1
from base64 import b64encode

raw_id = (u"%2.2X%2.2X%s" %
raw_id = (u"{:02X}{:02X}{}".format(
(self.first_track_number,
self.last_track_number,
u"".join([u"%8.8X" % (offset) for offset in
u"".join([u"{:08X}".format(offset) for offset in
[self.lead_out_offset] +
self.offsets +
[0] * (99 - len(self.offsets))])))
Expand Down Expand Up @@ -140,11 +140,11 @@ def perform_lookup(disc_id, musicbrainz_server, musicbrainz_port):
from audiotools.coverartarchive import perform_lookup as image_lookup

# query MusicBrainz web service (version 2) for <metadata>
m = urlopen("http://%s:%d/ws/2/discid/%s?%s" %
(musicbrainz_server,
musicbrainz_port,
disc_id,
urlencode({"inc": "artists labels recordings"})))
m = urlopen("http://{}:{:d}/ws/2/discid/{}?{}".format(
musicbrainz_server,
musicbrainz_port,
disc_id,
urlencode({"inc": "artists labels recordings"})))
xml = xml.dom.minidom.parse(m)
m.close()

Expand Down
2 changes: 1 addition & 1 deletion audiotools/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,4 +1213,4 @@ def open_output(output):
if audio_output.NAME == output:
return audio_output
else:
raise ValueError("no such outout %s" % (output))
raise ValueError("no such outout {}".format(output))
4 changes: 2 additions & 2 deletions audiotools/wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, chunk_id, chunk_size, chunk_data):
self.__data__ = chunk_data

def __repr__(self):
return "RIFF_Chunk(%s)" % (repr(self.id))
return "RIFF_Chunk({!r})".format(self.id)

def size(self):
"""returns size of chunk in bytes
Expand Down Expand Up @@ -98,7 +98,7 @@ def __del__(self):
self.__wav_file__.close()

def __repr__(self):
return "RIFF_File_Chunk(%s)" % (repr(self.id))
return "RIFF_File_Chunk({!r})".format(self.id)

def data(self):
"""returns chunk data as file-like object"""
Expand Down
2 changes: 1 addition & 1 deletion audiotools/wavpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def set_cuesheet(self, cuesheet):

cuesheet_data = BytesIO()
write_cuesheet(cuesheet,
u"%s" % (Filename(self.filename).basename(),),
u"{}".format(Filename(self.filename).basename()),
cuesheet_data)

metadata[b'Cuesheet'] = ApeTag.ITEM.string(
Expand Down

0 comments on commit 9e09945

Please sign in to comment.