comparison piecrust/baking/baker.py @ 6:f5ca5c5bed85

More Python 3 fixes, modularization, and new unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 16 Aug 2014 08:15:30 -0700
parents 474c9882decf
children 343d08ef5668
comparison
equal deleted inserted replaced
5:474c9882decf 6:f5ca5c5bed85
59 base_uri, ext = os.path.splitext(uri) 59 base_uri, ext = os.path.splitext(uri)
60 return base_uri + suffix + ext 60 return base_uri + suffix + ext
61 61
62 def getOutputPath(self, uri): 62 def getOutputPath(self, uri):
63 bake_path = [self.out_dir] 63 bake_path = [self.out_dir]
64 decoded_uri = urllib.parse.unquote(uri.lstrip('/')).decode('utf8') 64 decoded_uri = urllib.parse.unquote(uri.lstrip('/'))
65 if self.pretty_urls: 65 if self.pretty_urls:
66 bake_path.append(decoded_uri) 66 bake_path.append(decoded_uri)
67 bake_path.append('index.html') 67 bake_path.append('index.html')
68 else: 68 else:
69 name, ext = os.path.splitext(decoded_uri) 69 name, ext = os.path.splitext(decoded_uri)
70 if ext: 70 if decoded_uri == '':
71 bake_path.append('index.html')
72 elif ext:
71 bake_path.append(decoded_uri) 73 bake_path.append(decoded_uri)
72 else: 74 else:
73 bake_path.append(decoded_uri + '.html') 75 bake_path.append(decoded_uri + '.html')
74 76
75 return os.path.join(*bake_path) 77 return os.path.join(*bake_path)
189 out_dir = os.path.dirname(out_path) 191 out_dir = os.path.dirname(out_path)
190 if not os.path.isdir(out_dir): 192 if not os.path.isdir(out_dir):
191 os.makedirs(out_dir, 0o755) 193 os.makedirs(out_dir, 0o755)
192 194
193 with codecs.open(out_path, 'w', 'utf-8') as fp: 195 with codecs.open(out_path, 'w', 'utf-8') as fp:
194 fp.write(rp.content.decode('utf-8')) 196 fp.write(rp.content)
195 197
196 return ctx, rp 198 return ctx, rp
197 199
198 200
199 class Baker(object): 201 class Baker(object):