예제 #1
0
def test_non_ascii():
    from clldutils.path import Path, path_component, as_unicode

    assert path_component(b'abc') == 'abc'

    p = Path(path_component('äöü')).joinpath(path_component('äöü'))
    assert isinstance(as_unicode(p), text_type)
    assert isinstance(as_unicode(p.name), text_type)
예제 #2
0
파일: cli.py 프로젝트: lingpy/lingpy3
 def __call__(self, args):
     opargs, opkw = _args_kw(args.name)
     readargs, readkw = _args_kw(args.object)
     oname, if_, input_ = readargs
     input_ = text_type(input_)
     if Path(path_component(input_)).exists():
         # We heuristically interpret the input as filename, if a file with that name
         # exists.
         input_ = Path(path_component(input_))
     res = run(
         opargs[0],
         read(oname, getattr(interfaces, if_), input_, **readkw),
         **opkw)
     p = jsonlib.dump(res, outdir=Path(args.output))
     print('Result written to <%s>' % as_unicode(p))
     return p
예제 #3
0
파일: util.py 프로젝트: LinguList/lingpy
def _str_path(path, mkdir=False):
    """Get a file-system path as text_type, suitable for passing into io.open.

    Parameters
    ----------
    path : {text_type, Path}
        A fs path either as Path instance or as text_type.
    mkdir : bool (default=False)
        If True, create the directories within the path.

    Returns
    -------
    path : text_type
        The path as text_type.
    """
    res = Path(path_component(path))
    if mkdir and res.parent and not res.parent.exists():
        res.parent.mkdir(parents=True)
    return res.as_posix()
예제 #4
0
파일: util.py 프로젝트: tjade273/lingpy
def _str_path(path, mkdir=False):
    """Get a file-system path as text_type, suitable for passing into io.open.

    Parameters
    ----------
    path : {text_type, Path}
        A fs path either as Path instance or as text_type.
    mkdir : bool (default=False)
        If True, create the directories within the path.

    Returns
    -------
    path : text_type
        The path as text_type.
    """
    res = Path(path_component(path))
    if mkdir and res.parent and not res.parent.exists():
        res.parent.mkdir(parents=True)
    return res.as_posix()
예제 #5
0
def write(name, obj, _outdir=None, _stem=None, **kw):
    adapter = get_adapter(obj, interfaces.IWriter, name=name)
    outfile = _outdir.joinpath(path_component('{0}.{1}'.format(_stem, name)))
    adapter.write(outfile, **kw)
    file_written(outfile)
    return outfile
예제 #6
0
파일: test_path.py 프로젝트: clld/clldutils
    def test_non_ascii(self):
        from clldutils.path import Path, path_component, as_unicode

        p = Path(path_component('äöü')).joinpath(path_component('äöü'))
        self.assertIsInstance(as_unicode(p), text_type)
        self.assertIsInstance(as_unicode(p.name), text_type)
예제 #7
0
파일: jsonlib.py 프로젝트: lingpy/lingpy3
def path_from_checksum(checksum, outdir=None):
    return (outdir
            or Path('.')).joinpath(path_component('{0}.json'.format(checksum)))
예제 #8
0
파일: cache.py 프로젝트: xrotwang/lingpy3
 def _path(self, key):
     return self._dir.joinpath(path_component(key))