Instead of having `"%(path)s/%(filename)s"` inside the command line, you could join the two parts using `posixpath.join()` and quote them using `pipes.quote()`:

```python
from pipes import quote
import posixpath

dest = quote(posixpath.join(path, filename))
_run_as_pg('pg_dump %(port_option)s%(database)s --format=%(format)s --blobs --file=%(dest)s' % locals())
```