Пример #1
0
def load_encodings(doc):
  result = []
  for enc in doc.query["amqp/section/type/encoding",
                       lambda n: n.parent["@class"] == "primitive"]:
    type_name = pythonize(enc.parent["@name"])
    if enc["@name"]:
      enc_name = "%s_%s" % (type_name, pythonize(enc["@name"]))
    else:
      enc_name = type_name
    code = int(enc["@code"], 0)
    category = pythonize(enc["@category"])
    width = int(enc["@width"], 0)
    result.append(Encoding(enc_name, Primitive(type_name), code, category, width))
  return result
Пример #2
0
    def on_action_choice(self, e=None):
        '''
        Invoked when the "action" choice is changed. Controls under the choice
        need to be updated.'
        '''

        i = self.action_choice.GetSelection()
        if i == -1: return

        with self.Frozen():
            f = self.flex

            [
                c.Window.Destroy() for c in f.Children
                if c.Window not in (self.action_text, self.action_choice)
            ]

            self.action_ctrls.clear()

            f.Clear()  # does not Destroy child windows
            f.Add(self.action_text, 0, wx.EXPAND | wx.ALL, 10)
            f.Add(self.action_choice, 0, wx.EXPAND | wx.ALL, 10)

            # Call build_controls_XXX where XXX is the pythonized name of
            # the Reaction class (see notifications.py for possible
            # Reactions)
            name = pythonize(reactions[i].__name__)
            getattr(self, 'build_controls_%s' % name,
                    lambda s: None)(self.flex)

            self.Layout()
Пример #3
0
    def on_action_choice(self, e = None):
        '''
        Invoked when the "action" choice is changed. Controls under the choice
        need to be updated.'
        '''

        i = self.action_choice.GetSelection()
        if i == -1: return

        with self.Frozen():
            f = self.flex

            [c.Window.Destroy() for c in f.Children
             if c.Window not in (self.action_text, self.action_choice)]

            self.action_ctrls.clear()

            f.Clear() # does not Destroy child windows
            f.Add(self.action_text, 0, wx.EXPAND | wx.ALL, 10)
            f.Add(self.action_choice, 0, wx.EXPAND | wx.ALL, 10)

            # Call build_controls_XXX where XXX is the pythonized name of
            # the Reaction class (see notifications.py for possible
            # Reactions)
            name = pythonize(reactions[i].__name__)
            getattr(self, 'build_controls_%s' % name,
                    lambda s: None)(self.flex)

            self.Layout()
Пример #4
0
 def on_message(self, msg):
     """
     This function is called by MSNSockets when a new
     command is receieved
     """
     if self.log: self.log.log_s(1,"Got message: %r", str(msg)[:100].strip('\r\n'))
     mname = 'recv_%s' % pythonize(msg.cmd)
     getattr(self, mname, self.unknown_cmd)(msg)
Пример #5
0
def csd_to_storage(str):
    '''
    turn mime headers into a storage object
    '''
    info = csd_to_dict(str)
    for k in info.keys():
        info[util.pythonize(k)] = info.pop(k)

    return util.to_storage(info)
Пример #6
0
def csd_to_storage(str):
    '''
    turn mime headers into a storage object
    '''
    info = csd_to_dict(str)
    for k in info.keys():
        info[pythonize(k)] = info.pop(k)

    return to_storage(info)
Пример #7
0
def mime_to_storage(str):
    '''
    turn mime headers into a storage object
    '''
    info = mime_to_dict(str)
    for k in info.keys():
        info[pythonize(k)] = info[k]

    return to_storage(info)
Пример #8
0
    def complete_xml_element(self, xmlnode, doc):
        xmlnode.setProp("type", self.type) if self.type else None
        xmlnode.setProp("value", self.value) if self.value else None
        xmlnode.setProp("action", self.action)
        xmlnode.setProp("order", to_utf8(self.order))

        [xmlnode.newChild(None, child, None)
         for child in PRIVACY_TYPES
         if getattr(self, util.pythonize(child))]
Пример #9
0
    def complete_xml_element(self, xmlnode, doc):
        xmlnode.setProp("type", self.type) if self.type else None
        xmlnode.setProp("value", self.value) if self.value else None
        xmlnode.setProp("action", self.action)
        xmlnode.setProp("order", to_utf8(self.order))

        [
            xmlnode.newChild(None, child, None) for child in PRIVACY_TYPES
            if getattr(self, util.pythonize(child))
        ]
Пример #10
0
    def __from_xml(self, xmlnode):
        """Initialize ListItem from XML node."""
        if xmlnode.type != "element":
            raise ValueError, "XML node is not a list item (not en element)"
        ns = get_node_ns_uri(xmlnode)
        if ns and ns != PRIVACY_NS or xmlnode.name != "item":
            raise ValueError, "XML node is not a list item"

        [setattr(self, x, xmlnode.prop(x)) for x in PRIVACY_ATTRS]
        self.order = int(self.order) if self.order else 0

        n = xmlnode.children
        while n:
            if n.type != "element":
                n = n.next
                continue
            ns = get_node_ns_uri(n)
            if ns and ns != PRIVACY_NS or n.name not in PRIVACY_TYPES:
                n = n.next
                continue
            setattr(self, util.pythonize(n.name), True)
            n = n.next
Пример #11
0
    def __from_xml(self, xmlnode):
        """Initialize ListItem from XML node."""
        if xmlnode.type!="element":
            raise ValueError,"XML node is not a list item (not en element)"
        ns=get_node_ns_uri(xmlnode)
        if ns and ns!=PRIVACY_NS or xmlnode.name!="item":
            raise ValueError,"XML node is not a list item"

        [setattr(self, x, xmlnode.prop(x)) for x in PRIVACY_ATTRS]
        self.order = int(self.order) if self.order else 0

        n=xmlnode.children
        while n:
            if n.type!="element":
                n=n.next
                continue
            ns=get_node_ns_uri(n)
            if ns and ns!=PRIVACY_NS or n.name not in PRIVACY_TYPES:
                n=n.next
                continue
            setattr(self, util.pythonize(n.name), True)
            n=n.next
Пример #12
0
 def construct_map(cls, t, m):
   return cls(**dict([(pythonize(k.name), v) for (k, v) in m.iteritems()]))
Пример #13
0
def load_composite(types, **kwargs):
  sources = {"*": None}
  descriptors = {}
  composite = []
  for nd in types:
    name = nd["@name"]
    if nd["@source"]:
      sources[name] = nd["@source"]
    if nd["descriptor"]:
      sym = Symbol(str(nd["descriptor/@name"]))
      num = Value(Primitive("ulong"),
                  decode_numeric_desc(nd["descriptor/@code"]))
      descriptors[name] = (num, sym)
      composite.append(nd)

  result = []

  for nd in composite:
    archetypes = \
        [p.strip() for p in pythonize(nd["@provides"] or "").split(",")]
    cls_name = pythonize(nd["@name"], camel=True)
    if cls_name in kwargs:
      bases = kwargs[cls_name]
    else:
      bases = ()
      for arch in archetypes:
        b = kwargs.get(arch, ())
        if inspect.isclass(b):
          bases += (b,)
        else:
          bases += b
      if not bases:
        bases = kwargs.get(nd["@class"], ())
    if inspect.isclass(bases):
      bases = (bases,)

    dict = {}
    dict["NAME"] = pythonize(nd["@name"])
    dict["ARCHETYPES"] = archetypes
    dict["DESCRIPTORS"] = descriptors.get(nd["@name"])
    dict["SOURCE"] = Primitive(pythonize(resolve(nd["@source"], sources)))
    dict["TYPE"] = Described(dict["DESCRIPTORS"][0], dict["SOURCE"])
    encoded = []
    for f in nd.query["field"]:
      d = descriptors.get(f["@type"])
      ftype = pythonize(f["@type"])
      if ftype == "*":
        ftype = None
      else:
        ftype = Primitive(pythonize(resolve(f["@type"], sources)))
      if d:
        ftype = Described(d[0], ftype)
      encoded.append(Field(pythonize(f["@name"]),
                           Symbol(f["@name"]),
                           ftype,
                           f["@mandatory"] == "true",
                           f["@multiple"] == "true"))
    dict["ENCODED_FIELDS"] = encoded
    fields = encoded + \
        [f
         for b in bases
         for c in inspect.getmro(b) if c.__dict__.has_key("FIELDS")
         for f in c.FIELDS ]
    fieldnames = set([f.name for f in fields])
    assert len(fieldnames) == len(fields), "duplicate fields"
    dict["FIELDS"] = fields
    result.append(type(cls_name, bases, dict))

  return result
Пример #14
0
 def type(self):
     return pythonize(self.payload.get("Message-Type"))
Пример #15
0
 def recv_prp(self, msg):
     log.debug('got prp')
     type, val = msg.args
     type = pythonize(type)
     self.event('recv_prop', self._username, type, val)