Пример #1
0
    def check(u1, u2, owner, group):
        with url.Context():
            u1 = url.URL(u1)
            u2 = url.URL(u2)
            r = u1.open("wb")
            try:
                try:
                    r.write(b"foo")
                finally:
                    r.close()
                # Might have been left over from previous run
                if u2.exists():
                    u2.remove()
                try:
                    u1.symlink(u2)
                    u2.lchown(owner, group)
                    assert u1.owner() == owner
                    assert u1.group() == group
                    assert u2.owner() == owner
                    assert u2.group() == group

                    u2.chown(owner, group)
                    assert u1.owner() == owner
                    assert u1.group() == group
                    assert u2.owner() == owner
                    assert u2.group() == group
                finally:
                    u2.remove()
            finally:
                u1.remove()
Пример #2
0
def test_ssh_params():
    with url.Context():
        u = url.URL(
            "ssh://[email protected]/~/checkouts/LivingLogic.Python.xist/"
        )
        assert u.isdir(python="/usr/local/bin/python3.2") is True
        assert u.isdir(nice=20) is True
Пример #3
0
def main(args=None):
	def catone(urlread):
		if urlread.isdir():
			if args.recursive:
				for u in urlread.walkfiles(include=args.include, exclude=args.exclude, enterdirs=args.enterdir, skipdirs=args.skipdir):
					catone(urlread/u)
			else:
				raise IOError(errno.EISDIR, "Is a directory", str(urlread))
		else:
			try:
				with contextlib.closing(urlread.open("rb")) as fileread:
					size = 0
					while True:
						data = fileread.read(262144)
						if data:
							sys.stdout.buffer.write(data)
						else:
							break
			except Exception:
				if not args.ignoreerrors:
					raise

	p = argparse.ArgumentParser(description="print URL content on the screen", epilog="For more info see http://python.livinglogic.de/scripts_ucat.html")
	p.add_argument("urls", metavar="url", help="URLs to be printed", nargs="+", type=url.URL)
	p.add_argument("-r", "--recursive", dest="recursive", help="Print stuff recursively? (default: %(default)s)", action=misc.FlagAction, default=False)
	p.add_argument("-x", "--ignoreerrors", dest="ignoreerrors", help="Ignore errors? (default: %(default)s)", action=misc.FlagAction, default=False)
	p.add_argument("-i", "--include", dest="include", metavar="PATTERN", help="Include only URLs matching PATTERN", action="append")
	p.add_argument("-e", "--exclude", dest="exclude", metavar="PATTERN", help="Exclude URLs matching PATTERN", action="append")
	p.add_argument(      "--enterdir", dest="enterdir", metavar="PATTERN", help="Only enter directories matching PATTERN", action="append")
	p.add_argument(      "--skipdir", dest="skipdir", metavar="PATTERN", help="Skip directories matching PATTERN", action="append")

	args = p.parse_args(args)
	with url.Context():
		for u in args.urls:
			catone(u)
Пример #4
0
 def check(u):
     with url.Context():
         u = url.URL(u) / "foo/"
         u.mkdir(0o755)
         try:
             assert u.isdir()
             assert u.stat().st_mode & 0o777 == 0o755
         finally:
             u.rmdir()
Пример #5
0
 def check(u):
     with url.Context():
         try:
             u = url.URL(u)
             with u.openwrite() as f:
                 f.write(b"Hurz!")
         finally:
             u.remove()
             u.withoutfile().rmdir()
Пример #6
0
 def check(u):
     with url.Context():
         u = url.URL(u) / "foo/bar/"
         u.makedirs(0o755)
         try:
             assert u.isdir()
             assert u.stat().st_mode & 0o777 == 0o755
         finally:
             u.rmdir()
             (u / "../").rmdir()
Пример #7
0
 def check(u, pu, isfile, include=None, exclude=None):
     with url.Context():
         u = url.URL(u)
         pu = url.URL(pu)
         assert u in pu.listdir(include=include, exclude=exclude)
         if isfile:
             assert u in pu.files(include=include, exclude=exclude)
             assert u not in pu.dirs(include=include, exclude=exclude)
         else:
             assert u not in pu.files(include=include, exclude=exclude)
             assert u in pu.dirs(include=include, exclude=exclude)
Пример #8
0
 def check(u):
     with url.Context():
         u = url.URL(u)
         u2 = u / "foo"
         try:
             u.symlink(u2)
             assert u2.exists()
             assert u2.islink()
         finally:
             u2.remove()
         assert not u2.exists()
Пример #9
0
 def check(u):
     with url.Context():
         u = url.URL(u) / "foo"
         try:
             r = u.open("wb")
             r.write(b"testing...")
             r.seek(-3, os.SEEK_CUR)
             r.truncate()
             r.close()
             assert u.open("rb").read() == b"testing"
         finally:
             u.remove()
Пример #10
0
 def check(u):
     with url.Context():
         u = url.URL(u)
         u2 = u / "foo"
         r = u2.open("wb")
         try:
             r.write(b"testing...")
             r.close()
             assert u2.exists()
         finally:
             u2.remove()
         assert not u2.exists()
Пример #11
0
 def check(u):
     with url.Context():
         u = url.URL(u)
         r = u.open("wb")
         try:
             try:
                 r.write(b"testing ...")
             finally:
                 r.close()
             u.chmod(0o444)
             assert u.stat().st_mode & 0o777 == 0o444
         finally:
             u.remove()
Пример #12
0
 def check(u):
     with url.Context():
         u = url.URL(u)
         u2 = u / "foo"
         try:
             u.link(u2)
             assert u2.exists()
             assert u2.isfile()
             assert not u2.islink(
             )  # A hardlink is indistinguisable from the real thing
         finally:
             u2.remove()
         assert not u2.exists()
Пример #13
0
 def check(u):
     with url.Context():
         u = url.URL(u)
         r = u.open("rb")
         r.read()
         assert r.tell() == 1479
         r.seek(0)
         assert r.tell() == 0
         r.seek(100, os.SEEK_SET)
         assert r.tell() == 100
         r.seek(0, os.SEEK_END)
         assert r.tell() == 1479
         r.seek(-479, os.SEEK_END)
         assert r.tell() == 1000
         r.seek(479, os.SEEK_CUR)
         assert r.tell() == 1479
         assert r.read() == b""
Пример #14
0
def urls2xnd(urls, shareattrs=None, **kwargs):
    ns = xnd.Module(**kwargs)
    with url.Context():
        if not urls:
            urls = [sys.stdin]
        for u in urls:
            if isinstance(u, url.URL):
                u = u.openread()
            elif isinstance(u, str):
                u = io.StringIO(u)
            adddtd2xnd(ns, u)

    if shareattrs == "dupes":
        ns.shareattrs(False)
    elif shareattrs == "all":
        ns.shareattrs(True)
    return ns
Пример #15
0
def main(args=None):
    def printone(u):
        source = parse.URL(u) if isinstance(u, url.URL) else parse.Stream(u)
        node = parse.tree(source, parse.Tidy(), parse.NS(html),
                          parse.Node(base="", pool=xsc.Pool(html, xml)))
        if args.compact:
            node = node.normalized().compacted()
        node = node.pretty()
        print(node.string(encoding=sys.stdout.encoding))

    p = argparse.ArgumentParser(
        description="pretty print HTML files",
        epilog=
        "For more info see http://python.livinglogic.de/XIST_scripts_uhpp.html"
    )
    p.add_argument("urls",
                   metavar="url",
                   help="URLs to be pretty printed",
                   nargs="*",
                   type=url.URL)
    p.add_argument("-v",
                   "--verbose",
                   dest="verbose",
                   help="Ouput parse warnings?",
                   action=misc.FlagAction,
                   default=False)
    p.add_argument(
        "-c",
        "--compact",
        dest="compact",
        help="Compact HTML before pretty printing (default: %(default)s)",
        action=misc.FlagAction,
        default=False)

    args = p.parse_args(args)
    if not args.verbose:
        import warnings
        warnings.simplefilter("ignore", category=xsc.Warning)
    with url.Context():
        if args.urls:
            for u in args.urls:
                printone(u)
        else:
            printone(sys.stdin.buffer)
Пример #16
0
 def check(u, pu, isfile, include=None, exclude=None):
     with url.Context():
         u = url.URL(u)
         pu = url.URL(pu)
         assert any(u == wu
                    for wu in pu.walkall(include=include, exclude=exclude))
         if isfile:
             assert any(
                 u == wu
                 for wu in pu.walkfiles(include=include, exclude=exclude))
             assert all(
                 u != wu
                 for wu in pu.walkdirs(include=include, exclude=exclude))
         else:
             assert all(
                 u != wu
                 for wu in pu.walkfiles(include=include, exclude=exclude))
             assert any(
                 u == wu
                 for wu in pu.walkdirs(include=include, exclude=exclude))
Пример #17
0
 def check(u, firstline):
     with url.Context():
         u = url.URL(u)
         r = u.open("rb")
         canseektell = hasattr(r, "tell") and hasattr(r, "seek")
         if canseektell:
             try:
                 r.tell()
             except io.UnsupportedOperation:
                 canseektell = False
         assert r.readline() == firstline
         if canseektell:
             assert r.tell() == len(firstline)
             r.seek(0)
             assert r.readline() == firstline
             r.seek(0)
         else:
             r = u.open("rb")  # reopen
         assert r.read(len(firstline)) == firstline
         if canseektell:
             r.seek(0)
         else:
             r = u.open("rb")  # reopen
         assert r.read().startswith(firstline)
            out(".. rst-class:: download")
            out()
            out("=" * widthfile, "=" * widthtype, "=" * widthsize)
            out("{:{}} {:{}} {:{}}".format("File", widthfile, "Type",
                                           widthtype, "Size", widthsize))
            out("=" * widthfile, "=" * widthtype, "=" * widthsize)
            for f in self.files:
                out("{:{}} {:{}} {:{}}".format(f.restfile(), widthfile,
                                               f.type or "", widthtype,
                                               f.restsize(), widthsize))
            out("=" * widthfile, "=" * widthtype, "=" * widthsize)
        else:
            out("(no files for this version)")


with url.Context():
    versions = [
        Version("5.27", "03/21/2017"),
        Version("5.26.1", "03/03/2017"),
        Version("5.26", "02/28/2017"),
        Version("5.25.1", "02/15/2017"),
        Version("5.25", "02/13/2017"),
        Version("5.24", "02/12/2017"),
        Version("5.23", "12/16/2016"),
        Version("5.22.1", "11/02/2016"),
        Version("5.22", "10/18/2016"),
        Version("5.21", "09/19/2016"),
        Version("5.20.1", "08/04/2016"),
        Version("5.20", "07/29/2016"),
        Version("5.19.4", "06/30/2016"),
        Version("5.19.3", "06/29/2016"),
Пример #19
0
 def check(u):
     with url.Context():
         u = url.URL(u)
         stat = u.stat()
         assert stat.st_size > 1000
         assert stat.st_mode & 0o600 == 0o600
Пример #20
0
 def check(u, *groups):
     with url.Context():
         u = url.URL(u)
         assert u.group() in groups
         assert u.stat().st_gid == u.gid()
Пример #21
0
 def check(u, *args):
     with url.Context():
         u = url.URL(u)
         assert u.mdate() == u.open().mdate() >= datetime.datetime(*args)
Пример #22
0
 def check(u, exists):
     with url.Context():
         u = url.URL(u)
         assert u.exists() == exists
Пример #23
0
 def check(u, *args):
     with url.Context():
         assert url.URL(u).adate() >= datetime.datetime(*args)
Пример #24
0
 def check(u, headers):
     with url.Context():
         u = url.URL(u)
         realheaders = u.resheaders()
         for (k, v) in headers.items():
             assert realheaders[k] == v
Пример #25
0
 def check(u, firstline):
     with url.Context():
         u = url.URL(u)
         realdata = u.open("rb").resdata()
         assert realdata.splitlines(True)[0] == firstline
Пример #26
0
 def check(u, mode, result):
     with url.Context():
         u = url.URL(u)
         assert u.access(mode) == result
Пример #27
0
 def check(u, ismount):
     with url.Context():
         u = url.URL(u)
         assert u.ismount() == ismount
Пример #28
0
 def check(u, islink):
     with url.Context():
         u = url.URL(u)
         assert u.islink() == islink
Пример #29
0
 def check(u, isdir):
     with url.Context():
         u = url.URL(u)
         assert u.isdir() == isdir
Пример #30
0
 def check(u, isfile):
     with url.Context():
         u = url.URL(u)
         assert u.isfile() == isfile