~launchpad-pqm/mailman/2.1

353 by bwarsaw
__repr__(): Watch out for Unicode fullname or password.
1
# Copyright (C) 2001-2004 by the Free Software Foundation, Inc.
1 by
This commit was manufactured by cvs2svn to create branch
2
#
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
353 by bwarsaw
__repr__(): Watch out for Unicode fullname or password.
7
#
1 by
This commit was manufactured by cvs2svn to create branch
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
353 by bwarsaw
__repr__(): Watch out for Unicode fullname or password.
12
#
1 by
This commit was manufactured by cvs2svn to create branch
13
# You should have received a copy of the GNU General Public License
353 by bwarsaw
__repr__(): Watch out for Unicode fullname or password.
14
# along with this program; if not, write to the Free Software
749 by tkikuchi
FSF office has moved to 51 Franklin Street.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1 by
This commit was manufactured by cvs2svn to create branch
16
17
"""User description class/structure, for ApprovedAddMember and friends."""
18
353 by bwarsaw
__repr__(): Watch out for Unicode fullname or password.
19
20
from types import UnicodeType
21
22
23

1 by
This commit was manufactured by cvs2svn to create branch
24
class UserDesc:
25
    def __init__(self, address=None, fullname=None, password=None,
26
                 digest=None, lang=None):
27
        if address is not None:
28
            self.address = address
29
        if fullname is not None:
30
            self.fullname = fullname
31
        if password is not None:
32
            self.password = password
33
        if digest is not None:
34
            self.digest = digest
35
        if lang is not None:
36
            self.language = lang
37
38
    def __iadd__(self, other):
39
        if getattr(other, 'address', None) is not None:
40
            self.address = other.address
41
        if getattr(other, 'fullname', None) is not None:
42
            self.fullname = other.fullname
43
        if getattr(other, 'password', None) is not None:
44
            self.password = other.password
45
        if getattr(other, 'digest', None) is not None:
46
            self.digest = other.digest
47
        if getattr(other, 'language', None) is not None:
48
            self.language = other.language
49
        return self
50
51
    def __repr__(self):
52
        address = getattr(self, 'address', 'n/a')
53
        fullname = getattr(self, 'fullname', 'n/a')
54
        password = getattr(self, 'password', 'n/a')
55
        digest = getattr(self, 'digest', 'n/a')
56
        if digest == 0:
57
            digest = 'no'
58
        elif digest == 1:
59
            digest = 'yes'
60
        language = getattr(self, 'language', 'n/a')
353 by bwarsaw
__repr__(): Watch out for Unicode fullname or password.
61
        # Make sure fullname and password are encoded if they're strings
62
        if isinstance(fullname, UnicodeType):
63
            fullname = fullname.encode('ascii', 'replace')
64
        if isinstance(password, UnicodeType):
65
            password = password.encode('ascii', 'replace')
1 by
This commit was manufactured by cvs2svn to create branch
66
        return '<UserDesc %s (%s) [%s] [digest? %s] [%s]>' % (
67
            address, fullname, password, digest, language)