Test if raw packets are valid for initialization of Position.
518662
def from_raw(raw):
        """"""
        if not isinstance(raw, bytes):
            raise PyVLXException("Position::raw_must_be_bytes")
        if len(raw) != 2:
            raise PyVLXException("Position::raw_must_be_two_bytes")
        if raw != Position.from_int(Position.CURRENT_POSITION) and \
                raw != Position.from_int(Position.UNKNOWN_VALUE) and \
                Position.to_int(raw) > Position.MAX:
            raise PyVLXException("position::raw_exceed_limit", raw=raw)
        return raw
727493
def _is_tp(pkt):
        """"""

        tp = [SOMEIP.TYPE_TP_REQUEST, SOMEIP.TYPE_TP_REQUEST_NO_RET,
              SOMEIP.TYPE_TP_NOTIFICATION, SOMEIP.TYPE_TP_RESPONSE,
              SOMEIP.TYPE_TP_ERROR]
        if isinstance(pkt, Packet):
            return pkt.msg_type in tp
        else:
            return pkt[15] in tp
1172728
def _handle_ping(self, packet, protocol):
        
        if 'payload' in packet:
            is_valid_node = True
            node_ids = list(packet['payload'].values())
            for node_id in node_ids:
                if self._repository.get_node(node_id) is None:
                    is_valid_node = False
                    break
            if is_valid_node:
                self._pong(packet, protocol)
        else:
            self._pong(packet, protocol)
474010
private boolean isURLAbsolute(String url) {
        for (String protocol : PROTOCOLS) {
            if (url.startsWith(protocol)) {
                return true;
            }
        }

        return false;
    }
1364715
def _is_valid_position(self, position):
        '''
        
        '''
        row, col = position
        valid_r = row in self.row_labels
        valid_c = col in self.col_labels
        return valid_r and valid_c
440657
def rrInitialisationRequest():
    """"""
    a = TpPd(pd=0x6)
    b = MessageType(mesType=0x3c)  # 00111100
    c = CiphKeySeqNrAndMacModeAndChannelCodingRequest()
    e = MobileStationClassmark2()
    f = Tlli()
    g = ChannelRequestDescription()
    h = GprsMeasurementResults()
    packet = a / b / c / e / f / g / h
    return packet
1087383
function ensureInitialSetup() {
    if (!initialized) {
        initialized = true;
        process.stdin.resume();
        process.stdin.setEncoding("utf8");
        process.stdin.on("data", function (text) {
            // Store input in buffer
            inputBuffer += text;

            // After input received, if main fiber was waiting, wake it up
            if (inputListenerFiber)
                inputListenerFiber.run();
        });
    }
}
532177
private boolean verify(ByteBuffer content) {
        ByteBuffer bb = ByteBuffer.allocate(l2i(getContentSize() + (deadBytes != null ? deadBytes.limit() : 0)));
        getContent(bb);
        if (deadBytes != null) {
            deadBytes.rewind();
            while (deadBytes.remaining() > 0) {
                bb.put(deadBytes);
            }
        }
        content.rewind();
        bb.rewind();


        if (content.remaining() != bb.remaining()) {
            LOG.error("{}: remaining differs {}  vs. {}", this.getType(), content.remaining(), bb.remaining());
            return false;
        }
        int p = content.position();
        for (int i = content.limit() - 1, j = bb.limit() - 1; i >= p; i--, j--) {
            byte v1 = content.get(i);
            byte v2 = bb.get(j);
            if (v1 != v2) {
                LOG.error("{}: buffers differ at {}: {}/{}", this.getType(), i, v1, v2);
                byte[] b1 = new byte[content.remaining()];
                byte[] b2 = new byte[bb.remaining()];
                content.get(b1);
                bb.get(b2);
                LOG.error("original      : {}", Hex.encodeHex(b1, 4));
                LOG.error("reconstructed : {}", Hex.encodeHex(b2, 4));
                return false;
            }
        }
        return true;

    }
475134
def _parse_packet(rawdata):
    

    if (len(rawdata) < len(_MAGIC) + 1) or (_MAGIC != rawdata[:len(_MAGIC)]):
        # Wrong protocol
        return (None, None)

    opcode = rawdata[len(_MAGIC):len(_MAGIC)+1]
    payload = rawdata[len(_MAGIC)+1:]

    return (opcode, payload)
327227
def checkInitialState(self,initialState):
        
        assert initialState is not None, "Initial state has not been specified."
        assert isinstance(initialState,(int,list,tuple,np.ndarray,set)), "initialState %r is not an int, tuple, list, set or numpy array" % initialState

         
        if isinstance(initialState,list): 
            #Check whether all entries of the list are ints. Return an int if the len ==1, otherwise a tuple.
            assert all(isinstance(i, int) for i in initialState), "initialState %r is not integer" % initialState 
            initialState = int(initialState) if len(initialState)==1 else tuple(initialState)          

        elif isinstance(initialState,tuple): 
            #Check whether all entries are ints. Return an int if the len ==1, otherwise a tuple.
            assert all(isinstance(i, int) for i in initialState), "initialState %r is not integer" % initialState
            if len(initialState)==1:
                initialState = int(initialState)     
        
        elif isinstance(initialState,np.ndarray):
            #Check whether the state is a 1d numpy array. Return an int if it has length 1.
            assert issubclass(initialState.dtype.type, np.integer) and initialState.ndim==1, "initialState %r is not a one-dimensional integer numpy array" % initialState 
            initialState = int(initialState) if len(initialState)==1 else tuple(initialState)
            
        elif isinstance(initialState,set):
            #If we have a set, then check whether all elements are ints or tuples.
            for state in initialState:                
                assert isinstance(state,(tuple,int)), "the set initialState %r should contain tuples or ints" % initialState 
                if isinstance(state,tuple):
                    assert all(isinstance(i,int) for i in state), "the state %r should be integer" % initialState 
                
        return initialState
803618
private static boolean checkIpv4(byte[] bytes, int pos, int length) {
		int start = pos;
		for (int i = pos; i < length; i++) {
			// assume at least one more symbol is present after dot
			if (i == length - 1 && bytes[i] == '.') {
				return false;
			}
			if (bytes[i] == '.' || i == length - 1) {
				int v;
				if (i - start == 0 && i != length - 1) {
					return false;
				}
				try {
					v = trimAndDecodePositiveInt(bytes, start, i - start);
				} catch (ParseException e) {
					return false;
				}
				if (v < 0 || v > 255) return false;
				start = i + 1;
			}
		}
		return true;
	}
553961
def _validate(self):
        """"""
        if self.tpid.value not in (EtherType.VLAN, EtherType.VLAN_QINQ):
            raise UnpackException
        return
947060
def _assertsanity(self):
        """"""
        assert self.len >= 0
        assert 0 <= self._offset, "offset={0}".format(self._offset)
        assert (self.len + self._offset + 7) // 8 == self._datastore.bytelength + self._datastore.byteoffset
        return True
503825
private void checkAnyChunk(long p) {
    if (VALIDATING) {
      if (!isAligned(chunkToMem(p)))
        throw new AssertionError("Chunk address [mem:" + p + "=>chunk:" + chunkToMem(p) + "] is incorrectly aligned");
      if (!okAddress(p))
        throw new AssertionError("Memory address " + p + " is invalid");
    }
  }
1048467
def is_valid_ipv6_prefix(ipv6_prefix):
    """"""

    # Validate input type
    if not isinstance(ipv6_prefix, str):
        return False

    tokens = ipv6_prefix.split('/')
    if len(tokens) != 2:
        return False

    # Validate address/mask and return
    return is_valid_ipv6(tokens[0]) and is_valid_ip_prefix(tokens[1], 128)
249639
protected final void initializeFromRaw( RawDataBuffer rawMessage )
    {
    	this.rawMessage = rawMessage;
    	this.unserializationLevel = MessageSerializationLevel.BASE_HEADERS;
    	
    	// Only deserialize level 1 headers
    	byte lvl1Flags = rawMessage.readByte();
    	priority     = lvl1Flags & 0x0F;
    	redelivered  = (lvl1Flags & (1 << 4)) != 0;
    	deliveryMode = (lvl1Flags & (1 << 5)) != 0 ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
    	if ((lvl1Flags & (1 << 6)) != 0) expiration = rawMessage.readLong();
    	if ((lvl1Flags & (1 << 7)) != 0) id = rawMessage.readUTF();
    	destination = DestinationSerializer.unserializeFrom(rawMessage);
    }
1123116
def VerifyCoARequest(self):
        
        assert(self.raw_packet)
        hash = md5_constructor(self.raw_packet[0:4] + 16 * six.b('\x00') +
                self.raw_packet[20:] + self.secret).digest()
        return hash == self.authenticator