<commit_before>'''
Optimize a static website for hosting in S3, by including a
fingerprint into all assets\' filenames. The optimized website
is uploaded into the specified S3 bucket with the right cache
headers.
'''

from __future__ import print_function

import argparse
import os
import logging
import re
import gzip
from pkg_resources import require
from hashlib import sha256
from shutil import copyfile, move, rmtree
from fnmatch import fnmatch
from tempfile import mkdtemp, mkstemp
from urlparse import urlparse, urljoin

from boto import connect_s3
from boto.s3 import connect_to_region
from boto.s3.key import Key
from boto.exception import BotoClientError, BotoServerError

__author__ = "<NAME>"
__email__ = "<EMAIL>"
__copyright__ = "Copyright 2015, Appstrakt BVBA"
__license__ = "MIT"

logger = None


def calculate_fingerprint(fname):
    '''
    Calculate a hash from a file name.
    '''
    hasher = sha256()
    blocksize = 65536

    with open(fname, 'rb') as f:
        buf = f.read(blocksize)<commit_msg>Added a try/catch for urlparse. urllib.parse is used instead if Import error<commit_after>'''
Optimize a static website for hosting in S3, by including a
fingerprint into all assets\' filenames. The optimized website
is uploaded into the specified S3 bucket with the right cache
headers.
'''

from __future__ import print_function

import argparse
import os
import logging
import re
import gzip
from pkg_resources import require
from hashlib import sha256
from shutil import copyfile, move, rmtree
from fnmatch import fnmatch
from tempfile import mkdtemp, mkstemp
try:
    from urlparse import urlparse, urljoin
except ImportError:
    from urllib.parse import urlparse, urljoin

from boto import connect_s3
from boto.s3 import connect_to_region
from boto.s3.key import Key
from boto.exception import BotoClientError, BotoServerError

__author__ = "<NAME>"
__email__ = "<EMAIL>"
__copyright__ = "Copyright 2015, Appstrakt BVBA"
__license__ = "MIT"

logger = None


def calculate_fingerprint(fname):
    '''
    Calculate a hash from a file name.
    '''
    hasher = sha256()
    blocksize = 65536

    with open(fname, 'rb') as f:
        buf = f.read(blocksize)
{'fraction_non_alphanumeric': 0.06264288980338363, 'fraction_numerical': 0.01828989483310471, 'mean_word_length': 4.49748743718593, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3002868', 'n_tokens_mistral': 693, 'n_tokens_neox': 647, 'n_words': 266}