AlkantarClanX12

Your IP : 18.117.158.10


Current Path : /proc/thread-self/root/usr/lib/python2.7/site-packages/google/protobuf/internal/
Upload File :
Current File : //proc/thread-self/root/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyo

�
Du�ac@sydZdZddlZddlZddlmZdZeZd�Zd�Z	d�Z
d	�Zd
�Zd�Z
ee	�ZZZee�ZZee	ej�ZZe
d�ZZZe
d
�ZZZe
d�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$e#�Z%e$�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,e)ej-e&e	�Z.Z/Z0e)ej-e%e�Z1Z2e*ej-e%eej�Z3Z4e+ej5d�Z6e+ej7d�Z8e+ej5d�Z9e+ej7d �Z:e,ej5d!�Z;e,ej7d"�Z<d#�Z=d$�Z>d%�Z?d&�Z@d'�ZAd(�ZBd)�ZCdS(*s�Code for encoding protocol message primitives.

Contains the logic for encoding every logical protocol field type
into one of the 5 physical wire types.

This code is designed to push the Python interpreter's performance to the
limits.

The basic idea is that at startup time, for every field (i.e. every
FieldDescriptor) we construct two functions:  a "sizer" and an "encoder".  The
sizer takes a value of this field's type and computes its byte size.  The
encoder takes a writer function and a value.  It encodes the value into byte
strings and invokes the writer function to write those strings.  Typically the
writer function is the write() method of a BytesIO.

We try to do as much work as possible when constructing the writer and the
sizer rather than when calling them.  In particular:
* We copy any needed global functions to local variables, so that we do not need
  to do costly global table lookups at runtime.
* Similarly, we try to do any attribute lookups at startup time if possible.
* Every field's tag is encoded to bytes at startup, since it can't change at
  runtime.
* Whatever component of the field size we can compute at startup, we do.
* We *avoid* sharing code if doing so would make the code slower and not sharing
  does not burden us too much.  For example, encoders for repeated fields do
  not just call the encoders for singular fields in a loop because this would
  add an extra function call overhead for every loop iteration; instead, we
  manually inline the single-value encoder into the loop.
* If a Python function lacks a return statement, Python actually generates
  instructions to pop the result of the last statement off the stack, push
  None onto the stack, and then return that.  If we really don't care what
  value is returned, then we can save two instructions by returning the
  result of the last statement.  It looks funny but it helps.
* We assume that type and bounds checking has happened at a higher level.
s kenton@google.com (Kenton Varda)i����N(twire_formatg�cCs�|dkrdS|dkr dS|dkr0dS|dkr@dS|d	krPd
S|dkr`dS|d
krpdS|dkr�dS|dkr�dSdS(s#Compute the size of a varint value.iii�?ii��ii���il��il���il���il����il����i	i
((tvalue((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_VarintSizeRs&cCs�|dkrdS|dkr dS|dkr0dS|dkr@dS|d	krPd
S|dkr`dS|d
krpdS|dkr�dS|dkr�dS|dkr�dSdS(s*Compute the size of a signed varint value.ii
iii�?ii��ii���il��il���il���il����il����i	((R((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_SignedVarintSize`s*cCsttj|d��S(sQReturns the number of bytes required to serialize a tag with this field
  number.i(RRtPackTag(tfield_number((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_TagSizeoscs�fd�}|S(s�A sizer which uses the function compute_value_size to compute the size of
  each value.  Typically compute_value_size is _VarintSize.csgt|��|r1t����fd�}|S|rM��fd�}|S��fd�}|SdS(Ncs9d}x|D]}|�|�7}q
W|�|��S(Ni((Rtresulttelement(tcompute_value_sizetlocal_VarintSizettag_size(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytPackedFieldSize�s
cs5�t|�}x|D]}|�|�7}qW|S(N(tlen(RRR(R	R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytRepeatedFieldSize�s
cs��|�S(N((R(R	R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt	FieldSize�s(RR(Rtis_repeatedt	is_packedRRR(R	(R
RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt
SpecificSizer�s((R	R((R	sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_SimpleSizer~scs��fd�}|S(s�Like SimpleSizer, but modify_value is invoked on each value before it is
  passed to compute_value_size.  modify_value is typically ZigZagEncode.cspt|��|r4t�����fd�}|S|rS���fd�}|S���fd�}|SdS(Ncs?d}x$|D]}|��|��7}q
W|�|��S(Ni((RRR(R	R
tmodify_valueR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s
cs;�t|�}x$|D]}|��|��7}qW|S(N(R
(RRR(R	RR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s
cs���|��S(N((R(R	RR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s(RR(RRRRRR(R	R(R
RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s((R	RR((R	RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_ModifiedSizer�scs�fd�}|S(sWLike _SimpleSizer except for a fixed-size field.  The input is the size
  of one value.csut|��|r1t����fd�}|S|rT����fd�}|S����fd�}|SdS(Ncs"t|��}|�|��S(N(R
(RR(R
Rt
value_size(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�scst|��S(N(R
(R(telement_size(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�scs�S(N((R(t
field_size(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s(RR(RRRRRR(R(RRR
RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s

((RR((RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_FixedSizer�siiicsTt|��t�t�|r7���fd�}|S���fd�}|SdS(s#Returns a sizer for a string field.csN�t|�}x7|D]/}�|jd��}|�|�|7}qW|S(Nsutf-8(R
tencode(RRRtl(R
t	local_lenR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�s

cs'�|jd��}��|�|S(Nsutf-8(R(RR(R
RR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR�sN(RRR
(RRRRR((R
RRsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytStringSizer�scsTt|��t�t�|r7���fd�}|S���fd�}|SdS(s"Returns a sizer for a bytes field.csE�t|�}x.|D]&}�|�}|�|�|7}qW|S(N(R
(RRRR(R
RR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRs

cs�|�}��|�|S(N((RR(R
RR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRsN(RRR
(RRRRR((R
RRsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt
BytesSizer�scs@t|�d�|r)�fd�}|S�fd�}|SdS(s"Returns a sizer for a group field.ics5�t|�}x|D]}||j�7}qW|S(N(R
tByteSize(RRR(R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRs
cs�|j�S(N(R(R(R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRsN(R(RRRRR((RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt
GroupSizerscsHt|��t�|r.��fd�}|S��fd�}|SdS(s$Returns a sizer for a message field.csE�t|�}x.|D]&}|j�}|�|�|7}qW|S(N(R
R(RRRR(R
R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR+s

cs|j�}��|�|S(N(R(RR(R
R(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR3sN(RR(RRRRR((R
RsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytMessageSizer$scsJtd�dtd�t|�td��t���fd�}|S(s�Returns a sizer for extensions of MessageSet.

  The message set message looks like this:
    message MessageSet {
      repeated group Item = 1 {
        required int32 type_id = 2;
        required string message = 3;
      }
    }
  iiics|j�}��|�|S(N(R(RR(R
tstatic_size(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRLs(RR(RR((R
R"sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytMessageSetItemSizer=s
!
cs7|j�t|jtt�����fd�}|S(s Returns a sizer for a map field.cs`d}xS|D]K}||}�jd|d|�}|�|�7}�r
|j�q
q
W|S(NitkeyR(t_concrete_classR(t	map_valuettotalR$Rt	entry_msg(tis_message_mapt
message_sizertmessage_type(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyR_s

(R+R!tnumbertFalse(tfield_descriptorR)R((R)R*R+sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytMapSizerWs	cCs
d�}|S(sBReturn an encoder for a basic varint value (does not include tag).cSs_|d@}|dL}x5|rK|tjd|B��|d@}|dL}qW|tj|��S(Niii�(tsixtint2byte(twriteRtunused_deterministictbits((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytEncodeVarintws

	
((R5((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_VarintEncoderts		cCs
d�}|S(sKReturn an encoder for a basic signed varint value (does not include
  tag).cSsx|dkr|d7}n|d@}|dL}x5|rd|tjd|B��|d@}|dL}q0W|tj|��S(Niii@iii�l(R0R1(R2RR3R4((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytEncodeSignedVarint�s


	
((R7((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_SignedVarintEncoder�s	cCs&g}t|j|t�dj|�S(s�Encode the given integer as a varint and return the bytes.  This is only
  called at startup time so it doesn't need to be fast.t(t
_EncodeVarinttappendtTruetjoin(Rtpieces((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_VarintBytes�scCstjttj||���S(sCEncode the given tag and return the bytes.  Only called at startup.(R0tbinary_typeR?RR(Rt	wire_type((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytTagBytes�scs���fd�}|S(s_Return a constructor for an encoder for fields of a particular type.

  Args:
      wire_type:  The field's wire type, for encoding tags.
      encode_value:  A function which encodes an individual value, e.g.
        _EncodeVarint().
      compute_value_size:  A function which computes the size of an individual
        value, e.g. _VarintSize().
  cs�|r:t|tj��t�����fd�}|S|ret|�����fd�}|St|�����fd�}|SdS(Ncsf|��d}x|D]}|�|�7}qW�|||�x|D]}�|||�qHWdS(Ni((R2Rt
deterministictsizeR(R	tencode_valuetlocal_EncodeVarintt	tag_bytes(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytEncodePackedField�s


cs/x(|D] }|���|||�qWdS(N((R2RRCR(RERG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytEncodeRepeatedField�s

cs|���|||�S(N((R2RRC(RERG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytEncodeField�s
(RBRtWIRETYPE_LENGTH_DELIMITEDR:(RRRRHRIRJ(R	RERA(RFRGsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytSpecificEncoder�s((RARER	RL((R	RERAsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_SimpleEncoder�scs����fd�}|S(s�Like SimpleEncoder but additionally invokes modify_value on every value
  before passing it to encode_value.  Usually modify_value is ZigZagEncode.cs�|r=t|tj��t������fd�}|S|rkt|������fd�}|St|������fd�}|SdS(Ncsr|��d}x$|D]}|��|��7}qW�|||�x$|D]}�|�|�|�qNWdS(Ni((R2RRCRDR(R	RERFRRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRH�s


cs5x.|D]&}|���|�|�|�qWdS(N((R2RRCR(RERRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRI�s

cs |���|�|�|�S(N((R2RRC(RERRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ�s
(RBRRKR:(RRRRHRIRJ(R	RERRA(RFRGsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRL�s((RARER	RRL((R	RERRAsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_ModifiedEncoder�scs(tj������fd�}|S(s�Return a constructor for an encoder for a fixed-width field.

  Args:
      wire_type:  The field's wire type, for encoding tags.
      format:  The format string to pass to struct.pack().
  cs�tj�|rFt|tj��t������fd�}|S|rtt|������fd�}|St|������fd�}|SdS(NcsL|���|t|��|�x!|D]}|��|��q+WdS(N(R
(R2RRCR(tformatRFtlocal_struct_packRGR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRHs

cs2x+|D]#}|��|��|��qWdS(N((R2RR3R(RORPRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRIs

cs|��|��|��S(N((R2RR3(RORPRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJs
(tstructtpackRBRRKR:(RRRRHRIRJ(RORRA(RFRPRGsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRLs	(RQtcalcsize(RARORL((RORRAsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_StructPackEncoder�scsktj����dkr'd��n(�dkr?d��ntd�������fd�}|S(sqReturn a constructor for an encoder for float fields.

  This is like StructPackEncoder, but catches errors that may be due to
  passing non-finite floating-point values to struct.pack, and makes a
  second attempt to encode those values.

  Args:
      wire_type:  The field's wire type, for encoding tags.
      format:  The format string to pass to struct.pack().
  icSsR|tkr|d�n5|tkr2|d�n||krK|d�n�dS(Ns�s��s�(t_POS_INFt_NEG_INF(R2R((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytEncodeNonFiniteOrRaise+s


icSsR|tkr|d�n5|tkr2|d�n||krK|d�n�dS(Ns�s�s�(RURV(R2R((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRW6s


sGCan't encode floating-point values that are %d bytes long (only 4 or 8)cs�tj�|rIt|tj��t�������fd�}|S|rzt|�������fd�}|St|�������fd�}|SdS(Ncsq|���|t|��|�xF|D]>}y|��|��Wq+tk
rh�||�q+Xq+WdS(N(R
tSystemError(R2RRCR(RWRORFRPRGR(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRHHs


csWxP|D]H}|��y|��|��Wqtk
rN�||�qXqWdS(N(RX(R2RR3R(RWRORPRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRIUs


csF|��y|��|��Wntk
rA�||�nXdS(N(RX(R2RR3(RWRORPRG(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ_s


(RQRRRBRRKR:(RRRRHRIRJ(RWRORRA(RFRPRGsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRLCs	
(RQRSt
ValueError(RARORL((RWRORRAsD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt_FloatingPointEncoders


$s<Is<Qs<is<qs<fs<dcs�d�d�|rFt|tj��t�����fd�}|S|rwt|tj�����fd�}|St|tj�����fd�}|SdS(s'Returns an encoder for a boolean field.sscsR|���|t|�|�x+|D]#}|r@|��q'|��q'WdS(N(R
(R2RRCR(t
false_byteRFRGt	true_byte(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRH�s


cs<x5|D]-}|��|r*|��q|��qWdS(N((R2RR3R(R[RGR\(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRI�s



cs$|��|r|��S|��S(N((R2RR3(R[RGR\(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ�s

N(RBRRKR:tWIRETYPE_VARINT(RRRRHRIRJ((R[RFRGR\sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytBoolEncoder�scsZt|tj��t�t�|r=���fd�}|S���fd�}|SdS(s&Returns an encoder for a string field.csNxG|D]?}|jd�}|���|�|�|�||�qWdS(Nsutf-8(R(R2RRCRtencoded(RFRttag(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRI�s


cs9|jd�}|���|�|�|�||�S(Nsutf-8(R(R2RRCR_(RFRR`(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ�s
N(RBRRKR:R
(RRRRIRJ((RFRR`sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt
StringEncoder�scsZt|tj��t�t�|r=���fd�}|S���fd�}|SdS(s%Returns an encoder for a bytes field.cs?x8|D]0}|���|�|�|�||�qWdS(N((R2RRCR(RFRR`(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRI�s

cs*|���|�|�|�||�S(N((R2RRC(RFRR`(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ�s
N(RBRRKR:R
(RRRRIRJ((RFRR`sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytBytesEncoder�scsZt|tj��t|tj��|r@��fd�}|S��fd�}|SdS(s%Returns an encoder for a group field.cs9x2|D]*}|��|j||�|��qWdS(N(t_InternalSerialize(R2RRCR(tend_tagt	start_tag(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRI�s

cs$|��|j||�|��S(N(Rc(R2RRC(RdRe(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ�s
N(RBRtWIRETYPE_START_GROUPtWIRETYPE_END_GROUP(RRRRIRJ((RdResD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytGroupEncoder�scsNt|tj��t�|r4��fd�}|S��fd�}|SdS(s'Returns an encoder for a message field.csEx>|D]6}|���||j�|�|j||�qWdS(N(RRc(R2RRCR(RFR`(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRI�s

cs0|���||j�|�|j||�S(N(RRc(R2RRC(RFR`(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ�s
N(RBRRKR:(RRRRIRJ((RFR`sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytMessageEncoder�scsvdjtdtj�tdtj�t|�tdtj�g��tdtj��t����fd�}|S(s�Encoder for extensions of MessageSet.

  The message set message looks like this:
    message MessageSet {
      repeated group Item = 1 {
        required int32 type_id = 2;
        required string message = 3;
      }
    }
  R9iiics:|���||j�|�|j||�|��S(N(RRc(R2RRC(t	end_bytesRFtstart_bytes(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJs
(	R=RBRRfR]R?RKRgR:(RRJ((RjRFRksD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pytMessageSetItemEncoders	cs4|j�t|jtt����fd�}|S(s�Encoder for extensions of MessageSet.

  Maps always have a wire format like this:
    message MapEntry {
      key_type key = 1;
      value_type value = 2;
    }
    repeated MapEntry map = N;
  cs_|rt|j��n|}x:|D]2}�jd|d||�}�|||�q%WdS(NR$R(tsortedtkeysR%(R2RRCt
value_keysR$R((tencode_messageR+(sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyRJ5s
(R+RiR,R-(R.RJ((RpR+sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt
MapEncoder&s	(Dt__doc__t
__author__RQR0tgoogle.protobuf.internalRRURVRRRRRRt
Int32Sizert
Int64Sizert	EnumSizertUInt32SizertUInt64SizertZigZagEncodetSInt32SizertSInt64SizertFixed32Sizert
SFixed32Sizert
FloatSizertFixed64Sizert
SFixed64SizertDoubleSizert	BoolSizerRRR R!R#R/R6R8R:t_EncodeSignedVarintR?RBRMRNRTRZR]tInt32EncodertInt64EncodertEnumEncodert
UInt32Encodert
UInt64Encodert
SInt32Encodert
SInt64EncodertWIRETYPE_FIXED32tFixed32EncodertWIRETYPE_FIXED64tFixed64EncodertSFixed32EncodertSFixed64EncodertFloatEncodert
DoubleEncoderR^RaRbRhRiRlRq(((sD/usr/lib/python2.7/site-packages/google/protobuf/internal/encoder.pyt<module>Asn						!													
	)	"	&	R	%