diff options
author | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-20 18:05:48 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-20 18:05:48 -0400 |
commit | 17f0e5343a0e2e39660f5ee228a0c57a8dc7ade4 (patch) | |
tree | e301b3dab3255342295b22206319af4c9ba6a966 | |
parent | 50250e45f0c225198e08097a525cc5ff1b91474d (diff) | |
download | third_party-func-17f0e5343a0e2e39660f5ee228a0c57a8dc7ade4.tar.gz third_party-func-17f0e5343a0e2e39660f5ee228a0c57a8dc7ade4.tar.xz third_party-func-17f0e5343a0e2e39660f5ee228a0c57a8dc7ade4.zip |
Baseobj bites the dust.
-rwxr-xr-x | modules/baseobj.py | 115 | ||||
-rwxr-xr-x | modules/test.py | 13 | ||||
-rwxr-xr-x | modules/web_svc.py | 1 |
3 files changed, 2 insertions, 127 deletions
diff --git a/modules/baseobj.py b/modules/baseobj.py deleted file mode 100755 index 702f0a7..0000000 --- a/modules/baseobj.py +++ /dev/null @@ -1,115 +0,0 @@ -""" -Virt-factory backend code. - -Copyright 2006, Red Hat, Inc -Michael DeHaan <mdehaan@redhat.com> -Scott Seago <sseago@redhat.com> - -This software may be freely redistributed under the terms of the GNU -general public license. - -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., 675 Mass Ave, Cambridge, MA 02139, USA. -""" - -import string -import exceptions -import os - -class BaseObject(object): - - FIELDS = [] # subclasses should define a list of db column names here - - def load(self,hash,key,default=None): - """ - Access a hash element safely... - """ - # FIXME: it would be cool if load starts with a copy of the hash - # and clears off entries as recieved, such that we can tell if any - # entries are not loaded. This should result in a warning in the return - # object. - assert hash is not None, "hash is None" - assert key is not None, "key is None" - if hash.has_key(key): - return hash[key] - else: - return default - - def to_datastruct(self,to_caller=False): - """ - Return a hash representation of this object. - Defers to self.to_datastruct_internal which subclasses must implement. - """ - ds = self.to_datastruct_internal() - if to_caller: - # don't send NULLs - ds = self.remove_nulls(ds) - return ds - - def to_datastruct_internal(self): - """ - Subclasses: implement this. - """ - raise exceptions.NotImplementedError - - def deserialize(self, args): - for x in self.FIELDS: - if args.has_key(x): - setattr(self, x, args[x]) - else: - setattr(self, x, None) - - def serialize(self): - result = {} - for x in self.FIELDS: - result[x] = getattr(self, x, None) - return result - - def remove_nulls(self, x): - """ - If any entries are None in the datastructure, prune them. - XMLRPC can't marshall None and this is our workaround. Objects - that are None are removed from the hash -- including hash keys that - are not None and have None for the value. The WUI or other SW - should know how to deal with these returns. - """ - assert x is not None, "datastructure is None" - if type(x) == list: - newx = [] - for i in x: - if type(i) == list or type(i) == dict: - newx.append(self.remove_nulls(i)) - elif i is not None: - newx.append(i) - x = newx - elif type(x) == dict: - newx = {} - for i,j in x.iteritems(): - if type(j) == list or type(j) == dict: - newx[i] = self.remove_nulls(x) - elif j is not None: - newx[i] = j - x = newx - return x - - # ======================== - # random utility functions - - def is_printable(self, stringy): - # FIXME: use regex package - - if stringy == None: - return False - if type(stringy) != str: - stringy = "%s" % stringy - try: - for letter in stringy: - if letter not in string.printable: - return False - return True - except: - return False - - -
\ No newline at end of file diff --git a/modules/test.py b/modules/test.py index 7783b4e..eb2e3f4 100755 --- a/modules/test.py +++ b/modules/test.py @@ -1,26 +1,17 @@ #!/usr/bin/python - from codes import * from modules import web_svc - - class Test(web_svc.WebSvc): def __init__(self): self.methods = { - "test_add": self.add, - "test_blippy": self.blippy, + "test_add": self.add } web_svc.WebSvc.__init__(self) def add(self, numb1, numb2): - return success(int(numb1) + int(numb2)) - - def blippy(self, foo): - fh = open("/tmp/blippy","w+") - fh.close() - return success(foo) + return numb1 + numb2 methods = Test() register_rpc = methods.register_rpc diff --git a/modules/web_svc.py b/modules/web_svc.py index ed4ec19..134af37 100755 --- a/modules/web_svc.py +++ b/modules/web_svc.py @@ -15,7 +15,6 @@ from codes import * -import baseobj from server import config_data from server import logger |