Package gavo :: Package protocols :: Module products :: Class ProductBase
[frames] | no frames]

Class ProductBase

source code

object --+
         |
        ProductBase
Known Subclasses:

A base class for products returned by the product core.

See the module docstring for the big picture.

The constructor arguments of RAccrefs depend on what they are. The common interface is the the class method fromRAccref(rAccref, authGroups=None). It returns None if the RAccref is not for a product of the respective sort, the product otherwise.

authGroups is a set of groups authorised for the user when controlling access to embargoed products. This is the main reason you should never hand out products yourself but always expose the to the user through the product core.

The actual constructor requires a RAccref, which is exposed as the rAccref attribute. Do not use the productsRow attribute from rAccref, though, as constructors may want to manipulate the content of the product row (e.g., in NonExistingProduct). Access the product row as self.pr in product classes.

In addition to those, all Products have a name attribute, which must be something suitable as a file name; the default constructor calls a _makeName method to come up with one, and you should simply override it.

The iterData method has to yield reasonably-sized chunks of data (self.chunkSize should be a good choice). It must be synchronuous.

Products usually are used as nevow resources. Therefore, they must have a renderHTTP method. This must be asynchronuous, i.e., it should not block for extended periods of time.

Products also work as rudimentary files via read and close methods; by default, these are implemented on top of iterData. Clients must never mix calls to the file interface and to iterData. Derived classes that are based on actual files should set up optimized read and close methods using the setupRealFile class method (look for the getFile method on the instance to see if there's a real file). Again, the assumption is made there that clients use either iterData or read, but never both.

If a product knows how to (quickly) generate a preview for itself, it can define a makePreview() method. This must return content for a mime type conventional for that kind of product (which is laid down in the products table).

Instance Methods
 
__init__(self, rAccref)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
 
__eq__(self, other) source code
 
__ne__(self, other) source code
 
iterData(self) source code
 
renderHTTP(self, ctx) source code
 
read(self, size=None) source code
 
close(self) source code
 
__providedBy__(...)
Object Specification Descriptor
source code
 
__provides__(...)
Special descriptor for class __provides__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Methods
 
fromRAccref(self, accref, authGroups=None) source code
 
setupRealFile(cls, openMethod)
changes cls such that read and close work an an actual file-like object rather than the inefficient iterData.
source code
Class Variables
  chunkSize = 65536
  __implemented__ = <implementedBy gavo.protocols.products.Produ...
Properties

Inherited from object: __class__

Method Details

__init__(self, rAccref)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

setupRealFile(cls, openMethod)
Class Method

source code 

changes cls such that read and close work an an actual file-like object rather than the inefficient iterData.

openMethod has to be an instance method of the class returning an opened input file.

__provides__(...)

 

Special descriptor for class __provides__

The descriptor caches the implementedBy info, so that we can get declarations for objects without instance-specific interfaces a bit quicker.


Class Variable Details

__implemented__

Value:
<implementedBy gavo.protocols.products.ProductBase>