def set_property(self, name, value, type=None, format=None): """ name: String Atom name type: String Atom name format: 8, 16, 32 """ if name in PropertyMap: if type or format: raise ValueError, "Over-riding default type or format for property." type, format = PropertyMap[name] else: if None in (type, format): raise ValueError, "Must specify type and format for unknown property." if not utils.isSequenceLike(value): value = [value] buf = [] for i in value: # We'll expand these conversions as we need them if format == 32: buf.append(utils.multichar(i, 4)) elif format == 16: buf.append(utils.multichar(i, 2)) elif format == 8: if utils.isStringLike(i): # FIXME: Unicode -> bytes conversion needed here buf.append(i) else: buf.append(utils.multichar(i, 1)) buf = "".join(buf) length = len(buf)/(format/8) # This is a real balls-up interface-wise. As I understand it, each type # can have a different associated size. # - value is a string of bytes. # - length is the length of the data in terms of the specified format. self.conn.conn.core.ChangeProperty( xcb.xproto.PropMode.Replace, self.wid, self.conn.atoms[name], self.conn.atoms[type], format, # Format - 8, 16, 32 length, buf )
def _bytes(self): """ Converts a standard IPv6 address to 16 bytes. """ abbr = self.address.count("::") if self.address.find("::") > -1: if (self.address.count("::") > 1): s = "Mal-formed IPv6 address: only one :: abbreviation allowed." raise ValueError(s) first, second = self.address.split("::") first = getBlocks(first) second = getBlocks(second) padlen = 8 - len(first) - len(second) nums = first + [0] * padlen + second else: nums = getBlocks(self.address) if len(nums) != 8: raise ValueError, "Mal-formed IPv6 address." return "".join([utils.multichar(i, 2) for i in nums])
def _bytes(self): """ Converts a standard IPv6 address to 16 bytes. """ abbr = self.address.count("::") if self.address.find("::") > -1: if (self.address.count("::") > 1): s = "Mal-formed IPv6 address: only one :: abbreviation allowed." raise ValueError(s) first, second = self.address.split("::") first = getBlocks(first) second = getBlocks(second) padlen = 8 - len(first) - len(second) nums = first + [0]*padlen + second else: nums = getBlocks(self.address) if len(nums) != 8: raise ValueError, "Mal-formed IPv6 address." return "".join([utils.multichar(i, 2) for i in nums])
def fromInteger(klass, i): bytes = utils.multichar(i, klass.WIDTH) return klass.fromBytes(bytes)