File: baseresource.py

package info (click to toggle)
python-wikkid 0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 728 kB
  • sloc: python: 3,051; makefile: 12
file content (51 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# Copyright (C) 2010 Wikkid Developers.
#
# This software is licensed under the GNU Affero General Public License
# version 3 (see the file LICENSE).

"""The base resource class."""

import breezy.urlutils as urlutils

from wikkid.interface.resource import IRootResource


class BaseResource(object):
    """Information about a resource."""

    def __init__(self, server, path, write_filename,
                 file_resource, dir_resource):
        self.factory = server
        self.path = path
        self.write_filename = write_filename
        self.file_resource = file_resource
        self.dir_resource = dir_resource

    @property
    def preferred_path(self):
        return self.factory.get_preferred_path(self.path)

    @property
    def base_name(self):
        return urlutils.basename(self.path)

    @property
    def dir_name(self):
        return urlutils.dirname(self.path)

    @property
    def parent(self):
        if IRootResource.providedBy(self):
            return None
        return self.factory.get_resource_at_path(self.dir_name)

    @property
    def default_resource(self):
        """Any resource should be able to get to the default resource."""
        return self.factory.get_default_resource()

    @property
    def root_resource(self):
        """Any resource should be able to get to the root resource."""
        return self.factory.get_resource_at_path('/')