OLD | NEW |
(Empty) | |
| 1 # This Source Code Form is subject to the terms of the Mozilla Public |
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
| 5 """Module to store various helper functions used in mozdownload.""" |
| 6 |
| 7 import hashlib |
| 8 |
| 9 |
| 10 def urljoin(*fragments): |
| 11 """Concatenates multi part strings into urls""" |
| 12 |
| 13 # Strip possible already existent final slashes of fragments except for the
last one |
| 14 parts = [fragment.rstrip('/') for fragment in fragments[:len(fragments) - 1]
] |
| 15 parts.append(fragments[-1]) |
| 16 |
| 17 return '/'.join(parts) |
| 18 |
| 19 |
| 20 def create_md5(path): |
| 21 """Creates the md5 hash of a file using the hashlib library""" |
| 22 |
| 23 m = hashlib.md5() |
| 24 # rb necessary to run correctly in windows. |
| 25 with open(path, "rb") as f: |
| 26 while True: |
| 27 data = f.read(8192) |
| 28 if not data: |
| 29 break |
| 30 m.update(data) |
| 31 |
| 32 return m.hexdigest() |
OLD | NEW |