#!/usr/bin/env python
# -*- coding: utf-8 -*-
myconf_xml = """<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE myconfig>
<config>
<list name="TrafficRules_v2" identityCounter="777">
<listitem>
<variable name="Id">1</variable>
<variable name="Order">509</variable>
<variable name="Enabled">1</variable>
<variable name="Color">FFCCCC</variable>
<variable name="Name">VPN Services</variable>
<variable name="Description">Allows access to VPN</variable>
<variable name="IpVersion">4</variable>
<variable name="Dst">Firewall</variable>
<variable name="Proxy">default</variable>
<variable name="Service">"IPsec services" "Kerio VPN" </variable>
<variable name="ValidTime"></variable>
<variable name="Action">PERMIT,logpkt,logconn</variable>
<variable name="NAT">4</variable>
<variable name="SNAT"></variable>
<variable name="DNAT"></variable>
</listitem>
<listitem>
<variable name="Id">2</variable>
<variable name="Order">510</variable>
<variable name="Enabled">1</variable>
<variable name="Color">FFCCCC</variable>
<variable name="Name">Web Services</variable>
<variable name="Description">Allows access to HTTP and HTTPS from the Internet.</variable>
<variable name="IpVersion">4</variable>
<variable name="Dst">Firewall</variable>
<variable name="Proxy">default</variable>
<variable name="Service">"HTTP" "HTTPS" </variable>
<variable name="ValidTime"></variable>
<variable name="Action">PERMIT,chart,logconn</variable>
<variable name="NAT">4</variable>
<variable name="SNAT"></variable>
<variable name="DNAT"></variable>
</listitem>
<listitem>
<variable name="Id">3</variable>
<variable name="Order">511</variable>
<variable name="Enabled">1</variable>
<variable name="Color">C9EEC6</variable>
<variable name="Name">VPN Internet access (NAT)</variable>
<variable name="Description">Enables access from local machines and VPN clients to the Internet using address translation.</variable>
<variable name="IpVersion">4</variable>
<variable name="Src">user:"6sada6d9-bc8e-0b4e-dsdx-sdsadqwd97"</variable>
<variable name="Dst">ifgroup:"internet"</variable>
<variable name="Proxy">default</variable>
<variable name="Service"></variable>
<variable name="ValidTime"></variable>
<variable name="Action">PERMIT,chart,logconn</variable>
<variable name="NAT">4</variable>
<variable name="SNAT">auto</variable>
<variable name="DNAT"></variable>
</listitem>
<listitem>
<variable name="Id">3807</variable>
<variable name="Order">6</variable>
<variable name="Enabled">1</variable>
<variable name="Color">FFFFFF</variable>
<variable name="Name">Avay-IN</variable>
<variable name="Description"></variable>
<variable name="IpVersion">0</variable>
<variable name="Src">prefix:"172.1.1.0/23"</variable>
<variable name="Src">prefix:"192.1.1.0/23"</variable>
<variable name="Src">prefix:"192.1.1.0/24"</variable>
<variable name="Src">prefix:"172.1.1.0/24"</variable>
<variable name="Dst">10.101.10.10</variable>
<variable name="Proxy">default</variable>
<variable name="Service"></variable>
<variable name="ValidTime"></variable>
<variable name="Action">PERMIT</variable>
<variable name="NAT">4</variable>
<variable name="SNAT"></variable>
<variable name="DNAT"></variable>
</listitem>
<listitem>
<variable name="Id">3808</variable>
<variable name="Order">5</variable>
<variable name="Enabled">1</variable>
<variable name="Color">FFFFFF</variable>
<variable name="Name">media-NET-to-PC-IN</variable>
<variable name="Description"></variable>
<variable name="IpVersion">0</variable>
<variable name="Src">prefix:"192.168.1.0/24"</variable>
<variable name="Dst">192.168.120.25</variable>
<variable name="Proxy">default</variable>
<variable name="Service">tcp:3389 </variable>
<variable name="ValidTime"></variable>
<variable name="Action">PERMIT</variable>
<variable name="NAT">4</variable>
<variable name="SNAT"></variable>
<variable name="DNAT"></variable>
</listitem>
</list>
</config>"""
myconf_sceme = """
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="config" type="configType"/>
<xs:complexType name="variableType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="listitemType">
<xs:sequence>
<xs:element type="variableType" name="variable" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="listType">
<xs:sequence>
<xs:element type="listitemType" name="listitem" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:short" name="identityCounter"/>
</xs:complexType>
<xs:complexType name="configType">
<xs:sequence>
<xs:element type="listType" name="list"/>
</xs:sequence>
</xs:complexType>
</xs:schema>"""
# =================================================== #
import xmlschema
from pprint import pprint
my_schema = xmlschema.XMLSchema(myconf_sceme)
print(my_schema.is_valid(myconf_xml))
# загоняем в словарь
myconf_dict = my_schema.to_dict(myconf_xml)
pprint(myconf_dict)
# дальше манипулируем словарем
print('количество суб-объектов listitem', end=' ')
print(len(myconf_dict['list']['listitem']))
for l in myconf_dict['list']['listitem']:
print('----------------')
print('\nколичество суб-объектов variable', end=' ')
pprint(len(l['variable']))
print('\n')
pprint(l['variable'])
# таже можно раскидать в таблицу или куда хочешь
import csv
with open('input_data.csv', newline='') as f:
csvread = csv.reader(f)
batch_data = list(csvread)
import ast
import pprint
inpt = { 'data[PARAMS][CHAT_ENTITY_DATA_1]' : '...' ,
'data[PARAMS][CHAT_ENTITY_DATA_2]' : '...' ,
'data[PARAMS][CHAT_ENTITY_DATA_3]' : '...' }
results = {'data':{'PARAMS':{}}}
for k, v in inpt.items():
# print(k,v)
# корячим входную строку как нам нужно:
r_str = "{'" + k.replace("[","':{'").replace("]","") + "':'" + v + "'}}}"
print('строка ', r_str)
print(type(r_str))
# с помощью eval превращаем строку в словарь:
r = ast.literal_eval(r_str)
print('словарь ', r_str)
print(type(r))
results['data']['PARAMS'].update(r['data']['PARAMS'])
print('\nрезультат')
pprint.pprint( results)
Вот я залил цветом одну грань
vips composite2 cramps.png dice2.png x.png over
Выложите ваши примеры картинок если хотите более подробно
OpenGL: