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.
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
27 __pychecker__
= 'no-callinit no-argsused'
29 from google
.net
.proto
import ProtocolBuffer
31 class RawMessage(ProtocolBuffer
.ProtocolMessage
):
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.
39 def __init__(self
, initial
=None):
41 if initial
is not None:
42 self
.MergeFromString(initial
)
45 return self
.__contents
47 def set_contents(self
, contents
):
48 self
.__contents
= contents
53 def IsInitialized(self
, debug_strs
=None):
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
):
67 if pb
.__class
__ != self
.__class
__:
69 self
.__contents
= pb
.__contents
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
)
82 return len(self
.__contents
)