## $Id$ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import os from zope.component.zcml import handler from zope.configuration.exceptions import ConfigurationError from kofacustom.nigeria.paypal.interfaces import IPaypalConfig from kofacustom.nigeria.paypal.config import parse_paypal_config def paypal_handler(path): """ZCML handler that registers paypal configuration. We expect paypal credentials written down in a config file. The path to this config file can be set with the ZCML `paypalconf` directive, which is handled here and looks like this:: This handler requires the given path to exist and to be a file. If the file exists and is readable, a dict with ``path`` and other values read from the configuration file is registered as a global unnamed utility for the `IPaypalConfig` interface. """ if not os.path.exists(path): raise ConfigurationError("No such file: %s" % path) if not os.path.isfile(path): raise ConfigurationError("Not a regular file: %s" % path) config_dict = parse_paypal_config(path) config_dict["path"] = path return handler( 'registerUtility', config_dict, IPaypalConfig, '') def paypal_conf(context, path): """Handler for ZCML paypalconf directive. This handler registers the `paypal_handler` above to perform the real configuration action. """ context.action( discriminator=('utility', IPaypalConfig, ''), callable=paypal_handler, args=(path, ) )