1.1 --- a/moinformat/input/common.py Sun Aug 05 18:13:36 2018 +0200
1.2 +++ b/moinformat/input/common.py Sun Aug 05 18:15:54 2018 +0200
1.3 @@ -19,6 +19,7 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 +from os.path import split
1.8 import codecs
1.9
1.10 class Input:
1.11 @@ -34,9 +35,51 @@
1.12 self.parameters = parameters
1.13 self.encoding = parameters and parameters.get("encoding") or self.default_encoding
1.14
1.15 + def all(self):
1.16 +
1.17 + "Return all pages in the context."
1.18 +
1.19 + return []
1.20 +
1.21 + # Page characteristics.
1.22 +
1.23 + def parent(self, pagename):
1.24 +
1.25 + "Return the parent of 'pagename'."
1.26 +
1.27 + return pagename.rsplit("/", 1)[0]
1.28 +
1.29 + def subpages(self, pagename):
1.30 +
1.31 + "Return the subpages of 'pagename'."
1.32 +
1.33 + return []
1.34 +
1.35 + # Page access methods.
1.36 +
1.37 def readfile(self, filename, encoding=None):
1.38
1.39 """
1.40 + Return the contents of the file having the given 'filename' and optional
1.41 + 'encoding'. This implementation treats 'filename' as a path.
1.42 + """
1.43 +
1.44 + return self.readpath(filename, encoding)
1.45 +
1.46 + def readpage(self, pagename, encoding=None):
1.47 +
1.48 + """
1.49 + Return the contents of the file having the given 'pagename' and optional
1.50 + 'encoding'.
1.51 + """
1.52 +
1.53 + return self.readfile(self.to_filename(pagename), encoding)
1.54 +
1.55 + # Input methods.
1.56 +
1.57 + def readpath(self, filename, encoding=None):
1.58 +
1.59 + """
1.60 Return the contents of the file having the given 'filename'. If the
1.61 optional 'encoding' is specified, override the general encoding.
1.62 """
1.63 @@ -47,4 +90,20 @@
1.64 finally:
1.65 f.close()
1.66
1.67 + # Name translation methods.
1.68 +
1.69 + def to_filename(self, pagename):
1.70 +
1.71 + "Return the filename corresponding to 'pagename'."
1.72 +
1.73 + return pagename
1.74 +
1.75 + def to_pagename(self, filename):
1.76 +
1.77 + "Return the pagename corresponding to 'filename'."
1.78 +
1.79 + # Take the leafname as the pagename from an arbitrary filename.
1.80 +
1.81 + return split(filename)[-1]
1.82 +
1.83 # vim: tabstop=4 expandtab shiftwidth=4