<commit_before>#!/usr/bin/env python
import argparse
import json
import re
import requests
import shutil
import sys
import tempfile
import zipfile
from base64 import b64encode, b64decode
from requests_hawk import HawkAuth
from signing_clients.apps import JarExtractor


def call_signing(file_path, guid, endpoint, signer, user, key):
    """Get the jar signature and send it to the signing server to be signed."""

    # We only want the (unique) temporary file name.
    with tempfile.NamedTemporaryFile() as temp_file:
        temp_filename = temp_file.name

    # Extract jar signature.
    jar = JarExtractor(path=file_path)
    signed_manifest = jar.signatures

    # create the signing request
    sigreq = [{
        "input": bytes(b64encode(str(jar.signatures).encode("utf-8"))).decode("utf-8"),
        "keyid": signer,
        "options": {
            "id": guid,
        },
    }]

    # post the request
    response = requests.post(endpoint,
                             json=sigreq,
                             auth=HawkAuth(id=user, key=key))

    # convert the base64 encoded pkcs7 signature back to binary
    if response.status_code != 201:
        print('Posting to add-on signing failed: {0}'.format(response.text))
        exit(1)

    sigresp = json.loads(response.text)
    pkcs7 = b64decode(sigresp[0]["signature"])
    jar.make_signed(
<<<<<<< HEAD
        signed_manifest=str(signed_manifest).encode("utf-8"),
=======
        signed_manifest=signed_manifest.__str__(),
>>>>>>> 0072b243... Rewrite sign-addon tool for python 3
        signature=pkcs7,
        sigpath=u'mozilla',
        outpath=temp_filename)
    shutil.move(temp_filename, file_path)

    print("{0} signed!".format(file_path))<commit_msg>fix silly rebase<commit_after>#!/usr/bin/env python
import argparse
import json
import re
import requests
import shutil
import sys
import tempfile
import zipfile
from base64 import b64encode, b64decode
from requests_hawk import HawkAuth
from signing_clients.apps import JarExtractor


def call_signing(file_path, guid, endpoint, signer, user, key):
    """Get the jar signature and send it to the signing server to be signed."""

    # We only want the (unique) temporary file name.
    with tempfile.NamedTemporaryFile() as temp_file:
        temp_filename = temp_file.name

    # Extract jar signature.
    jar = JarExtractor(path=file_path)
    signed_manifest = jar.signatures

    # create the signing request
    sigreq = [{
        "input": bytes(b64encode(str(jar.signatures).encode("utf-8"))).decode("utf-8"),
        "keyid": signer,
        "options": {
            "id": guid,
        },
    }]

    # post the request
    response = requests.post(endpoint,
                             json=sigreq,
                             auth=HawkAuth(id=user, key=key))

    # convert the base64 encoded pkcs7 signature back to binary
    if response.status_code != 201:
        print('Posting to add-on signing failed: {0}'.format(response.text))
        exit(1)

    sigresp = json.loads(response.text)
    pkcs7 = b64decode(sigresp[0]["signature"])
    jar.make_signed(
        signed_manifest=str(signed_manifest).encode("utf-8"),
        signature=pkcs7,
        sigpath=u'mozilla',
        outpath=temp_filename)
    shutil.move(temp_filename, file_path)

    print("{0} signed!".format(file_path))
{'fraction_non_alphanumeric': 0.10891681627767803, 'fraction_numerical': 0.017354877318970677, 'mean_word_length': 2.9703087885985746, 'pattern_counts': {'":': 8, '<': 10, '<?xml version=': 0, '>': 10, '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': '1326748', 'n_tokens_mistral': 1052, 'n_tokens_neox': 992, 'n_words': 260}