Return the number of words free in the transmit packet
498314
def _get_free_words(self, blockAllowed, isRead):
        
        if blockAllowed:
            # DAP_TransferBlock request packet:
            #   BYTE | BYTE *****| SHORT**********| BYTE *************| WORD *********|
            # > 0x06 | DAP Index | Transfer Count | Transfer Request  | Transfer Data |
            #  ******|***********|****************|*******************|+++++++++++++++|
            send = self._size - 5 - 4 * self._write_count

            # DAP_TransferBlock response packet:
            #   BYTE | SHORT *********| BYTE *************| WORD *********|
            # < 0x06 | Transfer Count | Transfer Response | Transfer Data |
            #  ******|****************|*******************|+++++++++++++++|
            recv = self._size - 4 - 4 * self._read_count

            if isRead:
                return recv // 4
            else:
                return send // 4
        else:
            # DAP_Transfer request packet:
            #   BYTE | BYTE *****| BYTE **********| BYTE *************| WORD *********|
            # > 0x05 | DAP Index | Transfer Count | Transfer Request  | Transfer Data |
            #  ******|***********|****************|+++++++++++++++++++++++++++++++++++|
            send = self._size - 3 - 1 * self._read_count - 5 * self._write_count

            # DAP_Transfer response packet:
            #   BYTE | BYTE **********| BYTE *************| WORD *********|
            # < 0x05 | Transfer Count | Transfer Response | Transfer Data |
            #  ******|****************|*******************|+++++++++++++++|
            recv = self._size - 3 - 4 * self._read_count

            if isRead:
                # 1 request byte in request packet, 4 data bytes in response packet
                return min(send, recv // 4)
            else:
                # 1 request byte + 4 data bytes
                return send // 5
667646
def wsp(word):
    ''''''
    violations = 0
    unstressed = []

    for w in extract_words(word):
        unstressed += w.split('.')[1::2]  # even syllables

        # include extrametrical odd syllables as potential WSP violations
        if w.count('.') % 2 == 0:
            unstressed += [w.rsplit('.', 1)[-1], ]

    # SHSP
    for syll in unstressed:
        if re.search(r'[ieaouäöy]{2}[^$ieaouäöy]+', syll, flags=FLAGS):
            violations += 1

    # # WSP (CVV = heavy)
    # for syll in unstressed:
    #     if re.search(
    #             ur'[ieaouäöy]{2}|[ieaouäöy]+[^ieaouäöy]+',
    #             syll, flags=re.I | re.U):
    #         violations += 1

    return violations
730041
def recv_msg(self):
        ''''''
        if self._index >= self._count:
            return None
        m = self._msgs[self._index]
        type = m.get_type()
        self._index += 1
        self.percent = (100.0 * self._index) / self._count
        self.messages[type] = m
        self._timestamp = m._timestamp

        if self._flightmode_index < len(self._flightmodes):
            (mode, tstamp, t2) = self._flightmodes[self._flightmode_index]
            if m._timestamp >= tstamp:
                self.flightmode = mode
                self._flightmode_index += 1

        self.check_param(m)
        return m
1018463
def sr(self, multi=0):
        """"""  # noqa: E501
        remain = self.res[:]
        sr = []
        i = 0
        while i < len(remain):
            s = remain[i]
            j = i
            while j < len(remain) - 1:
                j += 1
                r = remain[j]
                if r.answers(s):
                    sr.append((s, r))
                    if multi:
                        remain[i]._answered = 1
                        remain[j]._answered = 2
                        continue
                    del(remain[j])
                    del(remain[i])
                    i -= 1
                    break
            i += 1
        if multi:
            remain = [x for x in remain if not hasattr(x, "_answered")]
        return SndRcvList(sr), PacketList(remain)
827296
private int getUnSeenMessageCount() 
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc,"getUnseenMessageCount");
      
      int remain = 0;
      for (int x = nextIndex; x < messages.length; x++)
      {
         if (messages[x] != null) remain++;
      }
      
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc,"getUnseenMessageCount", ""+remain);
      return remain;
   }
336082
def calculate_content_length(self):
        """"""
        try:
            self._ensure_sequence()
        except RuntimeError:
            return None
        return sum(len(x) for x in self.iter_encoded())
136716
def get_num_words_with_entropy(bits_of_entropy, wordlist):
    
    entropy_per_word = math.log(len(wordlist))/math.log(2)
    num_words = int(math.ceil(bits_of_entropy/entropy_per_word))
    return num_words
16233
def getNumPhones(isleDict, word, maxFlag):
    '''
    
    '''
    phoneCount = 0
    syllableCount = 0
    
    syllableCountList = []
    phoneCountList = []
    
    wordList = isleDict.lookup(word)
    entryList = zip(*wordList)
    
    for lookupResultList in entryList:
        syllableList = []
        for wordSyllableList in lookupResultList:
            syllableList.extend(wordSyllableList)
        
        syllableCountList.append(len(syllableList))
        phoneCountList.append(len([phon for phoneList in syllableList for
                                   phon in phoneList]))
    
    # The average number of phones for all possible pronunciations
    #    of this word
    if maxFlag is True:
        syllableCount += max(syllableCountList)
        phoneCount += max(phoneCountList)
    else:
        syllableCount += (sum(syllableCountList) /
                          float(len(syllableCountList)))
        phoneCount += sum(phoneCountList) / float(len(phoneCountList))
    
    return syllableCount, phoneCount
348216
function mpn_unpack(n) {
	var k = n.length, words = new Uint32Array(Math.floor(k * 31 / 32)), l, lr = 0, w = 0, wr = 32;
	for (var i = 0, j = 0;;) {
		if (lr == 0) {
			if (i >= k) {
				if (w != 0) {
					words[words.length - ++j] = w >>> wr;
				}
				return words;
			}
			l = n[i++], lr = 31;
		}
		var s = Math.min(lr, wr);
		w = w >>> s | (l & (1 << s) - 1) << 32 - s, l >>>= s;
		if ((wr -= s) == 0) {
			words[words.length - ++j] = w;
			w = 0, wr = 32;
		}
		lr -= s;
	}
}
260226
def untrain_token(self, word, count):
        
        if word not in self.tokens:
            return

        # If we're trying to untrain more tokens than we have, we end at 0
        count = min(count, self.tokens[word])

        self.tokens[word] -= count
        self.tally -= count
1344433
def _receive(self, sock, count):
        

        buf = b''

        while len(buf) < count:
            chunk = sock.recv(count - len(buf))
            if not chunk:
                break
            buf += chunk

        return buf
1107395
def _compute_frequencies(self, word_sent):
    
    freq = defaultdict(int)
    for s in word_sent:
      for word in s:
        if word not in self._stopwords:
          freq[word] += 1
    # frequencies normalization and fitering
    m = float(max(freq.values()))
    for w in freq.keys():
      freq[w] = freq[w]/m
      if freq[w] >= self._max_cut or freq[w] <= self._min_cut:
        del freq[w]
    return freq
589088
def packet_read(self):
        """"""
        bytes_received = 0
        
        if self.sock == NC.INVALID_SOCKET:
            return NC.ERR_NO_CONN
        
        if self.in_packet.command == 0:
            ba_data, errnum, errmsg = nyamuk_net.read(self.sock, 1)
            if errnum == 0 and len(ba_data) == 1:
                bytes_received += 1
                byte = ba_data[0]
                self.in_packet.command = byte
                
                if self.as_broker:
                    if self.bridge is None and self.state == NC.CS_NEW and (byte & 0xF0) != NC.CMD_CONNECT:
                        print "RETURN ERR_PROTOCOL"
                        return NC.ERR_PROTOCOL, bytes_received
            else:
                if errnum == errno.EAGAIN or errnum == errno.EWOULDBLOCK:
                    return NC.ERR_SUCCESS, bytes_received
                elif errnum == 0 and len(ba_data) == 0 or errnum == errno.ECONNRESET:
                    return NC.ERR_CONN_LOST, bytes_received
                else:
                    evt = event.EventNeterr(errnum, errmsg)
                    self.push_event(evt)
                    return NC.ERR_UNKNOWN, bytes_received
        
        if not self.in_packet.have_remaining:
            loop_flag = True
            while loop_flag:
                ba_data, errnum, errmsg = nyamuk_net.read(self.sock, 1)
                
                if errnum == 0 and len(ba_data) == 1:       
                    byte = ba_data[0]
                    bytes_received += 1
                    self.in_packet.remaining_count += 1
                    if self.in_packet.remaining_count > 4:
                        return NC.ERR_PROTOCOL, bytes_received
                    
                    self.in_packet.remaining_length += (byte & 127) * self.in_packet.remaining_mult
                    self.in_packet.remaining_mult *= 128
                else:
                    if errnum == errno.EAGAIN or errnum == errno.EWOULDBLOCK:
                        return NC.ERR_SUCCESS, bytes_received
                    elif errnum == 0 and len(ba_data) == 0 or errnum == errno.ECONNRESET:
                        return NC.ERR_CONN_LOST, bytes_received
                    else:
                        evt = event.EventNeterr(errnum, errmsg)
                        self.push_event(evt)
                        return NC.ERR_UNKNOWN, bytes_received
                
                if (byte & 128) == 0:
                    loop_flag = False
            
            if self.in_packet.remaining_length > 0:
                self.in_packet.payload = bytearray(self.in_packet.remaining_length)
                if self.in_packet.payload is None:
                    return NC.ERR_NO_MEM, bytes_received
                self.in_packet.to_process = self.in_packet.remaining_length
            
            self.in_packet.have_remaining = True
        
        if self.in_packet.to_process > 0:
            ba_data, errnum, errmsg = nyamuk_net.read(self.sock, self.in_packet.to_process)
            if errnum == 0 and len(ba_data) > 0:
                readlen = len(ba_data)
                bytes_received += readlen
                for idx in xrange(0, readlen):
                    self.in_packet.payload[self.in_packet.pos] = ba_data[idx]
                    self.in_packet.pos += 1
                    self.in_packet.to_process -= 1
            else:
                if errnum == errno.EAGAIN or errnum == errno.EWOULDBLOCK:
                        return NC.ERR_SUCCESS, bytes_received
                elif errnum == 0 and len(ba_data) == 0 or errnum == errno.ECONNRESET:
                    return NC.ERR_CONN_LOST, bytes_received
                else:
                    evt = event.EventNeterr(errnum, errmsg)
                    self.push_event(evt)
                    return NC.ERR_UNKNOWN, bytes_received

        #all data for this packet is read
        self.in_packet.pos = 0
        
        ret = self.packet_handle()
        
        self.in_packet.packet_cleanup()
        
        self.last_msg_in = time.time()
        
        return ret, bytes_received
663334
function wordCount(data) {
	var pattern = /[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
	var m = data.match(pattern);
	var count = 0;
	if(m === null) return count;
	for(var i = 0; i < m.length; i++) {
		if(m[i].charCodeAt(0) >= 0x4E00) {
			count += m[i].length;
		} else {
			count += 1;
		}
	}
	return count;
}
587417
def next (self):
        
        header, packet = self.read()

        if packet is None:
            raise StopIteration

        return header, packet
44299
def packet_lengths=(len)
      ptr = @ptr + Call::Transfer.size
      num_packets.times do
        ptr.write_uint(len)
        ptr += Call::IsoPacketDescriptor.size
      end
    end
1050705
def __pack_message(operation, data):
    
    rid = _randint()
    message = _pack_header(16 + len(data), rid, 0, operation)
    return rid, message + data