More f-string changes (#1025)

This commit is contained in:
JonnyWong16 2022-11-08 13:40:18 -08:00 committed by GitHub
parent 52b3abfe69
commit 9b0c8e5fd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 40 deletions

View file

@ -105,7 +105,7 @@ Usage Examples
# Example 5: List all content with the word 'Game' in the title.
for video in plex.search('Game'):
print('%s (%s)' % (video.title, video.TYPE))
print(f'{video.title} ({video.TYPE})')
.. code-block:: python

View file

@ -812,8 +812,8 @@ class Playable:
durationStr = durationStr + str(duration)
else:
durationStr = durationStr + str(self.duration)
key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s%s'
key %= (self.ratingKey, self.key, time, state, durationStr)
key = (f'/:/timeline?ratingKey={self.ratingKey}&key={self.key}&'
f'identifier=com.plexapp.plugins.library&time={int(time)}&state={state}{durationStr}')
self._server.query(key)
self._reload(_overwriteNone=False)

View file

@ -212,7 +212,7 @@ class PlexClient(PlexObject):
controller = command.split('/')[0]
headers = {'X-Plex-Target-Client-Identifier': self.machineIdentifier}
if controller not in self.protocolCapabilities:
log.debug(f"Client {self.title} doesn't support {controller} controller. What your trying might not work")
log.debug("Client %s doesn't support %s controller. What your trying might not work", self.title, controller)
proxy = self._proxyThroughServer if proxy is None else proxy
query = self._server.query if proxy else self.query

View file

@ -550,9 +550,8 @@ class Collection(
sync_item.metadataType = self.metadataType
sync_item.machineIdentifier = self._server.machineIdentifier
sync_item.location = 'library:///directory/%s' % quote_plus(
'%s/children?excludeAllLeaves=1' % (self.key)
)
key = quote_plus(f'{self.key}/children?excludeAllLeaves=1')
sync_item.location = f'library:///directory/{key}'
sync_item.policy = Policy.create(limit, unwatched)
if self.isVideo:

View file

@ -483,8 +483,8 @@ class LibrarySection(PlexObject):
xpath = (
'./MediaProvider[@identifier="com.plexapp.plugins.library"]'
'/Feature[@type="content"]'
'/Directory[@id="%s"]'
) % self.key
f'/Directory[@id="{self.key}"]'
)
directory = next(iter(data.findall(xpath)), None)
if directory:
self._totalDuration = utils.cast(int, directory.attrib.get('durationTotal'))
@ -710,7 +710,7 @@ class LibrarySection(PlexObject):
""" Edit a library's advanced settings. """
data = {}
idEnums = {}
key = 'prefs[%s]'
key = 'prefs[{}]'
for setting in self.settings():
if setting.type != 'bool':
@ -724,7 +724,7 @@ class LibrarySection(PlexObject):
except KeyError:
raise NotFound(f'{value} not found in {list(idEnums.keys())}')
if value in enums:
data[key % settingID] = value
data[key.format(settingID)] = value
else:
raise NotFound(f'{value} not found in {enums}')
@ -733,12 +733,12 @@ class LibrarySection(PlexObject):
def defaultAdvanced(self):
""" Edit all of library's advanced settings to default. """
data = {}
key = 'prefs[%s]'
key = 'prefs[{}]'
for setting in self.settings():
if setting.type == 'bool':
data[key % setting.id] = int(setting.default)
data[key.format(setting.id)] = int(setting.default)
else:
data[key % setting.id] = setting.default
data[key.format(setting.id)] = setting.default
return self.edit(**data)
@ -988,7 +988,7 @@ class LibrarySection(PlexObject):
field = 'genre' # Available filter field from listFields()
filterField = next(f for f in library.listFields() if f.key.endswith(field))
availableOperators = [o.key for o in library.listOperators(filterField.type)]
print("Available operators for %s:" % field, availableOperators)
print(f"Available operators for {field}:", availableOperators)
"""
return self.getFieldType(fieldType).operators
@ -1015,7 +1015,7 @@ class LibrarySection(PlexObject):
field = 'genre' # Available filter field from listFilters()
availableChoices = [f.title for f in library.listFilterChoices(field)]
print("Available choices for %s:" % field, availableChoices)
print(f"Available choices for {field}:", availableChoices)
"""
if isinstance(field, str):

View file

@ -95,7 +95,7 @@ class Media(PlexObject):
try:
return self._server.query(part, method=self._server._session.delete)
except BadRequest:
log.error(f"Failed to delete {part}. This could be because you haven't allowed items to be deleted")
log.error("Failed to delete %s. This could be because you haven't allowed items to be deleted", part)
raise

View file

@ -598,7 +598,7 @@ class MyPlexAccount(PlexObject):
values = []
for key, vals in filterDict.items():
if key not in ('contentRating', 'label', 'contentRating!', 'label!'):
raise BadRequest('Unknown filter key: %s', key)
raise BadRequest(f'Unknown filter key: {key}')
values.append(f"{key}={'%2C'.join(vals)}")
return '|'.join(values)
@ -615,7 +615,7 @@ class MyPlexAccount(PlexObject):
return self.setWebhooks(urls)
def setWebhooks(self, urls):
log.info(f'Setting webhooks: {urls}')
log.info('Setting webhooks: %s', urls)
data = {'urls[]': urls} if len(urls) else {'urls': ''}
data = self.query(self.WEBHOOKS, self._session.post, data=data)
self._webhooks = self.listAttrs(data, 'url', etag='webhook')
@ -686,7 +686,7 @@ class MyPlexAccount(PlexObject):
break
if not client:
raise BadRequest('Unable to find client by clientId=%s', clientId)
raise BadRequest(f'Unable to find client by clientId={clientId}')
if 'sync-target' not in client.provides:
raise BadRequest("Received client doesn't provides sync-target")
@ -1037,7 +1037,7 @@ class MyPlexUser(PlexObject):
if utils.cast(int, item.attrib.get('userID')) == self.id:
return item.attrib.get('accessToken')
except Exception:
log.exception(f'Failed to get access token for {self.title}')
log.exception('Failed to get access token for %s', self.title)
def server(self, name):
""" Returns the :class:`~plexapi.myplex.MyPlexServerShare` that matches the name specified.

View file

@ -911,8 +911,7 @@ class PlexServer(PlexObject):
gigabytes = round(bandwidth.bytes / 1024**3, 3)
local = 'local' if bandwidth.lan else 'remote'
date = bandwidth.at.strftime('%Y-%m-%d')
print('%s used %s GB of %s bandwidth on %s from %s'
% (account.name, gigabytes, local, date, device.name))
print(f'{account.name} used {gigabytes} GB of {local} bandwidth on {date} from {device.name}')
"""
params = {}
@ -1149,12 +1148,14 @@ class StatisticsBandwidth(PlexObject):
self.timespan = utils.cast(int, data.attrib.get('timespan'))
def __repr__(self):
return '<%s>' % ':'.join([p for p in [
self.__class__.__name__,
self._clean(self.accountID),
self._clean(self.deviceID),
self._clean(int(self.at.timestamp()))
] if p])
return '<{}>'.format(
':'.join([p for p in [
self.__class__.__name__,
self._clean(self.accountID),
self._clean(self.deviceID),
self._clean(int(self.at.timestamp()))
] if p])
)
def account(self):
""" Returns the :class:`~plexapi.server.SystemAccount` associated with the bandwidth data. """

View file

@ -77,7 +77,7 @@ class Settings(PlexObject):
params = {}
for setting in self.all():
if setting._setValue:
log.info(f'Saving PlexServer setting {setting.id} = {setting._setValue}')
log.info('Saving PlexServer setting %s = %s', setting.id, setting._setValue)
params[setting.id] = quote(setting._setValue)
if not params:
raise BadRequest('No setting have been modified.')

View file

@ -671,11 +671,13 @@ class Season(
yield episode
def __repr__(self):
return '<%s>' % ':'.join([p for p in [
self.__class__.__name__,
self.key.replace('/library/metadata/', '').replace('/children', ''),
'%s-s%s' % (self.parentTitle.replace(' ', '-')[:20], self.seasonNumber),
] if p])
return '<{}>'.format(
':'.join([p for p in [
self.__class__.__name__,
self.key.replace('/library/metadata/', '').replace('/children', ''),
f"{self.parentTitle.replace(' ', '-')[:20]}-{self.seasonNumber}",
] if p])
)
@property
def isPlayed(self):
@ -862,11 +864,13 @@ class Episode(
self.parentKey = f'/library/metadata/{self.parentRatingKey}'
def __repr__(self):
return '<%s>' % ':'.join([p for p in [
self.__class__.__name__,
self.key.replace('/library/metadata/', '').replace('/children', ''),
'%s-%s' % (self.grandparentTitle.replace(' ', '-')[:20], self.seasonEpisode),
] if p])
return '<{}>'.format(
':'.join([p for p in [
self.__class__.__name__,
self.key.replace('/library/metadata/', '').replace('/children', ''),
f"{self.grandparentTitle.replace(' ', '-')[:20]}-{self.seasonEpisode}",
] if p])
)
def _prettyfilename(self):
""" Returns a filename for use in download. """