~ubuntu-branches/ubuntu/utopic/python-apptools/utopic

« back to all changes in this revision

Viewing changes to enthought/naming/pyfs_state_factory.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 23:55:50 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110708235550-yz5u79ubeo4dhyfx
Tags: 4.0.0-1
* New upstream release
* Update debian/watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#------------------------------------------------------------------------------
2
 
# Copyright (c) 2005, Enthought, Inc.
3
 
# All rights reserved.
4
 
5
 
# This software is provided without warranty under the terms of the BSD
6
 
# license included in enthought/LICENSE.txt and may be redistributed only
7
 
# under the conditions described in the aforementioned license.  The license
8
 
# is also available online at http://www.enthought.com/licenses/BSD.txt
9
 
# Thanks for using Enthought open source!
10
 
11
 
# Author: Enthought, Inc.
12
 
# Description: <Enthought naming package component>
13
 
#------------------------------------------------------------------------------
14
 
""" State factory for Python File System contexts. """
15
 
 
16
 
 
17
 
# Enthought library imports.
18
 
from enthought.io.api import File
19
 
 
20
 
# Local imports.
21
 
from address import Address
22
 
from reference import Reference
23
 
from state_factory import StateFactory
24
 
 
25
 
 
26
 
class PyFSStateFactory(StateFactory):
27
 
    """ State factory for Python File System contexts. """
28
 
 
29
 
    ###########################################################################
30
 
    # 'StateFactory' interface.
31
 
    ###########################################################################
32
 
    
33
 
    def get_state_to_bind(self, obj, name, context):
34
 
        """ Returns the state of an object for binding. """
35
 
 
36
 
        state = None
37
 
 
38
 
        if isinstance(obj, File):
39
 
            # If the file is not actually in the directory represented by the
40
 
            # context then we create and bind a reference to it.
41
 
            if obj.parent.path != context.path:
42
 
                state = Reference(
43
 
                    class_name = obj.__class__.__name__,
44
 
                    addresses  = [Address(type='file', content=obj.path)]
45
 
                )
46
 
 
47
 
        return state
48
 
 
49
 
### EOF #######################################################################