Next / Previous / Contents / Shipman's homepage

6.15. PathInfo.__rwx(): Format three permission bits

This little method takes three permission values and returns a three-character string formatted in the “ls -l” convention. The read permission is formatted as "r" if true, "-" if false. Similarly, the write permission is formatted as "w" or "-", and the execute permission as "x" or "-".

Each argument is nonzero if the permission is set, zero if it is not set.
# - - -   P a t h I n f o . _ _ r w x   - - -

    def __rwx ( self, r, w, x ):
        """Format three permission bits.

          [ r, w, and x are Boolean values indicating read,
            write and execute permissions ->
              return a three-character string displaying those
              permissions as "ls -l" displays them ]

The .__dasher() method handles generation of either a letter or a dash depending on the permission value.
        return  ( "%s%s%s" %
                  (self.__dasher ( r, "r" ),
                   self.__dasher ( w, "w" ),
                   self.__dasher ( x, "x" ) ) )