Best Python code snippet using molecule_python
workingtree.py
Source:workingtree.py  
...196            self.branch.unlock()197            raise198    def get_physical_lock_status(self):199        return self._control_files.get_physical_lock_status()200    def _write_inventory(self, inv):201        """Write inventory as the current inventory."""202        with self.lock_tree_write():203            self._set_inventory(inv, dirty=True)204            self.flush()205    # XXX: This method should be deprecated in favour of taking in a proper206    # new Inventory object.207    def set_inventory(self, new_inventory_list):208        from .inventory import (209            Inventory,210            InventoryDirectory,211            InventoryFile,212            InventoryLink)213        with self.lock_tree_write():214            inv = Inventory(self.get_root_id())215            for path, file_id, parent, kind in new_inventory_list:216                name = os.path.basename(path)217                if name == "":218                    continue219                # fixme, there should be a factory function inv,add_??220                if kind == 'directory':221                    inv.add(InventoryDirectory(file_id, name, parent))222                elif kind == 'file':223                    inv.add(InventoryFile(file_id, name, parent))224                elif kind == 'symlink':225                    inv.add(InventoryLink(file_id, name, parent))226                else:227                    raise errors.BzrError("unknown kind %r" % kind)228            self._write_inventory(inv)229    def _write_basis_inventory(self, xml):230        """Write the basis inventory XML to the basis-inventory file"""231        path = self._basis_inventory_name()232        sio = BytesIO(xml)233        self._transport.put_file(path, sio,234                                 mode=self.controldir._get_file_mode())235    def _reset_data(self):236        """Reset transient data that cannot be revalidated."""237        self._inventory_is_modified = False238        with self._transport.get('inventory') as f:239            result = self._deserialize(f)240        self._set_inventory(result, dirty=False)241    def store_uncommitted(self):242        """Store uncommitted changes from the tree in the branch."""243        with self.lock_write():244            target_tree = self.basis_tree()245            from ..shelf import ShelfCreator246            shelf_creator = ShelfCreator(self, target_tree)247            try:248                if not shelf_creator.shelve_all():249                    return250                self.branch.store_uncommitted(shelf_creator)251                shelf_creator.transform()252            finally:253                shelf_creator.finalize()254            note('Uncommitted changes stored in branch "%s".',255                 self.branch.nick)256    def restore_uncommitted(self):257        """Restore uncommitted changes from the branch into the tree."""258        with self.lock_write():259            unshelver = self.branch.get_unshelver(self)260            if unshelver is None:261                return262            try:263                merger = unshelver.make_merger()264                merger.ignore_zero = True265                merger.do_merge()266                self.branch.store_uncommitted(None)267            finally:268                unshelver.finalize()269    def get_shelf_manager(self):270        """Return the ShelfManager for this WorkingTree."""271        from ..shelf import ShelfManager272        return ShelfManager(self, self._transport)273    def _set_root_id(self, file_id):274        """Set the root id for this tree, in a format specific manner.275        :param file_id: The file id to assign to the root. It must not be276            present in the current inventory or an error will occur. It must277            not be None, but rather a valid file id.278        """279        inv = self._inventory280        orig_root_id = inv.root.file_id281        # TODO: it might be nice to exit early if there was nothing282        # to do, saving us from trigger a sync on unlock.283        self._inventory_is_modified = True284        # we preserve the root inventory entry object, but285        # unlinkit from the byid index286        inv.delete(inv.root.file_id)287        inv.root.file_id = file_id288        # and link it into the index with the new changed id.289        inv._byid[inv.root.file_id] = inv.root290        # and finally update all children to reference the new id.291        # XXX: this should be safe to just look at the root.children292        # list, not the WHOLE INVENTORY.293        for fid in inv.iter_all_ids():294            entry = inv.get_entry(fid)295            if entry.parent_id == orig_root_id:296                entry.parent_id = inv.root.file_id297    def remove(self, files, verbose=False, to_file=None, keep_files=True,298               force=False):299        """Remove nominated files from the working tree metadata.300        :files: File paths relative to the basedir.301        :keep_files: If true, the files will also be kept.302        :force: Delete files and directories, even if they are changed and303            even if the directories are not empty.304        """305        if isinstance(files, (str, text_type)):306            files = [files]307        inv_delta = []308        all_files = set()  # specified and nested files309        if to_file is None:310            to_file = sys.stdout311        files_to_backup = []312        def recurse_directory_to_add_files(directory):313            # Recurse directory and add all files314            # so we can check if they have changed.315            for parent_info, file_infos in self.walkdirs(directory):316                for relpath, basename, kind, lstat, fileid, kind in file_infos:317                    # Is it versioned or ignored?318                    if self.is_versioned(relpath):319                        # Add nested content for deletion.320                        all_files.add(relpath)321                    else:322                        # Files which are not versioned323                        # should be treated as unknown.324                        files_to_backup.append(relpath)325        with self.lock_tree_write():326            for filename in files:327                # Get file name into canonical form.328                abspath = self.abspath(filename)329                filename = self.relpath(abspath)330                if len(filename) > 0:331                    all_files.add(filename)332                    recurse_directory_to_add_files(filename)333            files = list(all_files)334            if len(files) == 0:335                return  # nothing to do336            # Sort needed to first handle directory content before the337            # directory338            files.sort(reverse=True)339            # Bail out if we are going to delete files we shouldn't340            if not keep_files and not force:341                for (file_id, path, content_change, versioned, parent_id, name,342                     kind, executable) in self.iter_changes(343                         self.basis_tree(), include_unchanged=True,344                         require_versioned=False, want_unversioned=True,345                         specific_files=files):346                    if versioned[0] is False:347                        # The record is unknown or newly added348                        files_to_backup.append(path[1])349                    elif (content_change and (kind[1] is not None)350                            and osutils.is_inside_any(files, path[1])):351                        # Versioned and changed, but not deleted, and still352                        # in one of the dirs to be deleted.353                        files_to_backup.append(path[1])354            def backup(file_to_backup):355                backup_name = self.controldir._available_backup_name(356                    file_to_backup)357                osutils.rename(abs_path, self.abspath(backup_name))358                return "removed %s (but kept a copy: %s)" % (file_to_backup,359                                                             backup_name)360            # Build inv_delta and delete files where applicable,361            # do this before any modifications to meta data.362            for f in files:363                fid = self.path2id(f)364                message = None365                if not fid:366                    message = "%s is not versioned." % (f,)367                else:368                    if verbose:369                        # having removed it, it must be either ignored or370                        # unknown371                        if self.is_ignored(f):372                            new_status = 'I'373                        else:374                            new_status = '?'375                        # XXX: Really should be a more abstract reporter376                        # interface377                        kind_ch = osutils.kind_marker(self.kind(f))378                        to_file.write(379                            new_status + '       ' + f + kind_ch + '\n')380                    # Unversion file381                    inv_delta.append((f, None, fid, None))382                    message = "removed %s" % (f,)383                if not keep_files:384                    abs_path = self.abspath(f)385                    if osutils.lexists(abs_path):386                        if (osutils.isdir(abs_path)387                                and len(os.listdir(abs_path)) > 0):388                            if force:389                                osutils.rmtree(abs_path)390                                message = "deleted %s" % (f,)391                            else:392                                message = backup(f)393                        else:394                            if f in files_to_backup:395                                message = backup(f)396                            else:397                                osutils.delete_any(abs_path)398                                message = "deleted %s" % (f,)399                    elif message is not None:400                        # Only care if we haven't done anything yet.401                        message = "%s does not exist." % (f,)402                # Print only one message (if any) per file.403                if message is not None:404                    note(message)405            self.apply_inventory_delta(inv_delta)406    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):407        """See MutableTree.set_parent_trees."""408        parent_ids = [rev for (rev, tree) in parents_list]409        for revision_id in parent_ids:410            _mod_revision.check_not_reserved_id(revision_id)411        with self.lock_tree_write():412            self._check_parents_for_ghosts(parent_ids,413                                           allow_leftmost_as_ghost=allow_leftmost_as_ghost)414            parent_ids = self._filter_parent_ids_by_ancestry(parent_ids)415            if len(parent_ids) == 0:416                leftmost_parent_id = _mod_revision.NULL_REVISION417                leftmost_parent_tree = None418            else:419                leftmost_parent_id, leftmost_parent_tree = parents_list[0]420            if self._change_last_revision(leftmost_parent_id):421                if leftmost_parent_tree is None:422                    # If we don't have a tree, fall back to reading the423                    # parent tree from the repository.424                    self._cache_basis_inventory(leftmost_parent_id)425                else:426                    inv = leftmost_parent_tree.root_inventory427                    xml = self._create_basis_xml_from_inventory(428                        leftmost_parent_id, inv)429                    self._write_basis_inventory(xml)430            self._set_merges_from_parent_ids(parent_ids)431    def _cache_basis_inventory(self, new_revision):432        """Cache new_revision as the basis inventory."""433        # TODO: this should allow the ready-to-use inventory to be passed in,434        # as commit already has that ready-to-use [while the format is the435        # same, that is].436        try:437            # this double handles the inventory - unpack and repack -438            # but is easier to understand. We can/should put a conditional439            # in here based on whether the inventory is in the latest format440            # - perhaps we should repack all inventories on a repository441            # upgrade ?442            # the fast path is to copy the raw xml from the repository. If the443            # xml contains 'revision_id="', then we assume the right444            # revision_id is set. We must check for this full string, because a445            # root node id can legitimately look like 'revision_id' but cannot446            # contain a '"'.447            xml = self.branch.repository._get_inventory_xml(new_revision)448            firstline = xml.split(b'\n', 1)[0]449            if (b'revision_id="' not in firstline450                    or b'format="7"' not in firstline):451                inv = self.branch.repository._serializer.read_inventory_from_string(452                    xml, new_revision)453                xml = self._create_basis_xml_from_inventory(new_revision, inv)454            self._write_basis_inventory(xml)455        except (errors.NoSuchRevision, errors.RevisionNotPresent):456            pass457    def _basis_inventory_name(self):458        return 'basis-inventory-cache'459    def _create_basis_xml_from_inventory(self, revision_id, inventory):460        """Create the text that will be saved in basis-inventory"""461        inventory.revision_id = revision_id462        return xml7.serializer_v7.write_inventory_to_string(inventory)463    def set_conflicts(self, conflicts):464        with self.lock_tree_write():465            self._put_rio('conflicts', conflicts.to_stanzas(),466                          CONFLICT_HEADER_1)467    def add_conflicts(self, new_conflicts):468        with self.lock_tree_write():469            conflict_set = set(self.conflicts())470            conflict_set.update(set(list(new_conflicts)))471            self.set_conflicts(_mod_conflicts.ConflictList(472                sorted(conflict_set, key=_mod_conflicts.Conflict.sort_key)))473    def conflicts(self):474        with self.lock_read():475            try:476                confile = self._transport.get('conflicts')477            except errors.NoSuchFile:478                return _mod_conflicts.ConflictList()479            try:480                try:481                    if next(confile) != CONFLICT_HEADER_1 + b'\n':482                        raise errors.ConflictFormatError()483                except StopIteration:484                    raise errors.ConflictFormatError()485                reader = _mod_rio.RioReader(confile)486                return _mod_conflicts.ConflictList.from_stanzas(reader)487            finally:488                confile.close()489    def get_ignore_list(self):490        """Return list of ignore patterns.491        Cached in the Tree object after the first call.492        """493        ignoreset = getattr(self, '_ignoreset', None)494        if ignoreset is not None:495            return ignoreset496        ignore_globs = set()497        ignore_globs.update(ignores.get_runtime_ignores())498        ignore_globs.update(ignores.get_user_ignores())499        if self.has_filename(self._format.ignore_filename):500            with self.get_file(self._format.ignore_filename) as f:501                ignore_globs.update(ignores.parse_ignore_file(f))502        self._ignoreset = ignore_globs503        return ignore_globs504    def _cleanup(self):505        self._flush_ignore_list_cache()506    def _flush_ignore_list_cache(self):507        """Resets the cached ignore list to force a cache rebuild."""508        self._ignoreset = None509        self._ignoreglobster = None510    def is_ignored(self, filename):511        r"""Check whether the filename matches an ignore pattern.512        Patterns containing '/' or '\' need to match the whole path;513        others match against only the last component.  Patterns starting514        with '!' are ignore exceptions.  Exceptions take precedence515        over regular patterns and cause the filename to not be ignored.516        If the file is ignored, returns the pattern which caused it to517        be ignored, otherwise None.  So this can simply be used as a518        boolean if desired."""519        if getattr(self, '_ignoreglobster', None) is None:520            self._ignoreglobster = globbing.ExceptionGlobster(521                self.get_ignore_list())522        return self._ignoreglobster.match(filename)523    def read_basis_inventory(self):524        """Read the cached basis inventory."""525        path = self._basis_inventory_name()526        return self._transport.get_bytes(path)527    def read_working_inventory(self):528        """Read the working inventory.529        :raises errors.InventoryModified: read_working_inventory will fail530            when the current in memory inventory has been modified.531        """532        # conceptually this should be an implementation detail of the tree.533        # XXX: Deprecate this.534        # ElementTree does its own conversion from UTF-8, so open in535        # binary.536        with self.lock_read():537            if self._inventory_is_modified:538                raise errors.InventoryModified(self)539            with self._transport.get('inventory') as f:540                result = self._deserialize(f)541            self._set_inventory(result, dirty=False)542            return result543    def get_root_id(self):544        """Return the id of this trees root"""545        with self.lock_read():546            return self._inventory.root.file_id547    def has_id(self, file_id):548        # files that have been deleted are excluded549        inv, inv_file_id = self._unpack_file_id(file_id)550        if not inv.has_id(inv_file_id):551            return False552        path = inv.id2path(inv_file_id)553        return osutils.lexists(self.abspath(path))554    def has_or_had_id(self, file_id):555        if file_id == self.get_root_id():556            return True557        inv, inv_file_id = self._unpack_file_id(file_id)558        return inv.has_id(inv_file_id)559    def all_file_ids(self):560        """Iterate through file_ids for this tree.561        file_ids are in a WorkingTree if they are in the working inventory562        and the working file exists.563        """564        return {ie.file_id for path, ie in self.iter_entries_by_dir()}565    def all_versioned_paths(self):566        return {path for path, ie in self.iter_entries_by_dir()}567    def set_last_revision(self, new_revision):568        """Change the last revision in the working tree."""569        with self.lock_tree_write():570            if self._change_last_revision(new_revision):571                self._cache_basis_inventory(new_revision)572    def _get_check_refs(self):573        """Return the references needed to perform a check of this tree.574        The default implementation returns no refs, and is only suitable for575        trees that have no local caching and can commit on ghosts at any time.576        :seealso: breezy.check for details about check_refs.577        """578        return []579    def _check(self, references):580        """Check the tree for consistency.581        :param references: A dict with keys matching the items returned by582            self._get_check_refs(), and values from looking those keys up in583            the repository.584        """585        with self.lock_read():586            tree_basis = self.basis_tree()587            with tree_basis.lock_read():588                repo_basis = references[('trees', self.last_revision())]589                if len(list(repo_basis.iter_changes(tree_basis))) > 0:590                    raise errors.BzrCheckError(591                        "Mismatched basis inventory content.")592                self._validate()593    def check_state(self):594        """Check that the working state is/isn't valid."""595        with self.lock_read():596            check_refs = self._get_check_refs()597            refs = {}598            for ref in check_refs:599                kind, value = ref600                if kind == 'trees':601                    refs[ref] = self.branch.repository.revision_tree(value)602            self._check(refs)603    def reset_state(self, revision_ids=None):604        """Reset the state of the working tree.605        This does a hard-reset to a last-known-good state. This is a way to606        fix if something got corrupted (like the .bzr/checkout/dirstate file)607        """608        with self.lock_tree_write():609            if revision_ids is None:610                revision_ids = self.get_parent_ids()611            if not revision_ids:612                rt = self.branch.repository.revision_tree(613                    _mod_revision.NULL_REVISION)614            else:615                rt = self.branch.repository.revision_tree(revision_ids[0])616            self._write_inventory(rt.root_inventory)617            self.set_parent_ids(revision_ids)618    def flush(self):619        """Write the in memory inventory to disk."""620        # TODO: Maybe this should only write on dirty ?621        if self._control_files._lock_mode != 'w':622            raise errors.NotWriteLocked(self)623        sio = BytesIO()624        self._serialize(self._inventory, sio)625        sio.seek(0)626        self._transport.put_file('inventory', sio,627                                 mode=self.controldir._get_file_mode())628        self._inventory_is_modified = False629    def get_file_mtime(self, path):630        """See Tree.get_file_mtime."""631        try:632            return os.lstat(self.abspath(path)).st_mtime633        except OSError as e:634            if e.errno == errno.ENOENT:635                raise errors.NoSuchFile(path)636            raise637    def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):638        try:639            return self._path2ie(path).executable640        except errors.NoSuchFile:641            # For unversioned files on win32, we just assume they are not642            # executable643            return False644    def _is_executable_from_path_and_stat_from_stat(self, path, stat_result):645        mode = stat_result.st_mode646        return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)647    def is_executable(self, path):648        if not self._supports_executable():649            ie = self._path2ie(path)650            return ie.executable651        else:652            mode = os.lstat(self.abspath(path)).st_mode653            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)654    def _is_executable_from_path_and_stat(self, path, stat_result):655        if not self._supports_executable():656            return self._is_executable_from_path_and_stat_from_basis(657                path, stat_result)658        else:659            return self._is_executable_from_path_and_stat_from_stat(660                path, stat_result)661    def _add(self, files, ids, kinds):662        """See MutableTree._add."""663        with self.lock_tree_write():664            # TODO: Re-adding a file that is removed in the working copy665            # should probably put it back with the previous ID.666            # the read and write working inventory should not occur in this667            # function - they should be part of lock_write and unlock.668            # FIXME: nested trees669            inv = self.root_inventory670            for f, file_id, kind in zip(files, ids, kinds):671                if file_id is None:672                    inv.add_path(f, kind=kind)673                else:674                    inv.add_path(f, kind=kind, file_id=file_id)675                self._inventory_is_modified = True676    def revision_tree(self, revision_id):677        """See WorkingTree.revision_id."""678        if revision_id == self.last_revision():679            try:680                xml = self.read_basis_inventory()681            except errors.NoSuchFile:682                pass683            else:684                try:685                    inv = xml7.serializer_v7.read_inventory_from_string(xml)686                    # dont use the repository revision_tree api because we want687                    # to supply the inventory.688                    if inv.revision_id == revision_id:689                        return InventoryRevisionTree(690                            self.branch.repository, inv, revision_id)691                except errors.BadInventoryFormat:692                    pass693        # raise if there was no inventory, or if we read the wrong inventory.694        raise errors.NoSuchRevisionInTree(self, revision_id)695    def annotate_iter(self, path,696                      default_revision=_mod_revision.CURRENT_REVISION):697        """See Tree.annotate_iter698        This implementation will use the basis tree implementation if possible.699        Lines not in the basis are attributed to CURRENT_REVISION700        If there are pending merges, lines added by those merges will be701        incorrectly attributed to CURRENT_REVISION (but after committing, the702        attribution will be correct).703        """704        with self.lock_read():705            file_id = self.path2id(path)706            if file_id is None:707                raise errors.NoSuchFile(path)708            maybe_file_parent_keys = []709            for parent_id in self.get_parent_ids():710                try:711                    parent_tree = self.revision_tree(parent_id)712                except errors.NoSuchRevisionInTree:713                    parent_tree = self.branch.repository.revision_tree(714                        parent_id)715                with parent_tree.lock_read():716                    try:717                        kind = parent_tree.kind(path)718                    except errors.NoSuchFile:719                        continue720                    if kind != 'file':721                        # Note: this is slightly unnecessary, because symlinks722                        # and directories have a "text" which is the empty723                        # text, and we know that won't mess up annotations. But724                        # it seems cleaner725                        continue726                    parent_path = parent_tree.id2path(file_id)727                    parent_text_key = (728                        file_id,729                        parent_tree.get_file_revision(parent_path))730                    if parent_text_key not in maybe_file_parent_keys:731                        maybe_file_parent_keys.append(parent_text_key)732            graph = self.branch.repository.get_file_graph()733            heads = graph.heads(maybe_file_parent_keys)734            file_parent_keys = []735            for key in maybe_file_parent_keys:736                if key in heads:737                    file_parent_keys.append(key)738            # Now we have the parents of this content739            annotator = self.branch.repository.texts.get_annotator()740            text = self.get_file_text(path)741            this_key = (file_id, default_revision)742            annotator.add_special_text(this_key, file_parent_keys, text)743            annotations = [(key[-1], line)744                           for key, line in annotator.annotate_flat(this_key)]745            return annotations746    def _put_rio(self, filename, stanzas, header):747        self._must_be_locked()748        my_file = _mod_rio.rio_file(stanzas, header)749        self._transport.put_file(filename, my_file,750                                 mode=self.controldir._get_file_mode())751    def set_merge_modified(self, modified_hashes):752        def iter_stanzas():753            for file_id in modified_hashes:754                yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),755                                      hash=modified_hashes[file_id])756        with self.lock_tree_write():757            self._put_rio('merge-hashes', iter_stanzas(),758                          MERGE_MODIFIED_HEADER_1)759    def merge_modified(self):760        """Return a dictionary of files modified by a merge.761        The list is initialized by WorkingTree.set_merge_modified, which is762        typically called after we make some automatic updates to the tree763        because of a merge.764        This returns a map of file_id->sha1, containing only files which are765        still in the working inventory and have that text hash.766        """767        with self.lock_read():768            try:769                hashfile = self._transport.get('merge-hashes')770            except errors.NoSuchFile:771                return {}772            try:773                merge_hashes = {}774                try:775                    if next(hashfile) != MERGE_MODIFIED_HEADER_1 + b'\n':776                        raise errors.MergeModifiedFormatError()777                except StopIteration:778                    raise errors.MergeModifiedFormatError()779                for s in _mod_rio.RioReader(hashfile):780                    # RioReader reads in Unicode, so convert file_ids back to781                    # utf8782                    file_id = cache_utf8.encode(s.get("file_id"))783                    if not self.has_id(file_id):784                        continue785                    text_hash = s.get("hash").encode('ascii')786                    path = self.id2path(file_id)787                    if text_hash == self.get_file_sha1(path):788                        merge_hashes[file_id] = text_hash789                return merge_hashes790            finally:791                hashfile.close()792    def subsume(self, other_tree):793        def add_children(inventory, entry):794            for child_entry in entry.children.values():795                inventory._byid[child_entry.file_id] = child_entry796                if child_entry.kind == 'directory':797                    add_children(inventory, child_entry)798        with self.lock_write():799            if other_tree.get_root_id() == self.get_root_id():800                raise errors.BadSubsumeSource(self, other_tree,801                                              'Trees have the same root')802            try:803                other_tree_path = self.relpath(other_tree.basedir)804            except errors.PathNotChild:805                raise errors.BadSubsumeSource(806                    self, other_tree, 'Tree is not contained by the other')807            new_root_parent = self.path2id(osutils.dirname(other_tree_path))808            if new_root_parent is None:809                raise errors.BadSubsumeSource(810                    self, other_tree, 'Parent directory is not versioned.')811            # We need to ensure that the result of a fetch will have a812            # versionedfile for the other_tree root, and only fetching into813            # RepositoryKnit2 guarantees that.814            if not self.branch.repository.supports_rich_root():815                raise errors.SubsumeTargetNeedsUpgrade(other_tree)816            with other_tree.lock_tree_write():817                other_root = other_tree.root_inventory.root818                other_root.parent_id = new_root_parent819                other_root.name = osutils.basename(other_tree_path)820                self.root_inventory.add(other_root)821                add_children(self.root_inventory, other_root)822                self._write_inventory(self.root_inventory)823                # normally we don't want to fetch whole repositories, but i824                # think here we really do want to consolidate the whole thing.825                for parent_id in other_tree.get_parent_ids():826                    self.branch.fetch(other_tree.branch, parent_id)827                    self.add_parent_tree_id(parent_id)828            other_tree.controldir.retire_bzrdir()829    def extract(self, sub_path, format=None):830        """Extract a subtree from this tree.831        A new branch will be created, relative to the path for this tree.832        """833        def mkdirs(path):834            segments = osutils.splitpath(path)835            transport = self.branch.controldir.root_transport836            for name in segments:837                transport = transport.clone(name)838                transport.ensure_base()839            return transport840        with self.lock_tree_write():841            self.flush()842            branch_transport = mkdirs(sub_path)843            if format is None:844                format = self.controldir.cloning_metadir()845            branch_transport.ensure_base()846            branch_bzrdir = format.initialize_on_transport(branch_transport)847            try:848                repo = branch_bzrdir.find_repository()849            except errors.NoRepositoryPresent:850                repo = branch_bzrdir.create_repository()851            if not repo.supports_rich_root():852                raise errors.RootNotRich()853            new_branch = branch_bzrdir.create_branch()854            new_branch.pull(self.branch)855            for parent_id in self.get_parent_ids():856                new_branch.fetch(self.branch, parent_id)857            tree_transport = self.controldir.root_transport.clone(sub_path)858            if tree_transport.base != branch_transport.base:859                tree_bzrdir = format.initialize_on_transport(tree_transport)860                tree_bzrdir.set_branch_reference(new_branch)861            else:862                tree_bzrdir = branch_bzrdir863            wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)864            wt.set_parent_ids(self.get_parent_ids())865            # FIXME: Support nested trees866            my_inv = self.root_inventory867            child_inv = inventory.Inventory(root_id=None)868            file_id = self.path2id(sub_path)869            new_root = my_inv.get_entry(file_id)870            my_inv.remove_recursive_id(file_id)871            new_root.parent_id = None872            child_inv.add(new_root)873            self._write_inventory(my_inv)874            wt._write_inventory(child_inv)875            return wt876    def list_files(self, include_root=False, from_dir=None, recursive=True):877        """List all files as (path, class, kind, id, entry).878        Lists, but does not descend into unversioned directories.879        This does not include files that have been deleted in this880        tree. Skips the control directory.881        :param include_root: if True, return an entry for the root882        :param from_dir: start from this directory or None for the root883        :param recursive: whether to recurse into subdirectories or not884        """885        with self.lock_read():886            if from_dir is None and include_root is True:887                yield ('', 'V', 'directory', self.root_inventory.root)888            # Convert these into local objects to save lookup times889            pathjoin = osutils.pathjoin890            # transport.base ends in a slash, we want the piece891            # between the last two slashes892            transport_base_dir = self.controldir.transport.base.rsplit(893                '/', 2)[1]894            fk_entries = {895                'directory': TreeDirectory,896                'file': TreeFile,897                'symlink': TreeLink898                }899            # directory file_id, relative path, absolute path, reverse sorted900            # children901            if from_dir is not None:902                inv, from_dir_id = self._path2inv_file_id(from_dir)903                if from_dir_id is None:904                    # Directory not versioned905                    return906                from_dir_abspath = pathjoin(self.basedir, from_dir)907            else:908                inv = self.root_inventory909                from_dir_id = inv.root.file_id910                from_dir_abspath = self.basedir911            children = sorted(os.listdir(from_dir_abspath))912            # jam 20060527 The kernel sized tree seems equivalent whether we913            # use a deque and popleft to keep them sorted, or if we use a plain914            # list and just reverse() them.915            children = deque(children)916            stack = [(from_dir_id, u'', from_dir_abspath, children)]917            while stack:918                (from_dir_id, from_dir_relpath, from_dir_abspath,919                 children) = stack[-1]920                while children:921                    f = children.popleft()922                    # TODO: If we find a subdirectory with its own .bzr923                    # directory, then that is a separate tree and we924                    # should exclude it.925                    # the bzrdir for this tree926                    if transport_base_dir == f:927                        continue928                    # we know that from_dir_relpath and from_dir_abspath never929                    # end in a slash and 'f' doesn't begin with one, we can do930                    # a string op, rather than the checks of pathjoin(), all931                    # relative paths will have an extra slash at the beginning932                    fp = from_dir_relpath + '/' + f933                    # absolute path934                    fap = from_dir_abspath + '/' + f935                    dir_ie = inv.get_entry(from_dir_id)936                    if dir_ie.kind == 'directory':937                        f_ie = dir_ie.children.get(f)938                    else:939                        f_ie = None940                    if f_ie:941                        c = 'V'942                    elif self.is_ignored(fp[1:]):943                        c = 'I'944                    else:945                        # we may not have found this file, because of a unicode946                        # issue, or because the directory was actually a947                        # symlink.948                        f_norm, can_access = osutils.normalized_filename(f)949                        if f == f_norm or not can_access:950                            # No change, so treat this file normally951                            c = '?'952                        else:953                            # this file can be accessed by a normalized path954                            # check again if it is versioned955                            # these lines are repeated here for performance956                            f = f_norm957                            fp = from_dir_relpath + '/' + f958                            fap = from_dir_abspath + '/' + f959                            f_ie = inv.get_child(from_dir_id, f)960                            if f_ie:961                                c = 'V'962                            elif self.is_ignored(fp[1:]):963                                c = 'I'964                            else:965                                c = '?'966                    fk = osutils.file_kind(fap)967                    # make a last minute entry968                    if f_ie:969                        yield fp[1:], c, fk, f_ie970                    else:971                        try:972                            yield fp[1:], c, fk, fk_entries[fk]()973                        except KeyError:974                            yield fp[1:], c, fk, TreeEntry()975                        continue976                    if fk != 'directory':977                        continue978                    # But do this child first if recursing down979                    if recursive:980                        new_children = sorted(os.listdir(fap))981                        new_children = deque(new_children)982                        stack.append((f_ie.file_id, fp, fap, new_children))983                        # Break out of inner loop,984                        # so that we start outer loop with child985                        break986                else:987                    # if we finished all children, pop it off the stack988                    stack.pop()989    def move(self, from_paths, to_dir=None, after=False):990        """Rename files.991        to_dir must exist in the inventory.992        If to_dir exists and is a directory, the files are moved into993        it, keeping their old names.994        Note that to_dir is only the last component of the new name;995        this doesn't change the directory.996        For each entry in from_paths the move mode will be determined997        independently.998        The first mode moves the file in the filesystem and updates the999        inventory. The second mode only updates the inventory without1000        touching the file on the filesystem.1001        move uses the second mode if 'after == True' and the target is1002        either not versioned or newly added, and present in the working tree.1003        move uses the second mode if 'after == False' and the source is1004        versioned but no longer in the working tree, and the target is not1005        versioned but present in the working tree.1006        move uses the first mode if 'after == False' and the source is1007        versioned and present in the working tree, and the target is not1008        versioned and not present in the working tree.1009        Everything else results in an error.1010        This returns a list of (from_path, to_path) pairs for each1011        entry that is moved.1012        """1013        rename_entries = []1014        rename_tuples = []1015        # check for deprecated use of signature1016        if to_dir is None:1017            raise TypeError('You must supply a target directory')1018        # check destination directory1019        if isinstance(from_paths, (str, text_type)):1020            raise ValueError()1021        with self.lock_tree_write():1022            to_abs = self.abspath(to_dir)1023            if not osutils.isdir(to_abs):1024                raise errors.BzrMoveFailedError(1025                    '', to_dir, errors.NotADirectory(to_abs))1026            if not self.has_filename(to_dir):1027                raise errors.BzrMoveFailedError(1028                    '', to_dir, errors.NotInWorkingDirectory(to_dir))1029            to_inv, to_dir_id = self._path2inv_file_id(to_dir)1030            if to_dir_id is None:1031                raise errors.BzrMoveFailedError(1032                    '', to_dir, errors.NotVersionedError(path=to_dir))1033            to_dir_ie = to_inv.get_entry(to_dir_id)1034            if to_dir_ie.kind != 'directory':1035                raise errors.BzrMoveFailedError(1036                    '', to_dir, errors.NotADirectory(to_abs))1037            # create rename entries and tuples1038            for from_rel in from_paths:1039                from_tail = osutils.splitpath(from_rel)[-1]1040                from_inv, from_id = self._path2inv_file_id(from_rel)1041                if from_id is None:1042                    raise errors.BzrMoveFailedError(from_rel, to_dir,1043                                                    errors.NotVersionedError(path=from_rel))1044                from_entry = from_inv.get_entry(from_id)1045                from_parent_id = from_entry.parent_id1046                to_rel = osutils.pathjoin(to_dir, from_tail)1047                rename_entry = InventoryWorkingTree._RenameEntry(1048                    from_rel=from_rel,1049                    from_id=from_id,1050                    from_tail=from_tail,1051                    from_parent_id=from_parent_id,1052                    to_rel=to_rel, to_tail=from_tail,1053                    to_parent_id=to_dir_id)1054                rename_entries.append(rename_entry)1055                rename_tuples.append((from_rel, to_rel))1056            # determine which move mode to use. checks also for movability1057            rename_entries = self._determine_mv_mode(rename_entries, after)1058            original_modified = self._inventory_is_modified1059            try:1060                if len(from_paths):1061                    self._inventory_is_modified = True1062                self._move(rename_entries)1063            except BaseException:1064                # restore the inventory on error1065                self._inventory_is_modified = original_modified1066                raise1067            # FIXME: Should potentially also write the from_invs1068            self._write_inventory(to_inv)1069            return rename_tuples1070    def rename_one(self, from_rel, to_rel, after=False):1071        """Rename one file.1072        This can change the directory or the filename or both.1073        rename_one has several 'modes' to work. First, it can rename a physical1074        file and change the file_id. That is the normal mode. Second, it can1075        only change the file_id without touching any physical file.1076        rename_one uses the second mode if 'after == True' and 'to_rel' is not1077        versioned but present in the working tree.1078        rename_one uses the second mode if 'after == False' and 'from_rel' is1079        versioned but no longer in the working tree, and 'to_rel' is not1080        versioned but present in the working tree.1081        rename_one uses the first mode if 'after == False' and 'from_rel' is1082        versioned and present in the working tree, and 'to_rel' is not1083        versioned and not present in the working tree.1084        Everything else results in an error.1085        """1086        with self.lock_tree_write():1087            rename_entries = []1088            # create rename entries and tuples1089            from_tail = osutils.splitpath(from_rel)[-1]1090            from_inv, from_id = self._path2inv_file_id(from_rel)1091            if from_id is None:1092                # if file is missing in the inventory maybe it's in the1093                # basis_tree1094                basis_tree = self.branch.basis_tree()1095                from_id = basis_tree.path2id(from_rel)1096                if from_id is None:1097                    raise errors.BzrRenameFailedError(1098                        from_rel, to_rel,1099                        errors.NotVersionedError(path=from_rel))1100                try:1101                    from_entry = from_inv.get_entry(from_id)1102                except errors.NoSuchId:1103                    # put entry back in the inventory so we can rename it1104                    from_entry = basis_tree.root_inventory.get_entry(1105                        from_id).copy()1106                    from_inv.add(from_entry)1107            else:1108                from_inv, from_inv_id = self._unpack_file_id(from_id)1109                from_entry = from_inv.get_entry(from_inv_id)1110            from_parent_id = from_entry.parent_id1111            to_dir, to_tail = os.path.split(to_rel)1112            to_inv, to_dir_id = self._path2inv_file_id(to_dir)1113            rename_entry = InventoryWorkingTree._RenameEntry(1114                from_rel=from_rel,1115                from_id=from_id,1116                from_tail=from_tail,1117                from_parent_id=from_parent_id,1118                to_rel=to_rel, to_tail=to_tail,1119                to_parent_id=to_dir_id)1120            rename_entries.append(rename_entry)1121            # determine which move mode to use. checks also for movability1122            rename_entries = self._determine_mv_mode(rename_entries, after)1123            # check if the target changed directory and if the target directory1124            # is versioned1125            if to_dir_id is None:1126                raise errors.BzrMoveFailedError(1127                    from_rel, to_rel, errors.NotVersionedError(path=to_dir))1128            # all checks done. now we can continue with our actual work1129            mutter('rename_one:\n'1130                   '  from_id   {%s}\n'1131                   '  from_rel: %r\n'1132                   '  to_rel:   %r\n'1133                   '  to_dir    %r\n'1134                   '  to_dir_id {%s}\n',1135                   from_id, from_rel, to_rel, to_dir, to_dir_id)1136            self._move(rename_entries)1137            self._write_inventory(to_inv)1138    class _RenameEntry(object):1139        def __init__(self, from_rel, from_id, from_tail, from_parent_id,1140                     to_rel, to_tail, to_parent_id, only_change_inv=False,1141                     change_id=False):1142            self.from_rel = from_rel1143            self.from_id = from_id1144            self.from_tail = from_tail1145            self.from_parent_id = from_parent_id1146            self.to_rel = to_rel1147            self.to_tail = to_tail1148            self.to_parent_id = to_parent_id1149            self.change_id = change_id1150            self.only_change_inv = only_change_inv1151    def _determine_mv_mode(self, rename_entries, after=False):1152        """Determines for each from-to pair if both inventory and working tree1153        or only the inventory has to be changed.1154        Also does basic plausability tests.1155        """1156        # FIXME: Handling of nested trees1157        inv = self.root_inventory1158        for rename_entry in rename_entries:1159            # store to local variables for easier reference1160            from_rel = rename_entry.from_rel1161            from_id = rename_entry.from_id1162            to_rel = rename_entry.to_rel1163            to_id = inv.path2id(to_rel)1164            only_change_inv = False1165            # check the inventory for source and destination1166            if from_id is None:1167                raise errors.BzrMoveFailedError(1168                    from_rel, to_rel, errors.NotVersionedError(path=from_rel))1169            if to_id is not None:1170                allowed = False1171                # allow it with --after but only if dest is newly added1172                if after:1173                    basis = self.basis_tree()1174                    with basis.lock_read():1175                        if not basis.has_id(to_id):1176                            rename_entry.change_id = True1177                            allowed = True1178                if not allowed:1179                    raise errors.BzrMoveFailedError(1180                        from_rel, to_rel,1181                        errors.AlreadyVersionedError(path=to_rel))1182            # try to determine the mode for rename (only change inv or change1183            # inv and file system)1184            if after:1185                if not self.has_filename(to_rel):1186                    raise errors.BzrMoveFailedError(1187                        from_rel, to_rel,1188                        errors.NoSuchFile(1189                            path=to_rel,1190                            extra="New file has not been created yet"))1191                only_change_inv = True1192            elif not self.has_filename(from_rel) and self.has_filename(to_rel):1193                only_change_inv = True1194            elif self.has_filename(from_rel) and not self.has_filename(to_rel):1195                only_change_inv = False1196            elif (not self.case_sensitive and1197                  from_rel.lower() == to_rel.lower() and1198                  self.has_filename(from_rel)):1199                only_change_inv = False1200            else:1201                # something is wrong, so lets determine what exactly1202                if not self.has_filename(from_rel) and \1203                   not self.has_filename(to_rel):1204                    raise errors.BzrRenameFailedError(1205                        from_rel, to_rel,1206                        errors.PathsDoNotExist(paths=(from_rel, to_rel)))1207                else:1208                    raise errors.RenameFailedFilesExist(from_rel, to_rel)1209            rename_entry.only_change_inv = only_change_inv1210        return rename_entries1211    def _move(self, rename_entries):1212        """Moves a list of files.1213        Depending on the value of the flag 'only_change_inv', the1214        file will be moved on the file system or not.1215        """1216        moved = []1217        for entry in rename_entries:1218            try:1219                self._move_entry(entry)1220            except BaseException:1221                self._rollback_move(moved)1222                raise1223            moved.append(entry)1224    def _rollback_move(self, moved):1225        """Try to rollback a previous move in case of an filesystem error."""1226        for entry in moved:1227            try:1228                self._move_entry(WorkingTree._RenameEntry(1229                    entry.to_rel, entry.from_id,1230                    entry.to_tail, entry.to_parent_id, entry.from_rel,1231                    entry.from_tail, entry.from_parent_id,1232                    entry.only_change_inv))1233            except errors.BzrMoveFailedError as e:1234                raise errors.BzrMoveFailedError(1235                    '', '', "Rollback failed."1236                    " The working tree is in an inconsistent state."1237                    " Please consider doing a 'bzr revert'."1238                    " Error message is: %s" % e)1239    def _move_entry(self, entry):1240        inv = self.root_inventory1241        from_rel_abs = self.abspath(entry.from_rel)1242        to_rel_abs = self.abspath(entry.to_rel)1243        if from_rel_abs == to_rel_abs:1244            raise errors.BzrMoveFailedError(entry.from_rel, entry.to_rel,1245                                            "Source and target are identical.")1246        if not entry.only_change_inv:1247            try:1248                osutils.rename(from_rel_abs, to_rel_abs)1249            except OSError as e:1250                raise errors.BzrMoveFailedError(1251                    entry.from_rel, entry.to_rel, e[1])1252        if entry.change_id:1253            to_id = inv.path2id(entry.to_rel)1254            inv.remove_recursive_id(to_id)1255        inv.rename(entry.from_id, entry.to_parent_id, entry.to_tail)1256    def unversion(self, paths):1257        """Remove the paths in paths from the current versioned set.1258        When a path is unversioned, all of its children are automatically1259        unversioned.1260        :param paths: The paths to stop versioning.1261        :raises NoSuchFile: if any path is not currently versioned.1262        """1263        with self.lock_tree_write():1264            file_ids = set()1265            for path in paths:1266                file_id = self._inventory.path2id(path)1267                if file_id is None:1268                    raise errors.NoSuchFile(path, self)1269                file_ids.add(file_id)1270            for file_id in file_ids:1271                if self._inventory.has_id(file_id):1272                    self._inventory.remove_recursive_id(file_id)1273            if len(file_ids):1274                # in the future this should just set a dirty bit to wait for1275                # the final unlock. However, until all methods of workingtree1276                # start with the current in -memory inventory rather than1277                # triggering a read, it is more complex - we need to teach1278                # read_inventory to know when to read, and when to not read1279                # first... and possibly to save first when the in memory one1280                # may be corrupted.  so for now, we just only write it if it is1281                # indeed dirty.  - RBC 200609071282                self._write_inventory(self._inventory)1283    def stored_kind(self, path):1284        """See Tree.stored_kind"""1285        return self._path2ie(path).kind1286    def extras(self):1287        """Yield all unversioned files in this WorkingTree.1288        If there are any unversioned directories then only the directory is1289        returned, not all its children.  But if there are unversioned files1290        under a versioned subdirectory, they are returned.1291        Currently returned depth-first, sorted by name within directories.1292        This is the same order used by 'osutils.walkdirs'.1293        """1294        # TODO: Work from given directory downwards1295        for path, dir_entry in self.iter_entries_by_dir():1296            if dir_entry.kind != 'directory':...terraria_player_xbox_api.py
Source:terraria_player_xbox_api.py  
...264        for x in ['hair_color', 'skin_color', 'eye_color', 'shirt_color', 'under_shirt_color', 'pants_color', 'shoe_color']:265            _write_byte(data.get(x, {}).get('red', 0))266            _write_byte(data.get(x, {}).get('green', 0))267            _write_byte(data.get(x, {}).get('blue', 0))268    def _write_inventory(data):269        def _write_safe_or_piggy_bank(data):270            for x1 in range(0, 5):271                item_code = 0272                for x2 in range(7, -1, -1):273                    try:274                        data[x1][x2]275                        item_code *= 2276                        item_code += 1277                    except:278                        item_code *= 2279                _write_byte(item_code)280            for x1 in range(0, 5):281                for x2 in range(0, 8):282                    try:283                        _write_item(data[x1][x2], swap_stack_and_id=True)284                    except:285                        pass286            print(item_code)287        for x in range(0, 3):288            _write_item(data.get('armor', {}).get(x, {}).get('armor', {}), disable_stack=True)289        for x in range(0, 5):290            _write_item(data.get('accessories', {}).get(x, {}).get('accessory', {}), disable_stack=True)291        for x in range(0, 3):292            _write_item(data.get('armor', {}).get(x, {}).get('vanity_armor', {}), disable_stack=True)293        for x in range(0, 5):294            _write_item(data.get('accessories', {}).get(x, {}).get('vanity_accessory', {}), disable_stack=True)295        _write_byte(8)296        for x in range(0, 3):297            _write_item(data.get('armor', {}).get(x, {}).get('dye', {}), disable_stack=True, disable_prefix=True)298        for x in range(0, 5):299            _write_item(data.get('accessories', {}).get(x, {}).get('dye', {}), disable_stack=True, disable_prefix=True)300        for x1 in range(0, 4):301            for x2 in range(0, 10):302                _write_item(data.get('inventory', {}).get(x1, {}).get(x2, {}))303        for x in range(0, 4):304            _write_item(data.get('coins', {}).get(x, {}))305        for x in range(0, 4):306            _write_item(data.get('ammo', {}).get(x, {}))307        _write_byte(5)308        _write_safe_or_piggy_bank(data.get('piggy_bank', {}))309        _write_byte(5)310        _write_safe_or_piggy_bank(data.get('safe', {}))311    def _write_footer(data):312        nonlocal out_data313        _write_byte(len(data.get('buffs', [])))314        for x in data.get('buffs', []):315            _write_byte(x.get('id', 0))316            _write_int(x.get('time', 0))317        out_data += b'\xff\xff\xff\xff\xbd\x01\x0c\x02\x80\x80@\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \318                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \319                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \320                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \321                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \322                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \323                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \324                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \325                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \326                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \327                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \328                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \329                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \330                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \331                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \332                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \333                    b'\x00\x00\xb9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \334                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \335                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \336                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \337                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \338                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \339                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \340                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \341                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \342                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \343                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \344                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \345                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \346                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00+\x00\x00\xa0\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \347                    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'348        for x in data.get('spawn_points', []):349            _write_short(x.get('x'), 0)350            _write_short(x.get('y'), 0)351            _write_int(x.get('world_id'), 0)352            _write_string(x.get('world_name'), "")353        _write_short(-1)354        out_data += b'\x79\x99\x55\x83'355        _write_int(data.get('angler_quests_finished', 0))356        _write_short(0)357    _write_header(player.get('header', {}))358    _write_inventory(player.get('items', {}))359    _write_footer(player.get('footer', {}))...city.py
Source:city.py  
...18        return self.name19    def tick(self, time, period):20        for actor in self.actors:21            actor.tick(self, time, period)22        self._write_inventory(time)23    def _write_inventory(self, space_time):24        stock = dict([(item,self.stock(item)) for item in self.inventory.header])25        stock["time"] = space_time26        self.inventory.append( stock )27    def reserve(self, building, volume):28        structs = self._buildings(building)29        if not structs:30            raise OccupancyException("No {1} storage available in {0}", self, building)31        structs[0].reserve(volume)  # TODO: spread over stores32    33    def _store(self, item):34        store = self._buildings(item.specification.storage)35        if not store:36            raise StorageException("No store for item {1} in {0}", self, item)37        store[0].store(item)    # TODO: spread over stores...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!!
