1 # Copyright (C) 2010, Thomas Leonard
2 # See the COPYING file for details, or visit http://0install.net.
5 from zeroinstall
import SafeException
7 def escape_slashes(path
):
8 return path
.replace('/', '#')
10 def ensure_dirs(path
):
11 if not os
.path
.isdir(path
):
15 def format_date(date
):
16 return time
.strftime("%Y-%m-%dT%H:%M:%SZ", time
.gmtime(date
))
18 def get_feed_dir(feed
):
20 raise SafeException("Invalid URL '%s'" % feed
)
21 scheme
, rest
= feed
.split('://', 1)
22 domain
, rest
= rest
.split('/', 1)
23 assert scheme
in ('http', 'https', 'ftp') # Just to check for mal-formed lines; add more as needed
24 for x
in [scheme
, domain
, rest
]:
25 if not x
or x
.startswith('.'):
26 raise SafeException("Invalid URL '%s'" % feed
)
27 return os
.path
.join('feeds', scheme
, domain
, escape_slashes(rest
))