Atlas 0.7.0
Networking protocol for the Worldforge system.
encoder.py
1#base encoder class
2
3#Copyright 2002 by AIR-IX SUUNNITTELU/Ahiplan Oy
4
5#This library is free software; you can redistribute it and/or
6#modify it under the terms of the GNU Lesser General Public
7#License as published by the Free Software Foundation; either
8#version 2.1 of the License, or (at your option) any later version.
9
10#This library is distributed in the hope that it will be useful,
11#but WITHOUT ANY WARRANTY; without even the implied warranty of
12#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13#Lesser General Public License for more details.
14
15#You should have received a copy of the GNU Lesser General Public
16#License along with this library; if not, write to the Free Software
17#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19import atlas
20import string
21
23 def __init__(self, stream_flag=None):
24 self.set_stream_mode(stream_flag)
25 def set_stream_mode(self, mode=1):
26 self.stream_flag = mode
27 self.stream_begin_sent = 0
28 def __call__(self, object):
29 if self.stream_flag:
30 if isinstance(object, atlas.Messages):
31 slst = []
32 for obj in object:
33 slst.append(self(obj))
34 return string.join(slst, "")
35 str = self.encode1stream(object)
36 if self.stream_begin_sent:
37 str = self.middle_string + str
38 else:
39 self.stream_begin_sent = 1
40 str = self.begin_string + str
41 return str
42 else:
43 return self.encode1(object)
44 def close(self):
45 if self.stream_flag:
46 if self.stream_begin_sent:
47 self.stream_begin_sent = 0
48 return self.end_string
49 else:
50 return self.empty_end_string
51 else:
52 return ""
53
def set_stream_mode(self, mode=1)
Definition: encoder.py:25