Return a new :class:`~aeneas.textfile.TextFile` object,
        rooted at the given node ``root``.

        :param root: the root node
        :type  root: :class:`~aeneas.tree.Tree`
        :rtype: :class:`~aeneas.textfile.TextFile`
181534
def get_subtree(self, root):
        
        if not isinstance(root, Tree):
            self.log_exc(u"root is not an instance of Tree", None, True, TypeError)
        new_text_file = TextFile()
        new_text_file.fragments_tree = root
        return new_text_file
1159474
def _serialize_xml(self, root):
        
        if hasattr(etree, 'tostringlist'):
            if six.PY3:
                xml_content_list = [
                    x.decode("utf-8") for x in etree.tostringlist(root)]
            else:
                xml_content_list = etree.tostringlist(root)

            xml = '\r\n'.join(xml_content_list) + '\r\n'
        else:
            if six.PY3:
                xml_content = etree.tostring(root).decode("utf-8")
            else:
                xml_content = etree.tostring(root)
            xml = xml_content + '\r\n'
        return xml
1154626
def _create_doc(self):
        '''
        
        '''
        root = etree.Element('image')
        root.set('schemaversion', '6.3')
        root.set('name', self.name)

        return root
466223
def get_xml_root(xml_file):
    """"""
    try:
        xml_root = etree.parse(os.path.expanduser(xml_file), NO_BLANKS_PARSER).getroot()
    # pylint: disable=broad-except
    except Exception as err:
        raise Dump2PolarionException("Failed to parse XML file '{}': {}".format(xml_file, err))
    return xml_root
863568
def join(cls, root, subkey):
        
        if subkey is None:
            return root
        return enums.SPLITTER.join((root, subkey))
735935
def at(self, root):
        
        leafs = root.strip(" ").split('.')
        for leaf in leafs:
            if leaf:
                self._json_data = self.__get_value_from_data(leaf, self._json_data)
        return self
719763
def get_root_item(self, item):
        """"""
        root_item = item
        while isinstance(root_item.parent(), QTreeWidgetItem):
            root_item = root_item.parent()
        return root_item
25647
async def root(self):
        
        if self.writing:
            await self.iobj.awrite(binascii.unhexlify(b'011673657269616c697a6174696f6e3a3a617263686976650000'))

        else:
            hdr = bytearray(2)
            await self.iobj.areadinto(hdr)
            if hdr != bytearray(b'\x01\x16'):
                raise ValueError('Unsupported header')

            hdr = bytearray(22)
            await self.iobj.areadinto(hdr)
            if hdr != bytearray(b'serialization::archive'):
                raise ValueError('Unrecognized magic header')

            tra = await load_uvarint(self.iobj)
            ver = await load_uvarint(self.iobj)
            if tra != 0:
                raise ValueError('Tracking not supported')
936289
def _nav_to_tree(root):
    
    def expath(e, x):
        return e.xpath(x, namespaces=HTML_DOCUMENT_NAMESPACES)
    for li in expath(root, 'xhtml:ol/xhtml:li'):
        is_subtree = bool([e for e in li.getchildren()
                           if e.tag[e.tag.find('}')+1:] == 'ol'])
        if is_subtree:
            # It's a sub-tree and have a 'span' and 'ol'.
            itemid = li.get('cnx-archive-uri', 'subcol')
            shortid = li.get('cnx-archive-shortid')
            yield {'id': itemid,
                   # Title is wrapped in a span, div or some other element...
                   'title': squash_xml_to_text(expath(li, '*')[0],
                                               remove_namespaces=True),
                   'shortId': shortid,
                   'contents': [x for x in _nav_to_tree(li)],
                   }
        else:
            # It's a node and should only have an li.
            a = li.xpath('xhtml:a', namespaces=HTML_DOCUMENT_NAMESPACES)[0]
            yield {'id': a.get('href'),
                   'shortid': li.get('cnx-archive-shortid'),
                   'title': squash_xml_to_text(a, remove_namespaces=True)}
582139
def parse_root(raw):
    ""
    if sys.version < '3':
        fp = StringIO(raw)
    else:
        fp = BytesIO(raw.encode('UTF-8'))
    for event, element in etree.iterparse(fp, events=('start',)):
        return (element.tag, element.attrib)
1177227
def root(parent = @root, min_indent = -1)
      while (@line = @code[(@i += 1)])
        # Reset character position cursor
        @j = 0

        # Skip to next iteration if we have a blank line
        next if @line =~ /\A\s*\Z/

        # Reset the line offset
        @offset = 0

        # Parse the current line by trying to match each node type towards it
        # Add current indentation to the indent stack
        indent = accept(:indent).size

        # Stop using the current parent as root if it does not match the
        # minimum indentation includements
        unless min_indent < indent
          @i -= 1
          break
        end

        # If last include path had a greater indentation, pop the last file path
        @file.pop if @file[-1][1] >= indent

        # Try the main Opulent node types and process each one of them using
        # their matching evaluation procedure
        current_node = node(parent, indent) ||
                       text(parent, indent) ||
                       comment(parent, indent) ||
                       define(parent, indent) ||
                       control(parent, indent) ||
                       evaluate(parent, indent) ||
                       filter(parent, indent) ||
                       block_yield(parent, indent) ||
                       include_file(parent, indent) ||
                       html_text(parent, indent) ||
                       doctype(parent, indent)

        # Throw an error if we couldn't find any valid node
        unless current_node
          Logger.error :parse, @code, @i, @j, :unknown_node_type
        end
      end

      parent
    end
629774
def iter(self, root=None):
        
        if root is None:
            return iter(self._controls)
        return ((os.path.join(root, outdir), control)
                for outdir, control in self._controls)
81137
def load(root_file, use_proxy=True, key=None):
    
    if isinstance(root_file, string_types):
        root_file = root_open(root_file)
        own_file = True
    else:
        own_file = False
    obj = Unpickler(root_file, use_proxy).load(key)
    if own_file:
        root_file.Close()
    return obj
254196
def newText(content):
    
    ret = libxml2mod.xmlNewText(content)
    if ret is None:raise treeError('xmlNewText() failed')
    return xmlNode(_obj=ret)
1300074
def _element_find_from_root(
        root,  # type: ET.Element
        element_path  # type: Text
):
    # type: (...) -> Optional[ET.Element]
    
    element = None

    element_names = element_path.split('/')
    if element_names[0] == root.tag:
        if len(element_names) > 1:
            element = root.find('/'.join(element_names[1:]))
        else:
            element = root

    return element
1079623
private void readRoot() throws IOException {
        if (root != null) {
            return;
        }
        final ByteArrayOutputStream content = new ByteArrayOutputStream();
        final byte[] buffer = new byte[READ_BUFFER_SIZE];
        try {
            while (trans_.read(buffer, 0, READ_BUFFER_SIZE) > 0) {
                content.write(buffer);
            }
        } catch (TTransportException e) {
            if (TTransportException.END_OF_FILE != e.getType()) {
                throw new IOException(e);
            }
        }
        root = OBJECT_MAPPER.readTree(content.toByteArray());
    }
103771
def data(self, root):
        ''''''
        value = self.dict()
        children = [node for node in root if isinstance(node.tag, basestring)]
        for attr, attrval in root.attrib.items():
            attr = attr if self.attr_prefix is None else self.attr_prefix + attr
            value[attr] = self._fromstring(attrval)
        if root.text and self.text_content is not None:
            text = root.text.strip()
            if text:
                if self.simple_text and len(children) == len(root.attrib) == 0:
                    value = self._fromstring(text)
                else:
                    value[self.text_content] = self._fromstring(text)
        count = Counter(child.tag for child in children)
        for child in children:
            if count[child.tag] == 1:
                value.update(self.data(child))
            else:
                result = value.setdefault(child.tag, self.list())
                result += self.data(child).values()
        # if simple_text, elements with no children nor attrs become '', not {}
        if isinstance(value, dict) and not value and self.simple_text:
            value = ''
        return self.dict([(root.tag, value)])