Imported Upstream version 0.48
[platform/upstream/libical.git] / src / python / Gauge.py
1 #!/usr/bin/env python 
2 # -*- Mode: python -*-
3 #======================================================================
4 # FILE: Gauge.py
5 # CREATOR: mtearle 
6 #
7 # DESCRIPTION:
8 #   
9 #
10 #  $Id: Gauge.py,v 1.2 2002-07-08 17:56:11 acampi Exp $
11 #  $Locker:  $
12 #
13 # (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org>
14 # (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com>  
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of either: 
18 #
19 #    The LGPL as published by the Free Software Foundation, version
20 #    2.1, available at: http://www.fsf.org/copyleft/lesser.html
21 #
22 #  Or:
23 #
24 #    The Mozilla Public License Version 1.0. You may obtain a copy of
25 #    the License at http://www.mozilla.org/MPL/
26 #======================================================================
27
28 from LibicalWrap import *
29 from Error import LibicalError
30 from Component import Component
31
32 class Gauge:
33     """ 
34     Base class for gauge
35     """
36
37     class ConstructorFailedError(LibicalError):
38         "Failed to create a Guage "
39     
40     class CloneFailedError(LibicalError):
41         "Failed to clone a component given Gauge "
42     
43     class CompareFailedError(LibicalError):
44         "Failed to compare a component given Gauge "
45
46     def __init__(self,ref=None,sql=None,expand=0):
47         if ref != None:
48             self._ref = ref
49         elif sql != None:
50             s = str(sql)
51             self._ref = icalgauge_new_from_sql(s,expand)
52         else:
53             Gauge.ConstructorFailedError("No SQL Specified")
54
55     def __del__(self):
56         if self._ref != None:
57             icalgauge_free(self._ref)
58             self._ref = None
59
60     def ref(self):
61         return self._ref
62
63     def compare(self, comp):
64         if not isinstance(comp,Component):
65             raise Gauge.CompareFailedError("Argument is not a component")
66
67         if comp.ref() == None:
68             raise Gauge.CompareFailedError("Argument is not a component")
69
70         return icalgauge_compare(self._ref, comp.ref())
71
72     # Pending Implementation
73     #def as_sql_string(self):
74     #   return self.__str__()
75
76     #def __str__(self):
77     #   return icalgauge_as_sql(self._ref)
78
79     #def clone(self, comp):
80 #       if not isinstance(comp,Component):
81 #           raise Gauge.CloneFailedError("Argument is not a component")
82 #
83 #        comp_ref = icalgauge_new_clone(self._ref, comp)
84 #
85 #       if comp_ref == None:
86 #           return None
87 #
88 #       return Component(ref=comp_ref)