def test_space_and_plus_in_name(): assert url.URL("+").local() == "+" assert url.URL(" ").local() == " " assert url.URL("%20").local() == " " assert url.File("+").local() == "+" assert url.File(" ").local() == " " assert str(url.File(" ")) in ("file:%20", "file:+")
def _createlog(self): """ Create the logfile and the link to the logfile (if requested). """ if self.toemail and self.fromemail and self.smtphost: # Use the email logger as the first logger, so that when sending the email (in :meth:`EmailLogger.close`) fails, it will still be logged to the log file/stdout/stderr self._loggers.append(EmailLogger(self)) if self.log2stderr: self._loggers.append(StreamLogger(self, sys.stderr, self._formatlogline)) if self.log2stdout: self._loggers.append(StreamLogger(self, sys.stdout, self._formatlogline)) if self.log2file: # Create the log file logfilename = ul4c.Template(self.logfilename, "logfilename").renders(job=self) logfilename = url.File(logfilename).abs() self.logfileurl = str(url.Ssh(misc.sysinfo.user_name, misc.sysinfo.host_fqdn or misc.sysinfo.host_name, logfilename.local())) skipurls = [logfilename] logfile = logfilename.open(mode="w", encoding=self.encoding, errors=self.errors) if self.loglinkname is not None: # Create the log link loglinkname = ul4c.Template(self.loglinkname, "loglinkname").renders(job=self) loglinkname = url.File(loglinkname).abs() skipurls.append(loglinkname) logfilename = logfilename.relative(loglinkname) try: logfilename.symlink(loglinkname) except OSError as exc: if exc.errno == errno.EEXIST: loglinkname.remove() logfilename.symlink(loglinkname) else: raise self._loggers.append(URLResourceLogger(self, logfile, skipurls, self._formatlogline))
def __init__(self, filename, bufsize=8192): """ Create a :class:`File` object. :obj:`filename` is the name of the file and may start with ``~`` or ``~user`` for the home directory of the current or the specified user. :obj:`bufsize` specifies the chunksize for reads from the file. """ self.url = url_.File(filename) self._filename = os.path.expanduser(filename) self.bufsize = bufsize
def test_stat(): def check(u): with url.Context(): u = url.URL(u) stat = u.stat() assert stat.st_size > 1000 assert stat.st_mode & 0o600 == 0o600 check(url.File(__file__) / "../README.rst") check( "ssh://[email protected]/~/checkouts/LivingLogic.Python.xist/README.rst" )
def test_resheaders(): def check(u, headers): with url.Context(): u = url.URL(u) realheaders = u.resheaders() for (k, v) in list(headers.items()): assert realheaders[k] == v check( url.File(__file__) / "../README.rst", {"Content-type": "application/octet-stream"}) check( "ssh://[email protected]/~/checkouts/LivingLogic.Python.xist/README.rst", {"Content-Type": "application/octet-stream"}) check("http://www.livinglogic.de/Python/xist/", { "Content-type": "text/html", "Connection": "close", "Server": "Apache" })