Commits

Anonymous committed ae88f12

Path documentation.

Comments (0)

Files changed (3)

docs/contents.rst

    modules/misc
    modules/number
    modules/paginate
+   modules/path
    modules/pylonslib
    modules/text
    modules/util

docs/modules/path.rst

+:mod:`webhelpers.path`
+======================
+
+.. automodule:: webhelpers.path
+
+.. currentmodule:: webhelpers.path
+
+.. autoclass:: Path
+   :members:

webhelpers/path.py

         return self.__class__(p)
     
     #### HIGH-LEVEL OPERATIONS ####
-    def read_file(self, mode="rU"):
+    def read_file(self, mode="rU", encoding=None, errors="strict"):
+        """Read a file and return the contents.
+        
+        ``encoding`` and ``errors`` are used to decode the content to Unicode.
+        If ``encoding`` is not specified, the bytestring is returned as is.
+        """
         f = open(self, mode)
         content = f.read()
         f.close()
+        if encoding:
+            content = content.encode(encoding, errors)
         return content
 
-    def write_file(self, content, mode="w"):
+    def write_file(self, content, mode="w", encoding=None, errors="strict"):
+        """Write a file.
+        
+        ``encoding`` and ``errors`` are used to encode the content to a 
+        bytestring. If ``encoding`` is not specified, the content will be
+        written as is, which may raise an exception.
+        """
+        if encoding:
+            content = content.encode(encoding, errors)
         f = open(self, mode)
         f.write(content)
         f.close()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.