diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2008-05-07 16:03:08 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2008-05-07 16:03:08 +0000 |
| commit | b10ca140b947991309044155485d86ce8c9cb8ce (patch) | |
| tree | 95814740b9bd25dcd7e56fda164166a4dfcf1c49 /python/qpid | |
| parent | f25c7ddb3d6a0c6a2bd5df700b3a612ba101f0e1 (diff) | |
| download | qpid-python-b10ca140b947991309044155485d86ce8c9cb8ce.tar.gz | |
QPID-979: added convenience accessors for headers
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@654158 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid')
| -rw-r--r-- | python/qpid/datatypes.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/python/qpid/datatypes.py b/python/qpid/datatypes.py index 36b290700b..ba9eaa053f 100644 --- a/python/qpid/datatypes.py +++ b/python/qpid/datatypes.py @@ -72,11 +72,40 @@ class Message: else: self.body = None if len(args) > 1: - self.headers = args[:-1] + self.headers = list(args[:-1]) else: self.headers = None self.id = None + def has(self, name): + return self.get(name) != None + + def get(self, name): + if self.headers: + for h in self.headers: + if h._type.name == name: + return h + return None + + def set(self, header): + if self.headers is None: + self.headers = [] + idx = 0 + while idx < len(self.headers): + if self.headers[idx]._type == header._type: + self.headers[idx] = header + return + idx += 1 + self.headers.append(header) + + def clear(self, name): + idx = 0 + while idx < len(self.headers): + if self.headers[idx]._type.name == name: + del self.headers[idx] + return + idx += 1 + def __repr__(self): args = [] if self.headers: |
