def register(self, cls, name=None): """Register this class with an optional name @param cls: Class to register @type cls: class @param name: Optional name to use for this class @type name: str """ xmlize.register(cls, name)
def __init__(self, module, env=None): """Initialize the Environment object :param module: The Module that serves as the basis for this botoweb application :param env: Optional environment file that overrides any settings in our config """ self.module = module self._client_connection = None if not env: env = os.environ.get("BOTO_WEB_ENV") self.env = env # Config setup self.config = Config() self.config.env = self self.dist = get_provider(self.module) self.mgr = ResourceManager() if self.dist.has_resource("conf"): self.config.update(self.get_config("conf")) if env and os.path.exists(self.env): log.info("Loading environment: %s" % self.env) self.config.update(yaml.load(open(self.env, "r"))) # Set up the DB shortcuts if not self.config.has_key("DB"): self.config['DB'] = { "db_type": self.config.get("DB", "db_type", "SimpleDB"), "db_user": self.config.get("Credentials", "aws_access_key_id"), "db_passwd": self.config.get("Credentials", "aws_secret_access_key") } if self.config.has_key("auth_db"): self.config['DB']['User'] = {"db_name": self.config['auth_db']} if self.config.has_key("default_db"): self.config['DB']['db_name'] = self.config["default_db"] if self.config.has_key("session_db"): self.config['DB']['Session'] = { 'db_name': self.config["session_db"] } # Bootstrap importing all db_classes for XMLize if self.config['botoweb'].has_key("handlers"): for handler in self.config['botoweb']['handlers']: if handler.has_key("db_class"): try: db_class = find_class(handler['db_class']) except: log.exception("Could not load class: %s" % handler['db_class']) db_class = None if db_class: xmlize.register(db_class)
def test_datetime(self): """Try encoding and decoding a datetime""" xmlize.register(ObjectTest) obj = ObjectTest() obj.d = datetime.datetime(year=2009, month=9, day=9, hour=9, minute=9, second=9, tzinfo=pytz.utc) sr = xmlize.dumps(obj) obj2 = xmlize.loads(sr) print obj2.d.tzinfo assert obj2.d == obj.d
def test_str(self): """Test encoding a string""" xmlize.register(ObjectTest) obj = ObjectTest() obj.foo = "bar" obj.name = "Bizzle" obj.id = "12345" sr = xmlize.dumps(obj) obj2 = xmlize.loads(sr) assert obj2.foo == obj.foo assert obj2.name == obj.name assert obj2.__id__ == obj.id
def __init__(self, module, env=None): """Initialize the Environment object :param module: The Module that serves as the basis for this botoweb application :param env: Optional environment file that overrides any settings in our config """ self.module = module self._client_connection = None if not env: env = os.environ.get("BOTO_WEB_ENV") self.env = env # Config setup self.config = Config() self.config.env = self self.dist = get_provider(self.module) self.mgr = ResourceManager() if self.dist.has_resource("conf"): self.config.update(self.get_config("conf")) if env and os.path.exists(self.env): log.info("Loading environment: %s" % self.env) self.config.update(yaml.load(open(self.env, "r"))) # Set up the DB shortcuts if not self.config.has_key("DB"): self.config['DB'] = { "db_type": self.config.get("DB", "db_type", "SimpleDB"), "db_user": self.config.get("Credentials", "aws_access_key_id"), "db_passwd": self.config.get("Credentials", "aws_secret_access_key") } if self.config.has_key("auth_db"): self.config['DB']['User'] = {"db_name": self.config['auth_db']} if self.config.has_key("default_db"): self.config['DB']['db_name'] = self.config["default_db"] if self.config.has_key("session_db"): self.config['DB']['Session'] = {'db_name': self.config["session_db"]} # Bootstrap importing all db_classes for XMLize if self.config['botoweb'].has_key("handlers"): for handler in self.config['botoweb']['handlers']: if handler.has_key("db_class"): try: db_class = find_class(handler['db_class']) except: log.exception("Could not load class: %s" % handler['db_class']) db_class = None if db_class: xmlize.register(db_class)
def test_reference(self): """Test dumping a reference""" xmlize.register(ObjectTestReference) xmlize.register(ObjectTestReferenceSub) obj = ObjectTestReference() obj.name = "Parent Object" obj.id = "1234567890" obj_sub = ObjectTestReferenceSub() obj_sub.parent = obj obj_sub.id = "9378509283" obj_xml = xmlize.dumps(obj_sub) obj_loaded = xmlize.loads(obj_xml) print obj_xml assert obj_loaded.parent.__id__ == obj.id
def __init__(self, env, config): RequestHandler.__init__(self, env, config) db_class_name = self.config.get('db_class', None) if db_class_name: self.db_class = find_class(db_class_name) xmlize.register(self.db_class)