Python path.Path() Examples
The following are 30
code examples of path.Path().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
path
, or try the search function
.
Example #1
Source File: test_session.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_6_regenerate(self): self.getPage('/testStr') # grab the cookie ID id1 = self.cookies[0][1].split(';', 1)[0].split('=', 1)[1] self.getPage('/regen') assert self.body == b'logged in' id2 = self.cookies[0][1].split(';', 1)[0].split('=', 1)[1] assert id1 != id2 self.getPage('/testStr') # grab the cookie ID id1 = self.cookies[0][1].split(';', 1)[0].split('=', 1)[1] self.getPage('/testStr', headers=[ ('Cookie', 'session_id=maliciousid; ' 'expires=Sat, 27 Oct 2017 04:18:28 GMT; Path=/;')]) id2 = self.cookies[0][1].split(';', 1)[0].split('=', 1)[1] assert id1 != id2 assert id2 != 'maliciousid'
Example #2
Source File: make_readme.py From pytablereader with MIT License | 6 votes |
def write_examples(maker): maker.set_indent_level(0) maker.write_chapter("Examples") examples_root = Path("pages").joinpath("examples") maker.inc_indent_level() maker.write_chapter("Load a CSV table") maker.write_file(examples_root.joinpath("load_csv.txt")) maker.write_chapter("Get loaded table data as pandas.DataFrame instance") maker.write_file(examples_root.joinpath("as_dataframe.txt")) maker.write_chapter("For more information") maker.write_lines( [ "More examples are available at ", "https://{:s}.rtfd.io/en/latest/pages/examples/index.html".format(PROJECT_NAME), ] )
Example #3
Source File: static_opaque_analysis.py From idasec with GNU Lesser General Public License v2.1 | 6 votes |
def export_result(self, _): filename = QtWidgets.QFileDialog.getSaveFileName()[0] filepath = Path(filename) if not filepath.exists() and filepath != '': report = filepath if filepath.ext == ".html" else filepath.dirname() / filepath.namebase+".html" raw = filepath.dirname() / filepath.namebase+".csv" html_file = filepath.dirname() / filepath.namebase+".html" html_file.write_bytes(self.report.generate()) report.write_text(self.report.generate()) f = raw.open("w") for addr, infos in self.results.iteritems(): f.write_bytes(u"0x%x,%s,%d,%s,0x%x,0x%x\n" % (addr, to_status_name(infos.status), infos.k, infos.dependency, infos.alive_branch, infos.dead_branch)) f.close() self.log("[info]", "Export done in %s and %s" % (report.basename(), raw.basename())) else: self.log("[error]", "File already exists.. (do not save)")
Example #4
Source File: TraceWidget.py From idasec with GNU Lesser General Public License v2.1 | 6 votes |
def dump_trace(self): filename = QtWidgets.QFileDialog.getSaveFileName()[0] filepath = Path(filename) if not filepath.exists() and filepath != '': try: index = self.traces_tab.currentIndex() trace = self.core.traces[self.id_map[index]] f = filepath.open("w") for line in trace.to_string_generator(): f.write(line+"\n") f.close() print "Writing done" except KeyError: print "Trace not found" else: print "File already exists.. (do not dump)"
Example #5
Source File: test_csv_reader.py From pytablereader with MIT License | 6 votes |
def test_normal_multibyte( self, tmpdir, test_id, table_text, filename, encoding, headers, expected ): file_path = Path(str(tmpdir.join(filename))) file_path.parent.makedirs_p() with open(file_path, "w", encoding=encoding) as f: f.write(table_text) loader = ptr.CsvTableFileLoader(file_path) loader.headers = headers for tabledata in loader.load(): print("test-id={}".format(test_id)) print(dumps_tabledata(tabledata)) assert tabledata.in_tabledata_list(expected)
Example #6
Source File: transforms.py From matplotlib-4-abaqus with MIT License | 6 votes |
def update_from_data_xy(self, xy, ignore=None, updatex=True, updatey=True): """ Update the bounds of the :class:`Bbox` based on the passed in data. After updating, the bounds will have positive *width* and *height*; *x0* and *y0* will be the minimal values. *xy*: a numpy array of 2D points *ignore*: - when True, ignore the existing bounds of the :class:`Bbox`. - when False, include the existing bounds of the :class:`Bbox`. - when None, use the last value passed to :meth:`ignore`. *updatex*: when True, update the x values *updatey*: when True, update the y values """ if len(xy) == 0: return path = Path(xy) self.update_from_path(path, ignore=ignore, updatex=updatex, updatey=updatey)
Example #7
Source File: _common.py From sqlitebiter with MIT License | 6 votes |
def logging_success( self, source: Union[str, Path], table_name: str, is_create_table: bool ) -> None: table_schema = self.__schema_extractor.fetch_table_schema(table_name.strip()) self.__result_counter.inc_success(is_create_table) self.__logger.info( "convert '{source:s}' to '{table_info:s}' table".format( source=cyan(source), table_info=bright( green( table_schema.dumps( output_format="text", verbosity_level=self.__verbosity_level ) ) ), ) )
Example #8
Source File: do_waldofication_of_sql.py From edx2bigquery with GNU General Public License v2.0 | 6 votes |
def getCourseDir(cid, dtstr, basedir='', known_course_ids=None, is_edge=False): cdir = path(basedir) if is_edge: cdir = cdir / "EDGE" if not cdir.exists(): os.mkdir(cdir) else: if not cid in known_course_ids or []: cdir = cdir / "UNKNOWN" if not cdir.exists(): os.mkdir(cdir) cdir = cdir / (cid.replace('/','-')) if not cdir.exists(): os.mkdir(cdir) cdir2 = cdir / dtstr if not cdir2.exists(): os.mkdir(cdir2) return cdir2
Example #9
Source File: make_grades_persistent.py From edx2bigquery with GNU General Public License v2.0 | 6 votes |
def cleanup_rows_from_grade_persistent(csvfn, tempfn, field_to_fix="passed_timestamp"): """ Removes the null values from grades_persistentcoursegrade.csv.gz. The function also fixes course ids by changing them from their edX URL format to their usual format. For instance, course-v1:MITx+STL.162x+2T2017 should be MITx/STL.162x/2T2017. This operation permanently modifies the CSV. :param csvfn: The path of the csv.gz to be modified :param tempfn: The path of the temporary csv.gz :type csvfn: str :type tempfn: str """ with gzip.open(csvfn, "r") as open_csv: csv_dict = csv.DictReader(open_csv) with gzip.open(tempfn, "w+") as write_csv_file: write_csv = csv.DictWriter(write_csv_file, fieldnames=csv_dict.fieldnames) write_csv.writeheader() for row in csv_dict: row_dict = remove_nulls_from_row(row, field_to_fix) row_dict = fix_course_ids(row_dict) write_csv.writerow(row_dict) os.rename(tempfn, csvfn)
Example #10
Source File: transforms.py From Computable with MIT License | 6 votes |
def update_from_data_xy(self, xy, ignore=None, updatex=True, updatey=True): """ Update the bounds of the :class:`Bbox` based on the passed in data. After updating, the bounds will have positive *width* and *height*; *x0* and *y0* will be the minimal values. *xy*: a numpy array of 2D points *ignore*: - when True, ignore the existing bounds of the :class:`Bbox`. - when False, include the existing bounds of the :class:`Bbox`. - when None, use the last value passed to :meth:`ignore`. *updatex*: when True, update the x values *updatey*: when True, update the y values """ if len(xy) == 0: return path = Path(xy) self.update_from_path(path, ignore=ignore, updatex=updatex, updatey=updatey)
Example #11
Source File: manager.py From xqueue-watcher with GNU Affero General Public License v3.0 | 6 votes |
def configure_from_directory(self, directory): """ Load configuration files from the config_root and one or more queue configurations from a conf.d directory relative to the config_root """ directory = Path(directory) log_config = directory / 'logging.json' if log_config.exists(): with open(log_config) as config: logging.config.dictConfig(json.load(config)) else: logging.basicConfig(level="DEBUG") self.log = logging.getLogger('xqueue_watcher.manager') app_config_path = directory / 'xqwatcher.json' self.manager_config = get_manager_config_values(app_config_path) confd = directory / 'conf.d' for watcher in confd.files('*.json'): with open(watcher) as queue_config: self.configure(json.load(queue_config))
Example #12
Source File: pose_evaluation_utils.py From SfmLearner-Pytorch with MIT License | 6 votes |
def read_scene_data(data_root, sequence_set, seq_length=3, step=1): data_root = Path(data_root) im_sequences = [] poses_sequences = [] indices_sequences = [] demi_length = (seq_length - 1) // 2 shift_range = np.array([step*i for i in range(-demi_length, demi_length + 1)]).reshape(1, -1) sequences = set() for seq in sequence_set: corresponding_dirs = set((data_root/'sequences').dirs(seq)) sequences = sequences | corresponding_dirs print('getting test metadata for theses sequences : {}'.format(sequences)) for sequence in tqdm(sequences): poses = np.genfromtxt(data_root/'poses'/'{}.txt'.format(sequence.name)).astype(np.float64).reshape(-1, 3, 4) imgs = sorted((sequence/'image_2').files('*.png')) # construct 5-snippet sequences tgt_indices = np.arange(demi_length, len(imgs) - demi_length).reshape(-1, 1) snippet_indices = shift_range + tgt_indices im_sequences.append(imgs) poses_sequences.append(poses) indices_sequences.append(snippet_indices) return im_sequences, poses_sequences, indices_sequences
Example #13
Source File: transforms.py From matplotlib-4-abaqus with MIT License | 5 votes |
def transform_path_non_affine(self, path): """ Returns a path, transformed only by the non-affine part of this transform. *path*: a :class:`~matplotlib.path.Path` instance. ``transform_path(path)`` is equivalent to ``transform_path_affine(transform_path_non_affine(values))``. """ return Path(self.transform_non_affine(path.vertices), path.codes, path._interpolation_steps)
Example #14
Source File: transforms.py From matplotlib-4-abaqus with MIT License | 5 votes |
def transform_path_affine(self, path): """ Returns a path, transformed only by the affine part of this transform. *path*: a :class:`~matplotlib.path.Path` instance. ``transform_path(path)`` is equivalent to ``transform_path_affine(transform_path_non_affine(values))``. """ return self.get_affine().transform_path_affine(path)
Example #15
Source File: transforms.py From matplotlib-4-abaqus with MIT License | 5 votes |
def transform_path(self, path): """ Returns a transformed path. *path*: a :class:`~matplotlib.path.Path` instance. In some cases, this transform may insert curves into the path that began as line segments. """ return self.transform_path_affine(self.transform_path_non_affine(path))
Example #16
Source File: transforms.py From Computable with MIT License | 5 votes |
def transform_path_non_affine(self, path): """ Returns a path, transformed only by the non-affine part of this transform. *path*: a :class:`~matplotlib.path.Path` instance. ``transform_path(path)`` is equivalent to ``transform_path_affine(transform_path_non_affine(values))``. """ return Path(self.transform_non_affine(path.vertices), path.codes, path._interpolation_steps)
Example #17
Source File: transforms.py From Computable with MIT License | 5 votes |
def transform_path_affine(self, path): """ Returns a path, transformed only by the affine part of this transform. *path*: a :class:`~matplotlib.path.Path` instance. ``transform_path(path)`` is equivalent to ``transform_path_affine(transform_path_non_affine(values))``. """ return self.get_affine().transform_path_affine(path)
Example #18
Source File: transforms.py From Computable with MIT License | 5 votes |
def transform_path(self, path): """ Returns a transformed path. *path*: a :class:`~matplotlib.path.Path` instance. In some cases, this transform may insert curves into the path that began as line segments. """ return self.transform_path_affine(self.transform_path_non_affine(path))
Example #19
Source File: lines.py From matplotlib-4-abaqus with MIT License | 5 votes |
def _draw_steps_mid(self, renderer, gc, path, trans): vertices = self._xy steps = ma.zeros((2 * len(vertices), 2), np.float_) steps[1:-1:2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0]) steps[2::2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0]) steps[0, 0] = vertices[0, 0] steps[-1, 0] = vertices[-1, 0] steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:, 1] path = Path(steps) path = path.transformed(self.get_transform()) self._lineFunc(renderer, gc, path, IdentityTransform())
Example #20
Source File: lines.py From matplotlib-4-abaqus with MIT License | 5 votes |
def _draw_steps_post(self, renderer, gc, path, trans): vertices = self._xy steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_) steps[::2, 0], steps[1:-1:2, 0] = vertices[:, 0], vertices[1:, 0] steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:-1, 1] path = Path(steps) path = path.transformed(self.get_transform()) self._lineFunc(renderer, gc, path, IdentityTransform())
Example #21
Source File: transforms.py From Computable with MIT License | 5 votes |
def update_from_path(self, path, ignore=None, updatex=True, updatey=True): """ Update the bounds of the :class:`Bbox` based on the passed in data. After updating, the bounds will have positive *width* and *height*; *x0* and *y0* will be the minimal values. *path*: a :class:`~matplotlib.path.Path` instance *ignore*: - when True, ignore the existing bounds of the :class:`Bbox`. - when False, include the existing bounds of the :class:`Bbox`. - when None, use the last value passed to :meth:`ignore`. *updatex*: when True, update the x values *updatey*: when True, update the y values """ if ignore is None: ignore = self._ignore if path.vertices.size == 0: return points, minpos, changed = update_path_extents( path, None, self._points, self._minpos, ignore) if changed: self.invalidate() if updatex: self._points[:, 0] = points[:, 0] self._minpos[0] = minpos[0] if updatey: self._points[:, 1] = points[:, 1] self._minpos[1] = minpos[1]
Example #22
Source File: test_manager.py From xqueue-watcher with GNU Affero General Public License v3.0 | 5 votes |
def test_main_with_errors(self): stderr = sys.stderr sys.stderr = StringIO() self.assertRaises(SystemExit, manager.main, []) sys.stderr.seek(0) err_msg = sys.stderr.read() self.assertIn('usage: xqueue_watcher [-h] -d CONFIG_ROOT', err_msg) self.assertIn('-d/--config_root', err_msg) self.assertIn('required', err_msg) sys.stderr = stderr mydir = Path(__file__).dirname() args = ['-d', mydir / "fixtures/config"] self.assertEqual(manager.main(args), 0)
Example #23
Source File: grader.py From xqueue-watcher with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, grader_root='/tmp/', fork_per_item=True, logger_name=__name__): """ grader_root = root path to graders fork_per_item = fork a process for every request logger_name = name of logger """ self.log = logging.getLogger(logger_name) self.grader_root = Path(grader_root) self.fork_per_item = fork_per_item
Example #24
Source File: interface.py From pytablereader with MIT License | 5 votes |
def _get_filename_tablename_mapping(self): filename = "" if all([self.source_type == SourceType.FILE, typepy.is_not_null_string(self.source)]): filename = path.Path(self.source).stem return (tnt.FILENAME, filename)
Example #25
Source File: jailedgrader.py From xqueue-watcher with GNU Affero General Public License v3.0 | 5 votes |
def _run(self, grader_path, thecode, seed): files = SUPPORT_FILES + [grader_path] if self.locale_dir.exists(): files.append(self.locale_dir) extra_files = [('submission.py', thecode.encode('utf-8'))] argv = ["-m", "grader_support.run", Path(grader_path).basename(), 'submission.py', seed] r = codejail.jail_code.jail_code(self.codejail_python, files=files, extra_files=extra_files, argv=argv) return r
Example #26
Source File: jailedgrader.py From xqueue-watcher with GNU Affero General Public License v3.0 | 5 votes |
def path_to_six(): """ Return the full path to six.py """ if any(six.__file__.endswith(suffix) for suffix in ('.pyc', '.pyo')): # __file__ points to the compiled bytecode in python 2 return Path(six.__file__[:-1]) else: # __file__ points to the .py file in python 3 return Path(six.__file__)
Example #27
Source File: depth_evaluation_utils.py From SfmLearner-Pytorch with MIT License | 5 votes |
def read_scene_data(data_root, test_list, seq_length=3, step=1, use_gps=True): data_root = Path(data_root) gt_files = [] calib_dirs = [] im_files = [] cams = [] displacements = [] demi_length = (seq_length - 1) // 2 shift_range = step * np.arange(-demi_length, demi_length + 1) print('getting test metadata ... ') for sample in tqdm(test_list): tgt_img_path = data_root/sample date, scene, cam_id, _, index = sample[:-4].split('/') scene_length = len(tgt_img_path.parent.files('*.png')) ref_indices = shift_range + np.clip(int(index), step*demi_length, scene_length - step*demi_length - 1) ref_imgs_path = [tgt_img_path.dirname()/'{:010d}.png'.format(i) for i in ref_indices] vel_path = data_root/date/scene/'velodyne_points'/'data'/'{}.bin'.format(index[:10]) if tgt_img_path.isfile(): gt_files.append(vel_path) calib_dirs.append(data_root/date) im_files.append([tgt_img_path,ref_imgs_path]) cams.append(int(cam_id[-2:])) args = (data_root, date, scene, ref_indices, demi_length) if use_gps: displacements.append(get_displacements_from_GPS(*args)) else: displacements.append(get_displacements_from_speed(*args)) else: print('{} missing'.format(tgt_img_path)) return calib_dirs, gt_files, im_files, displacements, cams
Example #28
Source File: test_csv_reader.py From pytablereader with MIT License | 5 votes |
def test_normal(self, tmpdir, test_id, table_text, filename, headers, expected): file_path = Path(str(tmpdir.join(filename))) file_path.parent.makedirs_p() with open(file_path, "w", encoding="utf-8") as f: f.write(table_text) loader = ptr.CsvTableFileLoader(file_path) loader.headers = headers for tabledata in loader.load(): print("test-id={}".format(test_id)) print(dumps_tabledata(tabledata)) assert tabledata.in_tabledata_list(expected)
Example #29
Source File: sequence_folders.py From SfmLearner-Pytorch with MIT License | 5 votes |
def __init__(self, root, seed=None, train=True, sequence_length=3, transform=None, target_transform=None): np.random.seed(seed) random.seed(seed) self.root = Path(root) scene_list_path = self.root/'train.txt' if train else self.root/'val.txt' self.scenes = [self.root/folder[:-1] for folder in open(scene_list_path)] self.transform = transform self.crawl_folders(sequence_length)
Example #30
Source File: transforms.py From Computable with MIT License | 5 votes |
def _revalidate(self): # only recompute if the invalidation includes the non_affine part of the transform if ((self._invalid & self.INVALID_NON_AFFINE == self.INVALID_NON_AFFINE) or self._transformed_path is None): self._transformed_path = \ self._transform.transform_path_non_affine(self._path) self._transformed_points = \ Path(self._transform.transform_non_affine(self._path.vertices), None, self._path._interpolation_steps) self._invalid = 0