Exemplo n.º 1
0
    return 'Anonymous <*****@*****.**>'


def now():
    """The default method for determining the time a commit is
    made."""

    return time.time()


## The commit message is dynamically parameterized.

MESSAGE = fluid.cell('', type=fluid.private)

message = fluid.accessor(MESSAGE)

## To maintain the logical key/value space, commits use manifests and
## checkpoints use changesets.  A manifest is a complete snapshot of
## the space; a changeset is a delta.


class RefMap(tree):
    @classmethod
    def __adapt__(cls, other):
        if isinstance(obj, Mapping):
            obj = obj.iteritems()
        if not isinstance(obj, basestring) and isinstance(obj, Iterable):
            values = cls.type
            return (cls((Key, k), avro.cast(v, values)) for (k, v) in obj)
Exemplo n.º 2
0
    """zippers optionally accept a procedure that returns the email
    address of the current user.  This is the default."""

    return 'Anonymous <*****@*****.**>'

def now():
    """The default method for determining the time a commit is
    made."""

    return time.time()

## The commit message is dynamically parameterized.

MESSAGE = fluid.cell('', type=fluid.private)

message = fluid.accessor(MESSAGE)

## To maintain the logical key/value space, commits use manifests and
## checkpoints use changesets.  A manifest is a complete snapshot of
## the space; a changeset is a delta.

class RefMap(tree):

    @classmethod
    def __adapt__(cls, other):
        if isinstance(obj, Mapping):
            obj = obj.iteritems()
        if not isinstance(obj, basestring) and isinstance(obj, Iterable):
            values = cls.type
            return (cls((Key, k), avro.cast(v, values)) for (k, v) in obj)
Exemplo n.º 3
0
from .. import avro, data

__all__ = (
    'RepoError', 'repository', 'repository_transaction', 'source', 'use',
    'branches', 'make_branch', 'open_branch', 'get_branch', 'save_branch',
    'remove_branch',
    'get', 'find', 'new', 'update', 'delete', 'delta'
)

RepoError = data.RepoError

## The current branch and repository are accessible in the dynamic
## context.  They can be set globally using the init() method.

REPOSITORY = fluid.cell(None, type=fluid.acquired)
repository = fluid.accessor(REPOSITORY)

SOURCE = fluid.cell(None, type=fluid.acquired)
source = fluid.accessor(SOURCE)

def init_api(zs, created=False):
    """Set the global branch; this should be done near the beginning
    of a program.  See load.init()."""

    REPOSITORY.set(zs.open())
    if created:
        with repository_transaction('Make initial branches.'):
            make_branch('live', publish='')
            make_branch('staging', publish='live')

    use('staging')
Exemplo n.º 4
0
        raise ValueError('User does not exist: %r.' % name)
    return user

def valid_user(obj):
    if isinstance(obj, User):
        return obj
    return get_user(obj, True)

def is_admin(obj):
    return valid_user(obj).admin


### Dynamic Environment

CURRENT_USER = fluid.cell(fluid.UNDEFINED, validate=valid_user, type=fluid.acquired)
user = fluid.accessor(CURRENT_USER)

def set_user(user):
    CURRENT_USER.set(user)
    return user

CURRENT_AUTH = fluid.cell(None, type=fluid.acquired)
authenticator = fluid.accessor(CURRENT_AUTH)

def init_auth(auth=None, service=None, host=None):
    """Initialize the authentication service.  See load.init()."""

    auth = auth or LocalAuth(service, host)
    CURRENT_AUTH.set(auth)
    return auth
Exemplo n.º 5
0
def valid_user(obj):
    if isinstance(obj, User):
        return obj
    return get_user(obj, True)


def is_admin(obj):
    return valid_user(obj).admin


### Dynamic Environment

CURRENT_USER = fluid.cell(fluid.UNDEFINED,
                          validate=valid_user,
                          type=fluid.acquired)
user = fluid.accessor(CURRENT_USER)


def set_user(user):
    CURRENT_USER.set(user)
    return user


CURRENT_AUTH = fluid.cell(None, type=fluid.acquired)
authenticator = fluid.accessor(CURRENT_AUTH)


def init_auth(auth=None, service=None, host=None):
    """Initialize the authentication service.  See load.init()."""

    auth = auth or LocalAuth(service, host)
Exemplo n.º 6
0
def leaf(obj):
    """Is this object a leaf object?"""

    try:
        return obj.__leaf__()
    except AttributeError:
        ## This is a little weird, but the default value is True
        ## because being a non-leaf node is opt-in.
        return True


### Dynamic Context

# The original input sequence
COLLECTION = fluid.cell(())
collection = fluid.accessor(COLLECTION)

# The currently focused item
FOCUS = fluid.cell()
focus = fluid.accessor(FOCUS)

# The index of the currently focused item.
INDEX = fluid.cell()
index = fluid.accessor(INDEX)


### Top Level

def Path(exprs):
    if isinstance(exprs, Sequence):
        def xpath(items):
Exemplo n.º 7
0
def changed():
    return (c.cursor for c in current_journal().changed())


### Journal

class acquire_memory(fluid.acquired):
    def localize(self, loc):
        if isinstance(loc.value, Journal):
            return self.make_location(find_memory(loc.value))
        else:
            return super(acquire_memory, self).localize(loc)

def find_memory(journal):
    while journal.source:
        journal = journal.source
    return journal

JOURNAL = fluid.cell(type=acquire_memory)

current_journal = fluid.accessor(JOURNAL, name='current_journal')

def current_memory():
    return find_memory(current_journal())

def initialize(mem=None):
    journal = JOURNAL.value
    if isinstance(journal, Journal) and not isinstance(journal, Memory):
        raise RuntimeError('Cannot uninitialize a transaction', journal)
    JOURNAL.value = mem or memory()
Exemplo n.º 8
0
from md import fluid

CURRENT_REQUEST = fluid.cell(None, type=fluid.private)
current_request = fluid.accessor(CURRENT_REQUEST, 'request')

class RequestMiddleware(object):
    def process_request(self, request):
	CURRENT_REQUEST.value = request


Exemplo n.º 9
0
def leaf(obj):
    """Is this object a leaf object?"""

    try:
        return obj.__leaf__()
    except AttributeError:
        ## This is a little weird, but the default value is True
        ## because being a non-leaf node is opt-in.
        return True


### Dynamic Context

# The original input sequence
COLLECTION = fluid.cell(())
collection = fluid.accessor(COLLECTION)

# The currently focused item
FOCUS = fluid.cell()
focus = fluid.accessor(FOCUS)

# The index of the currently focused item.
INDEX = fluid.cell()
index = fluid.accessor(INDEX)

### Top Level


def Path(exprs):
    if isinstance(exprs, Sequence):