Convert FrameGet[All]Node[s]InformationNotification into Node object.
502817
def convert_frame_to_node(pyvlx, frame):
    """"""
    # pylint: disable=too-many-return-statements
    if frame.node_type == NodeTypeWithSubtype.WINDOW_OPENER:
        return Window(pyvlx=pyvlx, node_id=frame.node_id, name=frame.name, rain_sensor=False)
    if frame.node_type == NodeTypeWithSubtype.WINDOW_OPENER_WITH_RAIN_SENSOR:
        return Window(pyvlx=pyvlx, node_id=frame.node_id, name=frame.name, rain_sensor=True)
    if frame.node_type == NodeTypeWithSubtype.ROLLER_SHUTTER or \
            frame.node_type == NodeTypeWithSubtype.DUAL_ROLLER_SHUTTER:
        return RollerShutter(pyvlx=pyvlx, node_id=frame.node_id, name=frame.name)
    if frame.node_type == NodeTypeWithSubtype.INTERIOR_VENETIAN_BLIND or \
            frame.node_type == NodeTypeWithSubtype.VERTICAL_INTERIOR_BLINDS or \
            frame.node_type == NodeTypeWithSubtype.EXTERIOR_VENETIAN_BLIND or \
            frame.node_type == NodeTypeWithSubtype.LOUVER_BLIND:
        return Blind(pyvlx=pyvlx, node_id=frame.node_id, name=frame.name)
    if frame.node_type == NodeTypeWithSubtype.VERTICAL_EXTERIOR_AWNING or \
            frame.node_type == NodeTypeWithSubtype.HORIZONTAL_AWNING:
        return Awning(pyvlx=pyvlx, node_id=frame.node_id, name=frame.name)
    if frame.node_type == NodeTypeWithSubtype.ON_OFF_SWITCH:
        return OnOffSwitch(pyvlx=pyvlx, node_id=frame.node_id, name=frame.name)

    PYVLXLOG.warning("%s not implemented", frame.node_type)
    return None
11616
def struct_to_xml(node, struct):
    
    for obj in struct:
        for k, v in obj.items():
            etree.SubElement(node, k).text = v
727780
def from_etree(
    el, node=None, node_cls=None,
    tagsub=functools.partial(re.sub, r'\{.+?\}', ''),
    Node=Node):
    '''
    '''
    node_cls = node_cls or Node
    if node is None:
        node = node_cls()
    tag = tagsub(el.tag)
    attrib = dict((tagsub(k), v) for (k, v) in el.attrib.items())
    node.update(attrib, tag=tag)

    if el.text:
        node['text'] = el.text
    for child in el:
        child = from_etree(child, node_cls=node_cls)
        node.append(child)
    if el.tail:
        node['tail'] = el.tail
    return node
840456
def from_payload(self, payload):
        """"""
        self.node_id = payload[0]
        self.order = payload[1] * 256 + payload[2]
        self.placement = payload[3]
        self.name = bytes_to_string(payload[4:68])
        self.velocity = Velocity(payload[68])
        self.node_type = NodeTypeWithSubtype(payload[69] * 256 + payload[70])
        self.product_group = payload[71]
        self.product_type = payload[72]
        self.node_variation = NodeVariation(payload[73])
        self.power_mode = payload[74]
        self.build_number = payload[75]
        self._serial_number = payload[76:84]
        self.state = payload[84]
        self.current_position = Parameter(payload[85:87])
        self.target = Parameter(payload[87:89])
        self.current_position_fp1 = Parameter(payload[89:91])
        self.current_position_fp2 = Parameter(payload[91:93])
        self.current_position_fp3 = Parameter(payload[93:95])
        self.current_position_fp4 = Parameter(payload[95:97])
        self.remaining_time = payload[97] * 256 + payload[98]
        self.timestamp = struct.unpack(">I", payload[99:103])[0]
        self.alias_array = AliasArray(payload[103:125])
776333
def from_payload(self, payload):
        """"""
        self.node_id = payload[0]
        self.name = bytes_to_string(payload[1:65])
        self.order = payload[65] * 256 + payload[66]
        self.placement = payload[67]
        self.node_variation = NodeVariation(payload[68])
229622
def frameify(self, state, data):
        """"""

        # Pull in any partially-processed data
        data = state.recv_buf + data

        # Loop over the data
        while data:
            frame, sep, rest = data.partition('\0')

            # Did we have a whole frame?
            if sep != '\0':
                break

            # OK, update the data...
            data = rest

            # Now, decode the frame and yield it
            try:
                yield self._decode(frame, self._tables[0])
            except FrameSwitch:
                break

        # Put any remaining data back into the buffer
        state.recv_buf = data
680199
def to_etree(self):
        
        nodes_attrib_val = ' '.join('//@nodes.{}'.format(node_id)
                                    for node_id in self.nodes)
        edges_attrib_val = ' '.join('//@edges.{}'.format(edge_id)
                                    for edge_id in self.edges)

        attribs = {
            '{{{pre}}}type'.format(pre=NAMESPACES['xsi']): self.xsi_type,
            'nodes': nodes_attrib_val, 'edges': edges_attrib_val}
        # a layer might have no nodes or edges attributed to it
        non_empty_attribs = {key: val for (key, val) in attribs.items()
                             if val is not None}

        E = ElementMaker()
        layer = E('layers', non_empty_attribs)
        label_elements = (label.to_etree() for label in self.labels)
        layer.extend(label_elements)
        return layer
271518
def to_naf(self):
        
        if self.type == 'KAF':
            self.type = 'NAF'
            for node in self.__get_wf_nodes():
                node.set('id',node.get('wid'))
                del node.attrib['wid']
1278105
def from_dict(cls, d):
        
        makepred, charspan = Pred.surface_or_abstract, Lnk.charspan
        top = d.get('top')
        nodes, edges = [], []
        for nid, node in d.get('nodes', {}).items():
            props = node.get('properties', {})
            if 'type' in node:
                props[CVARSORT] = node['type']
            if not props:
                props = None
            lnk = None
            if 'lnk' in node:
                lnk = charspan(node['lnk']['from'], node['lnk']['to'])
            nodes.append(
                Node(
                    nodeid=nid,
                    pred=makepred(node['label']),
                    sortinfo=props,
                    lnk=lnk,
                    carg=node.get('carg')
                )
            )
            edges.extend(
                (nid, rargname, tgtnid)
                for rargname, tgtnid in node.get('edges', {}).items()
            )
        nodes.sort(key=lambda n: (n.cfrom, -n.cto))
        return cls(top, nodes=nodes, edges=edges)
891346
def to_python(fname, *args):
    
    [node] = read(fname)
    return node_to_obj(node, fname, *args)
542537
def encode_notifications(tokens, notifications):
  
  
  fmt = "!BH32sH%ds"
  structify = lambda t, p: struct.pack(fmt % len(p), 0, 32, t, len(p), p)
  binaryify = lambda t: t.decode('hex')
  if type(notifications) is dict and type(tokens) in (str, unicode):
    tokens, notifications = ([tokens], [notifications])
  if type(notifications) is list and type(tokens) is list:
    return ''.join(map(lambda y: structify(*y), ((binaryify(t), json.dumps(p, separators=(',',':'), ensure_ascii=False).encode('utf-8'))
                                    for t, p in zip(tokens, notifications))))
681816
async def handle_frame(self, frame):
        """"""
        if isinstance(frame, FrameGetAllNodesInformationConfirmation):
            self.number_of_nodes = frame.number_of_nodes
            # We are still waiting for FrameGetAllNodesInformationNotification
            return False
        if isinstance(frame, FrameGetAllNodesInformationNotification):
            self.notification_frames.append(frame)
        if isinstance(frame, FrameGetAllNodesInformationFinishedNotification):
            if self.number_of_nodes != len(self.notification_frames):
                PYVLXLOG.warning("Number of received scenes does not match expected number")
            self.success = True
            return True
        return False
1211862
def _StructMessageToJsonObject(self, message):
    """"""
    fields = message.fields
    ret = {}
    for key in fields:
      ret[key] = self._ValueMessageToJsonObject(fields[key])
    return ret
1345330
def _readData(self, id3, data):
        """"""

        for reader in self._framespec:
            if len(data) or reader.handle_nodata:
                try:
                    value, data = reader.read(id3, self, data)
                except SpecError as e:
                    raise ID3JunkFrameError(e)
            else:
                raise ID3JunkFrameError("no data left")
            self._setattr(reader.name, value)

        for reader in self._optionalspec:
            if len(data) or reader.handle_nodata:
                try:
                    value, data = reader.read(id3, self, data)
                except SpecError as e:
                    raise ID3JunkFrameError(e)
            else:
                break
            self._setattr(reader.name, value)

        return data
575640
def node_from_nid(self, nid):
        """"""
        for node in self.iflat_nodes():
            if node.node_id == nid: return node
        raise ValueError("Cannot find node with node id: %s" % nid)
1111570
def to_pandas_nodes(G):  # noqa: N803
    
    data = []
    for n, meta in G.nodes(data=True):
        d = dict()
        d["node"] = n
        d.update(meta)
        data.append(d)
    return pd.DataFrame(data)
1090004
def _from_dict(cls, _dict):
        """"""
        args = {}
        xtra = _dict.copy()
        if 'log_messages' in _dict:
            args['log_messages'] = [
                LogMessage._from_dict(x) for x in (_dict.get('log_messages'))
            ]
            del xtra['log_messages']
        else:
            raise ValueError(
                'Required property \'log_messages\' not present in OutputData JSON'
            )
        if 'text' in _dict:
            args['text'] = _dict.get('text')
            del xtra['text']
        else:
            raise ValueError(
                'Required property \'text\' not present in OutputData JSON')
        if 'generic' in _dict:
            args['generic'] = [
                DialogRuntimeResponseGeneric._from_dict(x)
                for x in (_dict.get('generic'))
            ]
            del xtra['generic']
        if 'nodes_visited' in _dict:
            args['nodes_visited'] = _dict.get('nodes_visited')
            del xtra['nodes_visited']
        if 'nodes_visited_details' in _dict:
            args['nodes_visited_details'] = [
                DialogNodeVisitedDetails._from_dict(x)
                for x in (_dict.get('nodes_visited_details'))
            ]
            del xtra['nodes_visited_details']
        args.update(xtra)
        return cls(**args)