346 aliases = [] |
346 aliases = [] |
347 if addresses: |
347 if addresses: |
348 aliases = [alias[0] for alias in addresses] |
348 aliases = [alias[0] for alias in addresses] |
349 return aliases |
349 return aliases |
350 |
350 |
351 def delete(self, delalias=False): |
351 def delete(self, force=False): |
352 """Delete the Account from the database. |
352 """Delete the Account from the database. |
353 |
353 |
354 Argument: |
354 Argument: |
355 |
355 |
356 `delalias` : bool |
356 `force` : bool |
357 if *delalias* is `True`, all aliases, which points to the Account, |
357 if *force* is `True`, all aliases, which points to the Account, |
358 will be also deleted. If there are aliases and *delalias* is |
358 will be also deleted. If there are aliases and *force* is |
359 `False`, an AccountError will be raised. |
359 `False`, an AccountError will be raised. |
360 """ |
360 """ |
361 assert isinstance(delalias, bool) |
361 if not isinstance(force, bool): |
|
362 raise TypeError('force must be a bool') |
362 self._chk_state() |
363 self._chk_state() |
363 dbc = self._dbh.cursor() |
364 dbc = self._dbh.cursor() |
364 if delalias: |
365 if force: |
365 dbc.execute('DELETE FROM users WHERE uid = %s', self._uid) |
366 dbc.execute('DELETE FROM users WHERE uid = %s', self._uid) |
366 # delete also all aliases where the destination address is the same |
367 # delete also all aliases where the destination address is the same |
367 # as for this account. |
368 # as for this account. |
368 dbc.execute("DELETE FROM alias WHERE destination = %s", |
369 dbc.execute("DELETE FROM alias WHERE destination = %s", |
369 str(self._addr)) |
370 str(self._addr)) |