Package trac :: Module resource :: Class Resource

Class Resource

source code

object --+
         |
        Resource

Resource identifier.

This specifies as precisely as possible which resource from a Trac environment is manipulated.

A resource is identified by:

Some generic and commonly used rendering methods are associated as well to the Resource object. Those properties and methods actually delegate the real work to the Resource's manager.

Instance Methods
 
__repr__(self)
repr(x)
source code
 
__eq__(self, other) source code
 
__hash__(self)
Hash this resource descriptor, including its hierarchy.
source code
 
__call__(self, realm=False, id=False, version=False, parent=False)
Create a new Resource using the current resource as a template.
source code
 
child(self, realm, id=False, version=False)
Retrieve a child resource for a secondary realm.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __init__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
a new object with type S, a subtype of T
__new__(cls, resource_or_realm=None, id=False, version=False, parent=False)
Create a new Resource object from a specification.
source code
Properties
  id
  parent
  realm
  version

Inherited from object: __class__

Method Details

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 
Hash this resource descriptor, including its hierarchy.
Overrides: object.__hash__

__new__(cls, resource_or_realm=None, id=False, version=False, parent=False)
Static Method

source code 

Create a new Resource object from a specification.

>>> main = Resource('wiki', 'WikiStart')
>>> repr(main)
"<Resource u'wiki:WikiStart'>"
>>> Resource(main) is main
True
>>> main3 = Resource(main, version=3)
>>> repr(main3)
"<Resource u'wiki:WikiStart@3'>"
>>> main0 = main3(version=0)
>>> repr(main0)
"<Resource u'wiki:WikiStart@0'>"

In a copy, if id is overridden, then the original version value will not be reused.

>>> repr(Resource(main3, id="WikiEnd"))
"<Resource u'wiki:WikiEnd'>"
>>> repr(Resource(None))
"<Resource ''>"
Parameters:
  • resource_or_realm - this can be either: - a Resource, which is then used as a base for making a copy - a basestring, used to specify a realm
  • id - the resource identifier
  • version - the version or None for indicating the latest version
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__call__(self, realm=False, id=False, version=False, parent=False)
(Call operator)

source code 

Create a new Resource using the current resource as a template.

Optional keyword arguments can be given to override id and version.

child(self, realm, id=False, version=False)

source code 

Retrieve a child resource for a secondary realm.

Same as __call__, except that this one sets the parent to self.

>>> repr(Resource(None).child('attachment', 'file.txt'))
"<Resource u', attachment:file.txt'>"