本文整理汇总了Python中abl.vpath.base.URI类的典型用法代码示例。如果您正苦于以下问题:Python URI类的具体用法?Python URI怎么用?Python URI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_split_windows
def test_split_windows(self):
path = URI(r'C:\some\path\on\windows', sep='\\')
pth, tail = path.split()
self.assertEqual(pth.uri, 'file:///C/some/path/on')
self.assertEqual(pth.path, r'C:\some\path\on')
self.assertEqual(pth, URI(r'C:\some\path\on', sep='\\'))
self.assertEqual(tail, 'windows')
示例2: test_dirname
def test_dirname(self):
pth = URI("/this/is/a/path")
self.assertEqual(pth.dirname(), URI("/this/is/a"))
self.assertEqual(pth.dirname(level=2), URI("/this/is"))
self.assertEqual(pth.dirname(level=3), URI("/this"))
self.assertEqual(pth.dirname(level=4), URI("/"))
self.assertEqual(pth.dirname(level=5), URI("/"))
示例3: test_write_two_files
def test_write_two_files(self):
foo = URI('zip://((%s))/foo.txt' % self.zip_uri)
with foo.open('wb') as fd:
fd.write(b'bar')
bar = URI('zip://((%s))/bar.txt' % self.zip_uri)
with bar.open('wb') as fd:
fd.write(b'foo')
示例4: TestAdvancedZip
class TestAdvancedZip(ZipTestCase):
def setUp(self):
super(TestAdvancedZip, self).setUp()
self.zip_path = URI('memory:///file.zip')
zip_handle = self.zip_path.open('wb')
try:
self.fp_zip = ZipFile(zip_handle, 'w')
self.fp_zip.writestr('/dir1/foo.txt', 'bar')
self.fp_zip.writestr('/dir1/bar.txt', 'bar')
self.fp_zip.writestr('/bar.txt', 'bar')
self.fp_zip.close()
finally:
zip_handle.close()
def tearDown(self):
self.zip_path.remove()
def test_walk(self):
root = URI('zip://((%s))/' % self.zip_path.uri)
self.assertEqual(len(root.listdir()), 2)
rlist = []
for base, dirs, files in root.walk():
rlist.append((base, dirs, files))
self.assertEqual(rlist,
[(root, ['dir1'], ['bar.txt']),
((root / 'dir1'), [], ['bar.txt', 'foo.txt'])])
示例5: TestWritingZip
class TestWritingZip(ZipTestCase):
def setUp(self):
super(TestWritingZip, self).setUp()
self.zip_uri = 'file://./file.zip'
self.zip_path = URI(self.zip_uri)
def tearDown(self):
# reset the connection registry, otherwise the zip file cannot
# be deleted on windows since it is still opened by the
# backend
CONNECTION_REGISTRY.cleanup(force=True)
if self.zip_path.exists():
self.zip_path.remove()
def test_write_file_to_non_existing_zip(self):
foo = URI('zip://((%s))/foo.txt' % self.zip_uri)
with foo.open('wb') as fd:
fd.write(b'bar')
def test_write_file_to_non_existing_zip_2(self):
foo = URI('zip://((%s))/deeper/foo.txt' % self.zip_uri)
with foo.open('wb') as fd:
fd.write(b'bar')
def test_write_two_files(self):
foo = URI('zip://((%s))/foo.txt' % self.zip_uri)
with foo.open('wb') as fd:
fd.write(b'bar')
bar = URI('zip://((%s))/bar.txt' % self.zip_uri)
with bar.open('wb') as fd:
fd.write(b'foo')
示例6: test_walk
def test_walk(self):
root = URI('zip://((%s))/' % self.zip_path.uri)
self.assertEqual(len(root.listdir()), 2)
rlist = []
for base, dirs, files in root.walk():
rlist.append((base, dirs, files))
self.assertEqual(rlist,
[(root, ['dir1'], ['bar.txt']),
((root / 'dir1'), [], ['bar.txt', 'foo.txt'])])
示例7: test_globbing_by_suffix
def test_globbing_by_suffix(self):
base = URI("memory:///")
a = base / "a.foo"
b = base / "b.bar"
for f in [a, b]:
with f.open("w") as outf:
outf.write("foo")
self.assertEqual([a], base.glob("a.*"))
示例8: test_split
def test_split(self):
local_path = URI('/some/long/dir/structure')
pth, tail = local_path.split()
self.assertEqual(pth, URI('/some/long/dir'))
self.assertEqual(tail, 'structure')
local_path = URI('somedir')
pth, tail = local_path.split()
self.assertEqual(pth, URI('.'))
self.assertEqual(tail, 'somedir')
示例9: test_setting_mode
def test_setting_mode(self):
# setting the permission flags are not supported on windows
if sys.platform != "win32":
p = URI("test.txt")
mode = p.info().mode
new_mode = mode | stat.S_IXUSR
p.info(dict(mode=new_mode))
self.assertEqual(
p.info().mode,
new_mode,
)
示例10: TestReadingZip
class TestReadingZip(ZipTestCase):
def setUp(self):
super(TestReadingZip, self).setUp()
self.zip_path = URI('memory:///file.zip')
zip_handle = self.zip_path.open('wb')
try:
self.fp_zip = ZipFile(zip_handle, 'w')
self.fp_zip.writestr('/foo.txt', 'bar')
self.fp_zip.close()
finally:
zip_handle.close()
def tearDown(self):
if self.zip_path.exists():
self.zip_path.remove()
def test_read_a_file(self):
p = URI('zip://((memory:///file.zip))/foo.txt')
with p.open('rb') as fd:
self.assertEqual(fd.read(), b'bar')
def test_write_a_file(self):
p = URI('zip://((memory:///file.zip))/bar.txt')
with p.open('wb') as fd:
fd.write(b'foo')
with p.open() as fd:
self.assertEqual(fd.read(), b'foo')
def test_exists(self):
p = URI('zip://((memory:///file.zip))/foo.txt')
with p.open('wb') as fd:
fd.write(b'foo')
self.assertTrue(p.exists())
def test_isfile(self):
p = URI('zip://((memory:///file.zip))/foo.txt')
with p.open('wb') as fd:
fd.write(b'foo')
self.assertTrue(p.isfile())
def test_isdir(self):
dir_path = URI('zip://((memory:///file.zip))/somedir')
p = dir_path / 'foo.txt'
with p.open('wb') as fd:
fd.write(b'foo')
self.assertTrue(dir_path.isdir())
def test_path(self):
dir_path = URI('zip://((memory:///file.zip))/somedir')
self.assertEqual(dir_path.path, '/somedir')
new_path = dir_path / 'other'
self.assertEqual(new_path.path, '/somedir/other')
示例11: test_globbing_by_prefix_in_subdir
def test_globbing_by_prefix_in_subdir(self):
base = URI("memory:///") / "dir"
base.mkdir()
a = base / "a.foo"
b = base / "b.bar"
for f in [a, b]:
with f.open("w") as outf:
outf.write("foo")
self.assertEqual([a], base.glob("*.foo"))
示例12: test_copy_empty_dirs_recursive
def test_copy_empty_dirs_recursive(self):
root = URI(self.baseurl)
root.makedirs()
gaz_path = root / 'gaz'
gaz_path.makedirs()
moo_path = root / 'moo'
gaz_path.copy(moo_path, recursive=True)
self.assertTrue((moo_path).isdir())
示例13: tearDown
def tearDown(self):
p = URI("test.txt")
if p.exists():
p.remove()
l = URI("test_link")
if l.islink():
l.remove()
示例14: test_remove_recursive_with_readonly_file
def test_remove_recursive_with_readonly_file(self):
foo_path = URI(self.baseurl) / 'foo'
bar_path = foo_path / 'bar'
bar_path.makedirs()
gaz_path = bar_path / 'ghaz.txt'
create_file(gaz_path)
mode = gaz_path.info().mode
gaz_path.info(set_info=dict(mode=mode & ~stat.S_IWUSR))
foo_path.remove(recursive=True)
self.assertTrue(not foo_path.exists())
示例15: tearDown
def tearDown(self):
p = URI(self.foo_dir)
if p.isdir():
p.remove(recursive=True)
b = URI(self.bar_dir)
if b.isdir():
b.remove(recursive=True)