Add google appengine to repo
[frozenviper.git] / google_appengine / google / net / proto / RawMessage.py
blob2d4d5f57cf485ff277a7f0ab94599d61f18f5f6a
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 """
19 This is the Python counterpart to the RawMessage class defined in rawmessage.h.
21 To use this, put the following line in your .proto file:
23 python from google.net.proto.RawMessage import RawMessage
25 """
27 __pychecker__ = 'no-callinit no-argsused'
29 from google.net.proto import ProtocolBuffer
31 class RawMessage(ProtocolBuffer.ProtocolMessage):
32 """
33 This is a special subclass of ProtocolMessage that doesn't interpret its data
34 in any way. Instead, it just stores it in a string.
36 See rawmessage.h for more details.
37 """
39 def __init__(self, initial=None):
40 self.__contents = ''
41 if initial is not None:
42 self.MergeFromString(initial)
44 def contents(self):
45 return self.__contents
47 def set_contents(self, contents):
48 self.__contents = contents
50 def Clear(self):
51 self.__contents = ''
53 def IsInitialized(self, debug_strs=None):
54 return 1
56 def __str__(self, prefix="", printElemNumber=0):
57 return prefix + self.DebugFormatString(self.__contents)
59 def OutputUnchecked(self, e):
60 e.putRawString(self.__contents)
62 def TryMerge(self, d):
63 self.__contents = d.getRawString()
65 def MergeFrom(self, pb):
66 assert pb is not self
67 if pb.__class__ != self.__class__:
68 return 0
69 self.__contents = pb.__contents
70 return 1
72 def Equals(self, pb):
73 return self.__contents == pb.__contents
75 def __eq__(self, other):
76 return (other is not None) and (other.__class__ == self.__class__) and self.Equals(other)
78 def __ne__(self, other):
79 return not (self == other)
81 def ByteSize(self):
82 return len(self.__contents)