Package proton :: Module _condition
[frames] | no frames]

Source Code for Module proton._condition

 1  # 
 2  # Licensed to the Apache Software Foundation (ASF) under one 
 3  # or more contributor license agreements.  See the NOTICE file 
 4  # distributed with this work for additional information 
 5  # regarding copyright ownership.  The ASF licenses this file 
 6  # to you under the Apache License, Version 2.0 (the 
 7  # "License"); you may not use this file except in compliance 
 8  # with the License.  You may obtain a copy of the License at 
 9  # 
10  #   http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, 
13  # software distributed under the License is distributed on an 
14  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
15  # KIND, either express or implied.  See the License for the 
16  # specific language governing permissions and limitations 
17  # under the License. 
18  # 
19   
20  from __future__ import absolute_import 
21   
22  from cproton import pn_condition_clear, pn_condition_set_name, pn_condition_set_description, pn_condition_info, \ 
23      pn_condition_is_set, pn_condition_get_name, pn_condition_get_description 
24   
25  from ._data import Data, dat2obj 
26   
27   
28 -class Condition:
29
30 - def __init__(self, name, description=None, info=None):
31 self.name = name 32 self.description = description 33 self.info = info
34
35 - def __repr__(self):
36 return "Condition(%s)" % ", ".join([repr(x) for x in 37 (self.name, self.description, self.info) 38 if x])
39
40 - def __eq__(self, o):
41 if not isinstance(o, Condition): return False 42 return self.name == o.name and \ 43 self.description == o.description and \ 44 self.info == o.info
45 46
47 -def obj2cond(obj, cond):
48 pn_condition_clear(cond) 49 if obj: 50 pn_condition_set_name(cond, str(obj.name)) 51 pn_condition_set_description(cond, obj.description) 52 info = Data(pn_condition_info(cond)) 53 if obj.info: 54 info.put_object(obj.info)
55 56
57 -def cond2obj(cond):
58 if pn_condition_is_set(cond): 59 return Condition(pn_condition_get_name(cond), 60 pn_condition_get_description(cond), 61 dat2obj(pn_condition_info(cond))) 62 else: 63 return None
64