Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Wrappers, which make working with ZEO little bit nicer.

Project Description

Introduction

Wrappers, which make working with ZEO little bit nicer.

By default, you have to do a lot of stuff, like create connection to database, maintain it, synchronize it (or running asyncore loop), handle reconnects and so on. Classes defined in this project makes all this work for you at the background.

Documentation

This module defines three classes:

  • ZEOWrapperPrototype
  • ZEOConfWrapper
  • ZEOWrapper

ZEOWrapperPrototype

ZEOWrapperPrototype contains methods and shared attributes, which may be used by derived classes.

You can pretty much ignore this class, unless you want to make your own connector.

ZEOConfWrapper

ZEOConfWrapper may be used to create connection to ZEO from XML configuration file.

Lets say you have file /tests/data/zeo_client.conf:

<zeoclient>
  server localhost:60985
</zeoclient>

You can now create the ZEOConfWrapper object:

from zeo_connector import ZEOConfWrapper

db_obj = ZEOConfWrapper(
    conf_path="/tests/data/zeo_client.conf",
    project_key="Some project key",
)

and save the data to the database:

import transaction

with transaction.manager:
    db_obj["data"] = "some data"

String "some data" is now saved under db._connection.root()[project_key]["data"] path.

ZEOWrapper

ZEOWrapper doesn’t use XML configuration file, but direct server/port specification:

from zeo_connector import ZEOWrapper

different_db_obj = ZEOWrapper(
    server="localhost",
    port=60985,
    project_key="Some project key",
)

So you can retreive the data you stored into the database:

import transaction

with transaction.manager:
    print different_db_obj["data"]

Running the ZEO server

The examples expects, that the ZEO server is running. To run the ZEO, look at the help page of the runzeo script which is part of the ZEO bundle. This script requires commandline or XML configuration.

You can generate the configuration files using provided zeo_connector_gen_defaults.py script, which is part of the zeo_connector_defaults <https://github.com/Bystroushaak/zeo_connector_defaults> package:

$ zeo_connector_gen_defaults.py --help
usage: zeo_connector_gen_defaults.py [-h] [-s SERVER] [-p PORT] [-C] [-S]
                                     [PATH]

This program will create the default ZEO XML configuration files.

positional arguments:
  PATH                  Path to the database on the server (used in server
                        configuration only.

optional arguments:
  -h, --help            show this help message and exit
  -s SERVER, --server SERVER
                        Server url. Default: localhost
  -p PORT, --port PORT  Port of the server. Default: 60985
  -C, --only-client     Create only CLIENT configuration.
  -S, --only-server     Create only SERVER configuration

For example:

$ zeo_connector_gen_defaults.py /tmp

will create zeo.conf file with following content:

<zeo>
  address localhost:60985
</zeo>

<filestorage>
  path /tmp/storage.fs
</filestorage>

<eventlog>
  level INFO
  <logfile>
    path /tmp/zeo.log
    format %(asctime)s %(message)s
  </logfile>
</eventlog>

and zeo_client.conf containing:

<zeoclient>
  server localhost:60985
</zeoclient>

You can change the ports and address of the server using --server or --port arguments.

To run the ZEO with the server configuration file, run the following command:

runzeo -C zeo.conf

To run the client, you may use ZEOConfWrapper, as was show above:

from zeo_connector import ZEOConfWrapper

db_obj = ZEOConfWrapper(
    conf_path="./zeo_client.conf",
    project_key="Some project key",
)

Installation

Module is hosted at PYPI, and can be easily installed using PIP:

sudo pip install zeo_connector

Source code

Project is released under the MIT license. Source code can be found at GitHub:

Unittests

You can run the tests using provided run_tests.sh script, which can be found in the root of the project.

If you have any trouble, just add --pdb switch at the end of your run_tests.sh command like this: ./run_tests.sh --pdb. This will drop you to PDB shell.

Requirements

This script expects that package pytest is installed. In case you don’t have it yet, it can be easily installed using following command:

pip install --user pytest

or for all users:

sudo pip install pytest

Example

$ ./run_tests.sh
============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2
rootdir: /home/bystrousak/Plocha/Dropbox/c0d3z/python/libs/zeo_connector, inifile:
plugins: cov
collected 7 items

tests/test_zeo_connector.py .......

=========================== 7 passed in 7.08 seconds ===========================

Changelog

0.4.8

0.4.7

  • Pinned older version of ZEO.

0.4.6

  • Cleanup of metadata files.

0.4.0 - 0.4.5

  • Added @retry_and_reset decorator for all internal dict-methods calls.
  • Project key is now optional, so this object may be used to access the root of the database.
  • Property ASYNCORE_RUNNING renamed to _ASYNCORE_RUNNING.
  • Implemented .pack().
  • Added @transaction_manager.
  • Added examples/database_handler.py and tests.
  • Added @wraps(fn) to decorators.
  • Added requirement for zope.interface.
  • Attempt to solve https://github.com/WebArchivCZ/WA-KAT/issues/86

0.3.0

0.2.0

  • Added standard dict methods, like .__contains__(), .__delitem__(), .__iter__() and so on.

0.1.0

  • Project created.
Release History

Release History

This version
History Node

0.4.8

History Node

0.4.7

History Node

0.4.6

History Node

0.4.5

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.0

History Node

0.2.0

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
zeo_connector-0.4.8.tar.gz (8.0 kB) Copy SHA256 Checksum SHA256 Source Oct 17, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting