from setuptools import setup

def fread(fn):
    return open(fn, 'rb').read().decode('utf-8')

setup(
    name='tox-travis',
    description='Seamless integration of Tox into Travis CI',
    long_description=fread('README.rst') + '\n\n' + fread('HISTORY.rst'),
    author='Ryan Hiebert',
    author_email='ryan@ryanhiebert.com',
    url='https://github.com/ryanhiebert/tox-travis',
    license='MIT',
    version='0.1',
    py_modules=['tox_travis'],
    entry_points={
        'tox': ['travis = tox_travis'],
    },
    install_requires=['tox>=2.0'],
    classifiers=[
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
    ],
)

Add Python 3.5 trove classifier

Add Python 3.5 trove classifier

Response:
<INSERT>     'Programming Language :: Python :: 3.5',
    <INSERT_END> <|endoftext|> from setuptools import setup

def fread(fn):
    return open(fn, 'rb').read().decode('utf-8')

setup(
    name='tox-travis',
    description='Seamless integration of Tox into Travis CI',
    long_description=fread('README.rst') + '\n\n' + fread('HISTORY.rst'),
    author='Ryan Hiebert',
    author_email='ryan@ryanhiebert.com',
    url='https://github.com/ryanhiebert/tox-travis',
    license='MIT',
    version='0.1',
    py_modules=['tox_travis'],
    entry_points={
        'tox': ['travis = tox_travis'],
    },
    install_requires=['tox>=2.0'],
    classifiers=[
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
    ],
)

Prompt:
Add Python 3.5 trove classifier

from setuptools import setup

def fread(fn):
    return open(fn, 'rb').read().decode('utf-8')

setup(
    name='tox-travis',
    description='Seamless integration of Tox into Travis CI',
    long_description=fread('README.rst') + '\n\n' + fread('HISTORY.rst'),
    author='Ryan Hiebert',
    author_email='ryan@ryanhiebert.com',
    url='https://github.com/ryanhiebert/tox-travis',
    license='MIT',
    version='0.1',
    py_modules=['tox_travis'],
    entry_points={
        'tox': ['travis = tox_travis'],
    },
    install_requires=['tox>=2.0'],
    classifiers=[
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
    ],
)


from base.consensus import Consensus

class ByzantineRandomizedConsensus(Consensus):
    """
    Implements a Byzantine Fault Tolerant Randomized Consensus Broadcast protocol.
    """

    def propose(self, message):
        pass

    def decide(self):
        pass

Update Byzantine Randomized Consensus protocol class

Response:
<INSERT> from base.consensus import Consensus

class ByzantineRandomizedConsensus(Consensus):
 <INSERT_END> <INSERT>   """
    Implements a Byzantine Fault Tolerant Randomized Consensus Broadcast protocol.
    """

    def propose(self, message):
        pass

    def decide(self):
        pass <INSERT_END> <|endoftext|> from base.consensus import Consensus

class ByzantineRandomizedConsensus(Consensus):
    """
    Implements a Byzantine Fault Tolerant Randomized Consensus Broadcast protocol.
    """

    def propose(self, message):
        pass

    def decide(self):
        pass

Prompt: Update Byzantine Randomized Consensus protocol class


from __future__ import division
import numpy as np
from utilBMF.HTSUtils import pFastqProxy, pFastqFile

consInFq1 = pFastqFile("/home/brett/Projects/BMFTools_Devel/lamda_data/lamda-50di"
                    "v_S4_L001_R1_001.fastq.rescued.shaded.BS.fastq")
consInFq2 = pFastqFile("/home/brett/Projects/BMFTools_Devel/lamda_data/kmer_test/"
                    "")

Add small script to start calculating error from kmer motifs, prototyping

Response:
<INSERT> from __future__ import division
import numpy as np
from utilBMF.HTSUtils import pFastqProxy, pFastqFile

consInFq1 = pFastqFile("/home/brett/Projects/BMFTools_Devel/lamda_data/lamda-50di"
 <INSERT_END> <INSERT>                   "v_S4_L001_R1_001.fastq.rescued.shaded.BS.fastq")
consInFq2 = pFastqFile("/home/brett/Projects/BMFTools_Devel/lamda_data/kmer_test/"
                    "")
 <INSERT_END> <|endoftext|> from __future__ import division
import numpy as np
from utilBMF.HTSUtils import pFastqProxy, pFastqFile

consInFq1 = pFastqFile("/home/brett/Projects/BMFTools_Devel/lamda_data/lamda-50di"
                    "v_S4_L001_R1_001.fastq.rescued.shaded.BS.fastq")
consInFq2 = pFastqFile("/home/brett/Projects/BMFTools_Devel/lamda_data/kmer_test/"
                    "")

Prompt: Add small script to start calculating error from kmer motifs, prototyping


from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError

from subscriptions.models import Subscription

class Command(BaseCommand):
    help = ("Active subscription holders need to be informed via audio file "
            "about the new missed call service.")

    def handle(self, *args, **options):
        self.stdout.write("Processing active subscriptions ...")
        count = 0
        try:
            active_subscriptions_list = list(
                Subscription.objects.filter(active=True))
        except ObjectDoesNotExist:
            self.stdout.write("No active subscriptions found")
        if len(active_subscriptions_list) > 0:
            for active_subscription in active_subscriptions_list:
                # Add audio file to subscription meta_data. Not sure how we'll
                # handle translations here.
                if (active_subscription.metadata is not None and
                        "welcome_message" not in active_subscription.metadata):
                    active_subscription["audo_file_url"] = "audio_file_url"
                    count += 1
        if count > 0:
            self.stdout.write(
                "Update {} subscriptions with voice notes".format(count))
        else:
            self.stdout.write(
                "No subscriptions updated with audio file notes")

Add missed call service audio notification to active subscriptions

Response:
<REPLACE_OLD>  <REPLACE_NEW> from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError

from subscriptions.models import Subscription

class Command(BaseCommand):
    help = ("Active subscription holders need to be informed via audio file "
            "about the new missed call service.")

    def handle(self, *args, **options):
        self.stdout.write("Processing active subscriptions ...")
        count = 0
        try:
            active_subscriptions_list = list(
                Subscription.objects.filter(active=True))
        except ObjectDoesNotExist:
            self.stdout.write("No active subscriptions found")
        if len(active_subscriptions_list) > 0:
            for active_subscription in active_subscriptions_list:
                # Add audio file to subscription meta_data. Not sure how we'll
                # handle translations here.
                if (active_subscription.metadata is not None and
                        "welcome_message" not in active_subscription.metadata):
                    active_subscription["audo_file_url"] = "audio_file_url"
                    count += 1
        if count > 0:
            self.stdout.write(
                "Update {} subscriptions with voice notes".format(count))
        else:
            self.stdout.write(
                "No subscriptions updated with audio file notes")
 <REPLACE_END> <|endoftext|> from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError

from subscriptions.models import Subscription

class Command(BaseCommand):
    help = ("Active subscription holders need to be informed via audio file "
            "about the new missed call service.")

    def handle(self, *args, **options):
        self.stdout.write("Processing active subscriptions ...")
        count = 0
        try:
            active_subscriptions_list = list(
                Subscription.objects.filter(active=True))
        except ObjectDoesNotExist:
            self.stdout.write("No active subscriptions found")
        if len(active_subscriptions_list) > 0:
            for active_subscription in active_subscriptions_list:
                # Add audio file to subscription meta_data. Not sure how we'll
                # handle translations here.
                if (active_subscription.metadata is not None and
                        "welcome_message" not in active_subscription.metadata):
                    active_subscription["audo_file_url"] = "audio_file_url"
                    count += 1
        if count > 0:
            self.stdout.write(
                "Update {} subscriptions with voice notes".format(count))
        else:
            self.stdout.write(
                "No subscriptions updated with audio file notes")

Prompt: Add missed call service audio notification to active subscriptions


#! -*- coding: koi8-r -*-
# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.

import unittest
from test import test_support

class PEP263Test(unittest.TestCase):

    def test_pep263(self):
        self.assertEqual(
            u"".encode("utf-8"),
            '\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
        )
        self.assertEqual(
            u"\".encode("utf-8"),
            '\\\xd0\x9f'
        )

def test_main():
    test_support.run_unittest(PEP263Test)

if __name__=="__main__":
    test_main()

Add a comment explaining -kb.

Add a comment explaining -kb.

Response:
<REPLACE_OLD> -*-

import <REPLACE_NEW> -*-
# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.

import <REPLACE_END> <|endoftext|> #! -*- coding: koi8-r -*-
# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.

import unittest
from test import test_support

class PEP263Test(unittest.TestCase):

    def test_pep263(self):
        self.assertEqual(
            u"".encode("utf-8"),
            '\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
        )
        self.assertEqual(
            u"\".encode("utf-8"),
            '\\\xd0\x9f'
        )

def test_main():
    test_support.run_unittest(PEP263Test)

if __name__=="__main__":
    test_main()

Prompt:
Add a comment explaining -kb.

#! -*- coding: koi8-r -*-

import unittest
from test import test_support

class PEP263Test(unittest.TestCase):

    def test_pep263(self):
        self.assertEqual(
            u"".encode("utf-8"),
            '\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
        )
        self.assertEqual(
            u"\".encode("utf-8"),
            '\\\xd0\x9f'
        )

def test_main():
    test_support.run_unittest(PEP263Test)

if __name__=="__main__":
    test_main()


from string import ascii_lowercase
import django
import os
import string

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from breach.models import Target, Victim

endpoint = 'https://dimkarakostas.com/rupture/test.php?ref=%s'
prefix = 'imper'
alphabet = ascii_lowercase
secretlength = 9

target_1 = Target(
    endpoint=endpoint,
    prefix=prefix,
    alphabet=alphabet,
    secretlength=secretlength,
    alignmentalphabet=string.ascii_uppercase
)
target_1.save()

print 'Created Target:\n\tendpoint: {}\n\tprefix: {}\n\talphabet: {}\n\tsecretlength: {}'.format(endpoint, prefix, alphabet, secretlength)

snifferendpoint = 'http://127.0.0.1:9000'
sourceip = '192.168.1.70'

victim_1 = Victim(
    target=target_1,
    snifferendpoint=snifferendpoint,
    sourceip=sourceip,
    # method='serial'
)
victim_1.save()

print 'Created Victim:\n\tvictim_id: {}\n\tsnifferendpoint: {}\n\tsourceip: {}'.format(victim_1.id, snifferendpoint, sourceip)

Response:
<REPLACE_OLD> os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', <REPLACE_NEW> os
import string

os.environ.setdefault('DJANGO_SETTINGS_MODULE', <REPLACE_END> <REPLACE_OLD> secretlength=secretlength
)
target_1.save()

print <REPLACE_NEW> secretlength=secretlength,
    alignmentalphabet=string.ascii_uppercase
)
target_1.save()

print <REPLACE_END> <|endoftext|> from string import ascii_lowercase
import django
import os
import string

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from breach.models import Target, Victim

endpoint = 'https://dimkarakostas.com/rupture/test.php?ref=%s'
prefix = 'imper'
alphabet = ascii_lowercase
secretlength = 9

target_1 = Target(
    endpoint=endpoint,
    prefix=prefix,
    alphabet=alphabet,
    secretlength=secretlength,
    alignmentalphabet=string.ascii_uppercase
)
target_1.save()

print 'Created Target:\n\tendpoint: {}\n\tprefix: {}\n\talphabet: {}\n\tsecretlength: {}'.format(endpoint, prefix, alphabet, secretlength)

snifferendpoint = 'http://127.0.0.1:9000'
sourceip = '192.168.1.70'

victim_1 = Victim(
    target=target_1,
    snifferendpoint=snifferendpoint,
    sourceip=sourceip,
    # method='serial'
)
victim_1.save()

print 'Created Victim:\n\tvictim_id: {}\n\tsnifferendpoint: {}\n\tsourceip: {}'.format(victim_1.id, snifferendpoint, sourceip)

Prompt:
Update dimkarakostas population with alignmentalphabet

from string import ascii_lowercase
import django
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from breach.models import Target, Victim

endpoint = 'https://dimkarakostas.com/rupture/test.php?ref=%s'
prefix = 'imper'
alphabet = ascii_lowercase
secretlength = 9

target_1 = Target(
    endpoint=endpoint,
    prefix=prefix,
    alphabet=alphabet,
    secretlength=secretlength
)
target_1.save()

print 'Created Target:\n\tendpoint: {}\n\tprefix: {}\n\talphabet: {}\n\tsecretlength: {}'.format(endpoint, prefix, alphabet, secretlength)

snifferendpoint = 'http://127.0.0.1:9000'
sourceip = '192.168.1.70'

victim_1 = Victim(
    target=target_1,
    snifferendpoint=snifferendpoint,
    sourceip=sourceip,
    # method='serial'
)
victim_1.save()

print 'Created Victim:\n\tvictim_id: {}\n\tsnifferendpoint: {}\n\tsourceip: {}'.format(victim_1.id, snifferendpoint, sourceip)


from geomancer import create_app

app = create_app()

if __name__ == "__main__":
    import sys
    try:
        port = int(sys.argv[1])
    except IndexError:
        port = 5000
    app.run(debug=True, port=port)

Make it so we can choose port

Make it so we can choose port

Response:
<REPLACE_OLD> app.run(debug=True)
 <REPLACE_NEW> import sys
    try:
        port = int(sys.argv[1])
    except IndexError:
        port = 5000
    app.run(debug=True, port=port)
 <REPLACE_END> <|endoftext|> from geomancer import create_app

app = create_app()

if __name__ == "__main__":
    import sys
    try:
        port = int(sys.argv[1])
    except IndexError:
        port = 5000
    app.run(debug=True, port=port)

Prompt:
Make it so we can choose port

from geomancer import create_app

app = create_app()

if __name__ == "__main__":
    app.run(debug=True)


from gdata.youtube.service import YouTubeService, YouTubeVideoQuery
from django.utils.encoding import smart_str

class YoutubeMusic:
    def __init__(self):
        self.service = YouTubeService()

    def search(self, artist):
        query = YouTubeVideoQuery()
        query.vq = artist
        query.orderby = 'viewCount'
        query.racy = 'exclude'
        query.categories.append("/Music")
        feed = self.service.YouTubeQuery(query)
        results = []
        for entry in feed.entry:
            if not self.is_valid_entry(artist, entry):
                continue
            results.append({
                'url': entry.media.player.url,
                'title': smart_str(entry.media.title.text),
                'duration': int(entry.media.duration.seconds),
            })
        return {'artist': smart_str(artist), 'results': results}

    def is_valid_entry(self, artist, entry):
        duration = int(entry.media.duration.seconds)
        if entry.rating is not None and float(entry.rating.average) < 3:
            return False
        if duration < (2 * 60) or duration > (9 * 60):
            return False
        if smart_str(artist).lower() not in smart_str(entry.media.title.text).lower():
            return False
        return True

Response:
<REPLACE_OLD> YouTubeVideoQuery

class <REPLACE_NEW> YouTubeVideoQuery
from django.utils.encoding import smart_str

class <REPLACE_END> <INSERT> 'title': smart_str(entry.media.title.text),
                <INSERT_END> <REPLACE_OLD> results

 <REPLACE_NEW> {'artist': smart_str(artist), 'results': results}

 <REPLACE_END> <REPLACE_OLD> artist.lower() <REPLACE_NEW> smart_str(artist).lower() <REPLACE_END> <REPLACE_OLD> entry.media.title.text.lower():
 <REPLACE_NEW> smart_str(entry.media.title.text).lower():
 <REPLACE_END> <|endoftext|> from gdata.youtube.service import YouTubeService, YouTubeVideoQuery
from django.utils.encoding import smart_str

class YoutubeMusic:
    def __init__(self):
        self.service = YouTubeService()

    def search(self, artist):
        query = YouTubeVideoQuery()
        query.vq = artist
        query.orderby = 'viewCount'
        query.racy = 'exclude'
        query.categories.append("/Music")
        feed = self.service.YouTubeQuery(query)
        results = []
        for entry in feed.entry:
            if not self.is_valid_entry(artist, entry):
                continue
            results.append({
                'url': entry.media.player.url,
                'title': smart_str(entry.media.title.text),
                'duration': int(entry.media.duration.seconds),
            })
        return {'artist': smart_str(artist), 'results': results}

    def is_valid_entry(self, artist, entry):
        duration = int(entry.media.duration.seconds)
        if entry.rating is not None and float(entry.rating.average) < 3:
            return False
        if duration < (2 * 60) or duration > (9 * 60):
            return False
        if smart_str(artist).lower() not in smart_str(entry.media.title.text).lower():
            return False
        return True

Prompt:
Use smart_str and include artist in results

from gdata.youtube.service import YouTubeService, YouTubeVideoQuery

class YoutubeMusic:
    def __init__(self):
        self.service = YouTubeService()

    def search(self, artist):
        query = YouTubeVideoQuery()
        query.vq = artist
        query.orderby = 'viewCount'
        query.racy = 'exclude'
        query.categories.append("/Music")
        feed = self.service.YouTubeQuery(query)
        results = []
        for entry in feed.entry:
            if not self.is_valid_entry(artist, entry):
                continue
            results.append({
                'url': entry.media.player.url,
                'duration': int(entry.media.duration.seconds),
            })
        return results

    def is_valid_entry(self, artist, entry):
        duration = int(entry.media.duration.seconds)
        if entry.rating is not None and float(entry.rating.average) < 3:
            return False
        if duration < (2 * 60) or duration > (9 * 60):
            return False
        if artist.lower() not in entry.media.title.text.lower():
            return False
        return True


"""
Tests for helper function for updating a target from a Vuforia database.
"""

import io

import pytest

from vws import VWS
from vws.exceptions import UnknownTarget

class TestUpdateTarget:
    """
    Test for updating a target.
    """

    def test_get_target(
        self,
        client: VWS,
        high_quality_image: io.BytesIO,
    ) -> None:
        """
        Details of a target are returned by ``get_target``.
        """
    #     target_id = client.add_target(
    #         name='x',
    #         width=1,
    #         image=high_quality_image,
    #     )
    #
    #     client.update_target(target_id=target_id)
    #     result = client.get_target(target_id=target_id)
    #     expected_keys = {
    #         'target_id',
    #         'active_flag',
    #         'name',
    #         'width',
    #         'tracking_rating',
    #         'reco_rating',
    #     }
    #     assert result['target_record'].keys() == expected_keys
    #
    # def test_no_such_target(
    #     self,
    #     client: VWS,
    #     high_quality_image: io.BytesIO,
    # ) -> None:
    #     """
    #     An ``UnknownTarget`` exception is raised when getting a target which
    #     does not exist.
    #     """
    #     with pytest.raises(UnknownTarget):
    #         client.get_target(target_id='a')

Comment out part done code

Comment out part done code

Response:
<INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <REPLACE_OLD>     )

    <REPLACE_NEW> #     )
    #
    # <REPLACE_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <REPLACE_OLD> expected_keys

    <REPLACE_NEW> expected_keys
    #
    # <REPLACE_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <INSERT> # <INSERT_END> <|endoftext|> """
Tests for helper function for updating a target from a Vuforia database.
"""

import io

import pytest

from vws import VWS
from vws.exceptions import UnknownTarget

class TestUpdateTarget:
    """
    Test for updating a target.
    """

    def test_get_target(
        self,
        client: VWS,
        high_quality_image: io.BytesIO,
    ) -> None:
        """
        Details of a target are returned by ``get_target``.
        """
    #     target_id = client.add_target(
    #         name='x',
    #         width=1,
    #         image=high_quality_image,
    #     )
    #
    #     client.update_target(target_id=target_id)
    #     result = client.get_target(target_id=target_id)
    #     expected_keys = {
    #         'target_id',
    #         'active_flag',
    #         'name',
    #         'width',
    #         'tracking_rating',
    #         'reco_rating',
    #     }
    #     assert result['target_record'].keys() == expected_keys
    #
    # def test_no_such_target(
    #     self,
    #     client: VWS,
    #     high_quality_image: io.BytesIO,
    # ) -> None:
    #     """
    #     An ``UnknownTarget`` exception is raised when getting a target which
    #     does not exist.
    #     """
    #     with pytest.raises(UnknownTarget):
    #         client.get_target(target_id='a')

Prompt:
Comment out part done code

"""
Tests for helper function for updating a target from a Vuforia database.
"""

import io

import pytest

from vws import VWS
from vws.exceptions import UnknownTarget

class TestUpdateTarget:
    """
    Test for updating a target.
    """

    def test_get_target(
        self,
        client: VWS,
        high_quality_image: io.BytesIO,
    ) -> None:
        """
        Details of a target are returned by ``get_target``.
        """
        target_id = client.add_target(
            name='x',
            width=1,
            image=high_quality_image,
        )

        client.update_target(target_id=target_id)
        result = client.get_target(target_id=target_id)
        expected_keys = {
            'target_id',
            'active_flag',
            'name',
            'width',
            'tracking_rating',
            'reco_rating',
        }
        assert result['target_record'].keys() == expected_keys

    def test_no_such_target(
        self,
        client: VWS,
        high_quality_image: io.BytesIO,
    ) -> None:
        """
        An ``UnknownTarget`` exception is raised when getting a target which
        does not exist.
        """
        with pytest.raises(UnknownTarget):
            client.get_target(target_id='a')


import re
import sys

class ProcessorImporter(object):
    """
    The processors were moved to the PILKit project so they could be used
    separtely from ImageKit (which has a bunch of Django dependencies). However,
    there's no real need to expose this fact (and we want to maintain backwards
    compatibility), so we proxy all "imagekit.processors" imports to
    "pilkit.processors" using this object.

    """
    pattern = re.compile(r'^imagekit\.processors((\..*)?)$')

    def find_module(self, name, path=None):
        if self.pattern.match(name):
            return self

    def load_module(self, name):
        if name in sys.modules:
            return sys.modules[name]

        from django.utils.importlib import import_module
        new_name = self.pattern.sub(r'pilkit.processors\1', name)
        return import_module(new_name)

sys.meta_path.insert(0, ProcessorImporter())

Insert importer at beginning of list

Insert importer at beginning of list

Response:
<REPLACE_OLD> import_module(new_name)

sys.meta_path.append(ProcessorImporter())
 <REPLACE_NEW> import_module(new_name)

sys.meta_path.insert(0, ProcessorImporter())
 <REPLACE_END> <|endoftext|> import re
import sys

class ProcessorImporter(object):
    """
    The processors were moved to the PILKit project so they could be used
    separtely from ImageKit (which has a bunch of Django dependencies). However,
    there's no real need to expose this fact (and we want to maintain backwards
    compatibility), so we proxy all "imagekit.processors" imports to
    "pilkit.processors" using this object.

    """
    pattern = re.compile(r'^imagekit\.processors((\..*)?)$')

    def find_module(self, name, path=None):
        if self.pattern.match(name):
            return self

    def load_module(self, name):
        if name in sys.modules:
            return sys.modules[name]

        from django.utils.importlib import import_module
        new_name = self.pattern.sub(r'pilkit.processors\1', name)
        return import_module(new_name)

sys.meta_path.insert(0, ProcessorImporter())

Prompt:
Insert importer at beginning of list

import re
import sys

class ProcessorImporter(object):
    """
    The processors were moved to the PILKit project so they could be used
    separtely from ImageKit (which has a bunch of Django dependencies). However,
    there's no real need to expose this fact (and we want to maintain backwards
    compatibility), so we proxy all "imagekit.processors" imports to
    "pilkit.processors" using this object.

    """
    pattern = re.compile(r'^imagekit\.processors((\..*)?)$')

    def find_module(self, name, path=None):
        if self.pattern.match(name):
            return self

    def load_module(self, name):
        if name in sys.modules:
            return sys.modules[name]

        from django.utils.importlib import import_module
        new_name = self.pattern.sub(r'pilkit.processors\1', name)
        return import_module(new_name)

sys.meta_path.append(ProcessorImporter())


from BeautifulSoup import *
import exception

def auth_fail(response, **kwargs):

	code    = response['http_code']
	message = 'Authentication failed - incorrect username and/or password'

	raise exception.PyAemException(code, message)

def method_not_allowed(response, **kwargs):

	code    = response['http_code']
	soup    = BeautifulSoup(response['body'])
	message = soup.p.string

	raise exception.PyAemException(code, message)

def unexpected(response, **kwargs):

	code    = response['http_code']
	message = 'Unexpected response http code {0} and body\n{1}'.format(response['http_code'], response['body'])

	raise exception.PyAemException(code, message)

Response:
<REPLACE_OLD> error'

	raise <REPLACE_NEW> response http code {0} and body\n{1}'.format(response['http_code'], response['body'])

	raise <REPLACE_END> <|endoftext|> from BeautifulSoup import *
import exception

def auth_fail(response, **kwargs):

	code    = response['http_code']
	message = 'Authentication failed - incorrect username and/or password'

	raise exception.PyAemException(code, message)

def method_not_allowed(response, **kwargs):

	code    = response['http_code']
	soup    = BeautifulSoup(response['body'])
	message = soup.p.string

	raise exception.PyAemException(code, message)

def unexpected(response, **kwargs):

	code    = response['http_code']
	message = 'Unexpected response http code {0} and body\n{1}'.format(response['http_code'], response['body'])

	raise exception.PyAemException(code, message)

Prompt:
Update unexpected handler message, with http code and body.

from BeautifulSoup import *
import exception

def auth_fail(response, **kwargs):

	code    = response['http_code']
	message = 'Authentication failed - incorrect username and/or password'

	raise exception.PyAemException(code, message)

def method_not_allowed(response, **kwargs):

	code    = response['http_code']
	soup    = BeautifulSoup(response['body'])
	message = soup.p.string

	raise exception.PyAemException(code, message)

def unexpected(response, **kwargs):

	code    = response['http_code']
	message = 'Unexpected error'

	raise exception.PyAemException(code, message)


from google.appengine.ext import db

TOP_LEVEL_DOMAINS = """
com net org biz info
ag am at
be by
ch ck
de
es eu
fm
in io is it
la li ly
me mobi ms
name
ru
se sh sy
tel th to travel tv
us
""".split()

# Omitting nu, ph, st, ws because they don't seem to have NXDOMAIN.

class UpgradeStringProperty(db.IntegerProperty):

    def validate(self, value):
        return unicode(value) if value else u''

class Lookup(db.Expando):
    """
    The datastore key name is the domain name, without top level.

    IP address fields use 0 (zero) for NXDOMAIN because None is
    returned for missing properties.

    Some updates on 2010-01-01 use negative numbers for 60 bit hashes of
    the SOA server name.

    Since 2010-01-02, this model inherits from Expando to flexibly add
    more top level domains. Each property stores the authority name
    server as string backwards, e.g. com.1and1.ns1 for better sorting.
    """
    backwards = db.StringProperty(required=True) # For suffix matching.
    timestamp = db.DateTimeProperty(required=True) # Created or updated.
    com = UpgradeStringProperty()
    net = UpgradeStringProperty()
    org = UpgradeStringProperty()
    biz = UpgradeStringProperty()
    info = UpgradeStringProperty()

Response:
<REPLACE_OLD> 'com <REPLACE_NEW> """
com <REPLACE_END> <REPLACE_OLD> info'.split()

class Lookup(db.Model):
 <REPLACE_NEW> info
ag am at
be by
ch ck
de
es eu
fm
in io is it
la li ly
me mobi ms
name
ru
se sh sy
tel th to travel tv
us
""".split()

# Omitting nu, ph, st, ws because they don't seem to have NXDOMAIN.

class UpgradeStringProperty(db.IntegerProperty):

    def validate(self, value):
        return unicode(value) if value else u''

class Lookup(db.Expando):
 <REPLACE_END> <REPLACE_OLD> Updates since <REPLACE_NEW> Some updates on <REPLACE_END> <REPLACE_OLD> name, see tools/update_dns.py.
 <REPLACE_NEW> name.

    Since 2010-01-02, this model inherits from Expando to flexibly add
    more top level domains. Each property stores the authority name
    server as string backwards, e.g. com.1and1.ns1 for better sorting.
 <REPLACE_END> <REPLACE_OLD> db.IntegerProperty(indexed=False)
 <REPLACE_NEW> UpgradeStringProperty()
 <REPLACE_END> <REPLACE_OLD> db.IntegerProperty(indexed=False)
 <REPLACE_NEW> UpgradeStringProperty()
 <REPLACE_END> <REPLACE_OLD> db.IntegerProperty(indexed=False)
 <REPLACE_NEW> UpgradeStringProperty()
 <REPLACE_END> <REPLACE_OLD> db.IntegerProperty(indexed=False)
 <REPLACE_NEW> UpgradeStringProperty()
 <REPLACE_END> <REPLACE_OLD> db.IntegerProperty(indexed=False)
 <REPLACE_NEW> UpgradeStringProperty()
 <REPLACE_END> <|endoftext|> from google.appengine.ext import db

TOP_LEVEL_DOMAINS = """
com net org biz info
ag am at
be by
ch ck
de
es eu
fm
in io is it
la li ly
me mobi ms
name
ru
se sh sy
tel th to travel tv
us
""".split()

# Omitting nu, ph, st, ws because they don't seem to have NXDOMAIN.

class UpgradeStringProperty(db.IntegerProperty):

    def validate(self, value):
        return unicode(value) if value else u''

class Lookup(db.Expando):
    """
    The datastore key name is the domain name, without top level.

    IP address fields use 0 (zero) for NXDOMAIN because None is
    returned for missing properties.

    Some updates on 2010-01-01 use negative numbers for 60 bit hashes of
    the SOA server name.

    Since 2010-01-02, this model inherits from Expando to flexibly add
    more top level domains. Each property stores the authority name
    server as string backwards, e.g. com.1and1.ns1 for better sorting.
    """
    backwards = db.StringProperty(required=True) # For suffix matching.
    timestamp = db.DateTimeProperty(required=True) # Created or updated.
    com = UpgradeStringProperty()
    net = UpgradeStringProperty()
    org = UpgradeStringProperty()
    biz = UpgradeStringProperty()
    info = UpgradeStringProperty()

Prompt:
Upgrade Lookup model to Expando and DNS result properties from integer to string.

from google.appengine.ext import db

TOP_LEVEL_DOMAINS = 'com net org biz info'.split()

class Lookup(db.Model):
    """
    The datastore key name is the domain name, without top level.

    IP address fields use 0 (zero) for NXDOMAIN because None is
    returned for missing properties.

    Updates since 2010-01-01 use negative numbers for 60 bit hashes of
    the SOA server name, see tools/update_dns.py.
    """
    backwards = db.StringProperty(required=True) # For suffix matching.
    timestamp = db.DateTimeProperty(required=True) # Created or updated.
    com = db.IntegerProperty(indexed=False)
    net = db.IntegerProperty(indexed=False)
    org = db.IntegerProperty(indexed=False)
    biz = db.IntegerProperty(indexed=False)
    info = db.IntegerProperty(indexed=False)


from django.contrib import admin

# Register your models here.
from .models import Question

class QuestionAdmin(admin.ModelAdmin):

    #fields = ['pub_date', 'question_text']

    fieldsets = [
        (None, {'fields' : ['question_text']}),
        ('Date Information', { 'fields' : ['pub_date'], 'classes': ['collapse']}),
    ]

admin.site.register(Question, QuestionAdmin)

Response:
<REPLACE_OLD> Question

class QuestionAdmin(admin.ModelAdmin):
 <REPLACE_NEW> Question

class QuestionAdmin(admin.ModelAdmin):

 <REPLACE_END> <REPLACE_OLD> fields <REPLACE_NEW> #fields <REPLACE_END> <REPLACE_OLD> 'question_text']

admin.site.register(Question, <REPLACE_NEW> 'question_text']

    fieldsets = [
        (None, {'fields' : ['question_text']}),
        ('Date Information', { 'fields' : ['pub_date'], 'classes': ['collapse']}),
    ]

admin.site.register(Question, <REPLACE_END> <|endoftext|> from django.contrib import admin

# Register your models here.
from .models import Question

class QuestionAdmin(admin.ModelAdmin):

    #fields = ['pub_date', 'question_text']

    fieldsets = [
        (None, {'fields' : ['question_text']}),
        ('Date Information', { 'fields' : ['pub_date'], 'classes': ['collapse']}),
    ]

admin.site.register(Question, QuestionAdmin)

Prompt:
Put Question Admin fields in a fieldset and added a collapse class to the date field

from django.contrib import admin

# Register your models here.
from .models import Question

class QuestionAdmin(admin.ModelAdmin):
    fields = ['pub_date', 'question_text']

admin.site.register(Question, QuestionAdmin)


#!/usr/bin/env python

import os

from distutils.core import setup, Extension, Command
from distutils.command.sdist import sdist

from distutils.command.build_py import build_py

from numpy import get_include as get_numpy_include

numpy_includes = get_numpy_include()

ext_modules = [Extension("reproject._overlap_wrapper",
                         ['reproject/_overlap_wrapper.c', 'reproject/overlapArea.c'],
                         include_dirs=[numpy_includes])]

class PyTest(Command):

    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):

        import os
        import shutil
        import tempfile

        # First ensure that we build the package so that 2to3 gets executed
        self.reinitialize_command('build')
        self.run_command('build')
        build_cmd = self.get_finalized_command('build')
        new_path = os.path.abspath(build_cmd.build_lib)

        # Copy the build to a temporary directory for the purposes of testing
        # - this avoids creating pyc and __pycache__ directories inside the
        # build directory
        tmp_dir = tempfile.mkdtemp(prefix='reprojection-test-')
        testing_path = os.path.join(tmp_dir, os.path.basename(new_path))
        shutil.copytree(new_path, testing_path)

        import sys
        import subprocess

        errno = subprocess.call([sys.executable, os.path.abspath('runtests.py')], cwd=testing_path)
        raise SystemExit(errno)

setup(name='reproject',
      version="0.1.0",
      author='Thomas Robitaille',
      author_email='thomas.robitaille@gmail.com',
      packages=['reproject', 'reproject.tests'],
      cmdclass = {'test': PyTest},
      ext_modules = ext_modules
     )

Response:
<REPLACE_OLD> PyTest(Command):
 <REPLACE_NEW> PyTest(Command):

 <REPLACE_END> <REPLACE_OLD> []
 <REPLACE_NEW> []

 <REPLACE_END> <REPLACE_OLD> pass
 <REPLACE_NEW> pass

 <REPLACE_END> <REPLACE_OLD> pass
 <REPLACE_NEW> pass

 <REPLACE_END> <REPLACE_OLD> run(self):
        import sys,subprocess
 <REPLACE_NEW> run(self):

        import os
        import shutil
        import tempfile

        # First ensure that we build the package so that 2to3 gets executed
        self.reinitialize_command('build')
        self.run_command('build')
        build_cmd = self.get_finalized_command('build')
        new_path = os.path.abspath(build_cmd.build_lib)

        # Copy the build to a temporary directory for the purposes of testing
        # - this avoids creating pyc and __pycache__ directories inside the
        # build directory
        tmp_dir = tempfile.mkdtemp(prefix='reprojection-test-')
        testing_path = os.path.join(tmp_dir, os.path.basename(new_path))
        shutil.copytree(new_path, testing_path)

        import sys
        import subprocess

 <REPLACE_END> <REPLACE_OLD> 'runtests.py'])
 <REPLACE_NEW> os.path.abspath('runtests.py')], cwd=testing_path)
 <REPLACE_END> <|endoftext|> #!/usr/bin/env python

import os

from distutils.core import setup, Extension, Command
from distutils.command.sdist import sdist

from distutils.command.build_py import build_py

from numpy import get_include as get_numpy_include

numpy_includes = get_numpy_include()

ext_modules = [Extension("reproject._overlap_wrapper",
                         ['reproject/_overlap_wrapper.c', 'reproject/overlapArea.c'],
                         include_dirs=[numpy_includes])]

class PyTest(Command):

    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):

        import os
        import shutil
        import tempfile

        # First ensure that we build the package so that 2to3 gets executed
        self.reinitialize_command('build')
        self.run_command('build')
        build_cmd = self.get_finalized_command('build')
        new_path = os.path.abspath(build_cmd.build_lib)

        # Copy the build to a temporary directory for the purposes of testing
        # - this avoids creating pyc and __pycache__ directories inside the
        # build directory
        tmp_dir = tempfile.mkdtemp(prefix='reprojection-test-')
        testing_path = os.path.join(tmp_dir, os.path.basename(new_path))
        shutil.copytree(new_path, testing_path)

        import sys
        import subprocess

        errno = subprocess.call([sys.executable, os.path.abspath('runtests.py')], cwd=testing_path)
        raise SystemExit(errno)

setup(name='reproject',
      version="0.1.0",
      author='Thomas Robitaille',
      author_email='thomas.robitaille@gmail.com',
      packages=['reproject', 'reproject.tests'],
      cmdclass = {'test': PyTest},
      ext_modules = ext_modules
     )

Prompt:
Make sure the package is built before it is tested
#!/usr/bin/env python

import os

from distutils.core import setup, Extension, Command
from distutils.command.sdist import sdist

from distutils.command.build_py import build_py

from numpy import get_include as get_numpy_include

numpy_includes = get_numpy_include()

ext_modules = [Extension("reproject._overlap_wrapper",
                         ['reproject/_overlap_wrapper.c', 'reproject/overlapArea.c'],
                         include_dirs=[numpy_includes])]

class PyTest(Command):
    user_options = []
    def initialize_options(self):
        pass
    def finalize_options(self):
        pass
    def run(self):
        import sys,subprocess
        errno = subprocess.call([sys.executable, 'runtests.py'])
        raise SystemExit(errno)

setup(name='reproject',
      version="0.1.0",
      author='Thomas Robitaille',
      author_email='thomas.robitaille@gmail.com',
      packages=['reproject', 'reproject.tests'],
      cmdclass = {'test': PyTest},
      ext_modules = ext_modules
     )


import setuptools

setuptools.setup(
    name='mailcap-fix',
    version='0.1.1',
    description='A patched mailcap module that conforms to RFC 1524',
    long_description=open('README.rst', encoding='utf-8').read(),
    url='https://github.com/michael-lazar/mailcap_fix',
    author='Michael Lazar',
    author_email='lazar.michael22@gmail.com',
    license='UNLICENSE',
    keywords='mailcap 1524',
    packages=['mailcap_fix'],
)

Fix if encoding is not utf-8

Fix if encoding is not utf-8

Response:
<REPLACE_OLD> long_description=open('README.rst').read(),
 <REPLACE_NEW> long_description=open('README.rst', encoding='utf-8').read(),
 <REPLACE_END> <|endoftext|> import setuptools

setuptools.setup(
    name='mailcap-fix',
    version='0.1.1',
    description='A patched mailcap module that conforms to RFC 1524',
    long_description=open('README.rst', encoding='utf-8').read(),
    url='https://github.com/michael-lazar/mailcap_fix',
    author='Michael Lazar',
    author_email='lazar.michael22@gmail.com',
    license='UNLICENSE',
    keywords='mailcap 1524',
    packages=['mailcap_fix'],
)

Prompt:
Fix if encoding is not utf-8

import setuptools

setuptools.setup(
    name='mailcap-fix',
    version='0.1.1',
    description='A patched mailcap module that conforms to RFC 1524',
    long_description=open('README.rst').read(),
    url='https://github.com/michael-lazar/mailcap_fix',
    author='Michael Lazar',
    author_email='lazar.michael22@gmail.com',
    license='UNLICENSE',
    keywords='mailcap 1524',
    packages=['mailcap_fix'],
)


import sys

from HTMLParser import HTMLParser

class MyHtmlParser(HTMLParser):

    def __init__(self):
        HTMLParser.__init__(self)
				self.state = 'NONE'

    def handle_starttag(self, tag, attrs):
        if self.state == 'FINISHED':
            return

        if tag == '
':
            self.state = 'PARSING_TABLE'
            print tag
        elif tag == '':
            self.state ='PARSING_VALUE'
        elif tag == '
':
            if skipped_header:
                self.state = 'PARSING_ENTRY'

    def handle_endtag(self, tag):
        if tag == '
':
            self.state ='FINISHED'
        elif tag == '':
            self.state = 'PARSING_ENTRY'
        elif tag == '
':
            self.state = 'PARSING_TABLE'

    def handle_data(self, data):
        if self.state == 'PARSING_VALUE':
            print data

def main():
    if len(sys.argv) != 2:
        print "Usage: python get_matrices.py <html_file>"
        return

    f = open(sys.argv[1])

    state = 'NONE'
    entry_count = 0

    text = ""
    max_lines = 100
    c = 0
    for line in f:
        text = text + '\n' + line
        if c > max_lines:
            break
        c += 1

    parser = MyHtmlParser()
    parser.feed('
bau
')

if __name__ == '__main__':
    main()

Add a simple python to fetch matrices from UoF collection.

Response:
<REPLACE_OLD>  <REPLACE_NEW> import sys

from HTMLParser import HTMLParser

class MyHtmlParser(HTMLParser):

    def __init__(self):
        HTMLParser.__init__(self)
				self.state = 'NONE'

    def handle_starttag(self, tag, attrs):
        if self.state == 'FINISHED':
            return

        if tag == '<table>':
            self.state = 'PARSING_TABLE'
            print tag
        elif tag == '<td>':
            self.state ='PARSING_VALUE'
        elif tag == '<tr>':
            if skipped_header:
                self.state = 'PARSING_ENTRY'

    def handle_endtag(self, tag):
        if tag == '<table>':
            self.state ='FINISHED'
        elif tag == '<td>':
            self.state = 'PARSING_ENTRY'
        elif tag == '<tr>':
            self.state = 'PARSING_TABLE'

    def handle_data(self, data):
        if self.state == 'PARSING_VALUE':
            print data

def main():
    if len(sys.argv) != 2:
        print "Usage: python get_matrices.py <html_file>"
        return

    f = open(sys.argv[1])

    state = 'NONE'
    entry_count = 0

    text = ""
    max_lines = 100
    c = 0
    for line in f:
        text = text + '\n' + line
        if c > max_lines:
            break
        c += 1

    parser = MyHtmlParser()
    parser.feed('<table>bau</table>')

if __name__ == '__main__':
    main()
 <REPLACE_END> <|endoftext|> import sys

from HTMLParser import HTMLParser

class MyHtmlParser(HTMLParser):

    def __init__(self):
        HTMLParser.__init__(self)
				self.state = 'NONE'

    def handle_starttag(self, tag, attrs):
        if self.state == 'FINISHED':
            return

        if tag == '<table>':
            self.state = 'PARSING_TABLE'
            print tag
        elif tag == '<td>':
            self.state ='PARSING_VALUE'
        elif tag == '<tr>':
            if skipped_header:
                self.state = 'PARSING_ENTRY'

    def handle_endtag(self, tag):
        if tag == '<table>':
            self.state ='FINISHED'
        elif tag == '<td>':
            self.state = 'PARSING_ENTRY'
        elif tag == '<tr>':
            self.state = 'PARSING_TABLE'

    def handle_data(self, data):
        if self.state == 'PARSING_VALUE':
            print data

def main():
    if len(sys.argv) != 2:
        print "Usage: python get_matrices.py <html_file>"
        return

    f = open(sys.argv[1])

    state = 'NONE'
    entry_count = 0

    text = ""
    max_lines = 100
    c = 0
    for line in f:
        text = text + '\n' + line
        if c > max_lines:
            break
        c += 1

    parser = MyHtmlParser()
    parser.feed('<table>bau</table>')

if __name__ == '__main__':
    main()

Prompt: Add a simple python to fetch matrices from UoF collection.


# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from setuptools import setup

version = '1.1'

setup(name='treeherder-client',
      version=version,
      description="Python library to submit data to treeherder-service",
      long_description="""\
""",
      classifiers=[
          'Environment :: Console',
          'Intended Audience :: Developers',
          'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
          'Natural Language :: English',
          'Operating System :: OS Independent',
          'Programming Language :: Python',
          'Topic :: Software Development :: Libraries :: Python Modules',
      ],
      keywords='',
      author='Mozilla Automation and Testing Team',
      author_email='tools@lists.mozilla.org',
      url='https://github.com/mozilla/treeherder-client',
      license='MPL',
      packages=['thclient'],
      zip_safe=False,
      install_requires=['oauth2'],
      test_suite='thclient.tests',
      tests_require=["mock"],
      )

Add various classifications for pypi

Add various classifications for pypi

Response:
<REPLACE_OLD> classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
 <REPLACE_NEW> classifiers=[
          'Environment :: Console',
          'Intended Audience :: Developers',
          'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
          'Natural Language :: English',
          'Operating System :: OS Independent',
          'Programming Language :: Python',
          'Topic :: Software Development :: Libraries :: Python Modules',
      ],
 <REPLACE_END> <|endoftext|> # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from setuptools import setup

version = '1.1'

setup(name='treeherder-client',
      version=version,
      description="Python library to submit data to treeherder-service",
      long_description="""\
""",
      classifiers=[
          'Environment :: Console',
          'Intended Audience :: Developers',
          'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
          'Natural Language :: English',
          'Operating System :: OS Independent',
          'Programming Language :: Python',
          'Topic :: Software Development :: Libraries :: Python Modules',
      ],
      keywords='',
      author='Mozilla Automation and Testing Team',
      author_email='tools@lists.mozilla.org',
      url='https://github.com/mozilla/treeherder-client',
      license='MPL',
      packages=['thclient'],
      zip_safe=False,
      install_requires=['oauth2'],
      test_suite='thclient.tests',
      tests_require=["mock"],
      )

Prompt:
Add various classifications for pypi

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from setuptools import setup

version = '1.1'

setup(name='treeherder-client',
      version=version,
      description="Python library to submit data to treeherder-service",
      long_description="""\
""",
      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
      keywords='',
      author='Mozilla Automation and Testing Team',
      author_email='tools@lists.mozilla.org',
      url='https://github.com/mozilla/treeherder-client',
      license='MPL',
      packages=['thclient'],
      zip_safe=False,
      install_requires=['oauth2'],
      test_suite='thclient.tests',
      tests_require=["mock"],
      )


import unittest2

from penchy.tests.util import MockPipelineElement

class PipelineElementHookTest(unittest2.TestCase):
    def setUp(self):
        self.e = MockPipelineElement()
        self.list_ = [23, 42, 5]

    def test_pre_hooks(self):
        self.e.prehooks = [
            lambda: self.list_.__setitem__(0, 1),
            lambda: self.list_.__setitem__(1, 1),
            lambda: self.list_.__setitem__(2, 1)]

        self.e.run()

        self.assertListEqual(self.list_, [1, 1, 1])

    def test_post_hooks(self):
        self.e.posthooks = [
            lambda: self.list_.__setitem__(0, 1),
            lambda: self.list_.__setitem__(1, 1),
            lambda: self.list_.__setitem__(2, 1)]

        self.e.run()

        self.assertListEqual(self.list_, [1, 1, 1])

Add test for PipelineElement hooks.

tests: Add test for PipelineElement hooks.

Signed-off-by: Michael Markert <5eb998b7ac86da375651a4cd767b88c9dad25896@googlemail.com>

Response:
<INSERT> import unittest2

from penchy.tests.util import MockPipelineElement

class PipelineElementHookTest(unittest2.TestCase):
 <INSERT_END> <INSERT>   def setUp(self):
        self.e = MockPipelineElement()
        self.list_ = [23, 42, 5]

    def test_pre_hooks(self):
        self.e.prehooks = [
            lambda: self.list_.__setitem__(0, 1),
            lambda: self.list_.__setitem__(1, 1),
            lambda: self.list_.__setitem__(2, 1)]

        self.e.run()

        self.assertListEqual(self.list_, [1, 1, 1])

    def test_post_hooks(self):
        self.e.posthooks = [
            lambda: self.list_.__setitem__(0, 1),
            lambda: self.list_.__setitem__(1, 1),
            lambda: self.list_.__setitem__(2, 1)]

        self.e.run()

        self.assertListEqual(self.list_, [1, 1, 1])
 <INSERT_END> <|endoftext|> import unittest2

from penchy.tests.util import MockPipelineElement

class PipelineElementHookTest(unittest2.TestCase):
    def setUp(self):
        self.e = MockPipelineElement()
        self.list_ = [23, 42, 5]

    def test_pre_hooks(self):
        self.e.prehooks = [
            lambda: self.list_.__setitem__(0, 1),
            lambda: self.list_.__setitem__(1, 1),
            lambda: self.list_.__setitem__(2, 1)]

        self.e.run()

        self.assertListEqual(self.list_, [1, 1, 1])

    def test_post_hooks(self):
        self.e.posthooks = [
            lambda: self.list_.__setitem__(0, 1),
            lambda: self.list_.__setitem__(1, 1),
            lambda: self.list_.__setitem__(2, 1)]

        self.e.run()

        self.assertListEqual(self.list_, [1, 1, 1])

Prompt:
tests: Add test for PipelineElement hooks.

Signed-off-by: Michael Markert <5eb998b7ac86da375651a4cd767b88c9dad25896@googlemail.com>


""" Remove a property from the datastore.
How to use:

$ cd experimental/db/
$ PYTHONPATH=. remote_api_shell.py -s homeawesomation.appspot.com
> import remove_property
"""

from google.appengine.api import namespace_manager
from google.appengine.ext import db

class Base(db.Expando): pass

def remove(namespace, field):
  namespace_manager.set_namespace(namespace)
  for base in Base.all().run():
    if hasattr(base, field):
      print "%s %s" % (base.key().id_or_name(), getattr(base, 'name', None))
      delattr(base, field)
      base.put()

Fix datastore delete field script.

Fix datastore delete field script.

Response:
<REPLACE_OLD> %(base.id, base.name)
 <REPLACE_NEW> % (base.key().id_or_name(), getattr(base, 'name', None))
 <REPLACE_END> <REPLACE_OLD> del base.category
 <REPLACE_NEW> delattr(base, field)
 <REPLACE_END> <|endoftext|> """ Remove a property from the datastore.
How to use:

$ cd experimental/db/
$ PYTHONPATH=. remote_api_shell.py -s homeawesomation.appspot.com
> import remove_property
"""

from google.appengine.api import namespace_manager
from google.appengine.ext import db

class Base(db.Expando): pass

def remove(namespace, field):
  namespace_manager.set_namespace(namespace)
  for base in Base.all().run():
    if hasattr(base, field):
      print "%s %s" % (base.key().id_or_name(), getattr(base, 'name', None))
      delattr(base, field)
      base.put()

Prompt:
Fix datastore delete field script.

""" Remove a property from the datastore.
How to use:

$ cd experimental/db/
$ PYTHONPATH=. remote_api_shell.py -s homeawesomation.appspot.com
> import remove_property
"""

from google.appengine.api import namespace_manager
from google.appengine.ext import db

class Base(db.Expando): pass

def remove(namespace, field):
  namespace_manager.set_namespace(namespace)
  for base in Base.all().run():
    if hasattr(base, field):
      print "%s %s" %(base.id, base.name)
      del base.category
      base.put()


# coding: utf8
from __future__ import unicode_literals

from pathlib import Path
import sys

is_python2 = sys.version_info[0] == 2
is_python3 = sys.version_info[0] == 3

if is_python2:
    basestring_ = basestring  # noqa: F821
else:
    basestring_ = str

def force_path(location, require_exists=True):
    if not isinstance(location, Path):
        location = Path(location)
    if require_exists and not location.exists():
        raise ValueError("Can't read file: {}".format(location))
    return location

def force_string(location):
    if isinstance(location, basestring_):
        return location
    if sys.version_info[0] == 2:  # Python 2
        return str(location).decode("utf8")
    return str(location)

Improve compat handling in force_string

Response:
<REPLACE_OLD> sys

def <REPLACE_NEW> sys

is_python2 = sys.version_info[0] == 2
is_python3 = sys.version_info[0] == 3

if is_python2:
    basestring_ = basestring  # noqa: F821
else:
    basestring_ = str

def <REPLACE_END> <INSERT> isinstance(location, basestring_):
        return location
    if <INSERT_END> <|endoftext|> # coding: utf8
from __future__ import unicode_literals

from pathlib import Path
import sys

is_python2 = sys.version_info[0] == 2
is_python3 = sys.version_info[0] == 3

if is_python2:
    basestring_ = basestring  # noqa: F821
else:
    basestring_ = str

def force_path(location, require_exists=True):
    if not isinstance(location, Path):
        location = Path(location)
    if require_exists and not location.exists():
        raise ValueError("Can't read file: {}".format(location))
    return location

def force_string(location):
    if isinstance(location, basestring_):
        return location
    if sys.version_info[0] == 2:  # Python 2
        return str(location).decode("utf8")
    return str(location)

Prompt:
Improve compat handling in force_string

If we know we already have a string, no need to force it into a strinbg

# coding: utf8
from __future__ import unicode_literals

from pathlib import Path
import sys

def force_path(location, require_exists=True):
    if not isinstance(location, Path):
        location = Path(location)
    if require_exists and not location.exists():
        raise ValueError("Can't read file: {}".format(location))
    return location

def force_string(location):
    if sys.version_info[0] == 2:  # Python 2
        return str(location).decode("utf8")
    return str(location)


from typing import IO, Union

from valohai_yaml.objs import Config

from .utils import read_yaml

def parse(yaml: Union[dict, list, bytes, str, IO], validate: bool = True) -> Config:
    """
    Parse the given YAML data into a `Config` object, optionally validating it first.

    :param yaml: YAML data (either a string, a stream, or pre-parsed Python dict/list)
    :param validate: Whether to validate the data before attempting to parse it.
    :return: Config object
    """
    data = read_yaml(yaml)
    if data is None:  # empty file
        return Config()
    if validate:  # pragma: no branch
        from .validation import validate as do_validate
        do_validate(data, raise_exc=True)
    return Config.parse(data)

Handle empty YAML files in parse()

Response:
<INSERT> data is None:  # empty file
        return Config()
    if <INSERT_END> <|endoftext|> from typing import IO, Union

from valohai_yaml.objs import Config

from .utils import read_yaml

def parse(yaml: Union[dict, list, bytes, str, IO], validate: bool = True) -> Config:
    """
    Parse the given YAML data into a `Config` object, optionally validating it first.

    :param yaml: YAML data (either a string, a stream, or pre-parsed Python dict/list)
    :param validate: Whether to validate the data before attempting to parse it.
    :return: Config object
    """
    data = read_yaml(yaml)
    if data is None:  # empty file
        return Config()
    if validate:  # pragma: no branch
        from .validation import validate as do_validate
        do_validate(data, raise_exc=True)
    return Config.parse(data)

Prompt:
Handle empty YAML files in parse()

Refs valohai/valohai-cli#170

from typing import IO, Union

from valohai_yaml.objs import Config

from .utils import read_yaml

def parse(yaml: Union[dict, list, bytes, str, IO], validate: bool = True) -> Config:
    """
    Parse the given YAML data into a `Config` object, optionally validating it first.

    :param yaml: YAML data (either a string, a stream, or pre-parsed Python dict/list)
    :param validate: Whether to validate the data before attempting to parse it.
    :return: Config object
    """
    data = read_yaml(yaml)
    if validate:  # pragma: no branch
        from .validation import validate as do_validate
        do_validate(data, raise_exc=True)
    return Config.parse(data)


"""
AutoEncoder Models
"""

from model_base import *
from metrics_base import *

class H2OAutoEncoderModel(ModelBase):
  """
  Class for AutoEncoder models.
  """
  def __init__(self, dest_key, model_json):
    super(H2OAutoEncoderModel, self).__init__(dest_key, model_json,H2OAutoEncoderModelMetrics)

  def anomaly(self,test_data,per_feature=False):
    """
    Obtain the reconstruction error for the input test_data.

    :param test_data: The dataset upon which the reconstruction error is computed.
    :param per_feature: Whether to return the square reconstruction error per feature. Otherwise, return the mean square error.
    :return: Return the reconstruction error.
    """
    if not test_data: raise ValueError("Must specify test data")
    j = H2OConnection.post_json("Predictions/models/" + self._id + "/frames/" + test_data._id, reconstruction_error=True, reconstruction_error_per_feature=per_feature)
    return h2o.get_frame(j["model_metrics"][0]["predictions"]["frame_id"]["name"])

Response:
<REPLACE_OLD> anomaly(self,test_data):
 <REPLACE_NEW> anomaly(self,test_data,per_feature=False):
 <REPLACE_END> <INSERT>    :param per_feature: Whether to return the square reconstruction error per feature. Otherwise, return the mean square error.
 <INSERT_END> <REPLACE_OLD> reconstruction_error=True)
 <REPLACE_NEW> reconstruction_error=True, reconstruction_error_per_feature=per_feature)
 <REPLACE_END> <|endoftext|> """
AutoEncoder Models
"""

from model_base import *
from metrics_base import *

class H2OAutoEncoderModel(ModelBase):
  """
  Class for AutoEncoder models.
  """
  def __init__(self, dest_key, model_json):
    super(H2OAutoEncoderModel, self).__init__(dest_key, model_json,H2OAutoEncoderModelMetrics)

  def anomaly(self,test_data,per_feature=False):
    """
    Obtain the reconstruction error for the input test_data.

    :param test_data: The dataset upon which the reconstruction error is computed.
    :param per_feature: Whether to return the square reconstruction error per feature. Otherwise, return the mean square error.
    :return: Return the reconstruction error.
    """
    if not test_data: raise ValueError("Must specify test data")
    j = H2OConnection.post_json("Predictions/models/" + self._id + "/frames/" + test_data._id, reconstruction_error=True, reconstruction_error_per_feature=per_feature)
    return h2o.get_frame(j["model_metrics"][0]["predictions"]["frame_id"]["name"])

Prompt:
PUBDEV-2078: Add extra argument to get per-feature reconstruction error for
anomaly detection from Python.

"""
AutoEncoder Models
"""

from model_base import *
from metrics_base import *

class H2OAutoEncoderModel(ModelBase):
  """
  Class for AutoEncoder models.
  """
  def __init__(self, dest_key, model_json):
    super(H2OAutoEncoderModel, self).__init__(dest_key, model_json,H2OAutoEncoderModelMetrics)

  def anomaly(self,test_data):
    """
    Obtain the reconstruction error for the input test_data.

    :param test_data: The dataset upon which the reconstruction error is computed.
    :return: Return the reconstruction error.
    """
    if not test_data: raise ValueError("Must specify test data")
    j = H2OConnection.post_json("Predictions/models/" + self._id + "/frames/" + test_data._id, reconstruction_error=True)
    return h2o.get_frame(j["model_metrics"][0]["predictions"]["frame_id"]["name"])


#!/usr/bin/env python3

import git

class PullPush:

    def __init__(self, repo_dir):
        self.repo_dir = repo_dir
        self.repo = None

    def pull(self, source_repo):
        """
        Pulls the remote source_repo and stores it in the repo_dir directory.
        """

        self.repo = git.Repo.init(self.repo_dir)
        origin = self.repo.create_remote('origin', source_repo)
        origin.fetch()
        origin.pull(origin.refs[0].remote_head)

    def set_target_repo(self, new_url):
        """
        Changes the target url of the previously pulled repo.
        """

        origin = self.repo.remotes.origin
        cw = origin.config_writer
        cw.set("url", new_url)
        cw.release()

    def push(self, target_repo):
        """
        Pushes the previously pulled repo to the target_repo.
        """

        if self.repo is None:
            # TODO Better handling
            return

        origin = self.repo.remotes.origin
        self.set_target_repo(target_repo)
        self.repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
        origin.push()

Check of repo was pulled

Check of repo was pulled

Response:
<INSERT> if self.repo is None:
            # TODO Better handling
            return

        <INSERT_END> <|endoftext|> #!/usr/bin/env python3

import git

class PullPush:

    def __init__(self, repo_dir):
        self.repo_dir = repo_dir
        self.repo = None

    def pull(self, source_repo):
        """
        Pulls the remote source_repo and stores it in the repo_dir directory.
        """

        self.repo = git.Repo.init(self.repo_dir)
        origin = self.repo.create_remote('origin', source_repo)
        origin.fetch()
        origin.pull(origin.refs[0].remote_head)

    def set_target_repo(self, new_url):
        """
        Changes the target url of the previously pulled repo.
        """

        origin = self.repo.remotes.origin
        cw = origin.config_writer
        cw.set("url", new_url)
        cw.release()

    def push(self, target_repo):
        """
        Pushes the previously pulled repo to the target_repo.
        """

        if self.repo is None:
            # TODO Better handling
            return

        origin = self.repo.remotes.origin
        self.set_target_repo(target_repo)
        self.repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
        origin.push()

Prompt:
Check of repo was pulled

#!/usr/bin/env python3

import git

class PullPush:

    def __init__(self, repo_dir):
        self.repo_dir = repo_dir
        self.repo = None

    def pull(self, source_repo):
        """
        Pulls the remote source_repo and stores it in the repo_dir directory.
        """

        self.repo = git.Repo.init(self.repo_dir)
        origin = self.repo.create_remote('origin', source_repo)
        origin.fetch()
        origin.pull(origin.refs[0].remote_head)

    def set_target_repo(self, new_url):
        """
        Changes the target url of the previously pulled repo.
        """

        origin = self.repo.remotes.origin
        cw = origin.config_writer
        cw.set("url", new_url)
        cw.release()

    def push(self, target_repo):
        """
        Pushes the previously pulled repo to the target_repo.
        """

        origin = self.repo.remotes.origin
        self.set_target_repo(target_repo)
        self.repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
        origin.push()


# coding: utf-8

# In[79]:

import math
import operator
import json
from geopy.distance import great_circle

# In[90]:

class Order_districts():

    def get_district_info():
        # -- get names and coordinates from csv file
        with open('coordinates.json') as coord_file:
            district_dict = json.load(coord_file)
        return district_dict

# In[134]:

get_district_info(); # test for json reading

# In[128]:

def distance(lat0, lon0, lat, lon):
    '''
    Calculates distance on Earth's surface in meters
    '''
    return great_circle((lat0,lon0), (lat,lon)).meters

def e_distance(x,y,w,z):
    '''
    Euclidean distance calculation for simple sorting purposes
    '''
    a = math.pow(x - w,2)
    b = math.pow(y - z,2)
    return math.sqrt(a+b)

# In[131]:

def order_districts(lat0, lon0, district_dict):
    '''
    function that return a list of names of districts ordered by distance from the point (lat0,lon0) passed from map
    Inputs: 'lat0' = latitude of point at center of map
            'lon0' = longitude of point at center of map
            'district_dict' = dict of district names and (lat,lon) from function get_district_info()
    Outputs: df with district names ordered by distance, coordinates of district (lat,lon)
    '''
    distance_dict={}
    # -- loop thru entries in coord/name dictionary
    for key, value in district_dict.iteritems():
        lat = float(value[0]); lon = float(value[1]);
        # -- calculate coords in radians
        #Delta_lat = math.radians(lat0-lat) # latitudinal distance
        #Delta_lon = math.radians(lon0-lon) # longitudinal distance
        #lat0 = math.radians(lat0) # convert to radians
        #lat = math.radians(lat)
        distance_dict[key] = distance(lat0, lon0, lat, lon)

    sorted_districts = sorted(distance_dict.items(), key=operator.itemgetter(1))

    return zip(*sorted_districts)

# In[136]:

#order_districts(27.67298,85.43005,get_district_info())[0] # test for distance

# In[121]:

# In[ ]:

Return the districts name by distance given coordinates

Response:
<REPLACE_OLD>  <REPLACE_NEW>
# coding: utf-8

# In[79]:

import math
import operator
import json
from geopy.distance import great_circle

# In[90]:

class Order_districts():

    def get_district_info():
        # -- get names and coordinates from csv file
        with open('coordinates.json') as coord_file:
            district_dict = json.load(coord_file)
        return district_dict

# In[134]:

get_district_info(); # test for json reading

# In[128]:

def distance(lat0, lon0, lat, lon):
    '''
    Calculates distance on Earth's surface in meters
    '''
    return great_circle((lat0,lon0), (lat,lon)).meters

def e_distance(x,y,w,z):
    '''
    Euclidean distance calculation for simple sorting purposes
    '''
    a = math.pow(x - w,2)
    b = math.pow(y - z,2)
    return math.sqrt(a+b)

# In[131]:

def order_districts(lat0, lon0, district_dict):
    '''
    function that return a list of names of districts ordered by distance from the point (lat0,lon0) passed from map
    Inputs: 'lat0' = latitude of point at center of map
            'lon0' = longitude of point at center of map
            'district_dict' = dict of district names and (lat,lon) from function get_district_info()
    Outputs: df with district names ordered by distance, coordinates of district (lat,lon)
    '''
    distance_dict={}
    # -- loop thru entries in coord/name dictionary
    for key, value in district_dict.iteritems():
        lat = float(value[0]); lon = float(value[1]);
        # -- calculate coords in radians
        #Delta_lat = math.radians(lat0-lat) # latitudinal distance
        #Delta_lon = math.radians(lon0-lon) # longitudinal distance
        #lat0 = math.radians(lat0) # convert to radians
        #lat = math.radians(lat)
        distance_dict[key] = distance(lat0, lon0, lat, lon)

    sorted_districts = sorted(distance_dict.items(), key=operator.itemgetter(1))

    return zip(*sorted_districts)

# In[136]:

#order_districts(27.67298,85.43005,get_district_info())[0] # test for distance

# In[121]:

# In[ ]:

 <REPLACE_END> <|endoftext|>
# coding: utf-8

# In[79]:

import math
import operator
import json
from geopy.distance import great_circle

# In[90]:

class Order_districts():

    def get_district_info():
        # -- get names and coordinates from csv file
        with open('coordinates.json') as coord_file:
            district_dict = json.load(coord_file)
        return district_dict

# In[134]:

get_district_info(); # test for json reading

# In[128]:

def distance(lat0, lon0, lat, lon):
    '''
    Calculates distance on Earth's surface in meters
    '''
    return great_circle((lat0,lon0), (lat,lon)).meters

def e_distance(x,y,w,z):
    '''
    Euclidean distance calculation for simple sorting purposes
    '''
    a = math.pow(x - w,2)
    b = math.pow(y - z,2)
    return math.sqrt(a+b)

# In[131]:

def order_districts(lat0, lon0, district_dict):
    '''
    function that return a list of names of districts ordered by distance from the point (lat0,lon0) passed from map
    Inputs: 'lat0' = latitude of point at center of map
            'lon0' = longitude of point at center of map
            'district_dict' = dict of district names and (lat,lon) from function get_district_info()
    Outputs: df with district names ordered by distance, coordinates of district (lat,lon)
    '''
    distance_dict={}
    # -- loop thru entries in coord/name dictionary
    for key, value in district_dict.iteritems():
        lat = float(value[0]); lon = float(value[1]);
        # -- calculate coords in radians
        #Delta_lat = math.radians(lat0-lat) # latitudinal distance
        #Delta_lon = math.radians(lon0-lon) # longitudinal distance
        #lat0 = math.radians(lat0) # convert to radians
        #lat = math.radians(lat)
        distance_dict[key] = distance(lat0, lon0, lat, lon)

    sorted_districts = sorted(distance_dict.items(), key=operator.itemgetter(1))

    return zip(*sorted_districts)

# In[136]:

#order_districts(27.67298,85.43005,get_district_info())[0] # test for distance

# In[121]:

# In[ ]:

Prompt: Return the districts name by distance given coordinates


class OneOf:
	def __init__(self, members):
		self.members = members

	def __call__(self, candidate):
		if candidate in self.members:
			return True
		return "%s not in %s" % (candidate, self.members)

	def __repr__(self):
		return "one of %s" % ', '.join(map(repr, self.members))

def oneof(*members):
	return OneOf(members)

class InRange:
	def __init__(self, start, end):
		self.start = start
		self.end = end

	def __call__(self, candidate):
		if self.start <= candidate <= self.end:
			return True
		return "%s not between %s and %s" % (candidate, self.start, self.end)

	def __repr__(self):
		return "between %s and %s" % (self.start, self.end)

def inrange(start, end):
	return InRange(start, end)

Response:
<REPLACE_OLD> '.join(self.members)

def <REPLACE_NEW> '.join(map(repr, self.members))

def <REPLACE_END> <|endoftext|> class OneOf:
	def __init__(self, members):
		self.members = members

	def __call__(self, candidate):
		if candidate in self.members:
			return True
		return "%s not in %s" % (candidate, self.members)

	def __repr__(self):
		return "one of %s" % ', '.join(map(repr, self.members))

def oneof(*members):
	return OneOf(members)

class InRange:
	def __init__(self, start, end):
		self.start = start
		self.end = end

	def __call__(self, candidate):
		if self.start <= candidate <= self.end:
			return True
		return "%s not between %s and %s" % (candidate, self.start, self.end)

	def __repr__(self):
		return "between %s and %s" % (self.start, self.end)

def inrange(start, end):
	return InRange(start, end)

Prompt:
Fix problem rendering oneof() predicate when the members aren't strings

class OneOf:
	def __init__(self, members):
		self.members = members

	def __call__(self, candidate):
		if candidate in self.members:
			return True
		return "%s not in %s" % (candidate, self.members)

	def __repr__(self):
		return "one of %s" % ', '.join(self.members)

def oneof(*members):
	return OneOf(members)

class InRange:
	def __init__(self, start, end):
		self.start = start
		self.end = end

	def __call__(self, candidate):
		if self.start <= candidate <= self.end:
			return True
		return "%s not between %s and %s" % (candidate, self.start, self.end)

	def __repr__(self):
		return "between %s and %s" % (self.start, self.end)

def inrange(start, end):
	return InRange(start, end)


from django import forms

from apps.careeropportunity.models import CareerOpportunity

class AddCareerOpportunityForm(forms.ModelForm):

    title = forms.CharField(label='Tittel', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Tittel for karrieremuligheten'}))
    ingress = forms.CharField(label='Ingress', required=True, widget=forms.Textarea(
        attrs={'placeholder': 'Kort ingress til karrieremuligheten (Max 250 tegn)'}))
    description = forms.CharField(label='Beskrivelse', required=True, widget=forms.Textarea(
        attrs={'placeholder': 'Detaljert beskrivelse av karrieremuligheten'}))
    start = forms.DateTimeField(label='Start-tid', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg start-tid'}))
    end = forms.DateTimeField(label='Slutt-tid', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg slutt-tid'}))
    deadline = forms.DateTimeField(label='Søknadsfrist', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg søknadsfrist'}))

    class Meta:
        model = CareerOpportunity
        fields = ('company', 'title', 'ingress', 'description', 'start', 'end', 'featured', 'deadline', 'employment', 'location')

Response:
<REPLACE_OLD> AddCareerOpportunityForm(forms.ModelForm):
 <REPLACE_NEW> AddCareerOpportunityForm(forms.ModelForm):

    title = forms.CharField(label='Tittel', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Tittel for karrieremuligheten'}))
    ingress = forms.CharField(label='Ingress', required=True, widget=forms.Textarea(
        attrs={'placeholder': 'Kort ingress til karrieremuligheten (Max 250 tegn)'}))
 <REPLACE_END> <REPLACE_OLD> ingress <REPLACE_NEW> start <REPLACE_END> <REPLACE_OLD> forms.CharField(label='Ingress', <REPLACE_NEW> forms.DateTimeField(label='Start-tid', <REPLACE_END> <REPLACE_OLD> 'Kort ingress til karrieremuligheten'}))

 <REPLACE_NEW> 'Velg start-tid'}))
    end = forms.DateTimeField(label='Slutt-tid', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg slutt-tid'}))
    deadline = forms.DateTimeField(label='Søknadsfrist', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg søknadsfrist'}))

 <REPLACE_END> <REPLACE_OLD> 'featured')
 <REPLACE_NEW> 'featured', 'deadline', 'employment', 'location')
 <REPLACE_END> <|endoftext|> from django import forms

from apps.careeropportunity.models import CareerOpportunity

class AddCareerOpportunityForm(forms.ModelForm):

    title = forms.CharField(label='Tittel', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Tittel for karrieremuligheten'}))
    ingress = forms.CharField(label='Ingress', required=True, widget=forms.Textarea(
        attrs={'placeholder': 'Kort ingress til karrieremuligheten (Max 250 tegn)'}))
    description = forms.CharField(label='Beskrivelse', required=True, widget=forms.Textarea(
        attrs={'placeholder': 'Detaljert beskrivelse av karrieremuligheten'}))
    start = forms.DateTimeField(label='Start-tid', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg start-tid'}))
    end = forms.DateTimeField(label='Slutt-tid', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg slutt-tid'}))
    deadline = forms.DateTimeField(label='Søknadsfrist', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Velg søknadsfrist'}))

    class Meta:
        model = CareerOpportunity
        fields = ('company', 'title', 'ingress', 'description', 'start', 'end', 'featured', 'deadline', 'employment', 'location')

Prompt:
Add inputfields for new attributes on careeropportunities and placeholdertext

from django import forms

from apps.careeropportunity.models import CareerOpportunity

class AddCareerOpportunityForm(forms.ModelForm):
    description = forms.CharField(label='Beskrivelse', required=True, widget=forms.Textarea(
        attrs={'placeholder': 'Detaljert beskrivelse av karrieremuligheten'}))
    ingress = forms.CharField(label='Ingress', required=True, widget=forms.TextInput(
        attrs={'placeholder': 'Kort ingress til karrieremuligheten'}))

    class Meta:
        model = CareerOpportunity
        fields = ('company', 'title', 'ingress', 'description', 'start', 'end', 'featured')


import logging

from scripts.util import documents

from scrapi import settings
from scrapi.linter import RawDocument
from scrapi.processing.elasticsearch import es
from scrapi.tasks import normalize, process_normalized, process_raw

logger = logging.getLogger(__name__)

def rename(source, target, dry=True):
    assert source != target, "Can't rename {} to {}, names are the same".format(source, target)
    count = 0
    exceptions = []

    for doc in documents(source):
        count += 1
        try:
            raw = RawDocument({
                'doc': doc.doc,
                'docID': doc.docID,
                'source': target,
                'filetype': doc.filetype,
                'timestamps': doc.timestamps,
                'versions': doc.versions
            })
            if not dry:
                process_raw(raw)
                process_normalized(normalize(raw, raw['source']), raw)
            logger.info('Processed document from {} with id {}'.format(source, raw['docID']))
        except Exception as e:
            logger.exception(e)
            exceptions.append(e)
        else:
            if not dry:
                # doc.delete()
                es.delete(index=settings.ELASTIC_INDEX, doc_type=source, id=raw['docID'], ignore=[404])
                es.delete(index='share_v1', doc_type=source, id=raw['docID'], ignore=[404])
            logger.info('Deleted document from {} with id {}'.format(source, raw['docID']))
    if dry:
        logger.info('Dry run complete')

    for ex in exceptions:
        logger.exception(e)
    logger.info('{} documents processed, with {} exceptions'.format(count, len(exceptions)))

Response:
<INSERT> # <INSERT_END> <INSERT> doc_type=source, id=raw['docID'], ignore=[404])
                es.delete(index='share_v1', <INSERT_END> <|endoftext|> import logging

from scripts.util import documents

from scrapi import settings
from scrapi.linter import RawDocument
from scrapi.processing.elasticsearch import es
from scrapi.tasks import normalize, process_normalized, process_raw

logger = logging.getLogger(__name__)

def rename(source, target, dry=True):
    assert source != target, "Can't rename {} to {}, names are the same".format(source, target)
    count = 0
    exceptions = []

    for doc in documents(source):
        count += 1
        try:
            raw = RawDocument({
                'doc': doc.doc,
                'docID': doc.docID,
                'source': target,
                'filetype': doc.filetype,
                'timestamps': doc.timestamps,
                'versions': doc.versions
            })
            if not dry:
                process_raw(raw)
                process_normalized(normalize(raw, raw['source']), raw)
            logger.info('Processed document from {} with id {}'.format(source, raw['docID']))
        except Exception as e:
            logger.exception(e)
            exceptions.append(e)
        else:
            if not dry:
                # doc.delete()
                es.delete(index=settings.ELASTIC_INDEX, doc_type=source, id=raw['docID'], ignore=[404])
                es.delete(index='share_v1', doc_type=source, id=raw['docID'], ignore=[404])
            logger.info('Deleted document from {} with id {}'.format(source, raw['docID']))
    if dry:
        logger.info('Dry run complete')

    for ex in exceptions:
        logger.exception(e)
    logger.info('{} documents processed, with {} exceptions'.format(count, len(exceptions)))

Prompt:
Stop cassandra from deleting documents, delete documents from old index as well

import logging

from scripts.util import documents

from scrapi import settings
from scrapi.linter import RawDocument
from scrapi.processing.elasticsearch import es
from scrapi.tasks import normalize, process_normalized, process_raw

logger = logging.getLogger(__name__)

def rename(source, target, dry=True):
    assert source != target, "Can't rename {} to {}, names are the same".format(source, target)
    count = 0
    exceptions = []

    for doc in documents(source):
        count += 1
        try:
            raw = RawDocument({
                'doc': doc.doc,
                'docID': doc.docID,
                'source': target,
                'filetype': doc.filetype,
                'timestamps': doc.timestamps,
                'versions': doc.versions
            })
            if not dry:
                process_raw(raw)
                process_normalized(normalize(raw, raw['source']), raw)
            logger.info('Processed document from {} with id {}'.format(source, raw['docID']))
        except Exception as e:
            logger.exception(e)
            exceptions.append(e)
        else:
            if not dry:
                doc.delete()
                es.delete(index=settings.ELASTIC_INDEX, doc_type=source, id=raw['docID'], ignore=[404])
            logger.info('Deleted document from {} with id {}'.format(source, raw['docID']))
    if dry:
        logger.info('Dry run complete')

    for ex in exceptions:
        logger.exception(e)
    logger.info('{} documents processed, with {} exceptions'.format(count, len(exceptions)))


# When using openfisca for a large population, having too many variables in cache make openfisca performances drop.
# The following variables are intermediate results and do not need to be cached in those usecases.

cache_blacklist = set([
    'aide_logement_loyer_retenu',
    'aide_logement_charges',
    'aide_logement_R0',
    'aide_logement_taux_famille',
    'aide_logement_taux_loyer',
    'aide_logement_participation_personnelle',
    'aide_logement_loyer_seuil_degressivite',
    'aide_logement_loyer_seuil_suppression',
    'aide_logement_montant_brut_avant_degressivite',
    'aides_logement_primo_accedant',
    'aides_logement_primo_accedant_k',
    'aides_logement_primo_accedant_nb_part',
    'aides_logement_primo_accedant_loyer_minimal',
    'aides_logement_primo_accedant_plafond_mensualite',
    'aides_logement_primo_accedant_ressources',
])

Add new variable to cache blacklist

Add new variable to cache blacklist

Response:
<REPLACE_OLD> intermadiate <REPLACE_NEW> intermediate <REPLACE_END> <REPLACE_OLD> 'aide_logement_montant_brut_avant_degressivite',
])
 <REPLACE_NEW> 'aide_logement_montant_brut_avant_degressivite',
    'aides_logement_primo_accedant',
    'aides_logement_primo_accedant_k',
    'aides_logement_primo_accedant_nb_part',
    'aides_logement_primo_accedant_loyer_minimal',
    'aides_logement_primo_accedant_plafond_mensualite',
    'aides_logement_primo_accedant_ressources',
])
 <REPLACE_END> <|endoftext|> # When using openfisca for a large population, having too many variables in cache make openfisca performances drop.
# The following variables are intermediate results and do not need to be cached in those usecases.

cache_blacklist = set([
    'aide_logement_loyer_retenu',
    'aide_logement_charges',
    'aide_logement_R0',
    'aide_logement_taux_famille',
    'aide_logement_taux_loyer',
    'aide_logement_participation_personnelle',
    'aide_logement_loyer_seuil_degressivite',
    'aide_logement_loyer_seuil_suppression',
    'aide_logement_montant_brut_avant_degressivite',
    'aides_logement_primo_accedant',
    'aides_logement_primo_accedant_k',
    'aides_logement_primo_accedant_nb_part',
    'aides_logement_primo_accedant_loyer_minimal',
    'aides_logement_primo_accedant_plafond_mensualite',
    'aides_logement_primo_accedant_ressources',
])

Prompt:
Add new variable to cache blacklist

# When using openfisca for a large population, having too many variables in cache make openfisca performances drop.
# The following variables are intermadiate results and do not need to be cached in those usecases.

cache_blacklist = set([
    'aide_logement_loyer_retenu',
    'aide_logement_charges',
    'aide_logement_R0',
    'aide_logement_taux_famille',
    'aide_logement_taux_loyer',
    'aide_logement_participation_personnelle',
    'aide_logement_loyer_seuil_degressivite',
    'aide_logement_loyer_seuil_suppression',
    'aide_logement_montant_brut_avant_degressivite',
])


import json
import subprocess
from ._run import Error
from ._utils import convert_kwargs_to_cmd_line_args

def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
    """Run ffprobe on the specified file and return a JSON representation of the output.

    Raises:
        :class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code,
            an :class:`Error` is returned with a generic error message.
            The stderr output can be retrieved by accessing the
            ``stderr`` property of the exception.
    """
    args = [cmd, '-show_format', '-show_streams', '-of', 'json']
    args += convert_kwargs_to_cmd_line_args(kwargs)
    args += [filename]

    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate(timeout=timeout)
    if p.returncode != 0:
        raise Error('ffprobe', out, err)
    return json.loads(out.decode('utf-8'))

__all__ = ['probe']

Add optional timeout argument to probe

Response:
<INSERT> timeout=None, <INSERT_END> <REPLACE_OLD> p.communicate()
 <REPLACE_NEW> p.communicate(timeout=timeout)
 <REPLACE_END> <|endoftext|> import json
import subprocess
from ._run import Error
from ._utils import convert_kwargs_to_cmd_line_args

def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
    """Run ffprobe on the specified file and return a JSON representation of the output.

    Raises:
        :class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code,
            an :class:`Error` is returned with a generic error message.
            The stderr output can be retrieved by accessing the
            ``stderr`` property of the exception.
    """
    args = [cmd, '-show_format', '-show_streams', '-of', 'json']
    args += convert_kwargs_to_cmd_line_args(kwargs)
    args += [filename]

    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate(timeout=timeout)
    if p.returncode != 0:
        raise Error('ffprobe', out, err)
    return json.loads(out.decode('utf-8'))

__all__ = ['probe']

Prompt:
Add optional timeout argument to probe

Popen.communicate() supports a timeout argument which is useful in case
there is a risk that the probe hangs.

import json
import subprocess
from ._run import Error
from ._utils import convert_kwargs_to_cmd_line_args

def probe(filename, cmd='ffprobe', **kwargs):
    """Run ffprobe on the specified file and return a JSON representation of the output.

    Raises:
        :class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code,
            an :class:`Error` is returned with a generic error message.
            The stderr output can be retrieved by accessing the
            ``stderr`` property of the exception.
    """
    args = [cmd, '-show_format', '-show_streams', '-of', 'json']
    args += convert_kwargs_to_cmd_line_args(kwargs)
    args += [filename]

    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if p.returncode != 0:
        raise Error('ffprobe', out, err)
    return json.loads(out.decode('utf-8'))

__all__ = ['probe']


def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('fparser',parent_package,top_path)
    config.add_data_files('log.config')
    return config

Response:
<INSERT> config.add_data_files('log.config')
    <INSERT_END> <|endoftext|>
def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('fparser',parent_package,top_path)
    config.add_data_files('log.config')
    return config

Prompt:
Add log.config to data files to fix installed fparser.

def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('fparser',parent_package,top_path)
    return config


# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

class Migration(migrations.Migration):

    dependencies = [
        ('django_mailbox', '0003_auto_20150409_0316'),
    ]

    operations = [
        migrations.AlterField(
            model_name='message',
            name='eml',
            field=models.FileField(verbose_name='Raw message contents', upload_to='messages', null=True, help_text='Original full content of message'),
        ),
        migrations.AlterField(
            model_name='messageattachment',
            name='document',
            field=models.FileField(verbose_name='Document', upload_to='mailbox_attachments/%Y/%m/%d/'),
        ),
    ]

Add migration to resolve inconsistency between python2 and python3 strings

Response:
<INSERT> # -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

class Migration(migrations.Migration):

 <INSERT_END> <INSERT>   dependencies = [
        ('django_mailbox', '0003_auto_20150409_0316'),
    ]

    operations = [
        migrations.AlterField(
            model_name='message',
            name='eml',
            field=models.FileField(verbose_name='Raw message contents', upload_to='messages', null=True, help_text='Original full content of message'),
        ),
        migrations.AlterField(
            model_name='messageattachment',
            name='document',
            field=models.FileField(verbose_name='Document', upload_to='mailbox_attachments/%Y/%m/%d/'),
        ),
    ]
 <INSERT_END> <|endoftext|> # -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

class Migration(migrations.Migration):

    dependencies = [
        ('django_mailbox', '0003_auto_20150409_0316'),
    ]

    operations = [
        migrations.AlterField(
            model_name='message',
            name='eml',
            field=models.FileField(verbose_name='Raw message contents', upload_to='messages', null=True, help_text='Original full content of message'),
        ),
        migrations.AlterField(
            model_name='messageattachment',
            name='document',
            field=models.FileField(verbose_name='Document', upload_to='mailbox_attachments/%Y/%m/%d/'),
        ),
    ]

Prompt: Add migration to resolve inconsistency between python2 and python3 strings


from django.db.models import Q
from django.shortcuts import render
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework_json_api.renderers import JSONRenderer
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView

from bookmarks.models import Bookmark
from bookmarks.serializers import BookmarkSerializer

class BookmarkListCreateAPIView(ListCreateAPIView):
    queryset = Bookmark.objects.all()
    serializer_class = BookmarkSerializer
    resource_name = 'bookmark'
    action = 'list'
    renderer_classes = (JSONRenderer,)
    filter_backends = (SearchFilter, OrderingFilter)
    search_fields = ('url', 'title')
    ordering_fields = ('id', 'url', 'title', 'bookmarked_at')

class BookmarkRetrieveUpdateDestroyAPIView(RetrieveUpdateDestroyAPIView):
    queryset = Bookmark.objects.all()
    serializer_class = BookmarkSerializer
    lookup_field = 'bookmark_id'

Response:
<DELETE> rest_framework.generics import ListAPIView
from <DELETE_END> <INSERT> ListCreateAPIView, <INSERT_END> <REPLACE_OLD> BookmarkListCreateAPIView(ListAPIView):
 <REPLACE_NEW> BookmarkListCreateAPIView(ListCreateAPIView):
 <REPLACE_END> <|endoftext|> from django.db.models import Q
from django.shortcuts import render
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework_json_api.renderers import JSONRenderer
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView

from bookmarks.models import Bookmark
from bookmarks.serializers import BookmarkSerializer

class BookmarkListCreateAPIView(ListCreateAPIView):
    queryset = Bookmark.objects.all()
    serializer_class = BookmarkSerializer
    resource_name = 'bookmark'
    action = 'list'
    renderer_classes = (JSONRenderer,)
    filter_backends = (SearchFilter, OrderingFilter)
    search_fields = ('url', 'title')
    ordering_fields = ('id', 'url', 'title', 'bookmarked_at')

class BookmarkRetrieveUpdateDestroyAPIView(RetrieveUpdateDestroyAPIView):
    queryset = Bookmark.objects.all()
    serializer_class = BookmarkSerializer
    lookup_field = 'bookmark_id'

Prompt:
Use ListCreateAPIView as base class to support bookmark creation

from django.db.models import Q
from django.shortcuts import render
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework.generics import ListAPIView
from rest_framework_json_api.renderers import JSONRenderer
from rest_framework.generics import RetrieveUpdateDestroyAPIView

from bookmarks.models import Bookmark
from bookmarks.serializers import BookmarkSerializer

class BookmarkListCreateAPIView(ListAPIView):
    queryset = Bookmark.objects.all()
    serializer_class = BookmarkSerializer
    resource_name = 'bookmark'
    action = 'list'
    renderer_classes = (JSONRenderer,)
    filter_backends = (SearchFilter, OrderingFilter)
    search_fields = ('url', 'title')
    ordering_fields = ('id', 'url', 'title', 'bookmarked_at')

class BookmarkRetrieveUpdateDestroyAPIView(RetrieveUpdateDestroyAPIView):
    queryset = Bookmark.objects.all()
    serializer_class = BookmarkSerializer
    lookup_field = 'bookmark_id'