code stringlengths 1 18.2k |
|---|
this is a list, create a 'and_' around it (otherwise and_ will return the validation function without # wrapping it) main_validator = and_(*validation_func) return not_(main_validator, catch_all=catch_all) |
def failure_raiser(*validation_func, # type: ValidationFuncs **kwargs ): # type: (...) -> Callable """ This function is automatically used if you provide a tuple `(<function>, <msg>_or_<Failure_type>)`, to any of the methods in this page or to one of the `valid8` decorators. It transforms the provided `<function>` into... |
an exception) :param validation_func: the base validation function or list of base validation functions to use. A callable, a tuple(callable, help_msg_str), a tuple(callable, failure_type), or a list of several such elements. Nested lists are supported and indicate an implicit `and_` (such as the main list). Tuples ind... |
automatically. :param failure_type: a subclass of `WrappingFailure` that should be raised in case of failure :param help_msg: a string help message for the raised `WrappingFailure`. Optional (default = WrappingFailure with no help message). :param kw_context_args :return: """ failure_type, help_msg = pop_kwargs(kwargs,... |
failure_type=failure_type, help_msg=help_msg, **kw_context_args) |
def pop_kwargs(kwargs, names_with_defaults, # type: List[Tuple[str, Any]] allow_others=False ): """ Internal utility method to extract optional arguments from kwargs. :param kwargs: :param names_with_defaults: :param allow_others: if False (default) then an error will be raised if kwargs still contains something at the... |
allow_others and len(kwargs) > 0: raise ValueError("Unsupported arguments: %s" % kwargs) if len(names_with_defaults) == 1: return all_arguments[0] else: return all_arguments |
def get_details(self): """ Overrides the base method in order to give details on the various successes and failures """ # transform the dictionary of failures into a printable form need_to_print_value = True failures_for_print = OrderedDict() for validator, failure in self.failures.items(): name = get_callable_name(val... |
if need_to_print_value: value_str = ' for value [{val}]'.format(val=self.wrong_value) else: value_str = '' # OrderedDict does not pretty print... key_values_str = [repr(key) + ': ' + repr(val) for key, val in failures_for_print.items()] failures_for_print_str = '{' + ', '.join(key_values_str) + '}' # Note: we do note c... |
{success} / Failures: {fails}' \ ''.format(what=self.get_what(), possibly_value=value_str, success=self.successes, fails=failures_for_print_str) return msg |
def play_all_validators(self, validators, value): """ Utility method to play all the provided validators on the provided value and output the :param validators: :param value: :return: """ successes = list() failures = OrderedDict() for validator in validators: name = get_callable_name(validator) try: res = validator(va... |
def gen_secret(length=64): """ Generates a secret of given length """ charset = string.ascii_letters + string.digits return ''.join(random.SystemRandom().choice(charset) for _ in range(length)) |
def encryptfile(filename, passphrase, algo='srp'): """ Encrypt a file and write it with .cryptoshop extension. :param filename: a string with the path to the file to encrypt. :param passphrase: a string with the user passphrase. :param algo: a string with the algorithm. Can be srp, aes, twf. Default is srp. :return: a ... |
= b"Cryptoshop srp " + b_version crypto_algo = "Serpent/GCM" if algo == "aes": header = b"Cryptoshop aes " + b_version crypto_algo = "AES-256/GCM" if algo == "twf": header = b"Cryptoshop twf " + b_version crypto_algo = "Twofish/GCM" if algo != "srp" and algo != "aes" and algo != "twf": return "No valid algo. Use 'srp' ... |
= botan.rng().get(internal_key_length) # Passphrase derivation... salt = botan.rng().get(__salt_size__) masterkey = calc_derivation(passphrase=passphrase, salt=salt) # Encrypt internal key... encrypted_key = encry_decry_cascade(data=internal_key, masterkey=masterkey, bool_encry=True, assoc_data=header) with open(filena... |
process. It's files_size // chunk_size bar = tqdm(range(file_size // __chunk_size__)) while not finished: chunk = filestream.read(__chunk_size__) if len(chunk) == 0 or len(chunk) % __chunk_size__ != 0: finished = True # An encrypted-chunk output is nonce, gcmtag, and cipher-chunk concatenation. encryptedchunk = encry_d... |
def decryptfile(filename, passphrase): """ Decrypt a file and write corresponding decrypted file. We remove the .cryptoshop extension. :param filename: a string with the path to the file to decrypt. :param passphrase: a string with the user passphrase. :return: a string with "successfully decrypted" or error. """ try: ... |
= os.stat(filename).st_size if file_size == 0: raise Exception("Error: You can't decrypt empty file.") fileheader = filestream.read(header_length) if fileheader == b"Cryptoshop srp " + b_version: decrypt_algo = "Serpent/GCM" if fileheader == b"Cryptoshop aes " + b_version: decrypt_algo = "AES-256/GCM" if fileheader == ... |
b_version and fileheader != b"Cryptoshop twf " + b_version: raise Exception("Integrity failure: Bad header") salt = filestream.read(__salt_size__) encrypted_key = filestream.read(encrypted_key_length) # Derive the passphrase... masterkey = calc_derivation(passphrase=passphrase, salt=salt) # Decrypt internal key... try:... |
to process. It's files_size // chunk_size bar = tqdm(range(files_size // __chunk_size__)) while True: # Don't forget... an encrypted chunk is nonce, gcmtag, and cipher-chunk concatenation. encryptedchunk = filestream.read(__nonce_length__ + __gcmtag_length__ + __chunk_size__) if len(encryptedchunk) == 0: break # Chunk ... |
\"" + filename + "\" was not found.") |
def _tokenize(cls, sentence): """ Split a sentence while preserving tags. """ while True: match = cls._regex_tag.search(sentence) if not match: yield from cls._split(sentence) return chunk = sentence[:match.start()] yield from cls._split(chunk) tag = match.group(0) yield tag sentence = sentence[(len(chunk) + len(tag)):... |
def map(process, paths, threads=None): """ Implements a distributed stategy for processing XML files. This function constructs a set of py:mod:`multiprocessing` threads (spread over multiple cores) and uses an internal queue to aggregate outputs. To use this function, implement a `process()` function that takes two arg... |
in turn from the :func:`mwxml.map` function. :Parameters: paths : `iterable` ( `str` | `file` ) a list of paths to dump files to process process : `func` A function that takes a :class:`~mwxml.iteration.dump.Dump` and the path the dump was loaded from and yields threads : int the number of individual processing threads... |
>>> >>> def page_info(dump, path): ... for page in dump: ... yield page.id, page.namespace, page.title ... >>> for id, namespace, title in mwxml.map(page_info, files): ... print(id, namespace, title) ... """ paths = [mwtypes.files.normalize_path(path) for path in paths] def process_path(path): dump = Dump.from_file(mwt... |
def dump(self): """Return the object itself.""" return { 'title': self.title, 'issue_id': self.issue_id, 'reporter': self.reporter, 'assignee': self.assignee, 'status': self.status, 'product': self.product, 'component': self.component, 'created_at': self.created_at, 'updated_at': self.updated_at, 'closed_at': self.clos... |
def apply_on_each_func_args_sig(func, cur_args, cur_kwargs, sig, # type: Signature func_to_apply, func_to_apply_params_dict): """ Applies func_to_apply on each argument of func according to what's received in current call (cur_args, cur_kwargs). For each argument of func named 'att' in its signature, the following meth... |
arguments with the signature to know who is who bound_values = sig.bind(*cur_args, **cur_kwargs) # add the default values in here to get a full list apply_defaults(bound_values) for att_name, att_value in bound_values.arguments.items(): if att_name in func_to_apply_params_dict.keys(): # value = a normal value, or cur_k... |
def is_product_owner(self, team_id): """Ensure the user is a PRODUCT_OWNER.""" if self.is_super_admin(): return True team_id = uuid.UUID(str(team_id)) return team_id in self.child_teams_ids |
def is_in_team(self, team_id): """Test if user is in team""" if self.is_super_admin(): return True team_id = uuid.UUID(str(team_id)) return team_id in self.teams or team_id in self.child_teams_ids |
def is_remoteci(self, team_id=None): """Ensure ther resource has the role REMOTECI.""" if team_id is None: return self._is_remoteci team_id = uuid.UUID(str(team_id)) if team_id not in self.teams_ids: return False return self.teams[team_id]['role'] == 'REMOTECI' |
def is_feeder(self, team_id=None): """Ensure ther resource has the role FEEDER.""" if team_id is None: return self._is_feeder team_id = uuid.UUID(str(team_id)) if team_id not in self.teams_ids: return False return self.teams[team_id]['role'] == 'FEEDER' |
def document(self): """ :return: the :class:`Document` node that contains this node, or ``self`` if this node is the document. """ if self.is_document: return self return self.adapter.wrap_document(self.adapter.impl_document) |
def root(self): """ :return: the root :class:`Element` node of the document that contains this node, or ``self`` if this node is the root element. """ if self.is_root: return self return self.adapter.wrap_node( self.adapter.impl_root_element, self.adapter.impl_document, self.adapter) |
def _convert_nodelist(self, impl_nodelist): """ Convert a list of underlying implementation nodes into a list of *xml4h* wrapper nodes. """ nodelist = [ self.adapter.wrap_node(n, self.adapter.impl_document, self.adapter) for n in impl_nodelist] return NodeList(nodelist) |
def parent(self): """ :return: the parent of this node, or *None* of the node has no parent. """ parent_impl_node = self.adapter.get_node_parent(self.impl_node) return self.adapter.wrap_node( parent_impl_node, self.adapter.impl_document, self.adapter) |
def children(self): """ :return: a :class:`NodeList` of this node's child nodes. """ impl_nodelist = self.adapter.get_node_children(self.impl_node) return self._convert_nodelist(impl_nodelist) |
def child(self, local_name=None, name=None, ns_uri=None, node_type=None, filter_fn=None): """ :return: the first child node matching the given constraints, or \ *None* if there are no matching child nodes. Delegates to :meth:`NodeList.filter`. """ return self.children(name=name, local_name=local_name, ns_uri=ns_uri, no... |
def siblings(self): """ :return: a list of this node's sibling nodes. :rtype: NodeList """ impl_nodelist = self.adapter.get_node_children(self.parent.impl_node) return self._convert_nodelist( [n for n in impl_nodelist if n != self.impl_node]) |
def siblings_before(self): """ :return: a list of this node's siblings that occur *before* this node in the DOM. """ impl_nodelist = self.adapter.get_node_children(self.parent.impl_node) before_nodelist = [] for n in impl_nodelist: if n == self.impl_node: break before_nodelist.append(n) return self._convert_nodelist(be... |
def siblings_after(self): """ :return: a list of this node's siblings that occur *after* this node in the DOM. """ impl_nodelist = self.adapter.get_node_children(self.parent.impl_node) after_nodelist = [] is_after_myself = False for n in impl_nodelist: if is_after_myself: after_nodelist.append(n) elif n == self.impl_no... |
def delete(self, destroy=True): """ Delete this node from the owning document. :param bool destroy: if True the child node will be destroyed in addition to being removed from the document. :returns: the removed child node, or *None* if the child was destroyed. """ removed_child = self.adapter.remove_node_child( self.ad... |
def clone_node(self, node): """ Clone a node from another document to become a child of this node, by copying the node's data into this document but leaving the node untouched in the source document. The node to be cloned can be a :class:`Node` based on the same underlying XML library implementation and adapter, or a "... |
in another document to clone. :type node: xml4h or implementation node """ if isinstance(node, xml4h.nodes.Node): child_impl_node = node.impl_node else: child_impl_node = node # Assume it's a valid impl node self.adapter.import_node(self.impl_node, child_impl_node, clone=True) |
def transplant_node(self, node): """ Transplant a node from another document to become a child of this node, removing it from the source document. The node to be transplanted can be a :class:`Node` based on the same underlying XML library implementation and adapter, or a "raw" node from that implementation. :param node... |
""" if isinstance(node, xml4h.nodes.Node): child_impl_node = node.impl_node original_parent_impl_node = node.parent.impl_node else: child_impl_node = node # Assume it's a valid impl node original_parent_impl_node = self.adapter.get_node_parent(node) self.adapter.import_node(self.impl_node, child_impl_node, original_par... |
def find(self, name=None, ns_uri=None, first_only=False): """ Find :class:`Element` node descendants of this node, with optional constraints to limit the results. :param name: limit results to elements with this name. If *None* or ``'*'`` all element names are matched. :type name: string or None :param ns_uri: limit re... |
string or None :param bool first_only: if *True* only return the first result node or *None* if there is no matching node. :returns: a list of :class:`Element` nodes matching any given constraints, or a single node if ``first_only=True``. """ if name is None: name = '*' # Match all element names if ns_uri is None: ns_u... |
self.adapter.find_node_elements( self.impl_node, name=name, ns_uri=ns_uri) if first_only: if impl_nodelist: return self.adapter.wrap_node( impl_nodelist[0], self.adapter.impl_document, self.adapter) else: return None return self._convert_nodelist(impl_nodelist) |
def find_first(self, name=None, ns_uri=None): """ Find the first :class:`Element` node descendant of this node that matches any optional constraints, or None if there are no matching elements. Delegates to :meth:`find` with ``first_only=True``. """ return self.find(name=name, ns_uri=ns_uri, first_only=True) |
def find_doc(self, name=None, ns_uri=None, first_only=False): """ Find :class:`Element` node descendants of the document containing this node, with optional constraints to limit the results. Delegates to :meth:`find` applied to this node's owning document. """ return self.document.find(name=name, ns_uri=ns_uri, first_o... |
def write(self, writer=None, encoding='utf-8', indent=0, newline='', omit_declaration=False, node_depth=0, quote_char='"'): """ Serialize this node and its descendants to text, writing the output to a given *writer* or to stdout. :param writer: an object such as a file or stream to which XML text is sent. If *None* tex... |
encoding for serialized text. :param indent: indentation prefix to apply to descendent nodes for pretty-printing. The value can take many forms: - *int*: the number of spaces to indent. 0 means no indent. - *string*: a literal prefix for indented nodes, such as ``\\t``. - *bool*: no indent if *False*, four spaces inden... |
or None :param newline: the string value used to separate lines of output. The value can take a number of forms: - *string*: the literal newline value, such as ``\\n`` or ``\\r``. An empty string means no newline. - *bool*: no newline if *False*, ``\\n`` newline if *True*. - *None*: no newline. :type newline: string, b... |
XML declaration header is omitted, otherwise it is included. Note that the declaration is only output when serializing an :class:`xml4h.nodes.Document` node. :param int node_depth: the indentation level to start at, such as 2 to indent output as if the given *node* has two ancestors. This parameter will only be useful ... |
document. This parameter has no effect unless indentation is applied. :param string quote_char: the character that delimits quoted content. You should never need to mess with this. Delegates to :func:`xml4h.writer.write_node` applied to this node. """ xml4h.write_node(self, writer=writer, encoding=encoding, indent=inde... |
def xml(self, indent=4, **kwargs): """ :return: this node as XML text. Delegates to :meth:`write` """ writer = StringIO() self.write(writer, indent=indent, **kwargs) return writer.getvalue() |
def xpath(self, xpath, **kwargs): """ Perform an XPath query on the current node. :param string xpath: XPath query. :param dict kwargs: Optional keyword arguments that are passed through to the underlying XML library implementation. :return: results of the query as a list of :class:`Node` objects, or a list of base typ... |
self.adapter.xpath_on_node(self.impl_node, xpath, **kwargs) if isinstance(result, (list, tuple)): return [self._maybe_wrap_node(r) for r in result] else: return self._maybe_wrap_node(result) |
def set_attributes(self, attr_obj=None, ns_uri=None, **attr_dict): """ Add or update this element's attributes, where attributes can be specified in a number of ways. :param attr_obj: a dictionary or list of attribute name/value pairs. :type attr_obj: dict, list, tuple, or None :param ns_uri: a URI defining a namespace... |
keyword arguments. """ self._set_element_attributes(self.impl_node, attr_obj=attr_obj, ns_uri=ns_uri, **attr_dict) |
def attributes(self): """ Get or set this element's attributes as name/value pairs. .. note:: Setting element attributes via this accessor will **remove** any existing attributes, as opposed to the :meth:`set_attributes` method which only updates and replaces them. """ attr_impl_nodes = self.adapter.get_node_attributes... |
def attribute_nodes(self): """ :return: a list of this element's attributes as :class:`Attribute` nodes. """ impl_attr_nodes = self.adapter.get_node_attributes(self.impl_node) wrapped_attr_nodes = [ self.adapter.wrap_node(a, self.adapter.impl_document, self.adapter) for a in impl_attr_nodes] return sorted(wrapped_attr_... |
def attribute_node(self, name, ns_uri=None): """ :param string name: the name of the attribute to return. :param ns_uri: a URI defining a namespace constraint on the attribute. :type ns_uri: string or None :return: this element's attributes that match ``ns_uri`` as :class:`Attribute` nodes. """ attr_impl_node = self.ad... |
def set_ns_prefix(self, prefix, ns_uri): """ Define a namespace prefix that will serve as shorthand for the given namespace URI in element names. :param string prefix: prefix that will serve as an alias for a the namespace URI. :param string ns_uri: namespace URI that will be denoted by the prefix. """ self._add_ns_pre... |
def add_element(self, name, ns_uri=None, attributes=None, text=None, before_this_element=False): """ Add a new child element to this element, with an optional namespace definition. If no namespace is provided the child will be assigned to the default namespace. :param string name: a name for the child node. The name ma... |
name of the form ``ns_prefix:element_name``, where the prefix has already been defined for a namespace URI (such as via :meth:`set_ns_prefix`). - a literal namespace URI value delimited by curly braces, of the form ``{ns_uri}element_name``. :param ns_uri: a URI specifying the new element's namespace. If the ``name`` pa... |
to assign to the new child. :type attributes: dict, list, tuple, or None :param text: text value to assign to the new child. :type text: string or None :param bool before_this_element: if *True* the new element is added as a sibling preceding this element, instead of as a child. In other words, the new element will be ... |
and will immediately precent this element in the DOM. :return: the new child as a an :class:`Element` node. """ # Determine local name, namespace and prefix info from tag name prefix, local_name, node_ns_uri = \ self.adapter.get_ns_info_from_node_name(name, self.impl_node) if prefix: qname = u'%s:%s' % (prefix, local_n... |
is None: # Default document namespace node_ns_uri = self.adapter.get_ns_uri_for_prefix( self.impl_node, None) else: # keyword-parameter namespace node_ns_uri = ns_uri # Create element child_elem = self.adapter.new_impl_element( qname, node_ns_uri, parent=self.impl_node) # If element's default namespace was defined by l... |
if any elif ns_uri is not None: self._set_element_attributes(child_elem, {'xmlns': ns_uri}, ns_uri=self.XMLNS_URI) # Create subordinate nodes if attributes is not None: self._set_element_attributes(child_elem, attr_obj=attributes) if text is not None: self._add_text(child_elem, text) # Add new element to its parent bef... |
def add_text(self, text): """ Add a text node to this element. Adding text with this method is subtly different from assigning a new text value with :meth:`text` accessor, because it "appends" to rather than replacing this element's set of text nodes. :param text: text content to add to this element. :param type: strin... |
isinstance(text, basestring): text = unicode(text) self._add_text(self.impl_node, text) |
def add_instruction(self, target, data): """ Add an instruction node to this element. :param string text: text content to add as an instruction. """ self._add_instruction(self.impl_node, target, data) |
def items(self): """ :return: a list of name/value attribute pairs sorted by attribute name. """ sorted_keys = sorted(self.keys()) return [(k, self[k]) for k in sorted_keys] |
def namespace_uri(self, name): """ :param string name: the name of an attribute to look up. :return: the namespace URI associated with the named attribute, or None. """ a_node = self.adapter.get_node_attribute_node(self.impl_element, name) if a_node is None: return None return self.adapter.get_node_namespace_uri(a_node... |
def prefix(self, name): """ :param string name: the name of an attribute to look up. :return: the prefix component of the named attribute's name, or None. """ a_node = self.adapter.get_node_attribute_node(self.impl_element, name) if a_node is None: return None return a_node.prefix |
def element(self): """ :return: the :class:`Element` that contains these attributes. """ return self.adapter.wrap_node( self.impl_element, self.adapter.impl_document, self.adapter) |
def filter(self, local_name=None, name=None, ns_uri=None, node_type=None, filter_fn=None, first_only=False): """ Apply filters to the set of nodes in this list. :param local_name: a local name used to filter the nodes. :type local_name: string or None :param name: a name used to filter the nodes. :type name: string or ... |
regardless of namespace. :type ns_uri: string or None :param node_type: a node type definition used to filter the nodes. :type node_type: int node type constant, class, or None :param filter_fn: an arbitrary function to filter nodes in this list. This function must accept a single :class:`Node` argument and return a bo... |
``filter_fn`` is provided all other filter arguments are ignore. :type filter_fn: function or None :return: the type of the return value depends on the value of the ``first_only`` parameter and how many nodes match the filter: - if ``first_only=False`` return a :class:`NodeList` of filtered nodes, which will be empty i... |
return the first matching :class:`Node` - if ``first_only=True`` and there are no matching nodes, return *None* """ # Build our own filter function unless a custom function is provided if filter_fn is None: def filter_fn(n): # Test node type first in case other tests require this type if node_type is not None: # Node t... |
ELEMENT_NODE) or a class. if isinstance(node_type, int): if not n.is_type(node_type): return False elif n.__class__ != node_type: return False if name is not None and n.name != name: return False if local_name is not None and n.local_name != local_name: return False if ns_uri is not None and n.ns_uri != ns_uri: return ... |
just the first node (or None if no nodes) if first_only: return nodelist[0] if nodelist else None else: return NodeList(nodelist) |
def get_all_analytics(user, job_id): """Get all analytics of a job.""" args = schemas.args(flask.request.args.to_dict()) v1_utils.verify_existence_and_get(job_id, models.JOBS) query = v1_utils.QueryBuilder(_TABLE, args, _A_COLUMNS) # If not admin nor rh employee then restrict the view to the team if user.is_not_super_a... |
def get_analytic(user, job_id, anc_id): """Get an analytic.""" v1_utils.verify_existence_and_get(job_id, models.JOBS) analytic = v1_utils.verify_existence_and_get(anc_id, _TABLE) analytic = dict(analytic) if not user.is_in_team(analytic['team_id']): raise dci_exc.Unauthorized() return flask.jsonify({'analytic': analyti... |
def write_node(node, writer=None, encoding='utf-8', indent=0, newline='', omit_declaration=False, node_depth=0, quote_char='"'): """ Serialize an *xml4h* DOM node and its descendants to text, writing the output to a given *writer* or to stdout. :param node: the DOM node whose content and descendants will be serialized.... |
If *None* text is sent to :attr:`sys.stdout`. :type writer: a file, stream, etc or None :param string encoding: the character encoding for serialized text. :param indent: indentation prefix to apply to descendent nodes for pretty-printing. The value can take many forms: - *int*: the number of spaces to indent. 0 means ... |
- *bool*: no indent if *False*, four spaces indent if *True*. - *None*: no indent. :type indent: string, int, bool, or None :param newline: the string value used to separate lines of output. The value can take a number of forms: - *string*: the literal newline value, such as ``\\n`` or ``\\r``. An empty string means no... |
``\\n`` newline if *True*. - *None*: no newline. :type newline: string, bool, or None :param boolean omit_declaration: if *True* the XML declaration header is omitted, otherwise it is included. Note that the declaration is only output when serializing an :class:`xml4h.nodes.Document` node. :param int node_depth: the in... |
This parameter will only be useful if you need to output XML text fragments that can be assembled into a document. This parameter has no effect unless indentation is applied. :param string quote_char: the character that delimits quoted content. You should never need to mess with this. """ def _sanitize_write_value(valu... |
.replace("\"", """) .replace(">", ">") ) def _write_node_impl(node, node_depth): """ Internal write implementation that does the real work while keeping track of node depth. """ # Output document declaration if we're outputting the whole doc if node.is_document: if not omit_declaration: writer.write( '<?xml ver... |
not incremented writer.write(newline) elif node.is_document_type: writer.write("<!DOCTYPE %s SYSTEM %s%s%s" % (node.name, quote_char, node.public_id)) if node.system_id is not None: writer.write( " %s%s%s" % (quote_char, node.system_id, quote_char)) if node.children: writer.write("[") for child in node.children: _write... |
node.is_entity: writer.write(newline + indent * node_depth) writer.write("<!ENTITY ") if node.is_paremeter_entity: writer.write('%% ') writer.write("%s %s%s%s>" % (node.name, quote_char, node.value, quote_char)) elif node.is_processing_instruction: writer.write(newline + indent * node_depth) writer.write("<?%s %s?>" % ... |
%s%s%s>" % (quote_char, node.external_id, quote_char)) elif node.is_system_identifier: writer.write(" system %s%s%s %s%s%s>" % (quote_char, node.external_id, quote_char, quote_char, node.uri, quote_char)) elif node.is_attribute: writer.write(" %s=%s" % (node.name, quote_char)) writer.write(_sanitize_write_value(node.va... |
child in node.children: _write_node_impl(child, node_depth + 1) if not (child.is_text or child.is_comment or child.is_cdata): found_indented_child = True if found_indented_child: writer.write(newline + indent * node_depth) writer.write('</%s>' % node.name) else: writer.write('/>') else: raise exceptions.Xml4hImplementa... |
indent = ' ' * indent # If indent but no newline set, always apply a newline (it makes sense) if indent and not newline: newline = True if newline is None or newline is False: newline = '' elif newline is True: newline = '\n' # We always need a writer, use stdout by default if writer is None: writer = sys.stdout # |
Apply a text encoding if we have one if encoding is None: writer = writer else: writer = codecs.getwriter(encoding)(writer) # Do the business... _write_node_impl(node, node_depth) |
def encry_decry_chunk(chunk, key, algo, bool_encry, assoc_data): """ When bool_encry is True, encrypt a chunk of the file with the key and a randomly generated nonce. When it is False, the function extract the nonce from the cipherchunk (first 16 bytes), and decrypt the rest of the chunk. :param chunk: a chunk in bytes... |
bytes. :param algo: a string of algorithm. Can be "srp" , "AES" or "twf" :param bool_encry: if bool_encry is True, chunk is encrypted. Else, it will be decrypted. :param assoc_data: bytes string of additional data for GCM Authentication. :return: if bool_encry is True, corresponding nonce + cipherchunk else, a decrypte... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.