| Index: sitescripts/stats/common.py |
| =================================================================== |
| --- a/sitescripts/stats/common.py |
| +++ b/sitescripts/stats/common.py |
| @@ -10,32 +10,31 @@ |
| # Adblock Plus is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| -import re, hashlib |
| +import re |
| +import hashlib |
| def filename_encode(name): |
| """ |
| This encodes any string to a valid file name while ensuring that the |
| original string can still be reconstructed. All characters except 0-9, A-Z, |
| the period and underscore are encoded as "-12cd" where "12cd" stands for the |
| hexadecimal representation of the character's ordinal. File names longer |
| than 150 characters will be still be unique but no longer reversible due to |
| file system limitations. |
| """ |
| result = re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), name) |
| if len(result) > 150: |
| - hash = hashlib.md5() |
| - hash.update(result[150:]) |
| - result = result[:150] + "--%s" % hash.hexdigest() |
| + result = result[:150] + "--%s" % hashlib.md5(result[150:]).hexdigest() |
| return result |
| def filename_decode(path): |
| """ |
| This reconstructs a string encoded with filename_encode(). |
| """ |
| path = re.sub(r"--[0-9A-Fa-f]{32}", u"\u2026", path) |
| path = re.sub(r"-([0-9a-f]{4})", lambda match: unichr(int(match.group(1), 16)), path) |