|
1 #!/usr/bin/env python |
|
2 # |
|
3 # Copyright 2007 Google Inc. |
|
4 # |
|
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 |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
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. |
|
16 # |
|
17 |
|
18 """ |
|
19 This is the Python counterpart to the RawMessage class defined in rawmessage.h. |
|
20 |
|
21 To use this, put the following line in your .proto file: |
|
22 |
|
23 python from google.net.proto.RawMessage import RawMessage |
|
24 |
|
25 """ |
|
26 |
|
27 __pychecker__ = 'no-callinit no-argsused' |
|
28 |
|
29 from google.net.proto import ProtocolBuffer |
|
30 |
|
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. |
|
35 |
|
36 See rawmessage.h for more details. |
|
37 """ |
|
38 |
|
39 def __init__(self, initial=None): |
|
40 self.__contents = '' |
|
41 if initial is not None: |
|
42 self.MergeFromString(initial) |
|
43 |
|
44 def contents(self): |
|
45 return self.__contents |
|
46 |
|
47 def set_contents(self, contents): |
|
48 self.__contents = contents |
|
49 |
|
50 def Clear(self): |
|
51 self.__contents = '' |
|
52 |
|
53 def IsInitialized(self, debug_strs=None): |
|
54 return 1 |
|
55 |
|
56 def __str__(self, prefix="", printElemNumber=0): |
|
57 return prefix + self.DebugFormatString(self.__contents) |
|
58 |
|
59 def OutputUnchecked(self, e): |
|
60 e.putRawString(self.__contents) |
|
61 |
|
62 def TryMerge(self, d): |
|
63 self.__contents = d.getRawString() |
|
64 |
|
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 |
|
71 |
|
72 def Equals(self, pb): |
|
73 return self.__contents == pb.__contents |
|
74 |
|
75 def __eq__(self, other): |
|
76 return (other is not None) and (other.__class__ == self.__class__) and self.Equals(other) |
|
77 |
|
78 def __ne__(self, other): |
|
79 return not (self == other) |
|
80 |
|
81 def ByteSize(self): |
|
82 return len(self.__contents) |
|
83 |