Hacked By AnonymousFox

Current Path : /lib/python2.7/site-packages/google/protobuf/internal/
Upload File :
Current File : //lib/python2.7/site-packages/google/protobuf/internal/decoder.pyo

�
Du�ac@s�dZdZddlZddlZejr6eZnddlmZddlm	Z	ddl
mZdZeZ
edZejZd	�Zd
�Zed(e�Zede�Zed*e�Zed
e�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zee	je�Zee	je�Z ee	je�Z!ee	je�Z"ee	jee	j#�Z$ee	jee	j#�Z%ee	j&d�Z'ee	j(d�Z)ee	j&d�Z*ee	j(d�Z+e�Z,e�Z-ee	jee.�Z/d�Z0d�Z1d�Z2d�Z3ej4de	j5�Z6d�Z7d�Z8d�Z9d �Z:d!�Z;d"�Z<d#�Z=d$�Z>d%�Z?d&�Z@e@�ZAdS(+s�	Code for decoding protocol buffer primitives.

This code is very similar to encoder.py -- read the docs for that module first.

A "decoder" is a function with the signature:
  Decode(buffer, pos, end, message, field_dict)
The arguments are:
  buffer:     The string containing the encoded message.
  pos:        The current position in the string.
  end:        The position in the string where the current message ends.  May be
              less than len(buffer) if we're reading a sub-message.
  message:    The message object into which we're parsing.
  field_dict: message._fields (avoids a hashtable lookup).
The decoder reads the field and stores it into field_dict, returning the new
buffer position.  A decoder for a repeated field may proactively decode all of
the elements of that field, if they appear consecutively.

Note that decoders may throw any of the following:
  IndexError:  Indicates a truncated message.
  struct.error:  Unpacking of a fixed-width field failed.
  message.DecodeError:  Other errors.

Decoders are expected to raise an exception if they are called with pos > end.
This allows callers to be lax about bounds checking:  it's fineto read past
"end" as long as you are sure that someone else will notice and throw an
exception later on.

Something up the call stack is expected to catch IndexError and struct.error
and convert them to message.DecodeError.

Decoders are constructed using decoder constructors with the signature:
  MakeDecoder(field_number, is_repeated, is_packed, key, new_default)
The arguments are:
  field_number:  The field number of the field we want to decode.
  is_repeated:   Is the field a repeated field? (bool)
  is_packed:     Is the field a packed field? (bool)
  key:           The key to use when looking up the field within field_dict.
                 (This is actually the FieldDescriptor but nothing in this
                 file should depend on that.)
  new_default:   A function which takes a message object as a parameter and
                 returns a new instance of the default value for this field.
                 (This is called for repeated fields and sub-messages, when an
                 instance does not already exist.)

As with encoders, we define a decoder constructor for every type of field.
Then, for every field of every message class we construct an actual decoder.
That decoder goes into a dict indexed by tag, so when we decode a message
we repeatedly read a tag, look up the corresponding decoder, and invoke it.
s kenton@google.com (Kenton Varda)i����N(tencoder(twire_format(tmessageg�ics��fd�}|S(s�Return an encoder for a basic varint value (does not include tag).

  Decoded values will be bitwise-anded with the given mask before being
  returned, e.g. to limit them to 32 bits.  The returned decoder does not
  take the usual "end" parameter -- the caller is expected to do bounds checking
  after the fact (often the caller can defer such checking until later).  The
  decoder returns a (value, new_pos) pair.
  cs�d}d}x�tj||�}||d@|>O}|d7}|d@sg|�M}�|�}||fS|d7}|dkrtd��qqWdS(Niiii�ii@s$Too many bytes when decoding varint.(tsixt
indexbytest_DecodeError(tbuffertpostresulttshifttb(tmasktresult_type(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytDecodeVarintus




((RRR
((RRsD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_VarintDecoderks
cs5d|d>�d|>d����fd�}|S(s0Like _VarintDecoder() but decodes signed values.ics�d}d}x�tj||�}||d@|>O}|d7}|d@su|�M}|�A�}�|�}||fS|d7}|dkrtd��qqWdS(Niiii�ii@s$Too many bytes when decoding varint.(RRR(RRRR	R
(RRtsignbit(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR
�s




((tbitsRR
((RRRsD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_SignedVarintDecoder�sii@i cCsQ|}x$tj||�d@r,|d7}q	W|d7}tj|||!�|fS(s�Read a tag from the buffer, and return a (tag_bytes, new_pos) tuple.

  We return the raw bytes of the tag rather than decoding them.  The raw
  bytes can then be used to look up the proper decoder.  This effectively allows
  us to trade some work that would be done in pure-python (decoding a varint)
  for work that is done in C (searching for a byte string in a hash table).
  In a low-level language it would be much cheaper to decode the varint and
  use that, but not in Python.
  i�i(RRtbinary_type(RRtstart((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytReadTag�s

cs��fd�}|S(s�Return a constructor for a decoder for fields of a particular type.

  Args:
      wire_type:  The field's wire type.
      decode_value:  A function which decodes an individual value, e.g.
        _DecodeVarint()
  cs�|r(t�����fd�}|S|rktj|���t��������fd�}|S��fd�}|SdS(Ncs�|j��}|dkr6|j��|��}n�||�\}}||7}||krptd��nx2||kr��||�\}}|j|�qsW||kr�|d=td��n|S(NsTruncated message.i����sPacked element was truncated.(tgettNonet
setdefaultRtappend(RRtendRt
field_dicttvaluetendpointtelement(tdecode_valuetkeytlocal_DecodeVarinttnew_default(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytDecodePackedField�s
cs�|j��}|dkr6|j��|��}nxn�||�\}}|j|�|�}|||!�ks�||kr9||kr�td��n|Sq9WdS(NsTruncated message.(RRRRR(RRRRRRRtnew_pos(RRR!t	tag_bytesttag_len(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytDecodeRepeatedField�s

cs?�||�\|�<}||kr;|�=td��n|S(NsTruncated message.(R(RRRRR(RR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytDecodeField�s
(t
_DecodeVarintRtTagBytestlen(tfield_numbertis_repeatedt	is_packedRR!R"R&R'(Rt	wire_type(RR R!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytSpecificDecoder�s((R.RR/((RR.sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_SimpleDecoder�s	/cs��fd�}t||�S(s�Like SimpleDecoder but additionally invokes modify_value on every value
  before storing it.  Usually modify_value is ZigZagDecode.
  cs%�||�\}}�|�|fS(N((RRRR#(Rtmodify_value(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytInnerDecodes(R0(R.RR1R2((RR1sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_ModifiedDecoder�scs:tj���tj����fd�}t||�S(s�Return a constructor for a decoder for a fixed-width field.

  Args:
      wire_type:  The field's wire type.
      format:  The format string to pass to struct.unpack().
  cs.|�}��|||!�d}||fS(Ni((RRR#R(tformattlocal_unpackt
value_size(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR2s
(tstructtcalcsizetunpackR0(R.R4R2((R4R5R6sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_StructPackDecoders		cs(tj��fd�}ttj|�S(s�Returns a decoder for a float field.

  This code works around a bug in struct.unpack for non-finite 32-bit
  floating-point values.
  cs�|d}|||!}|dd!dkr�|dd!dkr�|dd!dkrZt|fS|dd!dkrwt|fSt|fS�d	|�d}||fS(
Niis�is�is�s�s<f(t_NANt_NEG_INFt_POS_INF(RRR#tfloat_bytesR(R5(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR2)s

&


(R7R9R0RtWIRETYPE_FIXED32(R2((R5sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt
_FloatDecoder s	cs(tj��fd�}ttj|�S(skReturns a decoder for a double field.

  This code works around a bug in struct.unpack for not-a-number.
  csw|d}|||!}|dd!dkrZ|dd!dkrZ|dd!dkrZt|fS�d|�d}||fS(	Niis�is�is�s<d(R;(RRR#tdouble_bytesR(R5(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR2Ks


(R7R9R0RtWIRETYPE_FIXED64(R2((R5sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_DoubleDecoderCs	cs��j�|r4t������fd�}|S|rztj�tj��t��������fd�}|S���fd�}|SdS(Nc
sF|j��}|dkr6|j��|��}n�||�\}}||7}||krptd��nx�||kr|}t||�\}}|�jkr�|j|�qs|js�g|_ntj	�t
j�}	|jj|	|||!f�qsW||krB|�jkr)|d=n
|jd=td��n|S(NsTruncated message.i����sPacked element was truncated.(RRRRt_DecodeSignedVarint32tvalues_by_numberRt_unknown_fieldsRR)RtWIRETYPE_VARINT(
RRRRRRRtvalue_start_posRR$(t	enum_typeR+RR R!(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR"es0
			

cs�|j��}|dkr6|j��|��}nx�t||�\}}|�jkrm|j|�n2|js�g|_n|jj�|||!f�|�}|||!�ks�||kr9||kr�td��n|Sq9WdS(NsTruncated message.(RRRRDRERRFR(RRRRRRRR#(RIRR!R$R%(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR&�s 		
cs�|}t||�\}}||kr6td��n|�jkrR||�<nG|jsgg|_ntj�tj�}|jj||||!f�|S(NsTruncated message.(	RDRRERFRR)RRGR(RRRRRRHt
enum_valueR$(RIR+R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR'�s
			(RIR(RR)RRGR*(R+R,R-RR!R"R&R'((RIR+RR R!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytEnumDecoderas	s<Is<Qs<is<qcs�t�tj���fd��|rjtj|tj��t���������fd�}|S���fd�}|SdS(s%Returns a decoder for a string field.csDy�|d�SWn,tk
r?}d|�jf|_�nXdS(Nsutf-8s%s in field: %s(tUnicodeDecodeErrort	full_nametreason(tbyte_strte(Rt
local_unicode(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_ConvertToUnicode�s
cs�|j��}|dkr6|j��|��}nx��||�\}}||}||krstd��n|j�|||!��|�}|||!�ks�||kr9|Sq9WdS(NsTruncated string.(RRRRR(RRRRRRtsizeR#(RRRR R!R$R%(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR&�s

csU�||�\}}||}||kr:td��n�|||!�|�<|S(NsTruncated string.(R(RRRRRRSR#(RRRR (sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR'�s
N(R(Rt	text_typeRR)RtWIRETYPE_LENGTH_DELIMITEDR*(R+R,R-RR!R&R'((RRRR RQR!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt
StringDecoder�s			csft�|rLtj|tj��t��������fd�}|S��fd�}|SdS(s$Returns a decoder for a bytes field.cs�|j��}|dkr6|j��|��}nx�||�\}}||}||krstd��n|j|||!�|�}|||!�ks�||kr9|Sq9WdS(NsTruncated string.(RRRRR(RRRRRRRSR#(RR R!R$R%(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR&s

csO�||�\}}||}||kr:td��n|||!|�<|S(NsTruncated string.(R(RRRRRRSR#(RR (sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR's
N(R(RR)RRUR*(R+R,R-RR!R&R'((RR R!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytBytesDecoder�s	cs�tj|tj��t���|rjtj|tj��t���������fd�}|S����fd�}|SdS(s$Returns a decoder for a group field.cs�|j��}|dkr6|j��|��}nx�|j��}|dkro|j��|��}n|j�j|||�}|�}|||!�ks�||kr�td��n|�}|||!�ks�||kr9|Sq9WdS(NsMissing group end tag.(RRRtaddt_InternalParseR(RRRRRRR#(t
end_tag_bytestend_tag_lenRR!R$R%(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR&,s

cs�|j��}|dkr6|j��|��}n|j|||�}|�}|||!�kst||kr�td��n|S(NsMissing group end tag.(RRRRYR(RRRRRRR#(RZR[RR!(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR'As
N(RR)RtWIRETYPE_END_GROUPR*tWIRETYPE_START_GROUP(R+R,R-RR!R&R'((RZR[RR!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytGroupDecoder s		csit�|rLtj|tj��t��������fd�}|S���fd�}|SdS(s&Returns a decoder for a message field.cs�|j��}|dkr6|j��|��}nx��||�\}}||}||krstd��n|j�j|||�|kr�td��n|�}|||!�ks�||kr9|Sq9WdS(NsTruncated message.sUnexpected end-group tag.(RRRRRXRY(RRRRRRRSR#(RR R!R$R%(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR&Ys
!
cs�|j��}|dkr6|j��|��}n�||�\}}||}||krptd��n|j|||�|kr�td��n|S(NsTruncated message.sUnexpected end-group tag.(RRRRRY(RRRRRRRSR#(RR R!(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR'os
N(R(RR)RRUR*(R+R,R-RR!R&R'((RR R!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytMessageDecoderOs	csptjdtj��tjdtj��tjdtj��t�t�t}�����fd�}|S(sReturns a decoder for a MessageSet item.

  The parameter is the message Descriptor.

  The message set message looks like this:
    message MessageSet {
      repeated group Item = 1 {
        required int32 type_id = 2;
        required string message = 3;
      }
    }
  iiic
s�|}d}d}d}x��||�\}	}|	�krT�||�\}}q|	�kr��||�\}
}||
}}q|	�kr�Pqt||||	�}|dkrtd��qqW||kr�td��n|dkrtd��n|dkrtd��n|jj|�}|dk	r�|j|�}|dkrr|j||jj��}n|j	|||�|kr�td��q�n2|j
s�g|_
n|j
jt|||!f�|S(Ni����sMissing group end tag.sTruncated message.s MessageSet item missing type_id.s MessageSet item missing message.sUnexpected end-group tag.(
t	SkipFieldRt
Extensionst_FindExtensionByNumberRRRtmessage_typet_concrete_classRYRFRtMESSAGE_SET_ITEM_TAG(
RRRRRtmessage_set_item_startttype_idt
message_starttmessage_endR$RSt	extensionR(titem_end_tag_bytesR t
local_ReadTagtmessage_tag_bytesttype_id_tag_bytes(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt
DecodeItem�sF	(	RR)RRGRUR\RR(R`(t
descriptortlocal_SkipFieldRo((RkR RlRmRnsD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pytMessageSetItemDecoder�s0cs^|�tj|jtj��t���t�|j��������fd�}|S(s"Returns a decoder for a map field.c	s�j�}|j��}|dkrB|j��|��}nx��||�\}}||}||krtd��n|j�|j|||�|kr�td��n�r�||jj|j	�n|j	||j<|�}|||!�ks||krE|SqEWdS(NsTruncated message.sUnexpected end-group tag.(
RdRRRRtClearRYRt	MergeFromR(	RRRRRtsubmsgRRSR#(tis_message_mapRR RcR!R$R%(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt	DecodeMap�s$


(RR)tnumberRRUR*R(Rc(tfield_descriptorR!RvRw((RvRR RcR!R$R%sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt
MapDecoder�s	!cCsUx)t|||d!�d@r+|d7}qW|d7}||krQtd��n|S(s/Skip a varint value.  Returns the new position.ii�sTruncated message.(tordR(RRR((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_SkipVarint�s
cCs)|d7}||kr%td��n|S(s0Skip a fixed64 value.  Returns the new position.isTruncated message.(R(RRR((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_SkipFixed64	s
cCs>t||�\}}||7}||kr:td��n|S(s9Skip a length-delimited value.  Returns the new position.sTruncated message.(R(R(RRRRS((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_SkipLengthDelimiteds

cCsKxDt||�\}}t||||�}|dkr=|S|}qWdS(s*Skip sub-group.  Returns the new position.i����N(RR`(RRRR$R#((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt
_SkipGroupscCsdS(sFSkipping an END_GROUP tag returns -1 to tell the parent loop to break.i����((RRR((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt	_EndGroup$scCs)|d7}||kr%td��n|S(s0Skip a fixed32 value.  Returns the new position.isTruncated message.(R(RRR((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_SkipFixed32)s
cCstd��dS(s;Skip function for unknown wire types.  Raises an exception.sTag had invalid wire type.N(R(RRR((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt_RaiseInvalidWireType1scs=ttttttttg�tj���fd�}|S(s"Constructs the SkipField function.cs+t|dd!��@}�||||�S(sSkips a field with the specified tag.

    |pos| should point to the byte immediately after the tag.

    Returns:
        The new position (after the tag value), or -1 if the tag is an end-group
        tag (in which case the calling loop should break).
    ii(R{(RRRR$R.(tWIRETYPE_TO_SKIPPERt
wiretype_mask(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyR`Fs(	R|R}R~RR�R�R�Rt
TAG_TYPE_MASK(R`((R�R�sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt
_FieldSkipper6s		ll����ll��(Bt__doc__t
__author__R7RtPY3tinttlongtgoogle.protobuf.internalRRtgoogle.protobufRR=R<R;tDecodeErrorRRRR(t_DecodeSignedVarintt_DecodeVarint32RDRR0R3R:R@RCRKRGtInt32DecodertInt64Decodert
UInt32Decodert
UInt64DecodertZigZagDecodet
SInt32Decodert
SInt64DecoderR?tFixed32DecoderRBtFixed64DecodertSFixed32DecodertSFixed64DecodertFloatDecodert
DoubleDecodertbooltBoolDecoderRVRWR^R_R)R]ReRrRzR|R}R~RR�R�R�R�R`(((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/decoder.pyt<module>Osv		
					;			#		O			.	%	/	4	J	.					
				 

Hacked By AnonymousFox1.0, Coded By AnonymousFox