Best Python code snippet using slash
simple_dict2xml.py
Source:simple_dict2xml.py
...106 except:107 log.fatal(u'ÐÑибка опÑÐµÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð°ÑÑибÑÑов XML Ñега <%s>' % name)108 attrs = dict()109 return name, attrs110 def _do_write(self, data, parent_tag=None, tag_filter=None):111 """112 ÐÑоÑедÑÑа запиÑи.113 @param data: ÐаннÑе Ð´Ð»Ñ Ð·Ð°Ð¿Ð¸Ñи.114 @param parent_tag: РодиÑелÑÑкий Ñег длÑ115 обÑабоÑки ÑпиÑков.116 @param tag_filter: СловаÑÑ ÑилÑÑÑа Ñегов,117 опÑеделÑÑÑий ÑпиÑок и поÑÑдок доÑеÑниÑ
Ñегов длÑ118 каждого Ñега.119 ÐоÑÑдок Ñегов важен Ð´Ð»Ñ XML, поÑÑÐ¾Ð¼Ñ Ð²Ð²ÐµÐ´ÐµÐ½ ÑÑÐ¾Ñ ÑилÑÑÑ.120 """121 if isinstance(data, dict):122 keys = data.keys()123 if parent_tag and tag_filter:124 keys = tag_filter.get(parent_tag, keys)125 for key in keys:126 if key not in data:127 # ÐÑли Ð½ÐµÑ ÑакиÑ
даннÑÑ
,128 # Ñо и не вноÑиÑÑ Ð¸Ñ
в XML129 continue130 value = data[key]131 name, attrs = self.parse_key(key)132 if not data[key] or type(data[key]) not in (dict, list):133 self.startElement(name, attrs)134 self._do_write(value, name, tag_filter=tag_filter)135 self.endElement(name)136 else:137 self.startElementLevel(name, attrs)138 self._do_write(value, name, tag_filter=tag_filter)139 self.endElementLevel(name)140 elif isinstance(data, list):141 for item in data:142 self._do_write(item, parent_tag, tag_filter=tag_filter)143 else:144 self._my_write(data)145 def startWrite(self, data=None, tag_filter=None):146 """147 ÐаÑало запиÑи.148 @param data: ÐаннÑе Ð´Ð»Ñ Ð·Ð°Ð¿Ð¸Ñи.149 @param tag_filter: СловаÑÑ ÑилÑÑÑа Ñегов,150 опÑеделÑÑÑий ÑпиÑок и поÑÑдок доÑеÑниÑ
Ñегов длÑ151 каждого Ñега.152 ÐоÑÑдок Ñегов важен Ð´Ð»Ñ XML, поÑÑÐ¾Ð¼Ñ Ð²Ð²ÐµÐ´ÐµÐ½ ÑÑÐ¾Ñ ÑилÑÑÑ.153 """154 if data is None:155 data = self._data156 self._do_write(data, tag_filter=tag_filter)157def test():158 """159 ФÑнкÑÐ¸Ñ ÑеÑÑиÑованиÑ.160 """161 data = {'''ns:Documents Version="1.0"162xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"163xmlns:ns="http://fsrar.ru/WEGAIS/WB_DOC_SINGLE_01"164xmlns:c="http://fsrar.ru/WEGAIS/Common"165xmlns:oref="http://fsrar.ru/WEGAIS/ClientRef"166xmlns:pref="http://fsrar.ru/WEGAIS/ProductRef"167xmlns:wb="http://fsrar.ru/WEGAIS/TTNSingle"168''': {'Document': [{'Item': 'XXX'}, {'Item': '111'}, {'Item': '222'},]},169 }170 xml_file = None...
compat.py
Source:compat.py
...38else:39 from select import select40class BaseWaiter:41 def wakeup(self):42 self._do_write()43 def wait(self, timeout=None):44 if timeout is not None:45 ready, _, _ = select([self], [], [], timeout)46 else:47 ready = True48 if ready:49 self._do_read()50 return True51 else:52 return False53 def reading(self):54 return True55 def readable(self):56 self._do_read()57if sys.platform in ('win32', 'cygwin'):58 import socket59 class SockWaiter(BaseWaiter):60 def __init__(self, read_sock, write_sock):61 self.read_sock = read_sock62 self.write_sock = write_sock63 def _do_write(self):64 self.write_sock.send("\0")65 def _do_read(self):66 self.read_sock.recv(65536)67 def fileno(self):68 return self.read_sock.fileno()69 def close(self):70 if self.write_sock is not None:71 self.write_sock.close()72 self.write_sock = None73 self.read_sock.close()74 self.read_sock = None75 def __del__(self):76 self.close()77 def __repr__(self):78 return "SockWaiter(%r, %r)" % (self.read_sock, self.write_sock)79 def selectable_waiter():80 listener = socket.socket()81 listener.bind(('', 0))82 listener.listen(1)83 _, port = listener.getsockname()84 write_sock = socket.socket()85 write_sock.connect(("127.0.0.1", port))86 read_sock, _ = listener.accept()87 listener.close()88 return SockWaiter(read_sock, write_sock)89else:90 import os91 class PipeWaiter(BaseWaiter):92 def __init__(self):93 self.read_fd, self.write_fd = os.pipe()94 def _do_write(self):95 os.write(self.write_fd, "\0")96 def _do_read(self):97 os.read(self.read_fd, 65536)98 def fileno(self):99 return self.read_fd100 def close(self):101 if self.write_fd is not None:102 os.close(self.write_fd)103 self.write_fd = None104 os.close(self.read_fd)105 self.read_fd = None106 def __del__(self):107 self.close()108 def __repr__(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!