Package wtf :: Package app :: Package services :: Module resources :: Class Resource
[hide private]
[frames] | no frames]

Class Resource

source code

object --+
         |
        Resource

Base resource container
Instance Methods [hide private]
list
list(self)
List the directory
source code
str
resolve(self, name)
Resolve a filename relative to this directory
source code
ResourceStream
open(self, name, mode='rb', buffering=-1, blockiter=1)
Open a file relative to this directory
source code

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

Class Methods [hide private]
Resource
frommodule(cls, base, isfile=False)
Determine a resource relative to a module
source code
Static Methods [hide private]
a new object with type S, a subtype of T

__new__(cls, base, root=None, isfile=False)
Construction
source code
Class Variables [hide private]
  _encoding = 'UTF-8'
Instance Variables [hide private]
unicode _base
Base directory which is represented by this object
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, base, root=None, isfile=False)
Static Method

source code 
Construction
Parameters:
  • base (unicode) - Base directory to represent
  • root (str) - Root directory in case that base is relative. If it's None, the current working directory is taken.
  • isfile (bool) - Does it refer to a file?
Returns:
a new object with type S, a subtype of T

Raises:
  • IOError - path not found
Overrides: object.__new__

frommodule(cls, base, isfile=False)
Class Method

source code 
Determine a resource relative to a module
Parameters:
  • base (unicode) - The combined module and path. Like: wtf.app.sample:static. This resolves to the static subdirectory of the wtf.app.sample package. If the last part is a module, the directory is treated as parallel to the module, Like: wtf.app.sample.index:static resolves to the static subdir of wtf.app.sample, too; parallel to index.py.
  • isfile (Does it refer to a file?) - Does it refer to a file?
Returns: Resource
New resource instance
Raises:
  • ImportError - Module could not be imported
  • BuiltinModuleError - Module doesn't have a __file__ attribute
  • UnicodeError - Recoding according to the locale failed.

list(self)

source code 
List the directory
Returns: list
List of strings (as returned by os.listdir)

resolve(self, name)

source code 
Resolve a filename relative to this directory
Parameters:
  • name (unicode) - filename to resolve
Returns: str
resolved filename in system encoding
Raises:
  • UnicodeError - Recoding failed

open(self, name, mode='rb', buffering=-1, blockiter=1)

source code 
Open a file relative to this directory
Parameters:
  • name (unicode) - relative filename
  • mode (str) - File open mode
  • buffering (int) - buffer spec (-1 == default, 0 == unbuffered)
  • blockiter (int) - Iterator mode (<= 0: Default block size, 1: line, > 1: This block size)
Returns: ResourceStream
open stream
Raises:
  • IOError - Error opening file