~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-02 04:51:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1851.
  • Revision ID: john@arbash-meinel.com-20060702045133-cfda3358025568ff
Change the return value of unicode_filename, and make it testable on all platforms

Show diffs side-by-side

added added

removed removed

Lines of Context:
775
775
    return _platform_normalizes_filenames
776
776
 
777
777
 
 
778
def _accessible_unicode_filename(path):
 
779
    """Get the unicode normalized path, and if you can access the file.
 
780
 
 
781
    On platforms where the system normalizes filenames (Mac OSX),
 
782
    you can access a file by any path which will normalize correctly.
 
783
    On platforms where the system does not normalize filenames 
 
784
    (Windows, Linux), you have to access a file by its exact path.
 
785
 
 
786
    Internally, bzr only supports NFC/NFKC normalization, since that is 
 
787
    the standard for XML documents.
 
788
 
 
789
    So return the normalized path, and a flag indicating if the file
 
790
    can be accessed by that path.
 
791
    """
 
792
 
 
793
    return unicodedata.normalize('NFKC', path), True
 
794
 
 
795
 
 
796
def _inaccessible_unicode_filename(path):
 
797
    __doc__ = _accessible_unicode_filename.__doc__
 
798
 
 
799
    normalized = unicodedata.normalize('NFKC', path) 
 
800
    return normalized, normalized == path
 
801
 
 
802
 
778
803
if _platform_normalizes_filenames:
779
 
    def unicode_filename(path):
780
 
        """Make sure 'path' is a properly normalized filename.
781
 
 
782
 
        On platforms where the system normalizes filenames (Mac OSX),
783
 
        you can access a file by any path which will normalize
784
 
        correctly.
785
 
        Internally, bzr only supports NFC/NFKC normalization, since
786
 
        that is the standard for XML documents.
787
 
        So we return an normalized path, and indicate this has been
788
 
        properly normalized.
789
 
 
790
 
        :return: (path, is_normalized) Return a path which can
791
 
                access the file, and whether or not this path is
792
 
                normalized.
793
 
        """
794
 
        return unicodedata.normalize('NFKC', path), True
 
804
    unicode_filename = _accessible_unicode_filename
795
805
else:
796
 
    def unicode_filename(path):
797
 
        """Make sure 'path' is a properly normalized filename.
798
 
 
799
 
        On platforms where the system does not normalize filenames 
800
 
        (Windows, Linux), you have to access a file by its exact path.
801
 
        Internally, bzr only supports NFC/NFKC normalization, since
802
 
        that is the standard for XML documents.
803
 
        So we return the original path, and indicate if this is
804
 
        properly normalized.
805
 
 
806
 
        :return: (path, is_normalized) Return a path which can
807
 
                access the file, and whether or not this path is
808
 
                normalized.
809
 
        """
810
 
        return path, unicodedata.normalize('NFKC', path) == path
 
806
    unicode_filename = _inaccessible_unicode_filename
811
807
 
812
808
 
813
809
def terminal_width():