/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2010-06-24 06:53:06 UTC
  • mfrom: (5317 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5343.
  • Revision ID: mbp@sourcefrog.net-20100624065306-qcx1wg84ufuckime
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
import errno
17
18
import os
18
19
import re
19
20
import stat
20
 
from stat import (S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE,
21
 
                  S_ISCHR, S_ISBLK, S_ISFIFO, S_ISSOCK)
 
21
from stat import S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE
22
22
import sys
23
23
import time
24
 
import warnings
 
24
import codecs
25
25
 
26
26
from bzrlib.lazy_import import lazy_import
27
27
lazy_import(globals(), """
28
 
import codecs
29
28
from datetime import datetime
30
 
import errno
 
29
import getpass
31
30
from ntpath import (abspath as _nt_abspath,
32
31
                    join as _nt_join,
33
32
                    normpath as _nt_normpath,
39
38
from shutil import (
40
39
    rmtree,
41
40
    )
42
 
import signal
 
41
import socket
43
42
import subprocess
44
43
import tempfile
45
44
from tempfile import (
50
49
from bzrlib import (
51
50
    cache_utf8,
52
51
    errors,
 
52
    trace,
53
53
    win32utils,
54
54
    )
55
55
""")
56
56
 
 
57
from bzrlib.symbol_versioning import (
 
58
    deprecated_function,
 
59
    deprecated_in,
 
60
    )
 
61
 
57
62
# sha and md5 modules are deprecated in python2.6 but hashlib is available as
58
63
# of 2.5
59
64
if sys.version_info < (2, 5):
85
90
# be opened in binary mode, rather than text mode.
86
91
# On other platforms, O_BINARY doesn't exist, because
87
92
# they always open in binary mode, so it is okay to
88
 
# OR with 0 on those platforms
 
93
# OR with 0 on those platforms.
 
94
# O_NOINHERIT and O_TEXT exists only on win32 too.
89
95
O_BINARY = getattr(os, 'O_BINARY', 0)
 
96
O_TEXT = getattr(os, 'O_TEXT', 0)
 
97
O_NOINHERIT = getattr(os, 'O_NOINHERIT', 0)
90
98
 
91
99
 
92
100
def get_unicode_argv():
179
187
    try:
180
188
        return _kind_marker_map[kind]
181
189
    except KeyError:
182
 
        raise errors.BzrError('invalid file kind %r' % kind)
 
190
        # Slightly faster than using .get(, '') when the common case is that
 
191
        # kind will be found
 
192
        return ''
183
193
 
184
194
 
185
195
lexists = getattr(os.path, 'lexists', None)
661
671
def sha_file_by_name(fname):
662
672
    """Calculate the SHA1 of a file by reading the full text"""
663
673
    s = sha()
664
 
    f = os.open(fname, os.O_RDONLY | O_BINARY)
 
674
    f = os.open(fname, os.O_RDONLY | O_BINARY | O_NOINHERIT)
665
675
    try:
666
676
        while True:
667
677
            b = os.read(f, 1<<16)
921
931
 
922
932
def parent_directories(filename):
923
933
    """Return the list of parent directories, deepest first.
924
 
    
 
934
 
925
935
    For example, parent_directories("a/b/c") -> ["a/b", "a"].
926
936
    """
927
937
    parents = []
951
961
    # NB: This docstring is just an example, not a doctest, because doctest
952
962
    # currently can't cope with the use of lazy imports in this namespace --
953
963
    # mbp 20090729
954
 
    
 
964
 
955
965
    # This currently doesn't report the failure at the time it occurs, because
956
966
    # they tend to happen very early in startup when we can't check config
957
967
    # files etc, and also we want to report all failures but not spam the user
1027
1037
 
1028
1038
 
1029
1039
def delete_any(path):
1030
 
    """Delete a file, symlink or directory.  
1031
 
    
 
1040
    """Delete a file, symlink or directory.
 
1041
 
1032
1042
    Will delete even if readonly.
1033
1043
    """
1034
1044
    try:
1120
1130
 
1121
1131
 
1122
1132
def relpath(base, path):
1123
 
    """Return path relative to base, or raise exception.
 
1133
    """Return path relative to base, or raise PathNotChild exception.
1124
1134
 
1125
1135
    The path may be either an absolute path or a path relative to the
1126
1136
    current working directory.
1128
1138
    os.path.commonprefix (python2.4) has a bad bug that it works just
1129
1139
    on string prefixes, assuming that '/u' is a prefix of '/u2'.  This
1130
1140
    avoids that problem.
 
1141
 
 
1142
    NOTE: `base` should not have a trailing slash otherwise you'll get
 
1143
    PathNotChild exceptions regardless of `path`.
1131
1144
    """
1132
1145
 
1133
1146
    if len(base) < MIN_ABS_PATHLENGTH:
1220
1233
    # but for now, we haven't optimized...
1221
1234
    return [canonical_relpath(base, p) for p in paths]
1222
1235
 
 
1236
 
 
1237
def decode_filename(filename):
 
1238
    """Decode the filename using the filesystem encoding
 
1239
 
 
1240
    If it is unicode, it is returned.
 
1241
    Otherwise it is decoded from the the filesystem's encoding. If decoding
 
1242
    fails, a errors.BadFilenameEncoding exception is raised.
 
1243
    """
 
1244
    if type(filename) is unicode:
 
1245
        return filename
 
1246
    try:
 
1247
        return filename.decode(_fs_enc)
 
1248
    except UnicodeDecodeError:
 
1249
        raise errors.BadFilenameEncoding(filename, _fs_enc)
 
1250
 
 
1251
 
1223
1252
def safe_unicode(unicode_or_utf8_string):
1224
1253
    """Coerce unicode_or_utf8_string into unicode.
1225
1254
 
1308
1337
def normalizes_filenames():
1309
1338
    """Return True if this platform normalizes unicode filenames.
1310
1339
 
1311
 
    Mac OSX does, Windows/Linux do not.
 
1340
    Only Mac OSX.
1312
1341
    """
1313
1342
    return _platform_normalizes_filenames
1314
1343
 
1319
1348
    On platforms where the system normalizes filenames (Mac OSX),
1320
1349
    you can access a file by any path which will normalize correctly.
1321
1350
    On platforms where the system does not normalize filenames
1322
 
    (Windows, Linux), you have to access a file by its exact path.
 
1351
    (everything else), you have to access a file by its exact path.
1323
1352
 
1324
1353
    Internally, bzr only supports NFC normalization, since that is
1325
1354
    the standard for XML documents.
1344
1373
    normalized_filename = _inaccessible_normalized_filename
1345
1374
 
1346
1375
 
 
1376
def set_signal_handler(signum, handler, restart_syscall=True):
 
1377
    """A wrapper for signal.signal that also calls siginterrupt(signum, False)
 
1378
    on platforms that support that.
 
1379
 
 
1380
    :param restart_syscall: if set, allow syscalls interrupted by a signal to
 
1381
        automatically restart (by calling `signal.siginterrupt(signum,
 
1382
        False)`).  May be ignored if the feature is not available on this
 
1383
        platform or Python version.
 
1384
    """
 
1385
    try:
 
1386
        import signal
 
1387
        siginterrupt = signal.siginterrupt
 
1388
    except ImportError:
 
1389
        # This python implementation doesn't provide signal support, hence no
 
1390
        # handler exists
 
1391
        return None
 
1392
    except AttributeError:
 
1393
        # siginterrupt doesn't exist on this platform, or for this version
 
1394
        # of Python.
 
1395
        siginterrupt = lambda signum, flag: None
 
1396
    if restart_syscall:
 
1397
        def sig_handler(*args):
 
1398
            # Python resets the siginterrupt flag when a signal is
 
1399
            # received.  <http://bugs.python.org/issue8354>
 
1400
            # As a workaround for some cases, set it back the way we want it.
 
1401
            siginterrupt(signum, False)
 
1402
            # Now run the handler function passed to set_signal_handler.
 
1403
            handler(*args)
 
1404
    else:
 
1405
        sig_handler = handler
 
1406
    old_handler = signal.signal(signum, sig_handler)
 
1407
    if restart_syscall:
 
1408
        siginterrupt(signum, False)
 
1409
    return old_handler
 
1410
 
 
1411
 
1347
1412
default_terminal_width = 80
1348
1413
"""The default terminal width for ttys.
1349
1414
 
1351
1416
terminal_width() returns None.
1352
1417
"""
1353
1418
 
 
1419
# Keep some state so that terminal_width can detect if _terminal_size has
 
1420
# returned a different size since the process started.  See docstring and
 
1421
# comments of terminal_width for details.
 
1422
# _terminal_size_state has 3 possible values: no_data, unchanged, and changed.
 
1423
_terminal_size_state = 'no_data'
 
1424
_first_terminal_size = None
1354
1425
 
1355
1426
def terminal_width():
1356
1427
    """Return terminal width.
1360
1431
    The rules are:
1361
1432
    - if BZR_COLUMNS is set, returns its value
1362
1433
    - if there is no controlling terminal, returns None
 
1434
    - query the OS, if the queried size has changed since the last query,
 
1435
      return its value,
1363
1436
    - if COLUMNS is set, returns its value,
 
1437
    - if the OS has a value (even though it's never changed), return its value.
1364
1438
 
1365
1439
    From there, we need to query the OS to get the size of the controlling
1366
1440
    terminal.
1367
1441
 
1368
 
    Unices:
 
1442
    On Unices we query the OS by:
1369
1443
    - get termios.TIOCGWINSZ
1370
1444
    - if an error occurs or a negative value is obtained, returns None
1371
1445
 
1372
 
    Windows:
1373
 
    
 
1446
    On Windows we query the OS by:
1374
1447
    - win32utils.get_console_size() decides,
1375
1448
    - returns None on error (provided default value)
1376
1449
    """
 
1450
    # Note to implementors: if changing the rules for determining the width,
 
1451
    # make sure you've considered the behaviour in these cases:
 
1452
    #  - M-x shell in emacs, where $COLUMNS is set and TIOCGWINSZ returns 0,0.
 
1453
    #  - bzr log | less, in bash, where $COLUMNS not set and TIOCGWINSZ returns
 
1454
    #    0,0.
 
1455
    #  - (add more interesting cases here, if you find any)
 
1456
    # Some programs implement "Use $COLUMNS (if set) until SIGWINCH occurs",
 
1457
    # but we don't want to register a signal handler because it is impossible
 
1458
    # to do so without risking EINTR errors in Python <= 2.6.5 (see
 
1459
    # <http://bugs.python.org/issue8354>).  Instead we check TIOCGWINSZ every
 
1460
    # time so we can notice if the reported size has changed, which should have
 
1461
    # a similar effect.
1377
1462
 
1378
1463
    # If BZR_COLUMNS is set, take it, user is always right
1379
1464
    try:
1382
1467
        pass
1383
1468
 
1384
1469
    isatty = getattr(sys.stdout, 'isatty', None)
1385
 
    if  isatty is None or not isatty():
 
1470
    if isatty is None or not isatty():
1386
1471
        # Don't guess, setting BZR_COLUMNS is the recommended way to override.
1387
1472
        return None
1388
1473
 
1389
 
    # If COLUMNS is set, take it, the terminal knows better (even inside a
1390
 
    # given terminal, the application can decide to set COLUMNS to a lower
1391
 
    # value (splitted screen) or a bigger value (scroll bars))
 
1474
    # Query the OS
 
1475
    width, height = os_size = _terminal_size(None, None)
 
1476
    global _first_terminal_size, _terminal_size_state
 
1477
    if _terminal_size_state == 'no_data':
 
1478
        _first_terminal_size = os_size
 
1479
        _terminal_size_state = 'unchanged'
 
1480
    elif (_terminal_size_state == 'unchanged' and
 
1481
          _first_terminal_size != os_size):
 
1482
        _terminal_size_state = 'changed'
 
1483
 
 
1484
    # If the OS claims to know how wide the terminal is, and this value has
 
1485
    # ever changed, use that.
 
1486
    if _terminal_size_state == 'changed':
 
1487
        if width is not None and width > 0:
 
1488
            return width
 
1489
 
 
1490
    # If COLUMNS is set, use it.
1392
1491
    try:
1393
1492
        return int(os.environ['COLUMNS'])
1394
1493
    except (KeyError, ValueError):
1395
1494
        pass
1396
1495
 
1397
 
    width, height = _terminal_size(None, None)
1398
 
    if width <= 0:
1399
 
        # Consider invalid values as meaning no width
1400
 
        return None
 
1496
    # Finally, use an unchanged size from the OS, if we have one.
 
1497
    if _terminal_size_state == 'unchanged':
 
1498
        if width is not None and width > 0:
 
1499
            return width
1401
1500
 
1402
 
    return width
 
1501
    # The width could not be determined.
 
1502
    return None
1403
1503
 
1404
1504
 
1405
1505
def _win32_terminal_size(width, height):
1432
1532
    _terminal_size = _ioctl_terminal_size
1433
1533
 
1434
1534
 
1435
 
def _terminal_size_changed(signum, frame):
1436
 
    """Set COLUMNS upon receiving a SIGnal for WINdow size CHange."""
1437
 
    width, height = _terminal_size(None, None)
1438
 
    if width is not None:
1439
 
        os.environ['COLUMNS'] = str(width)
1440
 
 
1441
 
if sys.platform == 'win32':
1442
 
    # Martin (gz) mentioned WINDOW_BUFFER_SIZE_RECORD from ReadConsoleInput but
1443
 
    # I've no idea how to plug that in the current design -- vila 20091216
1444
 
    pass
1445
 
else:
1446
 
    signal.signal(signal.SIGWINCH, _terminal_size_changed)
1447
 
 
1448
 
 
1449
1535
def supports_executable():
1450
1536
    return sys.platform != "win32"
1451
1537
 
1574
1660
        dirblock = []
1575
1661
        append = dirblock.append
1576
1662
        try:
1577
 
            names = sorted(_listdir(top))
 
1663
            names = sorted(map(decode_filename, _listdir(top)))
1578
1664
        except OSError, e:
1579
1665
            if not _is_error_enotdir(e):
1580
1666
                raise
1769
1855
            real_handlers[kind](abspath, relpath)
1770
1856
 
1771
1857
 
 
1858
def copy_ownership_from_path(dst, src=None):
 
1859
    """Copy usr/grp ownership from src file/dir to dst file/dir.
 
1860
 
 
1861
    If src is None, the containing directory is used as source. If chown
 
1862
    fails, the error is ignored and a warning is printed.
 
1863
    """
 
1864
    chown = getattr(os, 'chown', None)
 
1865
    if chown is None:
 
1866
        return
 
1867
 
 
1868
    if src == None:
 
1869
        src = os.path.dirname(dst)
 
1870
        if src == '':
 
1871
            src = '.'
 
1872
 
 
1873
    try:
 
1874
        s = os.stat(src)
 
1875
        chown(dst, s.st_uid, s.st_gid)
 
1876
    except OSError, e:
 
1877
        trace.warning("Unable to copy ownership from '%s' to '%s': IOError: %s." % (src, dst, e))
 
1878
 
 
1879
 
1772
1880
def path_prefix_key(path):
1773
1881
    """Generate a prefix-order path key for path.
1774
1882
 
1860
1968
    return user_encoding
1861
1969
 
1862
1970
 
 
1971
def get_diff_header_encoding():
 
1972
    return get_terminal_encoding()
 
1973
 
 
1974
 
1863
1975
def get_host_name():
1864
1976
    """Return the current unicode host name.
1865
1977
 
1874
1986
        return socket.gethostname().decode(get_user_encoding())
1875
1987
 
1876
1988
 
1877
 
def recv_all(socket, bytes):
 
1989
# We must not read/write any more than 64k at a time from/to a socket so we
 
1990
# don't risk "no buffer space available" errors on some platforms.  Windows in
 
1991
# particular is likely to throw WSAECONNABORTED or WSAENOBUFS if given too much
 
1992
# data at once.
 
1993
MAX_SOCKET_CHUNK = 64 * 1024
 
1994
 
 
1995
def read_bytes_from_socket(sock, report_activity=None,
 
1996
        max_read_size=MAX_SOCKET_CHUNK):
 
1997
    """Read up to max_read_size of bytes from sock and notify of progress.
 
1998
 
 
1999
    Translates "Connection reset by peer" into file-like EOF (return an
 
2000
    empty string rather than raise an error), and repeats the recv if
 
2001
    interrupted by a signal.
 
2002
    """
 
2003
    while 1:
 
2004
        try:
 
2005
            bytes = sock.recv(max_read_size)
 
2006
        except socket.error, e:
 
2007
            eno = e.args[0]
 
2008
            if eno == getattr(errno, "WSAECONNRESET", errno.ECONNRESET):
 
2009
                # The connection was closed by the other side.  Callers expect
 
2010
                # an empty string to signal end-of-stream.
 
2011
                return ""
 
2012
            elif eno == errno.EINTR:
 
2013
                # Retry the interrupted recv.
 
2014
                continue
 
2015
            raise
 
2016
        else:
 
2017
            if report_activity is not None:
 
2018
                report_activity(len(bytes), 'read')
 
2019
            return bytes
 
2020
 
 
2021
 
 
2022
def recv_all(socket, count):
1878
2023
    """Receive an exact number of bytes.
1879
2024
 
1880
2025
    Regular Socket.recv() may return less than the requested number of bytes,
1881
 
    dependning on what's in the OS buffer.  MSG_WAITALL is not available
 
2026
    depending on what's in the OS buffer.  MSG_WAITALL is not available
1882
2027
    on all platforms, but this should work everywhere.  This will return
1883
2028
    less than the requested amount if the remote end closes.
1884
2029
 
1885
2030
    This isn't optimized and is intended mostly for use in testing.
1886
2031
    """
1887
2032
    b = ''
1888
 
    while len(b) < bytes:
1889
 
        new = until_no_eintr(socket.recv, bytes - len(b))
 
2033
    while len(b) < count:
 
2034
        new = read_bytes_from_socket(socket, None, count - len(b))
1890
2035
        if new == '':
1891
2036
            break # eof
1892
2037
        b += new
1893
2038
    return b
1894
2039
 
1895
2040
 
1896
 
def send_all(socket, bytes, report_activity=None):
 
2041
def send_all(sock, bytes, report_activity=None):
1897
2042
    """Send all bytes on a socket.
1898
2043
 
1899
 
    Regular socket.sendall() can give socket error 10053 on Windows.  This
1900
 
    implementation sends no more than 64k at a time, which avoids this problem.
 
2044
    Breaks large blocks in smaller chunks to avoid buffering limitations on
 
2045
    some platforms, and catches EINTR which may be thrown if the send is
 
2046
    interrupted by a signal.
 
2047
 
 
2048
    This is preferred to socket.sendall(), because it avoids portability bugs
 
2049
    and provides activity reporting.
1901
2050
 
1902
2051
    :param report_activity: Call this as bytes are read, see
1903
2052
        Transport._report_activity
1904
2053
    """
1905
 
    chunk_size = 2**16
1906
 
    for pos in xrange(0, len(bytes), chunk_size):
1907
 
        block = bytes[pos:pos+chunk_size]
1908
 
        if report_activity is not None:
1909
 
            report_activity(len(block), 'write')
1910
 
        until_no_eintr(socket.sendall, block)
 
2054
    sent_total = 0
 
2055
    byte_count = len(bytes)
 
2056
    while sent_total < byte_count:
 
2057
        try:
 
2058
            sent = sock.send(buffer(bytes, sent_total, MAX_SOCKET_CHUNK))
 
2059
        except socket.error, e:
 
2060
            if e.args[0] != errno.EINTR:
 
2061
                raise
 
2062
        else:
 
2063
            sent_total += sent
 
2064
            report_activity(sent, 'write')
1911
2065
 
1912
2066
 
1913
2067
def dereference_path(path):
1954
2108
    base = dirname(bzrlib.__file__)
1955
2109
    if getattr(sys, 'frozen', None):    # bzr.exe
1956
2110
        base = abspath(pathjoin(base, '..', '..'))
1957
 
    filename = pathjoin(base, resource_relpath)
1958
 
    return open(filename, 'rU').read()
1959
 
 
 
2111
    f = file(pathjoin(base, resource_relpath), "rU")
 
2112
    try:
 
2113
        return f.read()
 
2114
    finally:
 
2115
        f.close()
1960
2116
 
1961
2117
def file_kind_from_stat_mode_thunk(mode):
1962
2118
    global file_kind_from_stat_mode
1984
2140
 
1985
2141
 
1986
2142
def until_no_eintr(f, *a, **kw):
1987
 
    """Run f(*a, **kw), retrying if an EINTR error occurs."""
 
2143
    """Run f(*a, **kw), retrying if an EINTR error occurs.
 
2144
 
 
2145
    WARNING: you must be certain that it is safe to retry the call repeatedly
 
2146
    if EINTR does occur.  This is typically only true for low-level operations
 
2147
    like os.read.  If in any doubt, don't use this.
 
2148
 
 
2149
    Keep in mind that this is not a complete solution to EINTR.  There is
 
2150
    probably code in the Python standard library and other dependencies that
 
2151
    may encounter EINTR if a signal arrives (and there is signal handler for
 
2152
    that signal).  So this function can reduce the impact for IO that bzrlib
 
2153
    directly controls, but it is not a complete solution.
 
2154
    """
1988
2155
    # Borrowed from Twisted's twisted.python.util.untilConcludes function.
1989
2156
    while True:
1990
2157
        try:
1994
2161
                continue
1995
2162
            raise
1996
2163
 
 
2164
 
1997
2165
def re_compile_checked(re_string, flags=0, where=""):
1998
2166
    """Return a compiled re, or raise a sensible error.
1999
2167
 
2106
2274
        else:
2107
2275
            data, _ = self.encode(object, self.errors)
2108
2276
            self.stream.write(data)
 
2277
 
 
2278
if sys.platform == 'win32':
 
2279
    def open_file(filename, mode='r', bufsize=-1):
 
2280
        """This function is used to override the ``open`` builtin.
 
2281
 
 
2282
        But it uses O_NOINHERIT flag so the file handle is not inherited by
 
2283
        child processes.  Deleting or renaming a closed file opened with this
 
2284
        function is not blocking child processes.
 
2285
        """
 
2286
        writing = 'w' in mode
 
2287
        appending = 'a' in mode
 
2288
        updating = '+' in mode
 
2289
        binary = 'b' in mode
 
2290
 
 
2291
        flags = O_NOINHERIT
 
2292
        # see http://msdn.microsoft.com/en-us/library/yeby3zcb%28VS.71%29.aspx
 
2293
        # for flags for each modes.
 
2294
        if binary:
 
2295
            flags |= O_BINARY
 
2296
        else:
 
2297
            flags |= O_TEXT
 
2298
 
 
2299
        if writing:
 
2300
            if updating:
 
2301
                flags |= os.O_RDWR
 
2302
            else:
 
2303
                flags |= os.O_WRONLY
 
2304
            flags |= os.O_CREAT | os.O_TRUNC
 
2305
        elif appending:
 
2306
            if updating:
 
2307
                flags |= os.O_RDWR
 
2308
            else:
 
2309
                flags |= os.O_WRONLY
 
2310
            flags |= os.O_CREAT | os.O_APPEND
 
2311
        else: #reading
 
2312
            if updating:
 
2313
                flags |= os.O_RDWR
 
2314
            else:
 
2315
                flags |= os.O_RDONLY
 
2316
 
 
2317
        return os.fdopen(os.open(filename, flags), mode, bufsize)
 
2318
else:
 
2319
    open_file = open
 
2320
 
 
2321
 
 
2322
def getuser_unicode():
 
2323
    """Return the username as unicode.
 
2324
    """
 
2325
    try:
 
2326
        user_encoding = get_user_encoding()
 
2327
        username = getpass.getuser().decode(user_encoding)
 
2328
    except UnicodeDecodeError:
 
2329
        raise errors.BzrError("Can't decode username as %s." % \
 
2330
                user_encoding)
 
2331
    return username