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 from google
.net
.proto
import ProtocolBuffer
20 import dummy_thread
as thread
22 __pychecker__
= """maxreturns=0 maxbranches=0 no-callinit
23 unusednames=printElemNumber,debug_strs no-special"""
25 from google
.appengine
.api
.api_base_pb
import *
26 class URLFetchServiceError(ProtocolBuffer
.ProtocolMessage
):
32 RESPONSE_TOO_LARGE
= 4
39 3: "UNSPECIFIED_ERROR",
40 4: "RESPONSE_TOO_LARGE",
41 5: "DEADLINE_EXCEEDED",
44 def ErrorCode_Name(cls
, x
): return cls
._ErrorCode
_NAMES
.get(x
, "")
45 ErrorCode_Name
= classmethod(ErrorCode_Name
)
48 def __init__(self
, contents
=None):
50 if contents
is not None: self
.MergeFromString(contents
)
53 def MergeFrom(self
, x
):
57 if x
is self
: return 1
60 def IsInitialized(self
, debug_strs
=None):
71 def OutputUnchecked(self
, out
):
74 def TryMerge(self
, d
):
77 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
81 def __str__(self
, prefix
="", printElemNumber
=0):
91 ProtocolBuffer
.Encoder
.NUMERIC
,
95 _STYLE_CONTENT_TYPE
= """"""
96 class URLFetchRequest_Header(ProtocolBuffer
.ProtocolMessage
):
102 def __init__(self
, contents
=None):
103 if contents
is not None: self
.MergeFromString(contents
)
105 def key(self
): return self
.key_
107 def set_key(self
, x
):
116 def has_key(self
): return self
.has_key_
118 def value(self
): return self
.value_
120 def set_value(self
, x
):
124 def clear_value(self
):
129 def has_value(self
): return self
.has_value_
132 def MergeFrom(self
, x
):
134 if (x
.has_key()): self
.set_key(x
.key())
135 if (x
.has_value()): self
.set_value(x
.value())
138 if x
is self
: return 1
139 if self
.has_key_
!= x
.has_key_
: return 0
140 if self
.has_key_
and self
.key_
!= x
.key_
: return 0
141 if self
.has_value_
!= x
.has_value_
: return 0
142 if self
.has_value_
and self
.value_
!= x
.value_
: return 0
145 def IsInitialized(self
, debug_strs
=None):
147 if (not self
.has_key_
):
149 if debug_strs
is not None:
150 debug_strs
.append('Required field: key not set.')
151 if (not self
.has_value_
):
153 if debug_strs
is not None:
154 debug_strs
.append('Required field: value not set.')
159 n
+= self
.lengthString(len(self
.key_
))
160 n
+= self
.lengthString(len(self
.value_
))
167 def OutputUnchecked(self
, out
):
169 out
.putPrefixedString(self
.key_
)
171 out
.putPrefixedString(self
.value_
)
173 def TryMerge(self
, d
):
178 self
.set_key(d
.getPrefixedString())
181 self
.set_value(d
.getPrefixedString())
183 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
187 def __str__(self
, prefix
="", printElemNumber
=0):
189 if self
.has_key_
: res
+=prefix
+("Key: %s\n" % self
.DebugFormatString(self
.key_
))
190 if self
.has_value_
: res
+=prefix
+("Value: %s\n" % self
.DebugFormatString(self
.value_
))
193 class URLFetchRequest(ProtocolBuffer
.ProtocolMessage
):
201 _RequestMethod_NAMES
= {
209 def RequestMethod_Name(cls
, x
): return cls
._RequestMethod
_NAMES
.get(x
, "")
210 RequestMethod_Name
= classmethod(RequestMethod_Name
)
218 has_followredirects_
= 0
221 def __init__(self
, contents
=None):
223 if contents
is not None: self
.MergeFromString(contents
)
225 def method(self
): return self
.method_
227 def set_method(self
, x
):
231 def clear_method(self
):
236 def has_method(self
): return self
.has_method_
238 def url(self
): return self
.url_
240 def set_url(self
, x
):
249 def has_url(self
): return self
.has_url_
251 def header_size(self
): return len(self
.header_
)
252 def header_list(self
): return self
.header_
255 return self
.header_
[i
]
257 def mutable_header(self
, i
):
258 return self
.header_
[i
]
260 def add_header(self
):
261 x
= URLFetchRequest_Header()
262 self
.header_
.append(x
)
265 def clear_header(self
):
267 def payload(self
): return self
.payload_
269 def set_payload(self
, x
):
270 self
.has_payload_
= 1
273 def clear_payload(self
):
274 if self
.has_payload_
:
275 self
.has_payload_
= 0
278 def has_payload(self
): return self
.has_payload_
280 def followredirects(self
): return self
.followredirects_
282 def set_followredirects(self
, x
):
283 self
.has_followredirects_
= 1
284 self
.followredirects_
= x
286 def clear_followredirects(self
):
287 if self
.has_followredirects_
:
288 self
.has_followredirects_
= 0
289 self
.followredirects_
= 1
291 def has_followredirects(self
): return self
.has_followredirects_
294 def MergeFrom(self
, x
):
296 if (x
.has_method()): self
.set_method(x
.method())
297 if (x
.has_url()): self
.set_url(x
.url())
298 for i
in xrange(x
.header_size()): self
.add_header().CopyFrom(x
.header(i
))
299 if (x
.has_payload()): self
.set_payload(x
.payload())
300 if (x
.has_followredirects()): self
.set_followredirects(x
.followredirects())
303 if x
is self
: return 1
304 if self
.has_method_
!= x
.has_method_
: return 0
305 if self
.has_method_
and self
.method_
!= x
.method_
: return 0
306 if self
.has_url_
!= x
.has_url_
: return 0
307 if self
.has_url_
and self
.url_
!= x
.url_
: return 0
308 if len(self
.header_
) != len(x
.header_
): return 0
309 for e1
, e2
in zip(self
.header_
, x
.header_
):
310 if e1
!= e2
: return 0
311 if self
.has_payload_
!= x
.has_payload_
: return 0
312 if self
.has_payload_
and self
.payload_
!= x
.payload_
: return 0
313 if self
.has_followredirects_
!= x
.has_followredirects_
: return 0
314 if self
.has_followredirects_
and self
.followredirects_
!= x
.followredirects_
: return 0
317 def IsInitialized(self
, debug_strs
=None):
319 if (not self
.has_method_
):
321 if debug_strs
is not None:
322 debug_strs
.append('Required field: method not set.')
323 if (not self
.has_url_
):
325 if debug_strs
is not None:
326 debug_strs
.append('Required field: url not set.')
327 for p
in self
.header_
:
328 if not p
.IsInitialized(debug_strs
): initialized
=0
333 n
+= self
.lengthVarInt64(self
.method_
)
334 n
+= self
.lengthString(len(self
.url_
))
335 n
+= 2 * len(self
.header_
)
336 for i
in xrange(len(self
.header_
)): n
+= self
.header_
[i
].ByteSize()
337 if (self
.has_payload_
): n
+= 1 + self
.lengthString(len(self
.payload_
))
338 if (self
.has_followredirects_
): n
+= 2
346 self
.clear_followredirects()
348 def OutputUnchecked(self
, out
):
350 out
.putVarInt32(self
.method_
)
352 out
.putPrefixedString(self
.url_
)
353 for i
in xrange(len(self
.header_
)):
355 self
.header_
[i
].OutputUnchecked(out
)
357 if (self
.has_payload_
):
359 out
.putPrefixedString(self
.payload_
)
360 if (self
.has_followredirects_
):
362 out
.putBoolean(self
.followredirects_
)
364 def TryMerge(self
, d
):
368 self
.set_method(d
.getVarInt32())
371 self
.set_url(d
.getPrefixedString())
374 self
.add_header().TryMerge(d
)
377 self
.set_payload(d
.getPrefixedString())
380 self
.set_followredirects(d
.getBoolean())
382 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
386 def __str__(self
, prefix
="", printElemNumber
=0):
388 if self
.has_method_
: res
+=prefix
+("Method: %s\n" % self
.DebugFormatInt32(self
.method_
))
389 if self
.has_url_
: res
+=prefix
+("Url: %s\n" % self
.DebugFormatString(self
.url_
))
391 for e
in self
.header_
:
393 if printElemNumber
: elm
="(%d)" % cnt
394 res
+=prefix
+("Header%s {\n" % elm
)
395 res
+=e
.__str
__(prefix
+ " ", printElemNumber
)
398 if self
.has_payload_
: res
+=prefix
+("Payload: %s\n" % self
.DebugFormatString(self
.payload_
))
399 if self
.has_followredirects_
: res
+=prefix
+("FollowRedirects: %s\n" % self
.DebugFormatBool(self
.followredirects_
))
422 ProtocolBuffer
.Encoder
.NUMERIC
,
423 ProtocolBuffer
.Encoder
.NUMERIC
,
425 ProtocolBuffer
.Encoder
.STRING
,
427 ProtocolBuffer
.Encoder
.STARTGROUP
,
429 ProtocolBuffer
.Encoder
.STRING
,
431 ProtocolBuffer
.Encoder
.STRING
,
433 ProtocolBuffer
.Encoder
.STRING
,
435 ProtocolBuffer
.Encoder
.NUMERIC
,
440 _STYLE_CONTENT_TYPE
= """"""
441 class URLFetchResponse_Header(ProtocolBuffer
.ProtocolMessage
):
447 def __init__(self
, contents
=None):
448 if contents
is not None: self
.MergeFromString(contents
)
450 def key(self
): return self
.key_
452 def set_key(self
, x
):
461 def has_key(self
): return self
.has_key_
463 def value(self
): return self
.value_
465 def set_value(self
, x
):
469 def clear_value(self
):
474 def has_value(self
): return self
.has_value_
477 def MergeFrom(self
, x
):
479 if (x
.has_key()): self
.set_key(x
.key())
480 if (x
.has_value()): self
.set_value(x
.value())
483 if x
is self
: return 1
484 if self
.has_key_
!= x
.has_key_
: return 0
485 if self
.has_key_
and self
.key_
!= x
.key_
: return 0
486 if self
.has_value_
!= x
.has_value_
: return 0
487 if self
.has_value_
and self
.value_
!= x
.value_
: return 0
490 def IsInitialized(self
, debug_strs
=None):
492 if (not self
.has_key_
):
494 if debug_strs
is not None:
495 debug_strs
.append('Required field: key not set.')
496 if (not self
.has_value_
):
498 if debug_strs
is not None:
499 debug_strs
.append('Required field: value not set.')
504 n
+= self
.lengthString(len(self
.key_
))
505 n
+= self
.lengthString(len(self
.value_
))
512 def OutputUnchecked(self
, out
):
514 out
.putPrefixedString(self
.key_
)
516 out
.putPrefixedString(self
.value_
)
518 def TryMerge(self
, d
):
523 self
.set_key(d
.getPrefixedString())
526 self
.set_value(d
.getPrefixedString())
528 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
532 def __str__(self
, prefix
="", printElemNumber
=0):
534 if self
.has_key_
: res
+=prefix
+("Key: %s\n" % self
.DebugFormatString(self
.key_
))
535 if self
.has_value_
: res
+=prefix
+("Value: %s\n" % self
.DebugFormatString(self
.value_
))
538 class URLFetchResponse(ProtocolBuffer
.ProtocolMessage
):
543 has_contentwastruncated_
= 0
544 contentwastruncated_
= 0
546 def __init__(self
, contents
=None):
548 if contents
is not None: self
.MergeFromString(contents
)
550 def content(self
): return self
.content_
552 def set_content(self
, x
):
553 self
.has_content_
= 1
556 def clear_content(self
):
557 if self
.has_content_
:
558 self
.has_content_
= 0
561 def has_content(self
): return self
.has_content_
563 def statuscode(self
): return self
.statuscode_
565 def set_statuscode(self
, x
):
566 self
.has_statuscode_
= 1
569 def clear_statuscode(self
):
570 if self
.has_statuscode_
:
571 self
.has_statuscode_
= 0
574 def has_statuscode(self
): return self
.has_statuscode_
576 def header_size(self
): return len(self
.header_
)
577 def header_list(self
): return self
.header_
580 return self
.header_
[i
]
582 def mutable_header(self
, i
):
583 return self
.header_
[i
]
585 def add_header(self
):
586 x
= URLFetchResponse_Header()
587 self
.header_
.append(x
)
590 def clear_header(self
):
592 def contentwastruncated(self
): return self
.contentwastruncated_
594 def set_contentwastruncated(self
, x
):
595 self
.has_contentwastruncated_
= 1
596 self
.contentwastruncated_
= x
598 def clear_contentwastruncated(self
):
599 if self
.has_contentwastruncated_
:
600 self
.has_contentwastruncated_
= 0
601 self
.contentwastruncated_
= 0
603 def has_contentwastruncated(self
): return self
.has_contentwastruncated_
606 def MergeFrom(self
, x
):
608 if (x
.has_content()): self
.set_content(x
.content())
609 if (x
.has_statuscode()): self
.set_statuscode(x
.statuscode())
610 for i
in xrange(x
.header_size()): self
.add_header().CopyFrom(x
.header(i
))
611 if (x
.has_contentwastruncated()): self
.set_contentwastruncated(x
.contentwastruncated())
614 if x
is self
: return 1
615 if self
.has_content_
!= x
.has_content_
: return 0
616 if self
.has_content_
and self
.content_
!= x
.content_
: return 0
617 if self
.has_statuscode_
!= x
.has_statuscode_
: return 0
618 if self
.has_statuscode_
and self
.statuscode_
!= x
.statuscode_
: return 0
619 if len(self
.header_
) != len(x
.header_
): return 0
620 for e1
, e2
in zip(self
.header_
, x
.header_
):
621 if e1
!= e2
: return 0
622 if self
.has_contentwastruncated_
!= x
.has_contentwastruncated_
: return 0
623 if self
.has_contentwastruncated_
and self
.contentwastruncated_
!= x
.contentwastruncated_
: return 0
626 def IsInitialized(self
, debug_strs
=None):
628 if (not self
.has_statuscode_
):
630 if debug_strs
is not None:
631 debug_strs
.append('Required field: statuscode not set.')
632 for p
in self
.header_
:
633 if not p
.IsInitialized(debug_strs
): initialized
=0
638 if (self
.has_content_
): n
+= 1 + self
.lengthString(len(self
.content_
))
639 n
+= self
.lengthVarInt64(self
.statuscode_
)
640 n
+= 2 * len(self
.header_
)
641 for i
in xrange(len(self
.header_
)): n
+= self
.header_
[i
].ByteSize()
642 if (self
.has_contentwastruncated_
): n
+= 2
647 self
.clear_statuscode()
649 self
.clear_contentwastruncated()
651 def OutputUnchecked(self
, out
):
652 if (self
.has_content_
):
654 out
.putPrefixedString(self
.content_
)
656 out
.putVarInt32(self
.statuscode_
)
657 for i
in xrange(len(self
.header_
)):
659 self
.header_
[i
].OutputUnchecked(out
)
661 if (self
.has_contentwastruncated_
):
663 out
.putBoolean(self
.contentwastruncated_
)
665 def TryMerge(self
, d
):
669 self
.set_content(d
.getPrefixedString())
672 self
.set_statuscode(d
.getVarInt32())
675 self
.add_header().TryMerge(d
)
678 self
.set_contentwastruncated(d
.getBoolean())
680 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
684 def __str__(self
, prefix
="", printElemNumber
=0):
686 if self
.has_content_
: res
+=prefix
+("Content: %s\n" % self
.DebugFormatString(self
.content_
))
687 if self
.has_statuscode_
: res
+=prefix
+("StatusCode: %s\n" % self
.DebugFormatInt32(self
.statuscode_
))
689 for e
in self
.header_
:
691 if printElemNumber
: elm
="(%d)" % cnt
692 res
+=prefix
+("Header%s {\n" % elm
)
693 res
+=e
.__str
__(prefix
+ " ", printElemNumber
)
696 if self
.has_contentwastruncated_
: res
+=prefix
+("ContentWasTruncated: %s\n" % self
.DebugFormatBool(self
.contentwastruncated_
))
704 kContentWasTruncated
= 6
713 "ContentWasTruncated",
717 ProtocolBuffer
.Encoder
.NUMERIC
,
718 ProtocolBuffer
.Encoder
.STRING
,
720 ProtocolBuffer
.Encoder
.NUMERIC
,
722 ProtocolBuffer
.Encoder
.STARTGROUP
,
724 ProtocolBuffer
.Encoder
.STRING
,
726 ProtocolBuffer
.Encoder
.STRING
,
728 ProtocolBuffer
.Encoder
.NUMERIC
,
733 _STYLE_CONTENT_TYPE
= """"""
735 __all__
= ['URLFetchServiceError','URLFetchRequest','URLFetchRequest_Header','URLFetchResponse','URLFetchResponse_Header']