Remove every default argument using [] or {}.

This commit is contained in:
Emmanuel Gil Peyrot 2017-02-08 02:12:41 +00:00
parent 1f9ac730ce
commit 57fb80f1fa
15 changed files with 116 additions and 41 deletions

View file

@ -1151,7 +1151,7 @@ class ChatControl(ChatControlBase):
def print_conversation(self, text, frm='', tim=None, encrypted=False, def print_conversation(self, text, frm='', tim=None, encrypted=False,
subject=None, xhtml=None, simple=False, xep0184_id=None, subject=None, xhtml=None, simple=False, xep0184_id=None,
displaymarking=None, msg_log_id=None, correct_id=None, displaymarking=None, msg_log_id=None, correct_id=None,
msg_stanza_id=None, additional_data={}): msg_stanza_id=None, additional_data=None):
""" """
Print a line in the conversation Print a line in the conversation
@ -1166,6 +1166,9 @@ class ChatControl(ChatControlBase):
""" """
contact = self.contact contact = self.contact
if additional_data is None:
additional_data = {}
if frm == 'status': if frm == 'status':
if not gajim.config.get('print_status_in_chats'): if not gajim.config.get('print_status_in_chats'):
return return

View file

@ -737,7 +737,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return label return label
def send_message(self, message, keyID='', type_='chat', chatstate=None, def send_message(self, message, keyID='', type_='chat', chatstate=None,
msg_id=None, resource=None, xhtml=None, callback=None, callback_args=[], msg_id=None, resource=None, xhtml=None, callback=None, callback_args=None,
process_commands=True, attention=False): process_commands=True, attention=False):
""" """
Send the given message to the active tab. Doesn't return None if error Send the given message to the active tab. Doesn't return None if error
@ -745,6 +745,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if not message or message == '\n': if not message or message == '\n':
return None return None
if callback_args is None:
callback_args = []
if process_commands and self.process_as_command(message): if process_commands and self.process_as_command(message):
return return
@ -807,7 +810,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[], other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False, count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None, xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None,
msg_stanza_id=None, correct_id=None, additional_data={}): msg_stanza_id=None, correct_id=None, additional_data=None):
""" """
Print 'chat' type messages Print 'chat' type messages
correct_id = (message_id, correct_id) correct_id = (message_id, correct_id)
@ -819,6 +822,15 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if self.was_at_the_end or kind == 'outgoing': if self.was_at_the_end or kind == 'outgoing':
end = True end = True
if other_tags_for_name is None:
other_tags_for_name = []
if other_tags_for_time is None:
other_tags_for_time = []
if other_tags_for_text is None:
other_tags_for_text = []
if additional_data is None:
additional_data = {}
textview.print_conversation_line(text, jid, kind, name, tim, textview.print_conversation_line(text, jid, kind, name, tim,
other_tags_for_name, other_tags_for_time, other_tags_for_text, other_tags_for_name, other_tags_for_time, other_tags_for_text,
subject, old_kind, xhtml, simple=simple, graphics=graphics, subject, old_kind, xhtml, simple=simple, graphics=graphics,

View file

@ -94,13 +94,15 @@ def create_suitable_client_caps(node, caps_hash, hash_method, fjid=None):
client_caps = ClientCaps(caps_hash, node, hash_method) client_caps = ClientCaps(caps_hash, node, hash_method)
return client_caps return client_caps
def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'): def compute_caps_hash(identities, features, dataforms=None, hash_method='sha-1'):
""" """
Compute caps hash according to XEP-0115, V1.5 Compute caps hash according to XEP-0115, V1.5
dataforms are nbxmpp.DataForms objects as common.dataforms don't allow several dataforms are nbxmpp.DataForms objects as common.dataforms don't allow several
values without a field type list-multi values without a field type list-multi
""" """
if dataforms is None:
dataforms = []
def sort_identities_func(i1, i2): def sort_identities_func(i1, i2):
cat1 = i1['category'] cat1 = i1['category']
cat2 = i2['category'] cat2 = i2['category']

View file

@ -526,7 +526,9 @@ class CommonConnection:
subject, type_, msg_iq, xhtml) subject, type_, msg_iq, xhtml)
def log_message(self, jid, msg, forward_from, session, original_message, def log_message(self, jid, msg, forward_from, session, original_message,
subject, type_, xhtml=None, additional_data={}): subject, type_, xhtml=None, additional_data=None):
if additional_data is None:
additional_data = {}
if not forward_from and session and session.is_loggable(): if not forward_from and session and session.is_loggable():
ji = gajim.get_jid_without_resource(jid) ji = gajim.get_jid_without_resource(jid)
if gajim.config.should_log(self.name, ji): if gajim.config.should_log(self.name, ji):
@ -567,7 +569,7 @@ class CommonConnection:
""" """
raise NotImplementedError raise NotImplementedError
def request_subscription(self, jid, msg='', name='', groups=[], def request_subscription(self, jid, msg='', name='', groups=None,
auto_auth=False): auto_auth=False):
""" """
To be implemented by derivated classes To be implemented by derivated classes
@ -2251,10 +2253,12 @@ class Connection(CommonConnection, ConnectionHandlers):
p = nbxmpp.Presence(jid, 'unsubscribe') p = nbxmpp.Presence(jid, 'unsubscribe')
self.connection.send(p) self.connection.send(p)
def request_subscription(self, jid, msg='', name='', groups=[], def request_subscription(self, jid, msg='', name='', groups=None,
auto_auth=False, user_nick=''): auto_auth=False, user_nick=''):
if not gajim.account_is_connected(self.name): if not gajim.account_is_connected(self.name):
return return
if groups is None:
groups = []
log.debug('subscription request for %s' % jid) log.debug('subscription request for %s' % jid)
if auto_auth: if auto_auth:
self.jids_for_auto_auth.append(jid) self.jids_for_auto_auth.append(jid)

View file

@ -92,12 +92,14 @@ class Contact(CommonContact):
""" """
Information concerning a contact Information concerning a contact
""" """
def __init__(self, jid, account, name='', groups=[], show='', status='', def __init__(self, jid, account, name='', groups=None, show='', status='',
sub='', ask='', resource='', priority=0, keyID='', client_caps=None, sub='', ask='', resource='', priority=0, keyID='', client_caps=None,
our_chatstate=None, chatstate=None, last_status_time=None, msg_log_id=None, our_chatstate=None, chatstate=None, last_status_time=None, msg_log_id=None,
last_activity_time=None): last_activity_time=None):
if not isinstance(jid, str): if not isinstance(jid, str):
print('no str') print('no str')
if groups is None:
groups = []
CommonContact.__init__(self, jid, account, resource, show, status, name, CommonContact.__init__(self, jid, account, resource, show, status, name,
our_chatstate, chatstate, client_caps=client_caps) our_chatstate, chatstate, client_caps=client_caps)
@ -244,10 +246,12 @@ class LegacyContactsAPI:
del self._accounts[account] del self._accounts[account]
self._metacontact_manager.remove_account(account) self._metacontact_manager.remove_account(account)
def create_contact(self, jid, account, name='', groups=[], show='', def create_contact(self, jid, account, name='', groups=None, show='',
status='', sub='', ask='', resource='', priority=0, keyID='', status='', sub='', ask='', resource='', priority=0, keyID='',
client_caps=None, our_chatstate=None, chatstate=None, last_status_time=None, client_caps=None, our_chatstate=None, chatstate=None, last_status_time=None,
last_activity_time=None): last_activity_time=None):
if groups is None:
groups = []
# Use Account object if available # Use Account object if available
account = self._accounts.get(account, account) account = self._accounts.get(account, account)
return Contact(jid=jid, account=account, name=name, groups=groups, return Contact(jid=jid, account=account, name=name, groups=groups,
@ -348,12 +352,14 @@ class LegacyContactsAPI:
return contact return contact
return self.get_highest_prio_contact_from_contacts(contacts) return self.get_highest_prio_contact_from_contacts(contacts)
def get_nb_online_total_contacts(self, accounts=[], groups=[]): def get_nb_online_total_contacts(self, accounts=None, groups=None):
""" """
Return the number of online contacts and the total number of contacts Return the number of online contacts and the total number of contacts
""" """
if accounts == []: if not accounts:
accounts = self.get_accounts() accounts = self.get_accounts()
if groups is None:
groups = []
nbr_online = 0 nbr_online = 0
nbr_total = 0 nbr_total = 0
for account in accounts: for account in accounts:

View file

@ -247,11 +247,13 @@ class Events:
event.account = account event.account = account
self.fire_event_added(event) self.fire_event_added(event)
def remove_events(self, account, jid, event = None, types = []): def remove_events(self, account, jid, event=None, types=None):
""" """
If event is not specified, remove all events from this jid, optionally If event is not specified, remove all events from this jid, optionally
only from given type return True if no such event found only from given type return True if no such event found
""" """
if types is None:
types = []
if account not in self._events: if account not in self._events:
return True return True
if jid not in self._events[account]: if jid not in self._events[account]:
@ -297,15 +299,19 @@ class Events:
self._events[account][new_jid] = self._events[account][old_jid] self._events[account][new_jid] = self._events[account][old_jid]
del self._events[account][old_jid] del self._events[account][old_jid]
def get_nb_events(self, types = [], account = None): def get_nb_events(self, types=None, account=None):
if types is None:
types = []
return self._get_nb_events(types = types, account = account) return self._get_nb_events(types = types, account = account)
def get_events(self, account, jid = None, types = []): def get_events(self, account, jid=None, types=None):
""" """
Return all events from the given account of the form {jid1: [], jid2: Return all events from the given account of the form {jid1: [], jid2:
[]}. If jid is given, returns all events from the given jid in a list: [] []}. If jid is given, returns all events from the given jid in a list: []
optionally only from given type optionally only from given type
""" """
if types is None:
types = []
if account not in self._events: if account not in self._events:
return [] return []
if not jid: if not jid:
@ -342,11 +348,12 @@ class Events:
first_event = event first_event = event
return first_event return first_event
def _get_nb_events(self, account = None, jid = None, attribute = None, types def _get_nb_events(self, account=None, jid=None, attribute=None, types=None):
= []):
""" """
Return the number of pending events Return the number of pending events
""" """
if types is None:
types = []
nb = 0 nb = 0
if account: if account:
accounts = [account] accounts = [account]
@ -411,11 +418,13 @@ class Events:
first_event = event first_event = event
return first_account, first_jid, first_event return first_account, first_jid, first_event
def get_nb_systray_events(self, types = []): def get_nb_systray_events(self, types=None):
""" """
Return the number of events displayed in roster Return the number of events displayed in roster
""" """
return self._get_nb_events(attribute = 'systray', types = types) if types is None:
types = []
return self._get_nb_events(attribute='systray', types=types)
def get_systray_events(self): def get_systray_events(self):
""" """
@ -428,12 +437,14 @@ class Events:
events = self.get_systray_events() events = self.get_systray_events()
return self._get_first_event_with_attribute(events) return self._get_first_event_with_attribute(events)
def get_nb_roster_events(self, account = None, jid = None, types = []): def get_nb_roster_events(self, account=None, jid=None, types=None):
""" """
Return the number of events displayed in roster Return the number of events displayed in roster
""" """
return self._get_nb_events(attribute = 'roster', account = account, if types is None:
jid = jid, types = types) types = []
return self._get_nb_events(attribute='roster', account=account,
jid=jid, types=types)
def get_roster_events(self): def get_roster_events(self):
""" """

View file

@ -127,10 +127,12 @@ class JingleContent(object):
if candidates: if candidates:
self.add_remote_candidates(candidates) self.add_remote_candidates(candidates)
def __content(self, payload=[]): def __content(self, payload=None):
""" """
Build a XML content-wrapper for our data Build a XML content-wrapper for our data
""" """
if payload is None:
payload = []
return nbxmpp.Node('content', return nbxmpp.Node('content',
attrs={'name': self.name, 'creator': self.creator}, attrs={'name': self.name, 'creator': self.creator},
payload=payload) payload=payload)

View file

@ -89,9 +89,11 @@ class LocationListener:
def shut_down(self): def shut_down(self):
pass pass
def _on_geoclue_address_changed(self, timestamp=None, address={}, def _on_geoclue_address_changed(self, timestamp=None, address=None,
accuracy=None): accuracy=None):
# update data with info we just received # update data with info we just received
if address is None:
address = {}
for field in ['country', 'countrycode', 'locality', 'postalcode', for field in ['country', 'countrycode', 'locality', 'postalcode',
'region', 'street']: 'region', 'street']:
self._data[field] = address.get(field, None) self._data[field] = address.get(field, None)
@ -102,8 +104,10 @@ class LocationListener:
self._data['accuracy'] = accuracy[1] self._data['accuracy'] = accuracy[1]
self._send_location() self._send_location()
def _on_geoclue_position_changed(self, fields=[], timestamp=None, lat=None, def _on_geoclue_position_changed(self, fields=None, timestamp=None, lat=None,
lon=None, alt=None, accuracy=None): lon=None, alt=None, accuracy=None):
if fields is None:
fields = []
# update data with info we just received # update data with info we just received
_dict = {'lat': lat, 'lon': lon, 'alt': alt} _dict = {'lat': lat, 'lon': lon, 'alt': alt}
for field in _dict: for field in _dict:

View file

@ -490,7 +490,7 @@ class Logger:
all_messages.append(results[0]) all_messages.append(results[0])
return all_messages return all_messages
def write(self, kind, jid, message=None, show=None, tim=None, subject=None, additional_data={}): def write(self, kind, jid, message=None, show=None, tim=None, subject=None, additional_data=None):
""" """
Write a row (status, gcstatus, message etc) to logs database Write a row (status, gcstatus, message etc) to logs database
@ -504,6 +504,8 @@ class Logger:
ROOM_JID/nick if pm-related. ROOM_JID/nick if pm-related.
""" """
if additional_data is None:
additional_data = {}
if self.jids_already_in == []: # only happens if we just created the db if self.jids_already_in == []: # only happens if we just created the db
self.open_db() self.open_db()
@ -1101,7 +1103,9 @@ class Logger:
(account_jid_id,)) (account_jid_id,))
self._timeout_commit() self._timeout_commit()
def save_if_not_exists(self, with_, direction, tim, msg='', nick=None, additional_data={}): def save_if_not_exists(self, with_, direction, tim, msg='', nick=None, additional_data=None):
if additional_data is None:
additional_data = {}
if tim: if tim:
time_col = float(tim) time_col = float(tim)
else: else:

View file

@ -241,7 +241,8 @@ class OptionsParser:
caps_cache.capscache.initialize_from_db() caps_cache.capscache.initialize_from_db()
def assert_unread_msgs_table_exists(self): @staticmethod
def assert_unread_msgs_table_exists():
""" """
Create table unread_messages if there is no such table Create table unread_messages if there is no such table
""" """
@ -265,7 +266,12 @@ class OptionsParser:
pass pass
con.close() con.close()
def update_ft_proxies(self, to_remove=[], to_add=[]): @staticmethod
def update_ft_proxies(to_remove=None, to_add=None):
if to_remove is None:
to_remove = []
if to_add is None:
to_add = []
for account in gajim.config.get_per('accounts'): for account in gajim.config.get_per('accounts'):
proxies_str = gajim.config.get_per('accounts', account, proxies_str = gajim.config.get_per('accounts', account,
'file_transfer_proxies') 'file_transfer_proxies')

View file

@ -62,7 +62,9 @@ else:
should return the validated text, or raise ValueError should return the validated text, or raise ValueError
""" """
def uri_reference_role(role, rawtext, text, lineno, inliner, def uri_reference_role(role, rawtext, text, lineno, inliner,
options={}, content=[]): options=None, content=None):
if options is None:
options = {}
try: try:
valid_text = validator(text) valid_text = validator(text)
except ValueError as e: except ValueError as e:
@ -102,9 +104,10 @@ else:
It reuses the docutils.core.Publisher class, which means it is *not* It reuses the docutils.core.Publisher class, which means it is *not*
threadsafe. threadsafe.
""" """
def __init__(self, settings_spec=None, def __init__(self, settings_spec=None, settings_overrides=None,
settings_overrides=dict(report_level=5, halt_level=5), config_section='general'):
config_section='general'): if settings_overrides is None:
settings_overrides = {'report_level': 5, 'halt_level': 5}
self.pub = Publisher(reader=None, parser=None, writer=None, self.pub = Publisher(reader=None, parser=None, writer=None,
settings=None, settings=None,
source_class=io.StringInput, source_class=io.StringInput,

View file

@ -448,9 +448,10 @@ class ConversationTextview(GObject.GObject):
self.auto_scrolling = False self.auto_scrolling = False
return False # when called in an idle_add, just do it once return False # when called in an idle_add, just do it once
def bring_scroll_to_end(self, diff_y = 0, def bring_scroll_to_end(self, diff_y=0, use_smooth=None):
use_smooth=gajim.config.get('use_smooth_scrolling')):
''' scrolls to the end of textview if end is not visible ''' ''' scrolls to the end of textview if end is not visible '''
if use_smooth is None:
use_smooth = gajim.config.get('use_smooth_scrolling')
buffer_ = self.tv.get_buffer() buffer_ = self.tv.get_buffer()
end_iter = buffer_.get_end_iter() end_iter = buffer_.get_end_iter()
end_rect = self.tv.get_iter_location(end_iter) end_rect = self.tv.get_iter_location(end_iter)
@ -1014,7 +1015,7 @@ class ConversationTextview(GObject.GObject):
helpers.launch_browser_mailer(kind, word) helpers.launch_browser_mailer(kind, word)
def detect_and_print_special_text(self, otext, other_tags, graphics=True, def detect_and_print_special_text(self, otext, other_tags, graphics=True,
iter_=None, additional_data={}): iter_=None, additional_data=None):
""" """
Detect special text (emots & links & formatting), print normal text Detect special text (emots & links & formatting), print normal text
before any special text it founds, then print special text (that happens before any special text it founds, then print special text (that happens
@ -1024,6 +1025,8 @@ class ConversationTextview(GObject.GObject):
""" """
if not otext: if not otext:
return return
if additional_data is None:
additional_data = {}
buffer_ = self.tv.get_buffer() buffer_ = self.tv.get_buffer()
if other_tags: if other_tags:
insert_tags_func = buffer_.insert_with_tags_by_name insert_tags_func = buffer_.insert_with_tags_by_name
@ -1079,11 +1082,13 @@ class ConversationTextview(GObject.GObject):
return end_iter return end_iter
def print_special_text(self, special_text, other_tags, graphics=True, def print_special_text(self, special_text, other_tags, graphics=True,
iter_=None, additional_data={}): iter_=None, additional_data=None):
""" """
Is called by detect_and_print_special_text and prints special text Is called by detect_and_print_special_text and prints special text
(emots, links, formatting) (emots, links, formatting)
""" """
if additional_data is None:
additional_data = {}
# PluginSystem: adding GUI extension point for ConversationTextview # PluginSystem: adding GUI extension point for ConversationTextview
self.plugin_modified = False self.plugin_modified = False
@ -1538,10 +1543,12 @@ class ConversationTextview(GObject.GObject):
self.print_empty_line(end_iter) self.print_empty_line(end_iter)
def print_real_text(self, text, text_tags=[], name=None, xhtml=None, def print_real_text(self, text, text_tags=[], name=None, xhtml=None,
graphics=True, mark=None, additional_data={}): graphics=True, mark=None, additional_data=None):
""" """
Add normal and special text. call this to add text Add normal and special text. call this to add text
""" """
if additional_data is None:
additional_data = {}
buffer_ = self.tv.get_buffer() buffer_ = self.tv.get_buffer()
if not mark: if not mark:
iter_ = buffer_.get_end_iter() iter_ = buffer_.get_end_iter()

View file

@ -299,10 +299,12 @@ class ServicesCache:
if not self._cbs[cbkey]: if not self._cbs[cbkey]:
del self._cbs[cbkey] del self._cbs[cbkey]
def get_icon(self, identities = [], addr=''): def get_icon(self, identities=None, addr=''):
""" """
Return the icon for an agent Return the icon for an agent
""" """
if identities is None:
identities = []
# Grab the first identity with an icon # Grab the first identity with an icon
quiet = False quiet = False
for identity in identities: for identity in identities:
@ -334,10 +336,14 @@ class ServicesCache:
_icon_cache['jabber'] = pix _icon_cache['jabber'] = pix
return pix return pix
def get_browser(self, identities=[], features=[]): def get_browser(self, identities=None, features=None):
""" """
Return the browser class for an agent Return the browser class for an agent
""" """
if identities is None:
identities = []
if features is None:
features = []
# First pass, we try to find a ToplevelAgentBrowser # First pass, we try to find a ToplevelAgentBrowser
for identity in identities: for identity in identities:
try: try:

View file

@ -59,13 +59,15 @@ def build_resources_submenu(contacts, account, action, room_jid=None,
return sub_menu return sub_menu
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[], def build_invite_submenu(invite_menuitem, list_, ignore_rooms=None,
show_bookmarked=False, force_resource=False): show_bookmarked=False, force_resource=False):
""" """
list_ in a list of (contact, account) list_ in a list of (contact, account)
force_resource means we want to send invitation even if there is only one force_resource means we want to send invitation even if there is only one
resource resource
""" """
if ignore_rooms is None:
ignore_rooms = []
roster = gajim.interface.roster roster = gajim.interface.roster
# used if we invite only one contact with several resources # used if we invite only one contact with several resources
contact_list = [] contact_list = []

View file

@ -267,13 +267,16 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='', def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
subject=None, resource='', msg_log_id=None, user_nick='', xhtml=None, subject=None, resource='', msg_log_id=None, user_nick='', xhtml=None,
form_node=None, displaymarking=None, additional_data={}): form_node=None, displaymarking=None, additional_data=None):
""" """
Display the message or show notification in the roster Display the message or show notification in the roster
""" """
contact = None contact = None
fjid = jid fjid = jid
if additional_data is None:
additional_data = {}
# Try to catch the contact with correct resource # Try to catch the contact with correct resource
if resource: if resource:
fjid = jid + '/' + resource fjid = jid + '/' + resource