How to use _do_write method in Slash

Best Python code snippet using slash

simple_dict2xml.py

Source:simple_dict2xml.py Github

copy

Full Screen

...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...

Full Screen

Full Screen

compat.py

Source:compat.py Github

copy

Full Screen

...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):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful