Skip to content

Commit

Permalink
Migrated % string formating
Browse files Browse the repository at this point in the history
  • Loading branch information
quantifiedcode-bot committed Feb 21, 2017
1 parent 35c8678 commit 7dbec7b
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion examples/addcontacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():
for item in backup['PhonePhonebook']:
item['MemoryType'] = memory
loc = state_machine.AddMemory(item)
print(('Added item to location %d' % loc))
print(('Added item to location {0:d}'.format(loc)))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/batteryinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@

for x in status:
if status[x] != -1:
print(("%20s: %s" % (x, status[x])))
print(("{0:20!s}: {1!s}".format(x, status[x])))
8 changes: 4 additions & 4 deletions examples/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def main():
imei = state_machine.GetIMEI()
firmware = state_machine.GetFirmware()
print('Phone infomation:')
print(('%-15s: %s' % ('Manufacturer', manufacturer)))
print(('%-15s: %s (%s)' % ('Model', model[0], model[1])))
print(('%-15s: %s' % ('IMEI', imei)))
print(('%-15s: %s' % ('Firmware', firmware[0])))
print(('{0:<15!s}: {1!s}'.format('Manufacturer', manufacturer)))
print(('{0:<15!s}: {1!s} ({2!s})'.format('Model', model[0], model[1])))
print(('{0:<15!s}: {1!s}'.format('IMEI', imei)))
print(('{0:<15!s}: {1!s}'.format('Firmware', firmware[0])))


if __name__ == '__main__':
Expand Down
40 changes: 20 additions & 20 deletions examples/dummy_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def get_all_memory(state_machine, memory_type):
remain = remain - 1

print()
print(('%-15s: %d' % ('Location', entry['Location'])))
print(('{0:<15!s}: {1:d}'.format('Location', entry['Location'])))
for v in entry['Entries']:
if v['Type'] in ('Photo'):
print(('%-15s: %s...' % (v['Type'], repr(v['Value'])[:30])))
print(('{0:<15!s}: {1!s}...'.format(v['Type'], repr(v['Value'])[:30])))
else:
print((
'%-15s: %s' % (v['Type'], str(v['Value']).encode('utf-8'))
'{0:<15!s}: {1!s}'.format(v['Type'], str(v['Value']).encode('utf-8'))
))


Expand All @@ -74,18 +74,18 @@ def get_all_calendar(state_machine):
remain = remain - 1

print()
print(('%-20s: %d' % ('Location', entry['Location'])))
print(('%-20s: %s' % ('Type', entry['Type'])))
print(('{0:<20!s}: {1:d}'.format('Location', entry['Location'])))
print(('{0:<20!s}: {1!s}'.format('Type', entry['Type'])))
for v in entry['Entries']:
print(('%-20s: %s' % (v['Type'], str(v['Value']).encode('utf-8'))))
print(('{0:<20!s}: {1!s}'.format(v['Type'], str(v['Value']).encode('utf-8'))))


def get_battery_status(state_machine):
status = state_machine.GetBatteryCharge()

for x in status:
if status[x] != -1:
print(("%20s: %s" % (x, status[x])))
print(("{0:20!s}: {1!s}".format(x, status[x])))


def get_all_sms(state_machine):
Expand All @@ -110,22 +110,22 @@ def get_all_sms(state_machine):

def print_sms_header(message, folders):
print()
print('%-15s: %s' % ('Number', message['Number'].encode('utf-8')))
print('%-15s: %s' % ('Date', str(message['DateTime'])))
print('%-15s: %s' % ('State', message['State']))
print('%-15s: %s %s (%d)' % (
print('{0:<15!s}: {1!s}'.format('Number', message['Number'].encode('utf-8')))
print('{0:<15!s}: {1!s}'.format('Date', str(message['DateTime'])))
print('{0:<15!s}: {1!s}'.format('State', message['State']))
print('{0:<15!s}: {1!s} {2!s} ({3:d})'.format(
'Folder',
folders[message['Folder']]['Name'].encode('utf-8'),
folders[message['Folder']]['Memory'].encode('utf-8'),
message['Folder']
))
print('%-15s: %s' % ('Validity', message['SMSC']['Validity']))
print('{0:<15!s}: {1!s}'.format('Validity', message['SMSC']['Validity']))


def print_all_sms(sms, folders):
for m in sms:
print_sms_header(m, folders)
print('\n%s' % m['Text'].encode('utf-8'))
print('\n{0!s}'.format(m['Text'].encode('utf-8')))


def link_all_sms(sms, folders):
Expand All @@ -139,13 +139,13 @@ def link_all_sms(sms, folders):
loc = []
for m in x:
loc.append(str(m['Location']))
print('%-15s: %s' % ('Location(s)', ', '.join(loc)))
print('{0:<15!s}: {1!s}'.format('Location(s)', ', '.join(loc)))
if v is None:
print('\n%s' % m['Text'].encode('utf-8'))
print('\n{0!s}'.format(m['Text'].encode('utf-8')))
else:
for e in v['Entries']:
print()
print('%-15s: %s' % ('Type', e['ID']))
print('{0:<15!s}: {1!s}'.format('Type', e['ID']))
if e['Bitmap'] is not None:
for bmp in e['Bitmap']:
print('Bitmap:')
Expand Down Expand Up @@ -174,16 +174,16 @@ def get_all_todo(state_machine):
remain = remain - 1

print()
print('%-15s: %d' % ('Location', entry['Location']))
print('%-15s: %s' % ('Priority', entry['Priority']))
print('{0:<15!s}: {1:d}'.format('Location', entry['Location']))
print('{0:<15!s}: {1!s}'.format('Priority', entry['Priority']))
for v in entry['Entries']:
print('%-15s: %s' % (v['Type'], str(v['Value']).encode('utf-8')))
print('{0:<15!s}: {1!s}'.format(v['Type'], str(v['Value']).encode('utf-8')))


def get_sms_folders(state_machine):
folders = state_machine.GetSMSFolders()
for i, folder in enumerate(folders):
print('Folder %d: %s (%s)' % (
print('Folder {0:d}: {1!s} ({2!s})'.format(
i,
folder['Name'].encode('utf-8'),
folder['Memory'].encode('utf-8')
Expand Down
2 changes: 1 addition & 1 deletion examples/filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def main():
try:
fs_info = state_machine.GetFileSystemStatus()
fs_info["Total"] = fs_info["Free"] + fs_info["Used"]
print("Used: %(Used)d, Free: %(Free)d, Total: %(Total)d" % fs_info)
print("Used: {Used:d}, Free: {Free:d}, Total: {Total:d}".format(**fs_info))
except gammu.ERR_NOTSUPPORTED:
print("You will have to live without this knowledge")

Expand Down
6 changes: 3 additions & 3 deletions examples/getallcalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Display it
print()
print('%-20s: %d' % ('Location', entry['Location']))
print('%-20s: %s' % ('Type', entry['Type']))
print('{0:<20!s}: {1:d}'.format('Location', entry['Location']))
print('{0:<20!s}: {1!s}'.format('Type', entry['Type']))
for v in entry['Entries']:
print('%-20s: %s' % (v['Type'], str(v['Value'])))
print('{0:<20!s}: {1!s}'.format(v['Type'], str(v['Value'])))
4 changes: 2 additions & 2 deletions examples/getallmemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def main():
remain = remain - 1

print()
print('%-15s: %d' % ('Location', entry['Location']))
print('{0:<15!s}: {1:d}'.format('Location', entry['Location']))
for v in entry['Entries']:
print('%-15s: %s' % (v['Type'], str(v['Value'])))
print('{0:<15!s}: {1!s}'.format(v['Type'], str(v['Value'])))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions examples/getallmemory_nonext.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def main():
try:
entry = state_machine.GetMemory(Type=memory_type, Location=location)
print()
print('%-15s: %d' % ('Location', entry['Location']))
print('{0:<15!s}: {1:d}'.format('Location', entry['Location']))
for v in entry['Entries']:
print('%-15s: %s' % (v['Type'], str(v['Value'])))
print('{0:<15!s}: {1!s}'.format(v['Type'], str(v['Value'])))
remain = remain - 1
except gammu.ERR_EMPTY:
pass
Expand Down
8 changes: 4 additions & 4 deletions examples/getallsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def main():

for m in sms:
print()
print('%-15s: %s' % ('Number', m['Number']))
print('%-15s: %s' % ('Date', str(m['DateTime'])))
print('%-15s: %s' % ('State', m['State']))
print('\n%s' % m['Text'])
print('{0:<15!s}: {1!s}'.format('Number', m['Number']))
print('{0:<15!s}: {1!s}'.format('Date', str(m['DateTime'])))
print('{0:<15!s}: {1!s}'.format('State', m['State']))
print('\n{0!s}'.format(m['Text']))
except gammu.ERR_EMPTY:
# This error is raised when we've reached last entry
# It can happen when reported status does not match real counts
Expand Down
16 changes: 8 additions & 8 deletions examples/getallsms_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@

m = x[0]
print()
print('%-15s: %s' % ('Number', m['Number']))
print('%-15s: %s' % ('Date', str(m['DateTime'])))
print('%-15s: %s' % ('State', m['State']))
print('%-15s: %s' % ('Folder', m['Folder']))
print('%-15s: %s' % ('Validity', m['SMSC']['Validity']))
print('{0:<15!s}: {1!s}'.format('Number', m['Number']))
print('{0:<15!s}: {1!s}'.format('Date', str(m['DateTime'])))
print('{0:<15!s}: {1!s}'.format('State', m['State']))
print('{0:<15!s}: {1!s}'.format('Folder', m['Folder']))
print('{0:<15!s}: {1!s}'.format('Validity', m['SMSC']['Validity']))
loc = []
for m in x:
loc.append(str(m['Location']))
print('%-15s: %s' % ('Location(s)', ', '.join(loc)))
print('{0:<15!s}: {1!s}'.format('Location(s)', ', '.join(loc)))
if v is None:
print('\n%s' % m['Text'])
print('\n{0!s}'.format(m['Text']))
else:
for e in v['Entries']:
print()
print('%-15s: %s' % ('Type', e['ID']))
print('{0:<15!s}: {1!s}'.format('Type', e['ID']))
if e['Bitmap'] is not None:
for bmp in e['Bitmap']:
print('Bitmap:')
Expand Down
6 changes: 3 additions & 3 deletions examples/getalltodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def main():
remain = remain - 1

print()
print('%-15s: %d' % ('Location', entry['Location']))
print('%-15s: %s' % ('Priority', entry['Priority']))
print('{0:<15!s}: {1:d}'.format('Location', entry['Location']))
print('{0:<15!s}: {1!s}'.format('Priority', entry['Priority']))
for v in entry['Entries']:
print('%-15s: %s' % (v['Type'], str(v['Value'])))
print('{0:<15!s}: {1!s}'.format(v['Type'], str(v['Value'])))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions examples/incoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def callback(state_machine, callback_type, data):
@param data: event data
@type data: hash
'''
print('Received incoming event type %s, data:' % callback_type)
print('Received incoming event type {0!s}, data:'.format(callback_type))
print(data)


Expand Down Expand Up @@ -77,7 +77,7 @@ def main():
print('Press Ctrl+C to interrupt')
while 1:
signal = state_machine.GetSignalQuality()
print('Signal is at %d%%' % signal['SignalPercent'])
print('Signal is at {0:d}%'.format(signal['SignalPercent']))
time.sleep(1)

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/mass_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
try:
state_machine.SendSMS(message)
except gammu.GSMError as exc:
print('Sending to %s failed: %s' % (number, exc))
print('Sending to {0!s} failed: {1!s}'.format(number, exc))
16 changes: 8 additions & 8 deletions examples/read_sms_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ def main():

part = message[0]
print()
print('%-15s: %s' % ('Number', part['Number']))
print('%-15s: %s' % ('Date', str(part['DateTime'])))
print('%-15s: %s' % ('State', part['State']))
print('%-15s: %s' % ('Folder', part['Folder']))
print('%-15s: %s' % ('Validity', part['SMSC']['Validity']))
print('{0:<15!s}: {1!s}'.format('Number', part['Number']))
print('{0:<15!s}: {1!s}'.format('Date', str(part['DateTime'])))
print('{0:<15!s}: {1!s}'.format('State', part['State']))
print('{0:<15!s}: {1!s}'.format('Folder', part['Folder']))
print('{0:<15!s}: {1!s}'.format('Validity', part['SMSC']['Validity']))
loc = []
for part in message:
loc.append(str(part['Location']))
print('%-15s: %s' % ('Location(s)', ', '.join(loc)))
print('{0:<15!s}: {1!s}'.format('Location(s)', ', '.join(loc)))
if decoded is None:
print('\n%s' % charsetencoder(part['Text'], 'replace')[0])
print('\n{0!s}'.format(charsetencoder(part['Text'], 'replace')[0]))
else:
for entries in decoded['Entries']:
print()
print('%-15s: %s' % ('Type', entries['ID']))
print('{0:<15!s}: {1!s}'.format('Type', entries['ID']))
if entries['Bitmap'] is not None:
for bmp in entries['Bitmap']:
print('Bitmap:')
Expand Down
4 changes: 2 additions & 2 deletions examples/service_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def callback(state_machine, callback_type, data):
'''
global REPLY
if callback_type != 'USSD':
print('Unexpected event type: %s' % callback_type)
print('Unexpected event type: {0!s}'.format(callback_type))
sys.exit(1)

REPLY = True

print('Network reply:')
print('Status: %s' % data['Status'])
print('Status: {0!s}'.format(data['Status']))
print(data['Text'])

if data['Status'] == 'ActionNeeded':
Expand Down
6 changes: 3 additions & 3 deletions examples/sms_replier.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def reply_test(message):
if message['Number'] == '999':
# No reply to this number
return None
return 'Reply to %s' % message['Text']
return 'Reply to {0!s}'.format(message['Text'])


# Reply function, first element is matching string, second can be:
Expand All @@ -55,7 +55,7 @@ def reply_test(message):


def Callback(state_machine, callback_type, data):
verbose_print('Received incoming event type %s, data:' % callback_type)
verbose_print('Received incoming event type {0!s}, data:'.format(callback_type))
if callback_type != 'SMS':
print('Unsupported event!')
if 'Number' not in data:
Expand Down Expand Up @@ -97,7 +97,7 @@ def main():
while 1:
time.sleep(1)
status = state_machine.GetBatteryCharge()
print('Battery is at %d%%' % status['BatteryPercent'])
print('Battery is at {0:d}%'.format(status['BatteryPercent']))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def callback(name, result, error, percents):
to work with GUI here.
'''
print(
'-> %s completed %d%% with error %s , return value:' % (
'-> {0!s} completed {1:d}% with error {2!s} , return value:'.format(
name,
percents,
error
Expand Down
6 changes: 3 additions & 3 deletions gammu/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __str__(self):
'''
Returns textual representation of exception.
'''
return 'Invalid command: "%s"' % self.value
return 'Invalid command: "{0!s}"'.format(self.value)


def check_worker_command(command):
Expand Down Expand Up @@ -104,9 +104,9 @@ def __str__(self):
Returns textual representation.
'''
if self._params is not None:
return '%s %r' % (self._command, self._params)
return '{0!s} {1!r}'.format(self._command, self._params)
else:
return '%s ()' % self._command
return '{0!s} ()'.format(self._command)


class GammuTask(object):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def check_minimum_gammu_version():

def get_pkgconfig_data(args, mod, required=True):
"""Run pkg-config to and return content associated with it"""
f = os.popen("pkg-config %s %s" % (" ".join(args), mod))
f = os.popen("pkg-config {0!s} {1!s}".format(" ".join(args), mod))

line = f.readline()
if line is not None:
Expand All @@ -57,7 +57,7 @@ def get_pkgconfig_data(args, mod, required=True):
if line is None or line == "":
if required:
raise Exception(
"Cannot determine '%s' from pkg-config" % " ".join(args)
"Cannot determine '{0!s}' from pkg-config".format(" ".join(args))
)
else:
return ""
Expand Down
Loading

0 comments on commit 7dbec7b

Please sign in to comment.