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
223 def __init__(self
, contents
=None):
225 if contents
is not None: self
.MergeFromString(contents
)
227 def method(self
): return self
.method_
229 def set_method(self
, x
):
233 def clear_method(self
):
238 def has_method(self
): return self
.has_method_
240 def url(self
): return self
.url_
242 def set_url(self
, x
):
251 def has_url(self
): return self
.has_url_
253 def header_size(self
): return len(self
.header_
)
254 def header_list(self
): return self
.header_
257 return self
.header_
[i
]
259 def mutable_header(self
, i
):
260 return self
.header_
[i
]
262 def add_header(self
):
263 x
= URLFetchRequest_Header()
264 self
.header_
.append(x
)
267 def clear_header(self
):
269 def payload(self
): return self
.payload_
271 def set_payload(self
, x
):
272 self
.has_payload_
= 1
275 def clear_payload(self
):
276 if self
.has_payload_
:
277 self
.has_payload_
= 0
280 def has_payload(self
): return self
.has_payload_
282 def followredirects(self
): return self
.followredirects_
284 def set_followredirects(self
, x
):
285 self
.has_followredirects_
= 1
286 self
.followredirects_
= x
288 def clear_followredirects(self
):
289 if self
.has_followredirects_
:
290 self
.has_followredirects_
= 0
291 self
.followredirects_
= 1
293 def has_followredirects(self
): return self
.has_followredirects_
295 def deadline(self
): return self
.deadline_
297 def set_deadline(self
, x
):
298 self
.has_deadline_
= 1
301 def clear_deadline(self
):
302 if self
.has_deadline_
:
303 self
.has_deadline_
= 0
306 def has_deadline(self
): return self
.has_deadline_
309 def MergeFrom(self
, x
):
311 if (x
.has_method()): self
.set_method(x
.method())
312 if (x
.has_url()): self
.set_url(x
.url())
313 for i
in xrange(x
.header_size()): self
.add_header().CopyFrom(x
.header(i
))
314 if (x
.has_payload()): self
.set_payload(x
.payload())
315 if (x
.has_followredirects()): self
.set_followredirects(x
.followredirects())
316 if (x
.has_deadline()): self
.set_deadline(x
.deadline())
319 if x
is self
: return 1
320 if self
.has_method_
!= x
.has_method_
: return 0
321 if self
.has_method_
and self
.method_
!= x
.method_
: return 0
322 if self
.has_url_
!= x
.has_url_
: return 0
323 if self
.has_url_
and self
.url_
!= x
.url_
: return 0
324 if len(self
.header_
) != len(x
.header_
): return 0
325 for e1
, e2
in zip(self
.header_
, x
.header_
):
326 if e1
!= e2
: return 0
327 if self
.has_payload_
!= x
.has_payload_
: return 0
328 if self
.has_payload_
and self
.payload_
!= x
.payload_
: return 0
329 if self
.has_followredirects_
!= x
.has_followredirects_
: return 0
330 if self
.has_followredirects_
and self
.followredirects_
!= x
.followredirects_
: return 0
331 if self
.has_deadline_
!= x
.has_deadline_
: return 0
332 if self
.has_deadline_
and self
.deadline_
!= x
.deadline_
: return 0
335 def IsInitialized(self
, debug_strs
=None):
337 if (not self
.has_method_
):
339 if debug_strs
is not None:
340 debug_strs
.append('Required field: method not set.')
341 if (not self
.has_url_
):
343 if debug_strs
is not None:
344 debug_strs
.append('Required field: url not set.')
345 for p
in self
.header_
:
346 if not p
.IsInitialized(debug_strs
): initialized
=0
351 n
+= self
.lengthVarInt64(self
.method_
)
352 n
+= self
.lengthString(len(self
.url_
))
353 n
+= 2 * len(self
.header_
)
354 for i
in xrange(len(self
.header_
)): n
+= self
.header_
[i
].ByteSize()
355 if (self
.has_payload_
): n
+= 1 + self
.lengthString(len(self
.payload_
))
356 if (self
.has_followredirects_
): n
+= 2
357 if (self
.has_deadline_
): n
+= 9
365 self
.clear_followredirects()
366 self
.clear_deadline()
368 def OutputUnchecked(self
, out
):
370 out
.putVarInt32(self
.method_
)
372 out
.putPrefixedString(self
.url_
)
373 for i
in xrange(len(self
.header_
)):
375 self
.header_
[i
].OutputUnchecked(out
)
377 if (self
.has_payload_
):
379 out
.putPrefixedString(self
.payload_
)
380 if (self
.has_followredirects_
):
382 out
.putBoolean(self
.followredirects_
)
383 if (self
.has_deadline_
):
385 out
.putDouble(self
.deadline_
)
387 def TryMerge(self
, d
):
391 self
.set_method(d
.getVarInt32())
394 self
.set_url(d
.getPrefixedString())
397 self
.add_header().TryMerge(d
)
400 self
.set_payload(d
.getPrefixedString())
403 self
.set_followredirects(d
.getBoolean())
406 self
.set_deadline(d
.getDouble())
408 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
412 def __str__(self
, prefix
="", printElemNumber
=0):
414 if self
.has_method_
: res
+=prefix
+("Method: %s\n" % self
.DebugFormatInt32(self
.method_
))
415 if self
.has_url_
: res
+=prefix
+("Url: %s\n" % self
.DebugFormatString(self
.url_
))
417 for e
in self
.header_
:
419 if printElemNumber
: elm
="(%d)" % cnt
420 res
+=prefix
+("Header%s {\n" % elm
)
421 res
+=e
.__str
__(prefix
+ " ", printElemNumber
)
424 if self
.has_payload_
: res
+=prefix
+("Payload: %s\n" % self
.DebugFormatString(self
.payload_
))
425 if self
.has_followredirects_
: res
+=prefix
+("FollowRedirects: %s\n" % self
.DebugFormatBool(self
.followredirects_
))
426 if self
.has_deadline_
: res
+=prefix
+("Deadline: %s\n" % self
.DebugFormat(self
.deadline_
))
451 ProtocolBuffer
.Encoder
.NUMERIC
,
452 ProtocolBuffer
.Encoder
.NUMERIC
,
454 ProtocolBuffer
.Encoder
.STRING
,
456 ProtocolBuffer
.Encoder
.STARTGROUP
,
458 ProtocolBuffer
.Encoder
.STRING
,
460 ProtocolBuffer
.Encoder
.STRING
,
462 ProtocolBuffer
.Encoder
.STRING
,
464 ProtocolBuffer
.Encoder
.NUMERIC
,
466 ProtocolBuffer
.Encoder
.DOUBLE
,
471 _STYLE_CONTENT_TYPE
= """"""
472 class URLFetchResponse_Header(ProtocolBuffer
.ProtocolMessage
):
478 def __init__(self
, contents
=None):
479 if contents
is not None: self
.MergeFromString(contents
)
481 def key(self
): return self
.key_
483 def set_key(self
, x
):
492 def has_key(self
): return self
.has_key_
494 def value(self
): return self
.value_
496 def set_value(self
, x
):
500 def clear_value(self
):
505 def has_value(self
): return self
.has_value_
508 def MergeFrom(self
, x
):
510 if (x
.has_key()): self
.set_key(x
.key())
511 if (x
.has_value()): self
.set_value(x
.value())
514 if x
is self
: return 1
515 if self
.has_key_
!= x
.has_key_
: return 0
516 if self
.has_key_
and self
.key_
!= x
.key_
: return 0
517 if self
.has_value_
!= x
.has_value_
: return 0
518 if self
.has_value_
and self
.value_
!= x
.value_
: return 0
521 def IsInitialized(self
, debug_strs
=None):
523 if (not self
.has_key_
):
525 if debug_strs
is not None:
526 debug_strs
.append('Required field: key not set.')
527 if (not self
.has_value_
):
529 if debug_strs
is not None:
530 debug_strs
.append('Required field: value not set.')
535 n
+= self
.lengthString(len(self
.key_
))
536 n
+= self
.lengthString(len(self
.value_
))
543 def OutputUnchecked(self
, out
):
545 out
.putPrefixedString(self
.key_
)
547 out
.putPrefixedString(self
.value_
)
549 def TryMerge(self
, d
):
554 self
.set_key(d
.getPrefixedString())
557 self
.set_value(d
.getPrefixedString())
559 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
563 def __str__(self
, prefix
="", printElemNumber
=0):
565 if self
.has_key_
: res
+=prefix
+("Key: %s\n" % self
.DebugFormatString(self
.key_
))
566 if self
.has_value_
: res
+=prefix
+("Value: %s\n" % self
.DebugFormatString(self
.value_
))
569 class URLFetchResponse(ProtocolBuffer
.ProtocolMessage
):
574 has_contentwastruncated_
= 0
575 contentwastruncated_
= 0
576 has_externalbytessent_
= 0
577 externalbytessent_
= 0
578 has_externalbytesreceived_
= 0
579 externalbytesreceived_
= 0
581 def __init__(self
, contents
=None):
583 if contents
is not None: self
.MergeFromString(contents
)
585 def content(self
): return self
.content_
587 def set_content(self
, x
):
588 self
.has_content_
= 1
591 def clear_content(self
):
592 if self
.has_content_
:
593 self
.has_content_
= 0
596 def has_content(self
): return self
.has_content_
598 def statuscode(self
): return self
.statuscode_
600 def set_statuscode(self
, x
):
601 self
.has_statuscode_
= 1
604 def clear_statuscode(self
):
605 if self
.has_statuscode_
:
606 self
.has_statuscode_
= 0
609 def has_statuscode(self
): return self
.has_statuscode_
611 def header_size(self
): return len(self
.header_
)
612 def header_list(self
): return self
.header_
615 return self
.header_
[i
]
617 def mutable_header(self
, i
):
618 return self
.header_
[i
]
620 def add_header(self
):
621 x
= URLFetchResponse_Header()
622 self
.header_
.append(x
)
625 def clear_header(self
):
627 def contentwastruncated(self
): return self
.contentwastruncated_
629 def set_contentwastruncated(self
, x
):
630 self
.has_contentwastruncated_
= 1
631 self
.contentwastruncated_
= x
633 def clear_contentwastruncated(self
):
634 if self
.has_contentwastruncated_
:
635 self
.has_contentwastruncated_
= 0
636 self
.contentwastruncated_
= 0
638 def has_contentwastruncated(self
): return self
.has_contentwastruncated_
640 def externalbytessent(self
): return self
.externalbytessent_
642 def set_externalbytessent(self
, x
):
643 self
.has_externalbytessent_
= 1
644 self
.externalbytessent_
= x
646 def clear_externalbytessent(self
):
647 if self
.has_externalbytessent_
:
648 self
.has_externalbytessent_
= 0
649 self
.externalbytessent_
= 0
651 def has_externalbytessent(self
): return self
.has_externalbytessent_
653 def externalbytesreceived(self
): return self
.externalbytesreceived_
655 def set_externalbytesreceived(self
, x
):
656 self
.has_externalbytesreceived_
= 1
657 self
.externalbytesreceived_
= x
659 def clear_externalbytesreceived(self
):
660 if self
.has_externalbytesreceived_
:
661 self
.has_externalbytesreceived_
= 0
662 self
.externalbytesreceived_
= 0
664 def has_externalbytesreceived(self
): return self
.has_externalbytesreceived_
667 def MergeFrom(self
, x
):
669 if (x
.has_content()): self
.set_content(x
.content())
670 if (x
.has_statuscode()): self
.set_statuscode(x
.statuscode())
671 for i
in xrange(x
.header_size()): self
.add_header().CopyFrom(x
.header(i
))
672 if (x
.has_contentwastruncated()): self
.set_contentwastruncated(x
.contentwastruncated())
673 if (x
.has_externalbytessent()): self
.set_externalbytessent(x
.externalbytessent())
674 if (x
.has_externalbytesreceived()): self
.set_externalbytesreceived(x
.externalbytesreceived())
677 if x
is self
: return 1
678 if self
.has_content_
!= x
.has_content_
: return 0
679 if self
.has_content_
and self
.content_
!= x
.content_
: return 0
680 if self
.has_statuscode_
!= x
.has_statuscode_
: return 0
681 if self
.has_statuscode_
and self
.statuscode_
!= x
.statuscode_
: return 0
682 if len(self
.header_
) != len(x
.header_
): return 0
683 for e1
, e2
in zip(self
.header_
, x
.header_
):
684 if e1
!= e2
: return 0
685 if self
.has_contentwastruncated_
!= x
.has_contentwastruncated_
: return 0
686 if self
.has_contentwastruncated_
and self
.contentwastruncated_
!= x
.contentwastruncated_
: return 0
687 if self
.has_externalbytessent_
!= x
.has_externalbytessent_
: return 0
688 if self
.has_externalbytessent_
and self
.externalbytessent_
!= x
.externalbytessent_
: return 0
689 if self
.has_externalbytesreceived_
!= x
.has_externalbytesreceived_
: return 0
690 if self
.has_externalbytesreceived_
and self
.externalbytesreceived_
!= x
.externalbytesreceived_
: return 0
693 def IsInitialized(self
, debug_strs
=None):
695 if (not self
.has_statuscode_
):
697 if debug_strs
is not None:
698 debug_strs
.append('Required field: statuscode not set.')
699 for p
in self
.header_
:
700 if not p
.IsInitialized(debug_strs
): initialized
=0
705 if (self
.has_content_
): n
+= 1 + self
.lengthString(len(self
.content_
))
706 n
+= self
.lengthVarInt64(self
.statuscode_
)
707 n
+= 2 * len(self
.header_
)
708 for i
in xrange(len(self
.header_
)): n
+= self
.header_
[i
].ByteSize()
709 if (self
.has_contentwastruncated_
): n
+= 2
710 if (self
.has_externalbytessent_
): n
+= 1 + self
.lengthVarInt64(self
.externalbytessent_
)
711 if (self
.has_externalbytesreceived_
): n
+= 1 + self
.lengthVarInt64(self
.externalbytesreceived_
)
716 self
.clear_statuscode()
718 self
.clear_contentwastruncated()
719 self
.clear_externalbytessent()
720 self
.clear_externalbytesreceived()
722 def OutputUnchecked(self
, out
):
723 if (self
.has_content_
):
725 out
.putPrefixedString(self
.content_
)
727 out
.putVarInt32(self
.statuscode_
)
728 for i
in xrange(len(self
.header_
)):
730 self
.header_
[i
].OutputUnchecked(out
)
732 if (self
.has_contentwastruncated_
):
734 out
.putBoolean(self
.contentwastruncated_
)
735 if (self
.has_externalbytessent_
):
737 out
.putVarInt64(self
.externalbytessent_
)
738 if (self
.has_externalbytesreceived_
):
740 out
.putVarInt64(self
.externalbytesreceived_
)
742 def TryMerge(self
, d
):
746 self
.set_content(d
.getPrefixedString())
749 self
.set_statuscode(d
.getVarInt32())
752 self
.add_header().TryMerge(d
)
755 self
.set_contentwastruncated(d
.getBoolean())
758 self
.set_externalbytessent(d
.getVarInt64())
761 self
.set_externalbytesreceived(d
.getVarInt64())
763 if (tt
== 0): raise ProtocolBuffer
.ProtocolBufferDecodeError
767 def __str__(self
, prefix
="", printElemNumber
=0):
769 if self
.has_content_
: res
+=prefix
+("Content: %s\n" % self
.DebugFormatString(self
.content_
))
770 if self
.has_statuscode_
: res
+=prefix
+("StatusCode: %s\n" % self
.DebugFormatInt32(self
.statuscode_
))
772 for e
in self
.header_
:
774 if printElemNumber
: elm
="(%d)" % cnt
775 res
+=prefix
+("Header%s {\n" % elm
)
776 res
+=e
.__str
__(prefix
+ " ", printElemNumber
)
779 if self
.has_contentwastruncated_
: res
+=prefix
+("ContentWasTruncated: %s\n" % self
.DebugFormatBool(self
.contentwastruncated_
))
780 if self
.has_externalbytessent_
: res
+=prefix
+("ExternalBytesSent: %s\n" % self
.DebugFormatInt64(self
.externalbytessent_
))
781 if self
.has_externalbytesreceived_
: res
+=prefix
+("ExternalBytesReceived: %s\n" % self
.DebugFormatInt64(self
.externalbytesreceived_
))
789 kContentWasTruncated
= 6
790 kExternalBytesSent
= 7
791 kExternalBytesReceived
= 8
800 "ContentWasTruncated",
802 "ExternalBytesReceived",
806 ProtocolBuffer
.Encoder
.NUMERIC
,
807 ProtocolBuffer
.Encoder
.STRING
,
809 ProtocolBuffer
.Encoder
.NUMERIC
,
811 ProtocolBuffer
.Encoder
.STARTGROUP
,
813 ProtocolBuffer
.Encoder
.STRING
,
815 ProtocolBuffer
.Encoder
.STRING
,
817 ProtocolBuffer
.Encoder
.NUMERIC
,
819 ProtocolBuffer
.Encoder
.NUMERIC
,
821 ProtocolBuffer
.Encoder
.NUMERIC
,
826 _STYLE_CONTENT_TYPE
= """"""
828 __all__
= ['URLFetchServiceError','URLFetchRequest','URLFetchRequest_Header','URLFetchResponse','URLFetchResponse_Header']