Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._root = root
self._parents = {}
self._buildParents(None, [root])
self._real_open = io.open
io.open = self._open
self._real_listdir = pathlib._NormalAccessor.listdir
pathlib._NormalAccessor.listdir = self._listdir
self._real_stat = pathlib._NormalAccessor.stat
pathlib._NormalAccessor.stat = self._stat
self._real_isdir = pathlib.Path.is_dir
pathlib.Path.is_dir = lambda path: OsPatcher._is_dir(self, path)
stat_mode_predicate: types.FunctionType,
pathlib_path_predicate: Callable[[pathlib.Path], bool]):
self.type_argument = type_argument
self.pathlib_path_predicate = pathlib_path_predicate
self.stat_mode_predicate = stat_mode_predicate
self.description = name.singular
self.name = name
TYPE_INFO = {
FileType.REGULAR: FileTypeInfo('file',
NameWithGenderWithFormatting(name.a_name_with_plural_s('regular file')),
stat.S_ISREG, pathlib.Path.is_file),
FileType.DIRECTORY: FileTypeInfo('dir',
NameWithGenderWithFormatting(name.NameWithGender('a', 'directory', 'directories')),
stat.S_ISDIR, pathlib.Path.is_dir),
FileType.SYMLINK: FileTypeInfo('symlink',
NameWithGenderWithFormatting(name.a_name_with_plural_s('symbolic link')),
stat.S_ISLNK, pathlib.Path.is_symlink),
}
SYNTAX_TOKEN_2_FILE_TYPE = dict([(info.type_argument, ft) for ft, info in TYPE_INFO.items()])
def lookup_file_type(stat_result) -> Optional[FileType]:
"""
:return: None iff the type is an unknown type
"""
for file_type in TYPE_INFO:
if TYPE_INFO[file_type].stat_mode_predicate(stat_result.st_mode):
return file_type
return None
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i', '--input', dest='input',
help='folder or file for scripts', required=False)
parser.add_argument('--debug', dest='debug', default=False,
help='Output additional debug information for the code', action='store_true')
args = parser.parse_args()
if not sys.stdin.isatty() and not os.name == 'nt':
# TODO fix stdin for windows
src = sys.stdin.read()
print(compile_src(src, args.debug))
elif args.input:
a = Path(args.input)
if Path.is_dir(a):
for child in a.iterdir():
if child.suffix == '.py':
compile_file(child, args.debug)
elif a.suffix == '.py':
compile_file(a, args.debug)
else:
print("Nothing on stdin and no --input given")
sys.exit(1)
parser = initialize_parser()
args = parser.parse_args(sys.argv[1:])
if not args.pudl_in:
args.pudl_in = args.pudl_dir
if not args.pudl_out:
args.pudl_out = args.pudl_dir
# Given pudl_in and pudl_out, create a user settings file.
pudl_in = pathlib.Path(args.pudl_in).expanduser().resolve()
if not pathlib.Path.is_dir(pudl_in):
raise FileNotFoundError(
f"Directory not found: {pudl_in}")
pudl_out = pathlib.Path(args.pudl_out).expanduser().resolve()
if not pathlib.Path.is_dir(pudl_out):
raise FileNotFoundError(
f"Directory not found: {pudl_out}")
pudl_defaults_file = pathlib.Path.home() / ".pudl.yml"
# Only print out this information and do the defaults setting if that has
# been explicitly requested, or there are no defaults already:
if not pudl_defaults_file.exists() or args.clobber is True:
logger.info(f"Setting default pudl_in: {pudl_in}")
logger.info(f"Setting default pudl_out: {pudl_out}")
logger.info(f"You can update these default values by editing "
f"{pudl_defaults_file}")
pudl.workspace.setup.set_defaults(pudl_in, pudl_out,
clobber=args.clobber)
pudl.workspace.setup.init(pudl_in=pudl_in,
# Display logged output from the PUDL package:
logger = logging.getLogger(pudl.__name__)
log_format = '%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s'
coloredlogs.install(fmt=log_format, level='INFO', logger=logger)
parser = initialize_parser()
args = parser.parse_args(sys.argv[1:])
if not args.pudl_in:
args.pudl_in = args.pudl_dir
if not args.pudl_out:
args.pudl_out = args.pudl_dir
# Given pudl_in and pudl_out, create a user settings file.
pudl_in = pathlib.Path(args.pudl_in).expanduser().resolve()
if not pathlib.Path.is_dir(pudl_in):
raise FileNotFoundError(
f"Directory not found: {pudl_in}")
pudl_out = pathlib.Path(args.pudl_out).expanduser().resolve()
if not pathlib.Path.is_dir(pudl_out):
raise FileNotFoundError(
f"Directory not found: {pudl_out}")
pudl_defaults_file = pathlib.Path.home() / ".pudl.yml"
# Only print out this information and do the defaults setting if that has
# been explicitly requested, or there are no defaults already:
if not pudl_defaults_file.exists() or args.clobber is True:
logger.info(f"Setting default pudl_in: {pudl_in}")
logger.info(f"Setting default pudl_out: {pudl_out}")
logger.info(f"You can update these default values by editing "
async def get_path(self, path):
"""
Resolves a string path from a GET request to a path on the file system
Does safety checks to make sure they're not getting something forbidden
:param path: String path to reolve
:return: Path object resolved, or an int representing status code
"""
# any hardcoded redirects here
if path == "/":
path = "/index"
path = self.app["settings"]["base_path"] / path.lstrip("/")
# Now do logic to find the desired file. If found, return that path. If not, return an error code
if pathlib.Path.is_file(path):
return path
elif pathlib.Path.is_dir(path):
# Look for an index.html, if that's missing, look for [dirname].html, if that's missing 404
if (path / 'index.html').is_file():
return path / 'index.html'
elif (path / (str(path.name) + ".html")).is_file():
return path / (str(path.name) + ".html")
else:
return 404
elif path.with_suffix(".html").is_file():
return path.with_suffix(".html")
else:
return 404
def list_sub_folders(path):
'''List all the immediate sub-folders of the folder at `path`.'''
path = pathlib.Path(path)
assert path.is_dir()
return tuple(filter(pathlib.Path.is_dir, path.glob('*')))
streams = (Bits((x ^ y) >> p & 1
for x, y in zip(samples[::2], samples[1::2]))
for p in range(16, 24))
if any(s.find(MAGIC) for s in streams):
print('\x1b[1;31m MQA syncword present. [{}] \x1b[0m'.format(str(path)))
else:
print('\x1b[1;32m Didn\'t find an MQA syncword. [{}] \x1b[0m'.format(path.parts[-1]))
if __name__ == '__main__':
args = sys.argv[1:]
flacpaths = []
for path in args:
path = Path(path)
if Path.is_dir(path):
flacpaths += sorted(Path(path).glob('**/*.flac'))
elif str(path).endswith('.flac') and path.is_file():
flacpaths.append(path)
print('\x1b[1;33m Found {} flac file(s). Decoding now... \x1b[0m'.format(len(flacpaths)))
for fpath in flacpaths:
try:
main(fpath)
except Exception as ex:
print(ex)
output += f'{line}\n'
print(output)
fd_w.write(output)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i', '--input', dest='input',
help='folder or file for scripts')
parser.add_argument('--debug', dest='debug', default=False,
help='Output additional debug information for the code', action='store_true')
args = parser.parse_args()
a = Path(args.input)
if Path.is_dir(a):
for child in a.iterdir():
if child.suffix == '.py':
compile_file(child, args.debug)
elif a.suffix == '.py':
compile_file(a, args.debug)