"Fossies" - the Fresh Open Source Software Archive

Member "chandler-1.0.3/chandler/distrib/docs/schema-types.html" (14 Apr 2009, 6650 Bytes) of archive /windows/misc/Chandler_src_1.0.3.tar.gz:

Chandler Repository Types

Types in Chandler

This document describes the types that you can use when you are working with Schema API. These types are provided by the Chandler repository and are the basic building blocks for Chandler Items. The type names are top level names in the application.schema module. Unless otherwise noted, you can create values of these types by supplying the appropriate Python objects.

Type name Description Value syntax
Boolean A boolean A Python boolean
Bytes A string A Python string. See 4 below.
Complex A complex number A Python complex number
Date A date A Python datetime.date
DateTime A date and time A Python datetime.datetime
Dictionary A dictionary/hash table A Python dictionary
Enumeration One of a fixed number of string values - string1, ..., stringn Chandler Enumeration. See 1 below
Float A floating point number A Python float
Integer An integer A Python int
Item a Chandler Item a Chandler Item
List A list of values A Python list
Lob A large object Chandler large object. See 2 below
Long A long integer A Python long
Struct A collection of named fields Chandler struct. See 3 below
Symbol A symbolic name A Unicode string whose values are limited to [a-zA-Z0-9_]*. See 4 below.
Text A unicode string A Python unicode or ASCII string. See 4 below.
Time A time of day A Python datetime.time
TimeDelta An interval of time A Python datetime.timedelta
TimeZone A TimeZone A PyICU Timezone. You should call the appropriate PyICU method to get a Timezone
Tuple A tuple of values A Python tuple
URL A URL - a URL string A Chandler URL object which can be obtained by passing a (valid URL) string to repository.util.URL
UUID A UUID A Chandler UUID object

1. Enumerations

In order to use an enumeration you must first define a subclass of schema.Enumeration. This subclass must have a values attribute, which is a sequence of string separated by commas. See the definition of MyEnum below:

class MyEnum(schema.Enumeration):
    values = 'black', 'white'
Once you have defined your enumeration class, you may use any value that you listed in the values attribute as the value of a schema.Enumeration attribute

2. Lobs

Lob attributes need to have the Lob value created explicitly. The code below shows how it is done.

Let's say that i is an item that has a Lob valued attribute, lob_var. To create the initial Lob value, we're going to get the Item that represents the type of the attribute, and use that as a factory for the Lob value. To start, you call the getAttributeAspect method on i, and ask for the type of the lob_var attribute, storing it in attribute_type. You can then call the makeValue method on attribute_type in order to create the Lob value. The first argument to makeValue is the data that you want stored in the value. The second argument is a string whose value is a MIME type, which describes the type of binary data that is being stored in the Lob.

attribute_type = i.getAttributeAspect("lob_var",'type')
i.lob_var = attribute_type.makeValue("data","application/octet-stream")
Once you have a Lob value you can change the data in it by getting the output stream for the Lob (via getOutputStream) and then using the write method of the output stream to write the data.
stream = i.lob_var.getOutputStream()
stream.write("some data")

To retrieve your data, you ask the attribute for its input stream by calling the getInputStream() method and using read().

In addition to encoding the contents of a Lob, you can also encrypt and/or compress the contents.

3. Structs

To create a struct, you must create a subclass of schema.Struct, and set the value of the __slots__ attribute to a comma separated sequence of slot names. These will be the names of the fields in your struct. Also, instead of using schema.Struct as the name of the type, you should use the name of the schema.Struct subclass that you just defined.

You can then create instances of this struct by calling the constructor and passing the values of the slots to the constructor.

class MyStruct(schema.Struct):
    __slots__ = 'red', 'green', 'blue'

4. Text, Bytes and Symbol

Text should be used to represent any textual/string data in the application. Text can cantain either a Python unicode object or a 7 bit ASCII charset. It cannot be used for 8 bit charsets. If you need to store 8 bit charset data, you should use the Lob type. There is also a Bytes type which can accept any 8 bit value, but you should probably use a Lob if you are writing a parcel.

Symbols are names which can be used as symbolic constants. Each Symbol will be unique. Symbols work the same way in Chandler that they do in Lisp or Ruby.