~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/posixpath.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
307
307
 
308
308
def normpath(path):
309
309
    """Normalize path, eliminating double slashes, etc."""
 
310
    # Preserve unicode (if path is unicode)
 
311
    slash, dot = (u'/', u'.') if isinstance(path, unicode) else ('/', '.')
310
312
    if path == '':
311
 
        return '.'
 
313
        return dot
312
314
    initial_slashes = path.startswith('/')
313
315
    # POSIX allows one or two initial slashes, but treats three or more
314
316
    # as single slash.
326
328
        elif new_comps:
327
329
            new_comps.pop()
328
330
    comps = new_comps
329
 
    path = '/'.join(comps)
 
331
    path = slash.join(comps)
330
332
    if initial_slashes:
331
 
        path = '/'*initial_slashes + path
332
 
    return path or '.'
 
333
        path = slash*initial_slashes + path
 
334
    return path or dot
333
335
 
334
336
 
335
337
def abspath(path):
336
338
    """Return an absolute path."""
337
339
    if not isabs(path):
338
 
        path = join(os.getcwd(), path)
 
340
        if isinstance(path, unicode):
 
341
            cwd = os.getcwdu()
 
342
        else:
 
343
            cwd = os.getcwd()
 
344
        path = join(cwd, path)
339
345
    return normpath(path)
340
346
 
341
347