def getheader(im, info=None):
    """Return a list of strings representing a GIF header"""

    optimize = info and info.get("optimize", 0)

    s = [
        "GIF87a"
        + o16(im.size[0])  # magic
        + o16(im.size[1])  # size
        + chr(7 + 128)
        + chr(0)  # flags: bits + palette
        + chr(0)  # background  # reserved/aspect
    ]

    if optimize:
        # minimize color palette
        i = 0
        maxcolor = 0
        for count in im.histogram():
            if count:
                maxcolor = i
            i = i + 1
    else:
        maxcolor = 256

    # global palette
    if im.mode == "P":
        # colour palette
        s.append(im.im.getpalette("RGB")[: maxcolor * 3])
    else:
        # greyscale
        for i in range(maxcolor):
            s.append(chr(i) * 3)

    return s
Example #2
0
  def __decrypt_file(self, private_d, public_n, keys, path_to_file, CRT, k):
    if CRT:
      pool = Pool(processes = k)
      promises = []
    decrpted_data = ''
    with open(path_to_file, 'r') as f:
      encrypted_data = f.read()
      encrypted_data_chunks = list(map(''.join, zip(*[iter(encrypted_data)]*len(str(public_n)))))
      for i in range(len(encrypted_data_chunks)):
        stripped = encrypted_data_chunks[i].lstrip('0')
        if CRT:
          promise = pool.apply_async(self.compute_part_of_message, args=(stripped, keys, i))
          promises.append(promise)
        else:
          decrpted_data += chr(self.__decrypt_message(stripped, private_d, public_n))
    if CRT:
      results = [promise.get() for promise in promises]
      decrypted_sorted = sorted(results, key = lambda x: x[1])
      for data in decrypted_sorted:
        decrpted_data += chr(data[0])

    if CRT:
      pool.close()
    with open(path_to_file + '.dec', 'w') as f:
      f.write(decrpted_data)
    return decrpted_data
Example #3
0
    def populate(self):
        self._textures = []
        fname = self.filename
        if __debug__:
            Logger.trace('Image: %r, populate to textures (%d)' %
                         (fname, len(self._data)))

        for count in range(len(self._data)):

            # first, check if a texture with the same name already exist in the
            # cache
            chr = type(fname)
            uid = chr(u'%s|%d|%d') % (fname, self._mipmap, count)
            texture = Cache.get('kv.texture', uid)

            # if not create it and append to the cache
            if texture is None:
                imagedata = self._data[count]
                source = '{}{}|'.format(
                    'zip|' if fname.endswith('.zip') else '',
                    self._nocache)
                imagedata.source = chr(source) + uid
                texture = Texture.create_from_data(
                    imagedata, mipmap=self._mipmap)
                if not self._nocache:
                    Cache.append('kv.texture', uid, texture)
                if imagedata.flip_vertical:
                    texture.flip_vertical()

            # set as our current texture
            self._textures.append(texture)

            # release data if ask
            if not self.keep_data:
                self._data[count].release_data()
Example #4
0
	def createPositionerSetup(self, list):
		nim = self.nimConfig
		list.append(getConfigListEntry(_("Longitude"), nim.longitude))
		list.append(getConfigListEntry(" ", nim.longitudeOrientation))
		list.append(getConfigListEntry(_("Latitude"), nim.latitude))
		list.append(getConfigListEntry(" ", nim.latitudeOrientation))
		if SystemInfo["CanMeasureFrontendInputPower"]:
			self.advancedPowerMeasurement = getConfigListEntry(_("Use power measurement"), nim.powerMeasurement)
			list.append(self.advancedPowerMeasurement)
			if nim.powerMeasurement.value:
				list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
				self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
				list.append(self.turningSpeed)
				if nim.turningSpeed.value == "fast epoch":
					self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
					self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
					list.append(self.turnFastEpochBegin)
					list.append(self.turnFastEpochEnd)
		else:
			if nim.powerMeasurement.value:
				nim.powerMeasurement.value = False
				nim.powerMeasurement.save()
		if not hasattr(self, 'additionalMotorOptions'):
			self.additionalMotorOptions = ConfigYesNo(False)
		self.showAdditionalMotorOptions = getConfigListEntry(_("Extra motor options"), self.additionalMotorOptions)
		self.list.append(self.showAdditionalMotorOptions)
		if self.additionalMotorOptions.value:
			self.list.append(getConfigListEntry("   " + _("Horizontal turning speed") + " [" + chr(176) + "/sec]", nim.turningspeedH))
			self.list.append(getConfigListEntry("   " + _("Vertical turning speed") + " [" + chr(176) + "/sec]", nim.turningspeedV))
			self.list.append(getConfigListEntry("   " + _("Turning step size") + " [" + chr(176) + "]", nim.tuningstepsize))
			self.list.append(getConfigListEntry("   " + _("Max memory positions"), nim.rotorPositions))
Example #5
0
 def report_data(self):
     """"""
     if self.report_mode == 0x30:
         payload = self.buttons_pack()
     elif self.report_mode == 0x31:
         payload = self.buttons_pack() + self.accel_pack()
     elif self.report_mode == 0x32:
         payload = self.buttons_pack() + self.ext8_pack()
     elif self.report_mode == 0x33:
         payload = self.buttons_pack() + self.accel_pack() + self.ir12_pack()
     elif self.report_mode == 0x34:
         payload = self.buttons_pack() + self.ext19_pack()
     elif self.report_mode == 0x35:
         payload = self.buttons_pack() + self.accel_pack() + self.ext16_pack()
     elif self.report_mode == 0x36:
         payload = self.buttons_pack() + self.ir10_pack() + self.ext9_pack()
     elif self.report_mode == 0x37:
         payload = self.buttons_pack() + self.accel_pack() + self.ir10_pack() + self.ext6_pack()
     elif self.report_mode == 0x3d:
         payload = self.ext21_pack()
     elif self.report_mode == 0x3e or self.report_mode == 0x3f:
         print(("*** TODO: report_mode " + hex(self.report_mode)))
     else:
         print(("*** Unhandled report mode: " + self.report_mode))
         return 0
     return chr(0xA1) + chr(self.report_mode) + payload
Example #6
0
  def sendPixel(self,r,g,b):
    """Sends the next pixel data triplet in RGB format.
    
    Values are clamped to 0-254 automatically.

    Throws a RuntimeException if [ledCount] pixels are already set
    
    """
    data = ""
    if r < 0: r = 0
    if g < 0: g = 0
    if b < 0: b = 0
    if r >= 255: r = 254
    if g >= 255: g = 254
    if b >= 255: b = 254
    data = chr(r) + chr(g) + chr(b)
    if self.position < self.ledCount:
      if self.buffered:
        self.buf += data
      else:
        self.serial.write(data)
        self.serial.flush()
      self.position += 1
    else:
      raise RuntimeError("Attempting to set pixel outside range!")
Example #7
0
	def packed_attributes (self,addpath):
		if not self.nlris:
			return

		mpnlri = {}
		for nlri in self.nlris:
			if nlri.nexthop:
				# .packed and not .pack()
				# we do not want a next_hop attribute packed (with the _attribute()) but just the next_hop itself
				if nlri.safi.has_rd():
					nexthop = chr(0)*8 + nlri.nexthop.packed
				else:
					nexthop = nlri.nexthop.packed
			else:
				# EOR fo not and Flow may not have any next_hop
				nexthop = ''

			# mpunli[afi,safi][nexthop] = nlri
			mpnlri.setdefault((nlri.afi.pack(),nlri.safi.pack()),{}).setdefault(nexthop,[]).append(nlri.pack(addpath))

		for (pafi,psafi),data in mpnlri.iteritems():
			for nexthop,nlris in data.iteritems():
				yield self._attribute(
					pafi + psafi +
					chr(len(nexthop)) + nexthop +
					chr(0) + ''.join(nlris)
				)
Example #8
0
def decode_1033(pkt):
    # Don't really care about any of this stuff at this stage..
    des = ''
    sno = ''
    rec = ''
    ver = ''
    rsn = ''

    stat_id = pkt.read(12).uint

    n = pkt.read(8).uint
    for i in range(n):
        des = des + chr(pkt.read(8).uint)

    setup = pkt.read(8).uint

    n = pkt.read(8).uint
    for i in range(n):
        sno = sno + chr(pkt.read(8).uint)

    n = pkt.read(8).uint
    for i in range(n):
        rec = rec + chr(pkt.read(8).uint)

    n = pkt.read(8).uint
    for i in range(n):
        ver = ver + chr(pkt.read(8).uint)

    n = pkt.read(8).uint
    for i in range(n):
        rsn = rsn + chr(pkt.read(8).uint)
def check_inclusion_via_rfc_algorithm(hash, leaf_index, audit_path, tree_size, root_hash):
    # 1.  Set "fn" to "leaf_index" and "sn" to "tree_size - 1".
    fn, sn = leaf_index, tree_size - 1

    # 2.  Set "r" to "hash".
    r = hash

    # 3.  For each value "p" in the "audit_path" array:
    for p in audit_path:
        #  If "LSB(fn)" is set, or if "fn" is equal to "sn", then:
        if lsb(fn) or (fn == sn):
            # 1.  Set "r" to "HASH(0x01 || p || r)"
            r = sha256(chr(1) + p + r).digest()

            # 2.  If "LSB(fn)" is not set, then right-shift both "fn" and "sn"
            #     equally until either "LSB(fn)" is set or "fn" is "fn".
            while not ((fn == 0) or lsb(fn)):
                fn >>= 1
                sn >>= 1
        # Otherwise:
        else:
            #    Set "r" to "HASH(0x01 || r || p)"
            r = sha256(chr(1) + r + p).digest()
        #   Finally, right-shift both "fn" and "sn" one time.
        fn >>= 1
        sn >>= 1

    # 4.  Compare "r" against the "root_hash".  If they are equal,
    #     then the log has proven the inclusion of "hash".
    return r == root_hash
Example #10
0
	def startKinect(self):
		""" demarrer le prog C++ de la Kinect """
		self.prog = os.startfile("C:\Users\Matthieu\Documents\MI12\Projet_test\Kinect_test\Release\Kinect_test.exe")
		time.sleep(2)
		self.shm = mmap.mmap(0, 512, "Local\\Test") #You should "open" the memory map file instead of attempting to create it..
		if self.shm:
			#self.self.shm.write(bytes("5", 'UTF-8'));
			#self.shm.write(bytes("Hello", 'UTF-8'))
			time.sleep(0.5)
			self.shm.write_byte(chr(1))
			self.shm.seek(1)
			print "wrote 1"
			b = chr(0)
			while ord(b) == 0:
				b = self.shm.read_byte()
				self.shm.seek(1)
				print "recieved ", ord(b)
				time.sleep(0.1)
			print "Kinect programme pret pour enregistrement"
			self.isKinectConnected = True
			if self.isAndroidConnected:
				self.button_start_recording.config(state="normal")

			# init de la com
			self.shm.seek(0)
			self.shm.write_byte(chr(0))	# isTracking => 0
			self.shm.write_byte(chr(0))	# isRecording => 0
Example #11
0
def mkwave(octave):
    global sinewave, nowave
    sinewave = ''
    for i in range(100):
        val = int(math.sin(math.pi * float(i) * octave / 50.0) * 30000)
        sinewave = sinewave + chr((val >> 8) & 255) + chr(val & 255)
    nowave = '\0' * 200
Example #12
0
    def hashNote(self,n):
        '''
        Encodes a note
        
        >>> hasher = omr.correctors.MeasureHash()

        >>> n = note.Note('C')
        >>> n.duration.type = 'quarter'
        >>> hasher.hashNote(n)
        'P'
        >>> n2 = note.Note('C')
        >>> n2.duration.type = 'half'
        >>> hasher.hashNote(n2)
        'Z'
        >>> n3 = note.Note('C', quarterLength=1.5)
        >>> hasher.hashNote(n3)
        'V'
        '''
        
        duration1to127 = self.hashQuarterLength(n.duration.quarterLength)
        if duration1to127%2==0 and duration1to127>0:
            byteEncoding = chr(duration1to127)
        elif duration1to127%2==1 and duration1to127>0:
            byteEncoding = chr(duration1to127+1)
        elif duration1to127 < 0:
            byteEncoding = chr(1)
        return byteEncoding
Example #13
0
    def new_playback_stream(self, path):
        stream = self.bus.get_object(object_path=str(path))
        property_list = stream.Get('org.PulseAudio.Core1.Stream', 'PropertyList', dbus_interface='org.freedesktop.DBus.Properties')
        pid = ''.join([chr(char) for char in dict(property_list)['application.process.id'][:-1]])
        binary = ''.join([chr(char) for char in dict(property_list)['application.process.binary'][:-1]])
        name = ''.join([chr(char) for char in dict(property_list)['application.name'][:-1]])
        volume = int(stream.Get('org.PulseAudio.Core1.Stream', 'Volume', dbus_interface='org.freedesktop.DBus.Properties')[0])
        mute = bool(stream.Get('org.PulseAudio.Core1.Stream', 'Mute', dbus_interface='org.freedesktop.DBus.Properties'))
        base_volume = int(self.sink0.Get('org.PulseAudio.Core1.Device', 'BaseVolume', dbus_interface='org.freedesktop.DBus.Properties'))

        print(json.dumps({
            'newStream': {
                'pid': pid,
                'path': str(path),
                'name': name,
                'binary': binary,
            }
        }))

        print(json.dumps({
            'streamVolume': {
                'path': str(path),
                'volume': volume,
                'max': base_volume
             }
        }))

        print(json.dumps({
            'streamMute': {
                'path': str(path),
                'mute': mute,
            }
        }))
Example #14
0
    def build_shellcode(self, s):
        i  = 0
        sc = list()

        while i < len(s):
            if s[i] == '"':
                i += 1
                continue

            if s[i] == '%':
                if (i + 6) <= len(s) and s[i + 1] == 'u':
                    currchar = int(s[i + 2: i + 4], 16)
                    nextchar = int(s[i + 4: i + 6], 16)
                    sc.append(chr(nextchar))
                    sc.append(chr(currchar))
                    i += 6
                elif (i + 3) <= len(s) and s[i + 1] == 'u':
                    currchar = int(s[i + 2: i + 4], 16)
                    sc.append(chr(currchar))
                    i += 3
                else:
                    sc.append(s[i])
                    i += 1
            else:
                sc.append(s[i])
                i += 1

        return ''.join(sc)
Example #15
0
def OidFromAttid(prefixTable, attr):
    # separate the ATTRTYP into two parts
    upperWord = attr / 65536
    lowerWord = attr % 65536

    # search in the prefix table to find the upperWord, if found,
    # construct the binary OID by appending lowerWord to the end of
    # found prefix.

    binaryOID = None
    for j, item in enumerate(prefixTable):
        if item["ndx"] == upperWord:
            binaryOID = item["prefix"]["elements"][: item["prefix"]["length"]]
            if lowerWord < 128:
                binaryOID.append(chr(lowerWord))
            else:
                if lowerWord >= 32768:
                    lowerWord -= 32768
                binaryOID.append(chr(((lowerWord / 128) % 128) + 128))
                binaryOID.append(chr(lowerWord % 128))
            break

    if binaryOID is None:
        return None

    return str(decoder.decode("\x06" + chr(len(binaryOID)) + "".join(binaryOID), asn1Spec=univ.ObjectIdentifier())[0])
def cross_check_consistency_against_opensource_algorithm(first, second, first_hash, second_hash, consistency):
    try:
        node = first - 1
        last_node = second - 1

        while node & 1:
            node >>= 1
            last_node >>= 1

        p = iter(consistency)
        if node:
            old_hash = p.next()
        else:  # old was 2 ** n
            old_hash = first_hash
        new_hash = old_hash

        while node:
            if node & 1:
                x = p.next()
                old_hash = sha256(chr(1) + x + old_hash).digest()
                new_hash = sha256(chr(1) + x + new_hash).digest()
            elif node < last_node:
                new_hash = sha256(chr(1) + new_hash + p.next()).digest()
            node >>= 1
            last_node >>= 1
        while last_node:
            new_hash = sha256(chr(1) + new_hash + p.next()).digest()
            last_node >>= 1

        for remaining in p:
            return False  # we shouldn't have any elements left over

        return old_hash == first_hash and new_hash == second_hash
    except StopIteration:
        return False  # ran out of elements
Example #17
0
 def performcheck(self, expected):
     line = ""
     char = ""
     while char != chr(62):  # '>'
         char = self.read(1)
         if char == "":
             raise Exception("No proper answer from MCU")
         if char == chr(13) or char == chr(10):  # LF or CR
             if line != "":
                 line = line.strip()
                 if line + "\r" == expected and self.verbose:
                     sys.stdout.write(" -> ok")
                 else:
                     if line[:4] == "lua:":
                         sys.stdout.write("\r\n\r\nLua ERROR: %s" % line)
                         raise Exception("ERROR from Lua interpreter\r\n\r\n")
                     else:
                         expected = expected.split("\r")[0]
                         sys.stdout.write("\r\n\r\nERROR")
                         sys.stdout.write("\r\n send string    : '%s'" % expected)
                         sys.stdout.write("\r\n expected echo  : '%s'" % expected)
                         sys.stdout.write("\r\n but got answer : '%s'" % line)
                         sys.stdout.write("\r\n\r\n")
                         raise Exception("Error sending data to MCU\r\n\r\n")
                 line = ""
         else:
             line += char
def cross_check_inclusion_via_opensource(hash, leaf_index, audit_path, tree_size, root_hash):
    audit_path = audit_path[:]

    node_index = leaf_index
    calculated_hash = hash
    last_node = tree_size - 1
    while last_node > 0:
        if not audit_path:
            return False

        if node_index % 2:
            audit_hash = audit_path.pop(0)
            calculated_hash = sha256(chr(1) + audit_hash + calculated_hash).digest()
        elif node_index < last_node:
            audit_hash = audit_path.pop(0)
            calculated_hash = sha256(chr(1) + calculated_hash + audit_hash).digest()
        # node_index == last_node and node_index is even: A sibling does
        # not exist. Go further up the tree until node_index is odd so
        # calculated_hash will be used as the right-hand operand.
        node_index //= 2
        last_node //= 2
    if audit_path:
        return False

    return calculated_hash == root_hash
Example #19
0
    def requestDataBlock(self, block):
        if self.packetCounter == 0xFF:
            self.packetCounter = 0
        else:
            self.packetCounter += 1

        self.ser.write("\x04")
        packet = self.ser.read(1)

        packet = self.ser.read(1)  # this is the 0x04 kompliment

        self.ser.write(chr(self.packetCounter))
        packet = self.ser.read(1)

        packet = self.ser.read(1)  # this is the kompliment of the self.packetCounter

        self.ser.write("\x29")  # this is the command for a grp reading
        packet = self.ser.read(1)

        packet = self.ser.read(1)  # this is the compliment of 0x29

        # now send the grp ID number --
        self.ser.write(chr(block))
        packet = self.ser.read(1)

        packet = self.ser.read(1)  # should be compliment - yet again

        self.ser.write("\x03")
        packet = self.ser.read(1)
Example #20
0
def main():
	phrases_map={}
	build_phrase_map(phrases_map)
	fPhrase=codecs.open("murphytalk_phrase.dat","wt","utf-8")
	fPhrase.write("MurphyTalk Phrase Table\nVer 0.03\n");

	fIndex=open("murphytalk_phrase_idx.txt","wt")
	fIndex.write("MurphyTalk Pinyin Phrase Index Table\nVer 0.03\n");

	
	keys=phrases_map.keys()
	
	freq=chr(0)+chr(0)+chr(0)+chr(0)
	keys.sort()
	for k in keys:
		fIndex.write(k);
		fIndex.write("\t%d\t"%len(phrases_map[k]));
		for phrase in phrases_map[k]:
			#record offset in phrase file into index file
			fIndex.write("%d "%fPhrase.tell())
			#write frequency into phrase file (uint32,4 bytes)
			#we don't use the codec but its underlying file stream here
			fPhrase.stream.write(freq)
			#write phrase text into phrase file
			fPhrase.write("%s "%phrase)
			
		fIndex.write("\n");

	fIndex.close()
	fPhrase.close()
Example #21
0
	def __init__(self, fp):

		self.palette = map(lambda i: chr(i)*3, range(256))

		if fp.readline()[:12] != "GIMP Palette":
			raise SyntaxError, "not a GIMP palette file"

		i = 0

		while i <= 255:

			s = fp.readline()

			if not s:
				break
			# skip fields and comment lines
			if re.match("\w+:|#", s):
				continue
			if len(s) > 100:
				raise SyntaxError, "bad palette file"

			v = tuple(map(int, string.split(s)[:3]))
			if len(v) != 3:
				raise ValueError, "bad palette entry"

			if 0 <= i <= 255:
				self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2])

			i = i + 1

		self.palette = string.join(self.palette, "")
def pack_ascii(text):
	i = 0
	retstr = ""

	while(i+4 <= len(text)):
		ret = [0,0,0]
		ret[0] = (ord(text[i]) << 2) & 252
		ret[0] = ret[0] | (((ord(text[i+1]) << 2) & 192) >> 6 )

		ret[1] = (ord(text[i+1]) << 4) & 240
		ret[1] = ret[1] | (((ord(text[i+2]) << 2) & 240) >> 4)
		
		ret[2] = ((ord(text[i+2]) << 6) & 192) | (ord(text[i+3]) & 0x3F)
	
		i = i + 4
		
		retstr = retstr + chr(ret[0]) + chr(ret[1]) + chr(ret[2])
		
	#if(i < len(text)):
	#	ret = ret + "\x00"
		
	while(i < len(text)):
		retstr = retstr + text[i]
		i = i + 1
		
	return retstr
Example #23
0
def random_password(bit=12):
    """
    generate a password randomly which include
    numbers, letters and sepcial characters
    """
    numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    small_letters = [chr(i) for i in range(97, 123)]
    cap_letters = [chr(i) for i in range(65, 91)]
    special = ['@', '#', '$', '%', '^', '&', '*', '-']

    passwd = []
    for i in range(bit/4):
        passwd.append(random.choice(numbers))
        passwd.append(random.choice(small_letters))
        passwd.append(random.choice(cap_letters))
        passwd.append(random.choice(special))
    for i in range(bit%4):
        passwd.append(random.choice(numbers))
        passwd.append(random.choice(small_letters))
        passwd.append(random.choice(cap_letters))
        passwd.append(random.choice(special))

    passwd = passwd[:bit]
    random.shuffle(passwd)

    return ''.join(passwd)
def compress(uncompressed):
    
 
    
    dict_size = 256
    dictionary = dict((chr(i), chr(i)) for i in xrange(dict_size))
  
 
    w = ""
    result = []
    for c in uncompressed:
        wc = w + c
        if wc in dictionary:
            w = wc
        else:
            result.append(dictionary[w])
            
            dictionary[wc] = dict_size
            dict_size += 1
            w = c
 
    
    if w:
        result.append(dictionary[w])
    return result
def main(stdscr):
    stdscr.addstr(0,2,"Curses example: h)left, l)right, q)uit")
    horzPosition = 19
    delta = 0
    while True:
		stdscr.refresh()
		stdscr.nodelay(1)
		while True:
			a_char_code = stdscr.getch()
			if a_char_code != -1:
				break
			stdscr.addstr(3,horzPosition," ")
			horzPosition += delta
			if horzPosition < 0:
				horzPosition = 0
			elif horzPosition > 39:
				horzPosition = 39
			stdscr.addstr(3,horzPosition,'@')
			stdscr.refresh()
			time.sleep(0.02)
		stdscr.nodelay(0)
		if chr(a_char_code) == "q":
			break
		elif chr(a_char_code) == "h":
			delta = -1
		elif chr(a_char_code) == "l":
			delta = +1
Example #26
0
	def __init__(self, simple = False ):
		#Denmark (incl. Faroe island and Greenland )	
		self.prefixes = ['OU', 'OV', 'OW', 'OX', 'OY', 'OZ', 'XP', '5P', '5Q']
		#Norway
		self.prefixes += ['JW', 'JX', 'LA', 'LN', 'LB', 'LC', 'LD', 'LE', 'LF', 'LG', 'LH', 'LI', 'LJ', 'LK', 'LL', 'LM', 'LN', '3Y']
		# Sweden
		self.prefixes += ['SA', 'SB', 'SC', 'SD', 'SE', 'SF', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', '7S', '8S']
		# Germany
		# DA - DR
		for l in range(ord('A'),ord('S')):
			tmp = ['D' + chr(l)]
			self.prefixes += tmp
		# GB et. al
		self.prefixes += 'G'
		for l in range(ord('A'),ord('Z')+1):
			tmp = ['2'+chr(l)]
			self.prefixes += tmp
		for l in range(ord('A'),ord('Z')+1):
			tmp = ['G'+chr(l)] + ['M' +chr( l ) ]
			self.prefixes += tmp
		self.prefixes += ['VP', 'VQ', 'VS']
		for l in range(ord('A'),ord('I')+1):
			tmp = ['P'+chr(l)]
			self.prefixes += tmp

		# Ireland ( is _not_ GB ;) )
		self.prefixes += [ 'EI', 'EJ']
		# Spain 
		self.prefixes += ['AM', 'AN', 'AO']
		for l in range(ord('A'),ord('H')+1):
			tmp = ['E'+chr(l)]
			self.prefixes += tmp
		# Switzerland ( and Liechtenstein )
		self.prefixes += ['HB', 'HE']
		# Poland 
		self.prefixes += ['3Z', 'HF']
		for l in range(ord('N'),ord('R')+1):
			tmp = ['S'+chr(l)]
			self.prefixes += tmp
		# France (better remember them or they will get mad )
		self.prefixes += ['F', 'FU', 'FV', 'HW', 'HX', 'HY', 'TH', 'TQ' ]
		for l in range(ord('V'),ord('X')+1):
			tmp = ['T'+chr(l)]
			self.prefixes += tmp
	
		# This is for Belgium
		for l in range(ord('N'),ord('T')+1):
			tmp = ['O'+chr(l)]
			self.prefixes += tmp

		# Chekoslovakia (yes I know they're two different countries )
		for l in range(ord('K'),ord('M')+1):
			tmp = ['O'+chr(l)]
			self.prefixes += tmp
		
		# Italy (I cant't figure out their system, so these are the ones that gets picked
		self.prefixes += ['I', 'IK','IA']

		if ( simple == True ):
			self.prefixes = ['OZ','LA','SM','G','GM', 'DA', 'DB', 'DC', 'DD','DJ','DK','OY', 'OX', 'F', 'I', 'HB', 'SP', 'EA', 'EI', 'ON', 'OK', 'OM']
Example #27
0
	def createPositionerSetup(self, list):
		nim = self.nimConfig
		list.append(getConfigListEntry(_("Longitude"), nim.longitude))
		list.append(getConfigListEntry(" ", nim.longitudeOrientation))
		list.append(getConfigListEntry(_("Latitude"), nim.latitude))
		list.append(getConfigListEntry(" ", nim.latitudeOrientation))
		if SystemInfo["CanMeasureFrontendInputPower"]:
			self.advancedPowerMeasurement = getConfigListEntry(_("Use power measurement"), nim.powerMeasurement)
			list.append(self.advancedPowerMeasurement)
			if nim.powerMeasurement.getValue():
				list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
				self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
				list.append(self.turningSpeed)
				if nim.turningSpeed.getValue() == "fast epoch":
					self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
					self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
					list.append(self.turnFastEpochBegin)
					list.append(self.turnFastEpochEnd)
		else:
			if nim.powerMeasurement.getValue():
				nim.powerMeasurement.setValue(False)
				nim.powerMeasurement.save()
		list.append(getConfigListEntry(_("Tuning step size") + " [" + chr(176) + "]", nim.tuningstepsize))
		list.append(getConfigListEntry(_("Memory positions"), nim.rotorPositions))
		list.append(getConfigListEntry(_("Horizontal turning speed") + " [" + chr(176) + "/sec]", nim.turningspeedH))
		list.append(getConfigListEntry(_("Vertical turning speed") + " [" + chr(176) + "/sec]", nim.turningspeedV))
Example #28
0
def zen_of_python():
    interactive()
    s = """Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

    d = {}
    for c in (65, 97):
        for i in range(26):
            d[chr(i+c)] = chr((i+13) % 26 + c)


    switch_to_buffer("*The Zen of Python*")
    insert("".join([d.get(c, c) for c in s]))
Example #29
0
def intlist_to_bytes(xs):
    if not xs:
        return b''
    if isinstance(chr(0), bytes):  # Python 2
        return ''.join([chr(x) for x in xs])
    else:
        return bytes(xs)
Example #30
0
def deentity(data,mode=0):
    """Remove HTML entities from a string.
    
    Modes:
    
    0: Fast / common entities only (default)
    1: Comprehensive (slow)
    2: Syntax-critical escapes only
    3: Whole-file mode (skip syntax-critical escapes)
    """
    # The level of overhead which results from inefficiencies in this function is phenomenal.
    # TODO: convert this entire function to do it properly or at least using a compiled regex.
    from html.entities import name2codepoint,codepoint2name
    #
    # 0: Fast, 1: Comprehensive, 2: Syntax-critical only, 3: Whole-file mode (skip syntax-critical)
    if mode==0:
        foci = ('lt', 'gt', 'quot', 'nbsp', 'lsquo', 'rsquo', 'ldquo', 'rdquo', 'ndash', 'hellip', 'eacute')
    elif mode in (1,3):
        foci = list(name2codepoint.keys())
    elif mode == 2:
        foci = ('lt', 'gt')
    for name in foci:
        if name != "amp":
            if (mode != 3) or (name not in ('lt', 'gt')):
                data = data.replace("&" + name + ";", chr(name2codepoint[name]))
    if mode in (0, 2):
        data = data.replace("&#39;", chr(39))
    elif mode in (1, ):#3):
        for number in range(0x100):
            name = "#"+str(number)
            data = data.replace("&" + name + ";", chr(number))
    if mode != 3:
        data = data.replace("&amp;", "&")
    return data