import re

INCOMPLETE_TASK_RE = re.compile(r'
\[ \] (.*?)(
|
)', re.DOTALL)
INCOMPLETE_TASK_SUB = (r'
'
                       r'<input type="checkbox" '
                       r'class="task-list-item-checkbox" disabled=""> \1\2')
COMPLETE_TASK_RE = re.compile(r'
\[x\] (.*?)(
|
)', re.DOTALL)
COMPLETE_TASK_SUB = (r'
'
                     r'<input type="checkbox" class="task-list-item-checkbox" '
                     r'checked="" disabled=""> \1\2')

HEADER_PATCH_RE = re.compile(r'{:"aria-hidden"=>"true", :class=>'
                             r'"octicon octicon-link"}', re.DOTALL)
HEADER_PATCH_SUB = r''

def patch(html, user_content=False):
    """
    Processes the HTML rendered by the GitHub API, patching
    any inconsistencies from the main site.
    """
    # FUTURE: Remove this once GitHub API renders task lists
    # https://github.com/isaacs/github/issues/309
    if not user_content:
        html = INCOMPLETE_TASK_RE.sub(INCOMPLETE_TASK_SUB, html)
        html = COMPLETE_TASK_RE.sub(COMPLETE_TASK_SUB, html)

    # FUTURE: Remove this once GitHub API fixes the header bug
    # https://github.com/joeyespo/grip/issues/244
    html = HEADER_PATCH_RE.sub(HEADER_PATCH_SUB, html)

    return html

Response:
<REPLACE_OLD> \1\2')

def <REPLACE_NEW> \1\2')

HEADER_PATCH_RE = re.compile(r'<span>{:"aria-hidden"=&gt;"true", :class=&gt;'
                             r'"octicon octicon-link"}</span>', re.DOTALL)
HEADER_PATCH_SUB = r'<span class="octicon octicon-link"></span>'

def <REPLACE_END> <INSERT> # FUTURE: Remove this once GitHub API fixes the header bug
    # https://github.com/joeyespo/grip/issues/244
    html = HEADER_PATCH_RE.sub(HEADER_PATCH_SUB, html)

    <INSERT_END> <|endoftext|> import re

INCOMPLETE_TASK_RE = re.compile(r'<li>\[ \] (.*?)(<ul.*?>|</li>)', re.DOTALL)
INCOMPLETE_TASK_SUB = (r'<li class="task-list-item">'
                       r'<input type="checkbox" '
                       r'class="task-list-item-checkbox" disabled=""> \1\2')
COMPLETE_TASK_RE = re.compile(r'<li>\[x\] (.*?)(<ul.*?>|</li>)', re.DOTALL)
COMPLETE_TASK_SUB = (r'<li class="task-list-item">'
                     r'<input type="checkbox" class="task-list-item-checkbox" '
                     r'checked="" disabled=""> \1\2')

HEADER_PATCH_RE = re.compile(r'<span>{:"aria-hidden"=&gt;"true", :class=&gt;'
                             r'"octicon octicon-link"}</span>', re.DOTALL)
HEADER_PATCH_SUB = r'<span class="octicon octicon-link"></span>'

def patch(html, user_content=False):
    """
    Processes the HTML rendered by the GitHub API, patching
    any inconsistencies from the main site.
    """
    # FUTURE: Remove this once GitHub API renders task lists
    # https://github.com/isaacs/github/issues/309
    if not user_content:
        html = INCOMPLETE_TASK_RE.sub(INCOMPLETE_TASK_SUB, html)
        html = COMPLETE_TASK_RE.sub(COMPLETE_TASK_SUB, html)

    # FUTURE: Remove this once GitHub API fixes the header bug
    # https://github.com/joeyespo/grip/issues/244
    html = HEADER_PATCH_RE.sub(HEADER_PATCH_SUB, html)

    return html

Prompt:
Patch the GitHub API response to work around the header bug

import re

INCOMPLETE_TASK_RE = re.compile(r'
\[ \] (.*?)(
|
)', re.DOTALL)
INCOMPLETE_TASK_SUB = (r'
'
                       r'<input type="checkbox" '
                       r'class="task-list-item-checkbox" disabled=""> \1\2')
COMPLETE_TASK_RE = re.compile(r'
\[x\] (.*?)(
|
)', re.DOTALL)
COMPLETE_TASK_SUB = (r'
'
                     r'<input type="checkbox" class="task-list-item-checkbox" '
                     r'checked="" disabled=""> \1\2')

def patch(html, user_content=False):
    """
    Processes the HTML rendered by the GitHub API, patching
    any inconsistencies from the main site.
    """
    # FUTURE: Remove this once GitHub API renders task lists
    # https://github.com/isaacs/github/issues/309
    if not user_content:
        html = INCOMPLETE_TASK_RE.sub(INCOMPLETE_TASK_SUB, html)
        html = COMPLETE_TASK_RE.sub(COMPLETE_TASK_SUB, html)

    return html


# Copyright 2012-2014 Hewlett Packard Development Company, L.P.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""
HP 3PAR Client.

:Author: Walter A. Boring IV
:Author: Kurt Martin
:Copyright: Copyright 2012-2014, Hewlett Packard Development Company, L.P.
:License: Apache v2.0

"""

version_tuple = (3, 1, 1)

def get_version_string():
    """Current version of HP3PARClient."""
    if isinstance(version_tuple[-1], str):
        return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
    return '.'.join(map(str, version_tuple))

version = get_version_string()

Update the version to 3.1.1

Response:
<REPLACE_OLD> 0)

def <REPLACE_NEW> 1)

def <REPLACE_END> <|endoftext|> # Copyright 2012-2014 Hewlett Packard Development Company, L.P.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""
HP 3PAR Client.

:Author: Walter A. Boring IV
:Author: Kurt Martin
:Copyright: Copyright 2012-2014, Hewlett Packard Development Company, L.P.
:License: Apache v2.0

"""

version_tuple = (3, 1, 1)

def get_version_string():
    """Current version of HP3PARClient."""
    if isinstance(version_tuple[-1], str):
        return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
    return '.'.join(map(str, version_tuple))

version = get_version_string()

Prompt:
Update the version to 3.1.1

Change-Id: Ia24c8a9e62330243fa7413a649f885c2a40dd4fb

# Copyright 2012-2014 Hewlett Packard Development Company, L.P.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""
HP 3PAR Client.

:Author: Walter A. Boring IV
:Author: Kurt Martin
:Copyright: Copyright 2012-2014, Hewlett Packard Development Company, L.P.
:License: Apache v2.0

"""

version_tuple = (3, 1, 0)

def get_version_string():
    """Current version of HP3PARClient."""
    if isinstance(version_tuple[-1], str):
        return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
    return '.'.join(map(str, version_tuple))

version = get_version_string()


from mock import patch
from django.utils import timezone
from django.test import TestCase
from breach.strategy import Strategy
from breach.models import Target, Victim, SampleSet

class ErrorHandlingTestCase(TestCase):
    def setUp(self):
        self.target = Target.objects.create(
            endpoint='https://di.uoa.gr/?breach=%s',
            prefix='test',
            alphabet='01',
            secretlength=5,
            recordscardinality=1,
            samplesize=2
        )

        self.victim = Victim.objects.create(
            target=self.target,
            sourceip='192.168.10.140',
            snifferendpoint='http://localhost/',
            recordscardinality=1
        )

    def tearDown(self):
        for sampleset in SampleSet.objects.all():
            sampleset.completed = timezone.now()
            sampleset.save()

    @patch('breach.strategy.Sniffer')
    def test_calibration(self, Sniffer):
        capture0 = {'data': 'bigbignextround', 'records': 3}
        instance = Sniffer.return_value
        instance.read.return_value = capture0

        for _ in range(3):
            strategy = Strategy(self.victim)
            strategy.get_work()
            res = strategy.work_completed()
            self.assertTrue(not res)

        self.assertEqual(self.victim.calibration_wait, 0.1)

    @patch('breach.strategy.Sniffer')
    def test_cardinality(self, Sniffer):
        capture = {'data': 'bigbignextround', 'records': 2}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        strategy = Strategy(self.victim)
        strategy.get_work()
        res = strategy.work_completed()
        self.assertTrue(not res)

        capture = {'data': 'bigbignextround', 'records': 4}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        for _ in range(4):
            strategy = Strategy(self.victim)
            strategy.get_work()
            res = strategy.work_completed()
            self.assertTrue(not res)

        self.assertEqual(self.victim.recordscardinality, 2)
        self.assertEqual(self.target.recordscardinality, 2)

    @patch('breach.strategy.Sniffer')
    def test_success_error(self, Sniffer):
        capture = {'data': 'bigbignextround', 'records': 2}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        strategy = Strategy(self.victim)
        strategy.get_work()
        res = strategy.work_completed(False)
        self.assertTrue(not res)

Add strategy error handling tests

Add strategy error handling tests

Response:
<REPLACE_OLD>  <REPLACE_NEW> from mock import patch
from django.utils import timezone
from django.test import TestCase
from breach.strategy import Strategy
from breach.models import Target, Victim, SampleSet

class ErrorHandlingTestCase(TestCase):
    def setUp(self):
        self.target = Target.objects.create(
            endpoint='https://di.uoa.gr/?breach=%s',
            prefix='test',
            alphabet='01',
            secretlength=5,
            recordscardinality=1,
            samplesize=2
        )

        self.victim = Victim.objects.create(
            target=self.target,
            sourceip='192.168.10.140',
            snifferendpoint='http://localhost/',
            recordscardinality=1
        )

    def tearDown(self):
        for sampleset in SampleSet.objects.all():
            sampleset.completed = timezone.now()
            sampleset.save()

    @patch('breach.strategy.Sniffer')
    def test_calibration(self, Sniffer):
        capture0 = {'data': 'bigbignextround', 'records': 3}
        instance = Sniffer.return_value
        instance.read.return_value = capture0

        for _ in range(3):
            strategy = Strategy(self.victim)
            strategy.get_work()
            res = strategy.work_completed()
            self.assertTrue(not res)

        self.assertEqual(self.victim.calibration_wait, 0.1)

    @patch('breach.strategy.Sniffer')
    def test_cardinality(self, Sniffer):
        capture = {'data': 'bigbignextround', 'records': 2}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        strategy = Strategy(self.victim)
        strategy.get_work()
        res = strategy.work_completed()
        self.assertTrue(not res)

        capture = {'data': 'bigbignextround', 'records': 4}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        for _ in range(4):
            strategy = Strategy(self.victim)
            strategy.get_work()
            res = strategy.work_completed()
            self.assertTrue(not res)

        self.assertEqual(self.victim.recordscardinality, 2)
        self.assertEqual(self.target.recordscardinality, 2)

    @patch('breach.strategy.Sniffer')
    def test_success_error(self, Sniffer):
        capture = {'data': 'bigbignextround', 'records': 2}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        strategy = Strategy(self.victim)
        strategy.get_work()
        res = strategy.work_completed(False)
        self.assertTrue(not res)
 <REPLACE_END> <|endoftext|> from mock import patch
from django.utils import timezone
from django.test import TestCase
from breach.strategy import Strategy
from breach.models import Target, Victim, SampleSet

class ErrorHandlingTestCase(TestCase):
    def setUp(self):
        self.target = Target.objects.create(
            endpoint='https://di.uoa.gr/?breach=%s',
            prefix='test',
            alphabet='01',
            secretlength=5,
            recordscardinality=1,
            samplesize=2
        )

        self.victim = Victim.objects.create(
            target=self.target,
            sourceip='192.168.10.140',
            snifferendpoint='http://localhost/',
            recordscardinality=1
        )

    def tearDown(self):
        for sampleset in SampleSet.objects.all():
            sampleset.completed = timezone.now()
            sampleset.save()

    @patch('breach.strategy.Sniffer')
    def test_calibration(self, Sniffer):
        capture0 = {'data': 'bigbignextround', 'records': 3}
        instance = Sniffer.return_value
        instance.read.return_value = capture0

        for _ in range(3):
            strategy = Strategy(self.victim)
            strategy.get_work()
            res = strategy.work_completed()
            self.assertTrue(not res)

        self.assertEqual(self.victim.calibration_wait, 0.1)

    @patch('breach.strategy.Sniffer')
    def test_cardinality(self, Sniffer):
        capture = {'data': 'bigbignextround', 'records': 2}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        strategy = Strategy(self.victim)
        strategy.get_work()
        res = strategy.work_completed()
        self.assertTrue(not res)

        capture = {'data': 'bigbignextround', 'records': 4}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        for _ in range(4):
            strategy = Strategy(self.victim)
            strategy.get_work()
            res = strategy.work_completed()
            self.assertTrue(not res)

        self.assertEqual(self.victim.recordscardinality, 2)
        self.assertEqual(self.target.recordscardinality, 2)

    @patch('breach.strategy.Sniffer')
    def test_success_error(self, Sniffer):
        capture = {'data': 'bigbignextround', 'records': 2}
        instance = Sniffer.return_value
        instance.read.return_value = capture

        strategy = Strategy(self.victim)
        strategy.get_work()
        res = strategy.work_completed(False)
        self.assertTrue(not res)

Prompt: Add strategy error handling tests


# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models

class MailComposeMessage(models.TransientModel):
    _inherit = 'mail.compose.message'

    def send_mail(self, **kwargs):
        for wizard in self:
            if self._context.get('mark_coupon_as_sent') and wizard.model == 'sale.coupon' and wizard.partner_ids:
                # Mark coupon as sent in sudo, as helpdesk users don't have the right to write on coupons
                self.env[wizard.model].sudo().browse(wizard.res_id).state = 'sent'
        return super().send_mail(**kwargs)

Response:
<REPLACE_OLD> self.env[wizard.model].browse(wizard.res_id).state <REPLACE_NEW> # Mark coupon as sent in sudo, as helpdesk users don't have the right to write on coupons
                self.env[wizard.model].sudo().browse(wizard.res_id).state <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models

class MailComposeMessage(models.TransientModel):
    _inherit = 'mail.compose.message'

    def send_mail(self, **kwargs):
        for wizard in self:
            if self._context.get('mark_coupon_as_sent') and wizard.model == 'sale.coupon' and wizard.partner_ids:
                # Mark coupon as sent in sudo, as helpdesk users don't have the right to write on coupons
                self.env[wizard.model].sudo().browse(wizard.res_id).state = 'sent'
        return super().send_mail(**kwargs)

Prompt:
[IMP] sale_coupon: Allow helpdesk users to send coupon by email

Purpose
=======

Helpdesk users don't have the right to write on a coupon.

When sending a coupon by email, the coupon is marked as 'sent'.

Allow users to send coupons by executing the state change in sudo.

closes odoo/odoo#45091

Taskid: 2179609
Related: odoo/enterprise#8143
Signed-off-by: Yannick Tivisse (yti) <200a91eb0e5cc4726d6a3430713b580138f34298@odoo.com>

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models

class MailComposeMessage(models.TransientModel):
    _inherit = 'mail.compose.message'

    def send_mail(self, **kwargs):
        for wizard in self:
            if self._context.get('mark_coupon_as_sent') and wizard.model == 'sale.coupon' and wizard.partner_ids:
                self.env[wizard.model].browse(wizard.res_id).state = 'sent'
        return super().send_mail(**kwargs)


import pyxb.binding.generate
import pyxb.binding.datatypes as xs
import pyxb.binding.basis
import pyxb.utils.domutils

import os.path
xsd='''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="structure">
    <xs:complexType><xs:anyAttribute processContents="lax"/></xs:complexType>
  </xs:element>
</xs:schema>'''

#file('schema.xsd', 'w').write(xsd)
code = pyxb.binding.generate.GeneratePython(schema_text=xsd)
#file('code.py', 'w').write(code)

rv = compile(code, 'test', 'exec')
eval(rv)

from pyxb.exceptions_ import *

import unittest

AttributeNamespace = pyxb.namespace.NamespaceInstance('URN:attr:200908231005')

class TestTrac_200908231005 (unittest.TestCase):
    def testParsing (self):
        xmls = '<structure xmlns:attr="%s" attr:field="value"/>' % (AttributeNamespace.uri(),)
        instance = CreateFromDocument(xmls)
        wam = instance.wildcardAttributeMap()
        self.assertEqual(1, len(wam))
        self.assertEqual('value', wam.get(AttributeNamespace.createExpandedName('field')))

if __name__ == '__main__':
    unittest.main()

Response:
<REPLACE_OLD> pyxb.binding.generate.GeneratePython(schema_text=xsd)
file('code.py', <REPLACE_NEW> pyxb.binding.generate.GeneratePython(schema_text=xsd)
#file('code.py', <REPLACE_END> <|endoftext|> import pyxb.binding.generate
import pyxb.binding.datatypes as xs
import pyxb.binding.basis
import pyxb.utils.domutils

import os.path
xsd='''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="structure">
    <xs:complexType><xs:anyAttribute processContents="lax"/></xs:complexType>
  </xs:element>
</xs:schema>'''

#file('schema.xsd', 'w').write(xsd)
code = pyxb.binding.generate.GeneratePython(schema_text=xsd)
#file('code.py', 'w').write(code)

rv = compile(code, 'test', 'exec')
eval(rv)

from pyxb.exceptions_ import *

import unittest

AttributeNamespace = pyxb.namespace.NamespaceInstance('URN:attr:200908231005')

class TestTrac_200908231005 (unittest.TestCase):
    def testParsing (self):
        xmls = '<structure xmlns:attr="%s" attr:field="value"/>' % (AttributeNamespace.uri(),)
        instance = CreateFromDocument(xmls)
        wam = instance.wildcardAttributeMap()
        self.assertEqual(1, len(wam))
        self.assertEqual('value', wam.get(AttributeNamespace.createExpandedName('field')))

if __name__ == '__main__':
    unittest.main()

Prompt:
Stop writing generated code unnecessarily

import pyxb.binding.generate
import pyxb.binding.datatypes as xs
import pyxb.binding.basis
import pyxb.utils.domutils

import os.path
xsd='''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="structure">
    <xs:complexType><xs:anyAttribute processContents="lax"/></xs:complexType>
  </xs:element>
</xs:schema>'''

#file('schema.xsd', 'w').write(xsd)
code = pyxb.binding.generate.GeneratePython(schema_text=xsd)
file('code.py', 'w').write(code)

rv = compile(code, 'test', 'exec')
eval(rv)

from pyxb.exceptions_ import *

import unittest

AttributeNamespace = pyxb.namespace.NamespaceInstance('URN:attr:200908231005')

class TestTrac_200908231005 (unittest.TestCase):
    def testParsing (self):
        xmls = '<structure xmlns:attr="%s" attr:field="value"/>' % (AttributeNamespace.uri(),)
        instance = CreateFromDocument(xmls)
        wam = instance.wildcardAttributeMap()
        self.assertEqual(1, len(wam))
        self.assertEqual('value', wam.get(AttributeNamespace.createExpandedName('field')))

if __name__ == '__main__':
    unittest.main()


import os
from .exceptions import IncompleteEnv
from tempfile import TemporaryDirectory
import time

class Environment(object):
    def __init__(self, *args, **kwargs):
        self.environ = os.environ.copy()
        self.config = {}
        self.cbchome = None

        if 'CBC_HOME' in kwargs:
            self.cbchome = kwargs['CBC_HOME']

        # I want the local user environment to override what is
        # passed to the class.
        if 'CBC_HOME' in self.environ:
            self.cbchome = self.environ['CBC_HOME']

        if self.cbchome is None:
            raise IncompleteEnv('Environment.cbchome is undefined')

        if not os.path.exists(self.cbchome):
            os.makedirs(self.cbchome)

        self.config['script'] = {}
        self.config['script']['meta'] = self.join('meta.yaml')
        self.config['script']['build_linux'] = self.join('build.sh')
        self.config['script']['build_windows'] = self.join('bld.bat')

    def join(self, path):
        return os.path.join(self.cbchome, path)

    '''
    def local_temp(self):
        temp_prefix = os.path.basename(os.path.splitext(__name__)[0])
        return TemporaryDirectory(prefix=temp_prefix, dir=self.cbchome)
    '''

Response:
<INSERT>
        # I want the local user environment to override what is
        # passed to the class.
        <INSERT_END> <REPLACE_OLD> temp_prefix = os.path.basename(os.path.splitext(__name__)[0])
        tempdir = TemporaryDirectory(prefix=temp_prefix, dir=self.cbchome)
        self.working_dir = tempdir.name
        self.config['meta'] <REPLACE_NEW> self.config['script'] = {}
        self.config['script']['meta'] <REPLACE_END> <REPLACE_OLD> self.config['build'] <REPLACE_NEW> self.config['script']['build_linux'] <REPLACE_END> <REPLACE_OLD> self.config['build_windows'] <REPLACE_NEW> self.config['script']['build_windows'] <REPLACE_END> <DELETE>        print(self.working_dir)
 <DELETE_END> <REPLACE_OLD>
         <REPLACE_NEW>
    '''
    def local_temp(self):
        temp_prefix = os.path.basename(os.path.splitext(__name__)[0])
        return TemporaryDirectory(prefix=temp_prefix, dir=self.cbchome)
    '''
         <REPLACE_END> <|endoftext|> import os
from .exceptions import IncompleteEnv
from tempfile import TemporaryDirectory
import time

class Environment(object):
    def __init__(self, *args, **kwargs):
        self.environ = os.environ.copy()
        self.config = {}
        self.cbchome = None

        if 'CBC_HOME' in kwargs:
            self.cbchome = kwargs['CBC_HOME']

        # I want the local user environment to override what is
        # passed to the class.
        if 'CBC_HOME' in self.environ:
            self.cbchome = self.environ['CBC_HOME']

        if self.cbchome is None:
            raise IncompleteEnv('Environment.cbchome is undefined')

        if not os.path.exists(self.cbchome):
            os.makedirs(self.cbchome)

        self.config['script'] = {}
        self.config['script']['meta'] = self.join('meta.yaml')
        self.config['script']['build_linux'] = self.join('build.sh')
        self.config['script']['build_windows'] = self.join('bld.bat')

    def join(self, path):
        return os.path.join(self.cbchome, path)

    '''
    def local_temp(self):
        temp_prefix = os.path.basename(os.path.splitext(__name__)[0])
        return TemporaryDirectory(prefix=temp_prefix, dir=self.cbchome)
    '''

Prompt:
Remove temp directory creation... not worth it

import os
from .exceptions import IncompleteEnv
from tempfile import TemporaryDirectory
import time

class Environment(object):
    def __init__(self, *args, **kwargs):
        self.environ = os.environ.copy()
        self.config = {}
        self.cbchome = None

        if 'CBC_HOME' in kwargs:
            self.cbchome = kwargs['CBC_HOME']
        if 'CBC_HOME' in self.environ:
            self.cbchome = self.environ['CBC_HOME']

        if self.cbchome is None:
            raise IncompleteEnv('Environment.cbchome is undefined')

        if not os.path.exists(self.cbchome):
            os.makedirs(self.cbchome)

        temp_prefix = os.path.basename(os.path.splitext(__name__)[0])
        tempdir = TemporaryDirectory(prefix=temp_prefix, dir=self.cbchome)
        self.working_dir = tempdir.name
        self.config['meta'] = self.join('meta.yaml')
        self.config['build'] = self.join('build.sh')
        self.config['build_windows'] = self.join('bld.bat')
        print(self.working_dir)

    def join(self, path):
        return os.path.join(self.cbchome, path)


#!/usr/bin/python
#coding=utf8

from Tkinter import *
import sys
from ui import Gui

if __name__ == '__main__':
    Root = Tk()
    App = Gui(Root)
    App.pack(expand='yes',fill='both')
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    Root.overrideredirect(1)
    Root.geometry("%dx%d+0+0" % (w, h))
    Root.focus_set() # <-- move focus to this widget
    Root.bind("<Escape>", lambda e: e.widget.quit())
    Root.title('Mid!Magic')
    Root.mainloop()

Add support for full screen.

Add support for full screen.

Response:
<REPLACE_OLD> Root.geometry('320x240+10+10')
 <REPLACE_NEW> w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    Root.overrideredirect(1)
    Root.geometry("%dx%d+0+0" % (w, h))
    Root.focus_set() # <-- move focus to this widget
    Root.bind("<Escape>", lambda e: e.widget.quit())
 <REPLACE_END> <|endoftext|> #!/usr/bin/python
#coding=utf8

from Tkinter import *
import sys
from ui import Gui

if __name__ == '__main__':
    Root = Tk()
    App = Gui(Root)
    App.pack(expand='yes',fill='both')
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    Root.overrideredirect(1)
    Root.geometry("%dx%d+0+0" % (w, h))
    Root.focus_set() # <-- move focus to this widget
    Root.bind("<Escape>", lambda e: e.widget.quit())
    Root.title('Mid!Magic')
    Root.mainloop()

Prompt:
Add support for full screen.
#!/usr/bin/python
#coding=utf8

from Tkinter import *
import sys
from ui import Gui

if __name__ == '__main__':
    Root = Tk()
    App = Gui(Root)
    App.pack(expand='yes',fill='both')
    Root.geometry('320x240+10+10')
    Root.title('Mid!Magic')
    Root.mainloop()


from Adafruit_MotorHAT import Adafruit_MotorHAT

class Vehicle:
    def __init__(self, motor_hat=Adafruit_MotorHAT()):
        self.motor_hat = motor_hat
        self.motors = []

    def release(self):
        self.motor_hat.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(4).run(Adafruit_MotorHAT.RELEASE)

    def update_motor(self, index, command, speed):
        with self.motor_hat.getMotor(index) as motor:
            motor.run(command)
            motor.setSpeed(speed)

        motor = {"location": index, "command": command, "speed": speed}
        n = len(self.motors)

        if index < n:
            self.motors[index] = motor
        elif index == n:
            self.motors.append(motor)
        else:
            raise IndexError()

Build vehicle with motor hat.

Build vehicle with motor hat.

Response:
<REPLACE_OLD> motor_hat=None):
 <REPLACE_NEW> motor_hat=Adafruit_MotorHAT()):
 <REPLACE_END> <|endoftext|> from Adafruit_MotorHAT import Adafruit_MotorHAT

class Vehicle:
    def __init__(self, motor_hat=Adafruit_MotorHAT()):
        self.motor_hat = motor_hat
        self.motors = []

    def release(self):
        self.motor_hat.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(4).run(Adafruit_MotorHAT.RELEASE)

    def update_motor(self, index, command, speed):
        with self.motor_hat.getMotor(index) as motor:
            motor.run(command)
            motor.setSpeed(speed)

        motor = {"location": index, "command": command, "speed": speed}
        n = len(self.motors)

        if index < n:
            self.motors[index] = motor
        elif index == n:
            self.motors.append(motor)
        else:
            raise IndexError()

Prompt:
Build vehicle with motor hat.

from Adafruit_MotorHAT import Adafruit_MotorHAT

class Vehicle:
    def __init__(self, motor_hat=None):
        self.motor_hat = motor_hat
        self.motors = []

    def release(self):
        self.motor_hat.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
        self.motor_hat.getMotor(4).run(Adafruit_MotorHAT.RELEASE)

    def update_motor(self, index, command, speed):
        with self.motor_hat.getMotor(index) as motor:
            motor.run(command)
            motor.setSpeed(speed)

        motor = {"location": index, "command": command, "speed": speed}
        n = len(self.motors)

        if index < n:
            self.motors[index] = motor
        elif index == n:
            self.motors.append(motor)
        else:
            raise IndexError()


from datetime import date
from django.test import TestCase
from django.core.exceptions import ValidationError
from contacts.validators import year_to_now

today = date.today()
this_year = today.year

class ValidatorTests(TestCase):
    def test_year_to_now(self):
        self.assertRaises(ValidationError, year_to_now, 1899)
        self.assertRaises(ValidationError, year_to_now, '1899')

        self.assertRaises(ValidationError, year_to_now, this_year)
        self.assertRaises(ValidationError, year_to_now, this_year + 3)

        self.assertIsNone(year_to_now(1900))
        self.assertIsNone(year_to_now(this_year - 1))

    def test_calling_year_to_now_with_non_integer_throws_value_error(self):
        self.assertRaises(ValidationError, year_to_now, 'a')
        self.assertRaises(ValidationError, year_to_now, '1900.1')

Response:
<REPLACE_OLD> 1))
 <REPLACE_NEW> 1))

    def test_calling_year_to_now_with_non_integer_throws_value_error(self):
        self.assertRaises(ValidationError, year_to_now, 'a')
        self.assertRaises(ValidationError, year_to_now, '1900.1')
 <REPLACE_END> <|endoftext|> from datetime import date
from django.test import TestCase
from django.core.exceptions import ValidationError
from contacts.validators import year_to_now

today = date.today()
this_year = today.year

class ValidatorTests(TestCase):
    def test_year_to_now(self):
        self.assertRaises(ValidationError, year_to_now, 1899)
        self.assertRaises(ValidationError, year_to_now, '1899')

        self.assertRaises(ValidationError, year_to_now, this_year)
        self.assertRaises(ValidationError, year_to_now, this_year + 3)

        self.assertIsNone(year_to_now(1900))
        self.assertIsNone(year_to_now(this_year - 1))

    def test_calling_year_to_now_with_non_integer_throws_value_error(self):
        self.assertRaises(ValidationError, year_to_now, 'a')
        self.assertRaises(ValidationError, year_to_now, '1900.1')

Prompt:
Add test for year_to_now with non-integer values
from datetime import date
from django.test import TestCase
from django.core.exceptions import ValidationError
from contacts.validators import year_to_now

today = date.today()
this_year = today.year

class ValidatorTests(TestCase):
    def test_year_to_now(self):
        self.assertRaises(ValidationError, year_to_now, 1899)
        self.assertRaises(ValidationError, year_to_now, '1899')

        self.assertRaises(ValidationError, year_to_now, this_year)
        self.assertRaises(ValidationError, year_to_now, this_year + 3)

        self.assertIsNone(year_to_now(1900))
        self.assertIsNone(year_to_now(this_year - 1))


# -*- coding: utf-8 -*-

# This work was created by participants in the DataONE project, and is
# jointly copyrighted by participating institutions in DataONE. For
# more information on DataONE, see our web site at http://dataone.org.
#
#   Copyright 2009-2016 DataONE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for handling the DataONE Node and NodeList types
"""

def pyxb_to_dict(node_list_pyxb):
  """Return a dict representation of {node_list_pyxb}, keyed on
  the Node identifier (urn:node:*). E.g.:
  {
    u'urn:node:ARCTIC': {
      'base_url': u'https://arcticdata.io/metacat/d1/mn',
      'description': u'The US National Science Foundation...',
      'name': u'Arctic Data Center',
      'ping': None,
      'replicate': 0,
      'state': u'up',
      'synchronize': 1,
      'type': u'mn'
    },
    u'urn:node:BCODMO': {
      'base_url': u'https://www.bco-dmo.org/d1/mn',
      'description': u'Biological and Chemical Oceanography Data...',
      'name': u'Biological and Chemical Oceanography Data...',
      'ping': None,
      'replicate': 0,
      'state': u'up',
      'synchronize': 1,
      'type': u'mn'
    },
  }
  """
  f_dict = {}
  for f_pyxb in sorted(node_list_pyxb.node, key=lambda x: x.identifier.value()):
    f_dict[f_pyxb.identifier.value()] = {
      'name': f_pyxb.name,
      'description': f_pyxb.description,
      'base_url': f_pyxb.baseURL,
      'ping': f_pyxb.ping,
      'replicate': f_pyxb.replicate,
      'synchronize': f_pyxb.synchronize,
      'type': f_pyxb.type,
      'state': f_pyxb.state,
    }
    # TODO:
    # f_pyxb.services
    # f_pyxb.synchronization
    # f_pyxb.subject
    # f_pyxb.contactSubject
    # f_pyxb.nodeReplicationPolicy,

  return f_dict

Add utility module for working with the Node type

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

# This work was created by participants in the DataONE project, and is
# jointly copyrighted by participating institutions in DataONE. For
# more information on DataONE, see our web site at http://dataone.org.
#
#   Copyright 2009-2016 DataONE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for handling the DataONE Node and NodeList types
"""

def pyxb_to_dict(node_list_pyxb):
  """Return a dict representation of {node_list_pyxb}, keyed on
  the Node identifier (urn:node:*). E.g.:
  {
    u'urn:node:ARCTIC': {
      'base_url': u'https://arcticdata.io/metacat/d1/mn',
      'description': u'The US National Science Foundation...',
      'name': u'Arctic Data Center',
      'ping': None,
      'replicate': 0,
      'state': u'up',
      'synchronize': 1,
      'type': u'mn'
    },
    u'urn:node:BCODMO': {
      'base_url': u'https://www.bco-dmo.org/d1/mn',
      'description': u'Biological and Chemical Oceanography Data...',
      'name': u'Biological and Chemical Oceanography Data...',
      'ping': None,
      'replicate': 0,
      'state': u'up',
      'synchronize': 1,
      'type': u'mn'
    },
  }
  """
  f_dict = {}
  for f_pyxb in sorted(node_list_pyxb.node, key=lambda x: x.identifier.value()):
    f_dict[f_pyxb.identifier.value()] = {
      'name': f_pyxb.name,
      'description': f_pyxb.description,
      'base_url': f_pyxb.baseURL,
      'ping': f_pyxb.ping,
      'replicate': f_pyxb.replicate,
      'synchronize': f_pyxb.synchronize,
      'type': f_pyxb.type,
      'state': f_pyxb.state,
    }
    # TODO:
    # f_pyxb.services
    # f_pyxb.synchronization
    # f_pyxb.subject
    # f_pyxb.contactSubject
    # f_pyxb.nodeReplicationPolicy,

  return f_dict
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-

# This work was created by participants in the DataONE project, and is
# jointly copyrighted by participating institutions in DataONE. For
# more information on DataONE, see our web site at http://dataone.org.
#
#   Copyright 2009-2016 DataONE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for handling the DataONE Node and NodeList types
"""

def pyxb_to_dict(node_list_pyxb):
  """Return a dict representation of {node_list_pyxb}, keyed on
  the Node identifier (urn:node:*). E.g.:
  {
    u'urn:node:ARCTIC': {
      'base_url': u'https://arcticdata.io/metacat/d1/mn',
      'description': u'The US National Science Foundation...',
      'name': u'Arctic Data Center',
      'ping': None,
      'replicate': 0,
      'state': u'up',
      'synchronize': 1,
      'type': u'mn'
    },
    u'urn:node:BCODMO': {
      'base_url': u'https://www.bco-dmo.org/d1/mn',
      'description': u'Biological and Chemical Oceanography Data...',
      'name': u'Biological and Chemical Oceanography Data...',
      'ping': None,
      'replicate': 0,
      'state': u'up',
      'synchronize': 1,
      'type': u'mn'
    },
  }
  """
  f_dict = {}
  for f_pyxb in sorted(node_list_pyxb.node, key=lambda x: x.identifier.value()):
    f_dict[f_pyxb.identifier.value()] = {
      'name': f_pyxb.name,
      'description': f_pyxb.description,
      'base_url': f_pyxb.baseURL,
      'ping': f_pyxb.ping,
      'replicate': f_pyxb.replicate,
      'synchronize': f_pyxb.synchronize,
      'type': f_pyxb.type,
      'state': f_pyxb.state,
    }
    # TODO:
    # f_pyxb.services
    # f_pyxb.synchronization
    # f_pyxb.subject
    # f_pyxb.contactSubject
    # f_pyxb.nodeReplicationPolicy,

  return f_dict

Prompt: Add utility module for working with the Node type


import redis

class Benchmark(object):
    def __init__(self, author, author_url, date_submitted, date_updated,
                 name, summary, tags, title, url):
        self.author = author
        self.author_url = author_url
        self.date_submitted = date_submitted
        self.date_updated = date_updated
        self.name = name
        self.summary = summary
        self.tags = tags
        self.title = title
        self.url = url

    def __repr__(self):
        return '<Benchmark: %s>' % self.name

class BenchmarkDoesNotExist(Exception):
    pass

class BenchmarkAlreadyExists(Exception):
    pass

class McBenchClient(object):
    def __init__(self, redis):
        self.redis = redis

    def get_benchmark_by_id(self, benchmark_id):
        data = self.redis.hgetall('benchmark:%s' % benchmark_id)
        if not data:
            raise BenchmarkDoesNotExist
        return Benchmark(**data)

    def get_benchmark_by_name(self, name):
        benchmark_id = self.redis.get('name:%s:id' % name)
        if benchmark_id is None:
            raise BenchmarkDoesNotExist
        return self.get_benchmark_by_id(benchmark_id)

    def get_all_benchmarks(self):
        return [self.get_benchmark_by_id(key[len('benchmark:'):])
                for key in self.redis.keys('benchmark:*')]

    def insert_benchmark(self, benchmark):
        benchmark_id = self.redis.get('name:%s:id' % benchmark.name)
        if benchmark_id is not None:
            raise BenchmarkAlreadyExists
        benchmark_id = self.redis.incr('global:next_benchmark_id')
        self.redis.set('name:%s:id' % benchmark.name, benchmark_id)
        self.redis.hmset('benchmark:%s' % benchmark_id, vars(benchmark))

def from_redis_url(redis_url):
    return McBenchClient(redis.from_url(redis_url))

Response:
<REPLACE_OLD> collections

import redis

BENCHMARK_FIELDS = [
    'author', 'author_url', 'date_submitted', 'date_updated',
    'name', 'summary', 'tags', 'title', 'url'
]

Benchmark = collections.namedtuple('Benchmark', ' '.join(BENCHMARK_FIELDS))

class <REPLACE_NEW> redis

class Benchmark(object):
    def __init__(self, author, author_url, date_submitted, date_updated,
                 name, summary, tags, title, url):
        self.author = author
        self.author_url = author_url
        self.date_submitted = date_submitted
        self.date_updated = date_updated
        self.name = name
        self.summary = summary
        self.tags = tags
        self.title = title
        self.url = url

    def __repr__(self):
        return '<Benchmark: %s>' % self.name

class BenchmarkDoesNotExist(Exception):
    pass

class BenchmarkAlreadyExists(Exception):
    pass

class <REPLACE_END> <REPLACE_OLD> return Benchmark(**self.redis.hgetall('benchmark:%s' % benchmark_id))

 <REPLACE_NEW> data = self.redis.hgetall('benchmark:%s' % benchmark_id)
        if not data:
            raise BenchmarkDoesNotExist
        return Benchmark(**data)

 <REPLACE_END> <REPLACE_OLD> self.redis.get('benchmark:%s:id', <REPLACE_NEW> self.redis.get('name:%s:id' % <REPLACE_END> <INSERT> if benchmark_id is None:
            raise BenchmarkDoesNotExist
        <INSERT_END> <INSERT>    def get_all_benchmarks(self):
        return [self.get_benchmark_by_id(key[len('benchmark:'):])
                for key in self.redis.keys('benchmark:*')]

 <INSERT_END> <INSERT> self.redis.get('name:%s:id' % benchmark.name)
        if benchmark_id is not None:
            raise BenchmarkAlreadyExists
        benchmark_id = <INSERT_END> <REPLACE_OLD> self.redis.set('benchmark:%s:id' <REPLACE_NEW> self.redis.set('name:%s:id' <REPLACE_END> <REPLACE_OLD> benchmark._asdict())

def <REPLACE_NEW> vars(benchmark))

def <REPLACE_END> <|endoftext|> import redis

class Benchmark(object):
    def __init__(self, author, author_url, date_submitted, date_updated,
                 name, summary, tags, title, url):
        self.author = author
        self.author_url = author_url
        self.date_submitted = date_submitted
        self.date_updated = date_updated
        self.name = name
        self.summary = summary
        self.tags = tags
        self.title = title
        self.url = url

    def __repr__(self):
        return '<Benchmark: %s>' % self.name

class BenchmarkDoesNotExist(Exception):
    pass

class BenchmarkAlreadyExists(Exception):
    pass

class McBenchClient(object):
    def __init__(self, redis):
        self.redis = redis

    def get_benchmark_by_id(self, benchmark_id):
        data = self.redis.hgetall('benchmark:%s' % benchmark_id)
        if not data:
            raise BenchmarkDoesNotExist
        return Benchmark(**data)

    def get_benchmark_by_name(self, name):
        benchmark_id = self.redis.get('name:%s:id' % name)
        if benchmark_id is None:
            raise BenchmarkDoesNotExist
        return self.get_benchmark_by_id(benchmark_id)

    def get_all_benchmarks(self):
        return [self.get_benchmark_by_id(key[len('benchmark:'):])
                for key in self.redis.keys('benchmark:*')]

    def insert_benchmark(self, benchmark):
        benchmark_id = self.redis.get('name:%s:id' % benchmark.name)
        if benchmark_id is not None:
            raise BenchmarkAlreadyExists
        benchmark_id = self.redis.incr('global:next_benchmark_id')
        self.redis.set('name:%s:id' % benchmark.name, benchmark_id)
        self.redis.hmset('benchmark:%s' % benchmark_id, vars(benchmark))

def from_redis_url(redis_url):
    return McBenchClient(redis.from_url(redis_url))

Prompt:
Make Benchmark a class, not a namedtuple.

import collections

import redis

BENCHMARK_FIELDS = [
    'author', 'author_url', 'date_submitted', 'date_updated',
    'name', 'summary', 'tags', 'title', 'url'
]

Benchmark = collections.namedtuple('Benchmark', ' '.join(BENCHMARK_FIELDS))

class McBenchClient(object):
    def __init__(self, redis):
        self.redis = redis

    def get_benchmark_by_id(self, benchmark_id):
        return Benchmark(**self.redis.hgetall('benchmark:%s' % benchmark_id))

    def get_benchmark_by_name(self, name):
        benchmark_id = self.redis.get('benchmark:%s:id', name)
        return self.get_benchmark_by_id(benchmark_id)

    def insert_benchmark(self, benchmark):
        benchmark_id = self.redis.incr('global:next_benchmark_id')
        self.redis.set('benchmark:%s:id' % benchmark.name, benchmark_id)
        self.redis.hmset('benchmark:%s' % benchmark_id, benchmark._asdict())

def from_redis_url(redis_url):
    return McBenchClient(redis.from_url(redis_url))


"""
scrapple.utils.config
~~~~~~~~~~~~~~~~~~~~~

Functions related to traversing the configuration file
"""

from __future__ import print_function
from colorama import init, Fore, Back

init()

def traverse_next(page, next, results):
    """
    Recursive generator to traverse through the next attribute and \
    crawl through the links to be followed
    """
    for link in page.extract_links(next['follow_link']):
        print(Back.YELLOW + Fore.BLUE + "Loading page ", link.url + Back.RESET + Fore.RESET)
        r = results.copy()
        for attribute in next['scraping'].get('data'):
            if attribute['field'] != "":
                print("\nExtracting", attribute['field'], "attribute", sep=' ')
                r[attribute['field']] = link.extract_content(attribute['selector'], attribute['attr'], attribute['default'])
        if not next['scraping'].get('next'):
            yield r
        else:
            for next2 in next['scraping'].get('next'):
                for result in traverse_next(link, next2, r):
                    yield result

Modify stdout logging in crawler run

Modify stdout logging in crawler run

Response:
<REPLACE_OLD> print_function

def <REPLACE_NEW> print_function
from colorama import init, Fore, Back

init()

def <REPLACE_END> <REPLACE_OLD> print("Loading page", link.url)
 <REPLACE_NEW> print(Back.YELLOW + Fore.BLUE + "Loading page ", link.url + Back.RESET + Fore.RESET)
 <REPLACE_END> <|endoftext|> """
scrapple.utils.config
~~~~~~~~~~~~~~~~~~~~~

Functions related to traversing the configuration file
"""

from __future__ import print_function
from colorama import init, Fore, Back

init()

def traverse_next(page, next, results):
    """
    Recursive generator to traverse through the next attribute and \
    crawl through the links to be followed
    """
    for link in page.extract_links(next['follow_link']):
        print(Back.YELLOW + Fore.BLUE + "Loading page ", link.url + Back.RESET + Fore.RESET)
        r = results.copy()
        for attribute in next['scraping'].get('data'):
            if attribute['field'] != "":
                print("\nExtracting", attribute['field'], "attribute", sep=' ')
                r[attribute['field']] = link.extract_content(attribute['selector'], attribute['attr'], attribute['default'])
        if not next['scraping'].get('next'):
            yield r
        else:
            for next2 in next['scraping'].get('next'):
                for result in traverse_next(link, next2, r):
                    yield result

Prompt:
Modify stdout logging in crawler run

"""
scrapple.utils.config
~~~~~~~~~~~~~~~~~~~~~

Functions related to traversing the configuration file
"""

from __future__ import print_function

def traverse_next(page, next, results):
    """
    Recursive generator to traverse through the next attribute and \
    crawl through the links to be followed
    """
    for link in page.extract_links(next['follow_link']):
        print("Loading page", link.url)
        r = results.copy()
        for attribute in next['scraping'].get('data'):
            if attribute['field'] != "":
                print("\nExtracting", attribute['field'], "attribute", sep=' ')
                r[attribute['field']] = link.extract_content(attribute['selector'], attribute['attr'], attribute['default'])
        if not next['scraping'].get('next'):
            yield r
        else:
            for next2 in next['scraping'].get('next'):
                for result in traverse_next(link, next2, r):
                    yield result


#!/usr/bin/env python
# Copyright (c) 2012 Cloudera, Inc. All rights reserved.
#
import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestStringQueries(ImpalaTestSuite):

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  def setup_method(self, method):
    self.__cleanup_char_tables()
    self.__create_char_tables()

  def teardown_method(self, method):
    self.__cleanup_char_tables()

  def __cleanup_char_tables(self):
    self.client.execute('drop table if exists functional.test_char_tmp');
    self.client.execute('drop table if exists functional.test_varchar_tmp');

  def __create_char_tables(self):
    self.client.execute(
        'create table if not exists functional.test_varchar_tmp (vc varchar(5))')
    self.client.execute(
        'create table if not exists functional.test_char_tmp (c char(5))')

  @classmethod
  def add_test_dimensions(cls):
    super(TestStringQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
      create_exec_option_dimension(disable_codegen_options=[True]))
    cls.TestMatrix.add_constraint(lambda v:\
        v.get_value('table_format').file_format in ['text'] and
        v.get_value('table_format').compression_codec in ['none'])

  def test_varchar(self, vector):
    self.run_test_case('QueryTest/chars', vector)

Fix char test to only run on test/none.

Response:
<REPLACE_OLD> ['text'])

 <REPLACE_NEW> ['text'] and
        v.get_value('table_format').compression_codec in ['none'])

 <REPLACE_END> <|endoftext|> #!/usr/bin/env python
# Copyright (c) 2012 Cloudera, Inc. All rights reserved.
#
import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestStringQueries(ImpalaTestSuite):

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  def setup_method(self, method):
    self.__cleanup_char_tables()
    self.__create_char_tables()

  def teardown_method(self, method):
    self.__cleanup_char_tables()

  def __cleanup_char_tables(self):
    self.client.execute('drop table if exists functional.test_char_tmp');
    self.client.execute('drop table if exists functional.test_varchar_tmp');

  def __create_char_tables(self):
    self.client.execute(
        'create table if not exists functional.test_varchar_tmp (vc varchar(5))')
    self.client.execute(
        'create table if not exists functional.test_char_tmp (c char(5))')

  @classmethod
  def add_test_dimensions(cls):
    super(TestStringQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
      create_exec_option_dimension(disable_codegen_options=[True]))
    cls.TestMatrix.add_constraint(lambda v:\
        v.get_value('table_format').file_format in ['text'] and
        v.get_value('table_format').compression_codec in ['none'])

  def test_varchar(self, vector):
    self.run_test_case('QueryTest/chars', vector)

Prompt:
Fix char test to only run on test/none.

Change-Id: I8f5ac5a6e7399ce2fdbe78d07ae24deaa1d7532d
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4326
Tested-by: jenkins
Reviewed-by: Alex Behm <fe1626037acfc2dc542d2aa723a6d14f2464a20c@cloudera.com>

#!/usr/bin/env python
# Copyright (c) 2012 Cloudera, Inc. All rights reserved.
#
import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestStringQueries(ImpalaTestSuite):

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  def setup_method(self, method):
    self.__cleanup_char_tables()
    self.__create_char_tables()

  def teardown_method(self, method):
    self.__cleanup_char_tables()

  def __cleanup_char_tables(self):
    self.client.execute('drop table if exists functional.test_char_tmp');
    self.client.execute('drop table if exists functional.test_varchar_tmp');

  def __create_char_tables(self):
    self.client.execute(
        'create table if not exists functional.test_varchar_tmp (vc varchar(5))')
    self.client.execute(
        'create table if not exists functional.test_char_tmp (c char(5))')

  @classmethod
  def add_test_dimensions(cls):
    super(TestStringQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
      create_exec_option_dimension(disable_codegen_options=[True]))
    cls.TestMatrix.add_constraint(lambda v:\
        v.get_value('table_format').file_format in ['text'])

  def test_varchar(self, vector):
    self.run_test_case('QueryTest/chars', vector)


from django.core.paginator import InvalidPage, Paginator
from django.http import Http404
from django.utils.translation import gettext as _
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView

class SearchView(FacetedSearchView):
    template = 'search/search.htm'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.form_class = FacetedSearchForm
        self.searchqueryset = SearchQuerySet()

    def build_page(self):
        page = self.request.resolver_match.kwargs.get('page') or self.request.GET.get('page') or 1
        try:
            page_number = int(page)
        except ValueError:
            if page == 'last':
                page_number = paginator.num_pages
            else:
                raise Http404(_("Page is not 'last', nor can it be converted to an int."))

        paginator = Paginator(self.results, self.results_per_page)
        try:
            page = paginator.page(page_number)
        except InvalidPage:
            raise Http404(_('Invalid page (%(page_number)s)') % {
                                'page_number': page_number
            })

        return (paginator, page)

    def extra_context(self):
        context = super().extra_context()
        context.update({'is_paginated': bool(self.query)})
        return context

Switch import from ugettext to gettext

Switch import from ugettext to gettext

Response:
<REPLACE_OLD> ugettext <REPLACE_NEW> gettext <REPLACE_END> <|endoftext|> from django.core.paginator import InvalidPage, Paginator
from django.http import Http404
from django.utils.translation import gettext as _
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView

class SearchView(FacetedSearchView):
    template = 'search/search.htm'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.form_class = FacetedSearchForm
        self.searchqueryset = SearchQuerySet()

    def build_page(self):
        page = self.request.resolver_match.kwargs.get('page') or self.request.GET.get('page') or 1
        try:
            page_number = int(page)
        except ValueError:
            if page == 'last':
                page_number = paginator.num_pages
            else:
                raise Http404(_("Page is not 'last', nor can it be converted to an int."))

        paginator = Paginator(self.results, self.results_per_page)
        try:
            page = paginator.page(page_number)
        except InvalidPage:
            raise Http404(_('Invalid page (%(page_number)s)') % {
                                'page_number': page_number
            })

        return (paginator, page)

    def extra_context(self):
        context = super().extra_context()
        context.update({'is_paginated': bool(self.query)})
        return context

Prompt:
Switch import from ugettext to gettext

from django.core.paginator import InvalidPage, Paginator
from django.http import Http404
from django.utils.translation import ugettext as _
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView

class SearchView(FacetedSearchView):
    template = 'search/search.htm'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.form_class = FacetedSearchForm
        self.searchqueryset = SearchQuerySet()

    def build_page(self):
        page = self.request.resolver_match.kwargs.get('page') or self.request.GET.get('page') or 1
        try:
            page_number = int(page)
        except ValueError:
            if page == 'last':
                page_number = paginator.num_pages
            else:
                raise Http404(_("Page is not 'last', nor can it be converted to an int."))

        paginator = Paginator(self.results, self.results_per_page)
        try:
            page = paginator.page(page_number)
        except InvalidPage:
            raise Http404(_('Invalid page (%(page_number)s)') % {
                                'page_number': page_number
            })

        return (paginator, page)

    def extra_context(self):
        context = super().extra_context()
        context.update({'is_paginated': bool(self.query)})
        return context


from flask import jsonify

from . import app
from . import firebase

@app.route("/", methods=["GET"])
def index():
	response = firebase.get("/", None)
	response = response or {}

	return jsonify(response)

Response:
<REPLACE_OLD> request, jsonify, session, g
import numpy as np
from DatasetCreation import ConstructDataset

from <REPLACE_NEW> jsonify

from <REPLACE_END> <REPLACE_OLD> firebase

from sklearn.ensemble import RandomForestClassifier
from sklearn import preprocessing
from sklearn.cross_validation import cross_val_score

@app.route("/", <REPLACE_NEW> firebase

@app.route("/", <REPLACE_END> <REPLACE_OLD> {}

	datapoints, labels = ConstructDataset(response)
	print len(datapoints)
	print len(labels)

	#	print datapoints[ labels == True ]
	print datapoints[10]

	#enc = preprocessing.OneHotEncoder()
	#print enc.fit(datapoints)

	#clf = RandomForestClassifier(n_estimators=10, min_samples_split=1)
	#clf = clf.fit(datapoints, labels)

	#scores = cross_val_score(clf, datapoints, labels)
	#scores.mean()

	#clf = DecisionTreeClassifier(max_depth=None, min_samples_split=1, random_state=0)
	#scores = cross_val_score(clf, datapoints, labels)
	#scores.mean()

	return jsonify(response) <REPLACE_NEW> {}

	return jsonify(response)
 <REPLACE_END> <|endoftext|> from flask import jsonify

from . import app
from . import firebase

@app.route("/", methods=["GET"])
def index():
	response = firebase.get("/", None)
	response = response or {}

	return jsonify(response)

Prompt:
Remove commented code and unused imports

from flask import request, jsonify, session, g
import numpy as np
from DatasetCreation import ConstructDataset

from . import app
from . import firebase

from sklearn.ensemble import RandomForestClassifier
from sklearn import preprocessing
from sklearn.cross_validation import cross_val_score

@app.route("/", methods=["GET"])
def index():
	response = firebase.get("/", None)
	response = response or {}

	datapoints, labels = ConstructDataset(response)
	print len(datapoints)
	print len(labels)

	#	print datapoints[ labels == True ]
	print datapoints[10]

	#enc = preprocessing.OneHotEncoder()
	#print enc.fit(datapoints)

	#clf = RandomForestClassifier(n_estimators=10, min_samples_split=1)
	#clf = clf.fit(datapoints, labels)

	#scores = cross_val_score(clf, datapoints, labels)
	#scores.mean()

	#clf = DecisionTreeClassifier(max_depth=None, min_samples_split=1, random_state=0)
	#scores = cross_val_score(clf, datapoints, labels)
	#scores.mean()

	return jsonify(response)


#!/usr/bin/env python
# Copyright 2014 Boundary, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from subprocess import Popen,PIPE
import shlex
import logging

class ExecProc:

    def __init__(self):
        self.command = None
        self.debug = False

    def setDebug(self,debug):
        self.debug = debug

    def setCommand(self,command):
        if type(command) != str:
            raise ValueError
        self.command = command

    def execute(self):
        if self.command == None:
            raise ValueError
        # Remove Carriage Returns
        command = self.command.strip('\r')
        args = shlex.split(command)
        if self.debug == True:
            logging.info("command=\"%s\"",args)
        p = Popen(args,stdout=PIPE)
        o,e = p.communicate()
        if self.debug == True:
            logging.info("output=\"%s\"",o)
            logging.info(':'.join(x.encode('hex') for x in o))
        return o

Add output of command in hex

Add output of command in hex

Response:
<REPLACE_OLD> logging

class <REPLACE_NEW> logging

class <REPLACE_END> <INSERT> # Remove Carriage Returns
        command = self.command.strip('\r')
        <INSERT_END> <REPLACE_OLD> shlex.split(self.command)
 <REPLACE_NEW> shlex.split(command)
 <REPLACE_END> <REPLACE_OLD> logging.info("command=\"%s\"",self.command)
 <REPLACE_NEW> logging.info("command=\"%s\"",args)
 <REPLACE_END> <INSERT>     logging.info(':'.join(x.encode('hex') for x in o))
        <INSERT_END> <REPLACE_OLD> o <REPLACE_NEW> o

 <REPLACE_END> <|endoftext|> #!/usr/bin/env python
# Copyright 2014 Boundary, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from subprocess import Popen,PIPE
import shlex
import logging

class ExecProc:

    def __init__(self):
        self.command = None
        self.debug = False

    def setDebug(self,debug):
        self.debug = debug

    def setCommand(self,command):
        if type(command) != str:
            raise ValueError
        self.command = command

    def execute(self):
        if self.command == None:
            raise ValueError
        # Remove Carriage Returns
        command = self.command.strip('\r')
        args = shlex.split(command)
        if self.debug == True:
            logging.info("command=\"%s\"",args)
        p = Popen(args,stdout=PIPE)
        o,e = p.communicate()
        if self.debug == True:
            logging.info("output=\"%s\"",o)
            logging.info(':'.join(x.encode('hex') for x in o))
        return o

Prompt:
Add output of command in hex

#!/usr/bin/env python
# Copyright 2014 Boundary, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from subprocess import Popen,PIPE
import shlex
import logging

class ExecProc:

    def __init__(self):
        self.command = None
        self.debug = False

    def setDebug(self,debug):
        self.debug = debug

    def setCommand(self,command):
        if type(command) != str:
            raise ValueError
        self.command = command

    def execute(self):
        if self.command == None:
            raise ValueError
        args = shlex.split(self.command)
        if self.debug == True:
            logging.info("command=\"%s\"",self.command)
        p = Popen(args,stdout=PIPE)
        o,e = p.communicate()
        if self.debug == True:
            logging.info("output=\"%s\"",o)
        return o


from xml.etree import ElementTree
from django.core.management.base import BaseCommand

from casexml.apps.case.mock import CaseBlock
from casexml.apps.case.models import CommCareCase
from dimagi.utils.chunked import chunked
from dimagi.utils.couch.database import iter_docs

from corehq.apps.domain.models import Domain
from corehq.apps.hqcase.utils import submit_case_blocks

def needs_update(case):
    return (case.get('location_id', None) and
            case['owner_id'] != case['location_id'])

def case_block(case):
    return ElementTree.tostring(CaseBlock(
        create=False,
        case_id=case['_id'],
        owner_id=case['location_id'],
    ).as_xml())

def get_cases(domain):
    supply_point_ids = (case['id'] for case in CommCareCase.get_db().view(
        'commtrack/supply_point_by_loc',
        startkey=[domain],
        endkey=[domain, {}],
        reduce=False,
        include_docs=False,
    ).all())
    return iter_docs(CommCareCase.get_db(), supply_point_ids)

def update_supply_points(domain):
    case_blocks = (case_block(c) for c in get_cases(domain) if needs_update(c))
    if case_blocks:
        for chunk in chunked(case_blocks, 100):
            submit_case_blocks(chunk, domain)
            print "updated {} cases on domain {}".format(len(chunk), domain)

class Command(BaseCommand):
    help = ("Make sure all supply point cases have their owner_id set "
            "to the location_id")

    def handle(self, *args, **options):
        all_domains = Domain.get_all_names()
        total = len(all_domains)
        finished = 0
        for domain in all_domains:
            update_supply_points(domain)
            finished += 1
            if finished % 100 == 0:
                print "Processed {} of {} domains".format(finished, total)

Use CaseBlocks to update case owner_ids

Use CaseBlocks to update case owner_ids

Response:
<INSERT> xml.etree import ElementTree
from <INSERT_END> <REPLACE_OLD> BaseCommand
from <REPLACE_NEW> BaseCommand

from casexml.apps.case.mock import CaseBlock
from <REPLACE_END> <REPLACE_OLD> corehq.util.couch import iter_update, DocUpdate

class <REPLACE_NEW> dimagi.utils.chunked import chunked
from dimagi.utils.couch.database import iter_docs

from corehq.apps.domain.models import Domain
from corehq.apps.hqcase.utils import submit_case_blocks

def needs_update(case):
    return (case.get('location_id', None) and
            case['owner_id'] != case['location_id'])

def case_block(case):
    return ElementTree.tostring(CaseBlock(
        create=False,
        case_id=case['_id'],
        owner_id=case['location_id'],
    ).as_xml())

def get_cases(domain):
    supply_point_ids = (case['id'] for case in CommCareCase.get_db().view(
        'commtrack/supply_point_by_loc',
        startkey=[domain],
        endkey=[domain, {}],
        reduce=False,
        include_docs=False,
    ).all())
    return iter_docs(CommCareCase.get_db(), supply_point_ids)

def update_supply_points(domain):
    case_blocks = (case_block(c) for c in get_cases(domain) if needs_update(c))
    if case_blocks:
        for chunk in chunked(case_blocks, 100):
            submit_case_blocks(chunk, domain)
            print "updated {} cases on domain {}".format(len(chunk), domain)

class <REPLACE_END> <REPLACE_OLD> def add_location(case):
 <REPLACE_NEW> all_domains = Domain.get_all_names()
        total = len(all_domains)
        finished = 0
        for domain in all_domains:
            update_supply_points(domain)
            finished += 1
 <REPLACE_END> <REPLACE_OLD> not case['location_id']:
                return None
            if case['owner_id'] != case['location_id']:
                case['owner_id'] = case['location_id']
                return DocUpdate(case)

        iter_update(
            CommCareCase.get_db(),
            add_location,
            self.get_case_ids(),
            verbose=True
        )

    def get_case_ids(self):
        return (case['id'] for case in CommCareCase.get_db().view(
            'commtrack/supply_point_by_loc',
            reduce=False,
            include_docs=False,
        ).all())
 <REPLACE_NEW> finished % 100 == 0:
                print "Processed {} of {} domains".format(finished, total)
 <REPLACE_END> <|endoftext|> from xml.etree import ElementTree
from django.core.management.base import BaseCommand

from casexml.apps.case.mock import CaseBlock
from casexml.apps.case.models import CommCareCase
from dimagi.utils.chunked import chunked
from dimagi.utils.couch.database import iter_docs

from corehq.apps.domain.models import Domain
from corehq.apps.hqcase.utils import submit_case_blocks

def needs_update(case):
    return (case.get('location_id', None) and
            case['owner_id'] != case['location_id'])

def case_block(case):
    return ElementTree.tostring(CaseBlock(
        create=False,
        case_id=case['_id'],
        owner_id=case['location_id'],
    ).as_xml())

def get_cases(domain):
    supply_point_ids = (case['id'] for case in CommCareCase.get_db().view(
        'commtrack/supply_point_by_loc',
        startkey=[domain],
        endkey=[domain, {}],
        reduce=False,
        include_docs=False,
    ).all())
    return iter_docs(CommCareCase.get_db(), supply_point_ids)

def update_supply_points(domain):
    case_blocks = (case_block(c) for c in get_cases(domain) if needs_update(c))
    if case_blocks:
        for chunk in chunked(case_blocks, 100):
            submit_case_blocks(chunk, domain)
            print "updated {} cases on domain {}".format(len(chunk), domain)

class Command(BaseCommand):
    help = ("Make sure all supply point cases have their owner_id set "
            "to the location_id")

    def handle(self, *args, **options):
        all_domains = Domain.get_all_names()
        total = len(all_domains)
        finished = 0
        for domain in all_domains:
            update_supply_points(domain)
            finished += 1
            if finished % 100 == 0:
                print "Processed {} of {} domains".format(finished, total)

Prompt:
Use CaseBlocks to update case owner_ids

from django.core.management.base import BaseCommand
from casexml.apps.case.models import CommCareCase
from corehq.util.couch import iter_update, DocUpdate

class Command(BaseCommand):
    help = ("Make sure all supply point cases have their owner_id set "
            "to the location_id")

    def handle(self, *args, **options):
        def add_location(case):
            if not case['location_id']:
                return None
            if case['owner_id'] != case['location_id']:
                case['owner_id'] = case['location_id']
                return DocUpdate(case)

        iter_update(
            CommCareCase.get_db(),
            add_location,
            self.get_case_ids(),
            verbose=True
        )

    def get_case_ids(self):
        return (case['id'] for case in CommCareCase.get_db().view(
            'commtrack/supply_point_by_loc',
            reduce=False,
            include_docs=False,
        ).all())


#!/usr/bin/env python
#-*- coding: utf-8 -*-

#This software is distributed under the Creative Commons license (CC0) version 1.0. A copy of this license should have been distributed with this software.
#The license can also be read online: <https://creativecommons.org/publicdomain/zero/1.0/>. If this online license differs from the license provided with this software, the license provided with this software should be applied.

import luna.plugins

_configurations = {}
"""
The configuration classes that have been registered here so far, keyed by their
identities.
"""

def register(identity, metadata):
	"""
	Registers a new configuration plug-in to track configuration with.

	This expects the metadata to already be verified as configuration's
	metadata.

	:param identity: The identity of the plug-in to register.
	:param metadata: The metadata of a configuration plug-in.
	"""
	if identity in _configurations:
		luna.plugins.api("logger").warning("Configuration {configuration} is already registered.", configuration=identity)
		return
	_configurations[identity] = metadata["configuration"]["class"]

def unregister(identity):
	"""
	Undoes the registration of a configuration plug-in.

	The configuration plug-in will no longer keep track of any configuration.
	Existing configuration will be stored persistently.

	:param identity: The identity of the plug-in to unregister.
	"""
	if identity not in _configurations:
		luna.plugins.api("logger").warning("Configuration {configuration} is not registered, so I can't unregister it.", configuration=identity)
		return
	del _configurations[identity] #The actual unregistration.

def validate_metadata(metadata):
	raise Exception("Not implemented yet.")

Response:
<REPLACE_OLD> unregister(identity):
	raise Exception("Not implemented yet.")

def <REPLACE_NEW> unregister(identity):
	"""
	Undoes the registration of a configuration plug-in.

	The configuration plug-in will no longer keep track of any configuration.
	Existing configuration will be stored persistently.

	:param identity: The identity of the plug-in to unregister.
	"""
	if identity not in _configurations:
		luna.plugins.api("logger").warning("Configuration {configuration} is not registered, so I can't unregister it.", configuration=identity)
		return
	del _configurations[identity] #The actual unregistration.

def <REPLACE_END> <|endoftext|> #!/usr/bin/env python
#-*- coding: utf-8 -*-

#This software is distributed under the Creative Commons license (CC0) version 1.0. A copy of this license should have been distributed with this software.
#The license can also be read online: <https://creativecommons.org/publicdomain/zero/1.0/>. If this online license differs from the license provided with this software, the license provided with this software should be applied.

import luna.plugins

_configurations = {}
"""
The configuration classes that have been registered here so far, keyed by their
identities.
"""

def register(identity, metadata):
	"""
	Registers a new configuration plug-in to track configuration with.

	This expects the metadata to already be verified as configuration's
	metadata.

	:param identity: The identity of the plug-in to register.
	:param metadata: The metadata of a configuration plug-in.
	"""
	if identity in _configurations:
		luna.plugins.api("logger").warning("Configuration {configuration} is already registered.", configuration=identity)
		return
	_configurations[identity] = metadata["configuration"]["class"]

def unregister(identity):
	"""
	Undoes the registration of a configuration plug-in.

	The configuration plug-in will no longer keep track of any configuration.
	Existing configuration will be stored persistently.

	:param identity: The identity of the plug-in to unregister.
	"""
	if identity not in _configurations:
		luna.plugins.api("logger").warning("Configuration {configuration} is not registered, so I can't unregister it.", configuration=identity)
		return
	del _configurations[identity] #The actual unregistration.

def validate_metadata(metadata):
	raise Exception("Not implemented yet.")

Prompt:
Implement unregistration of configuration plug-ins

Perhaps we should not give a warning, but instead an exception, when registering or unregistering fails?

#!/usr/bin/env python
#-*- coding: utf-8 -*-

#This software is distributed under the Creative Commons license (CC0) version 1.0. A copy of this license should have been distributed with this software.
#The license can also be read online: <https://creativecommons.org/publicdomain/zero/1.0/>. If this online license differs from the license provided with this software, the license provided with this software should be applied.

import luna.plugins

_configurations = {}
"""
The configuration classes that have been registered here so far, keyed by their
identities.
"""

def register(identity, metadata):
	"""
	Registers a new configuration plug-in to track configuration with.

	This expects the metadata to already be verified as configuration's
	metadata.

	:param identity: The identity of the plug-in to register.
	:param metadata: The metadata of a configuration plug-in.
	"""
	if identity in _configurations:
		luna.plugins.api("logger").warning("Configuration {configuration} is already registered.", configuration=identity)
		return
	_configurations[identity] = metadata["configuration"]["class"]

def unregister(identity):
	raise Exception("Not implemented yet.")

def validate_metadata(metadata):
	raise Exception("Not implemented yet.")


import gettext

class Version(object):
    def __init__(self, canonical_version, final):
        self.canonical_version = canonical_version
        self.final = final

    @property
    def pretty_version(self):
        if self.final:
            return self.canonical_version
        else:
            return '%s-dev' % (self.canonical_version,)

_version = Version('1.4.3', False)
__version__ = _version.pretty_version
__canonical_version__ = _version.canonical_version

gettext.install('swift')

Switch trunk to 1.4.3 development

Switch trunk to 1.4.3 development

Response:
<REPLACE_OLD> Version('1.4.2', <REPLACE_NEW> Version('1.4.3', <REPLACE_END> <|endoftext|> import gettext

class Version(object):
    def __init__(self, canonical_version, final):
        self.canonical_version = canonical_version
        self.final = final

    @property
    def pretty_version(self):
        if self.final:
            return self.canonical_version
        else:
            return '%s-dev' % (self.canonical_version,)

_version = Version('1.4.3', False)
__version__ = _version.pretty_version
__canonical_version__ = _version.canonical_version

gettext.install('swift')

Prompt:
Switch trunk to 1.4.3 development
import gettext

class Version(object):
    def __init__(self, canonical_version, final):
        self.canonical_version = canonical_version
        self.final = final

    @property
    def pretty_version(self):
        if self.final:
            return self.canonical_version
        else:
            return '%s-dev' % (self.canonical_version,)

_version = Version('1.4.2', False)
__version__ = _version.pretty_version
__canonical_version__ = _version.canonical_version

gettext.install('swift')


Add a blank line in the end

Add a blank line in the end

Response:
<REPLACE_OLD> print(generate_key())
 <REPLACE_NEW> print(generate_key())

 <REPLACE_END> <|endoftext|> # Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-11-30
# Python 3.4

"""

做为 Apple Store App 独立开发者，你要搞限时促销，为你的应用生成激活码（或者优惠券），
使用 Python 如何生成 200 个激活码（或者优惠券）？

"""

import uuid

def generate_key():
    key_list = []
    for i in range(200):
        uuid_key = uuid.uuid3(uuid.NAMESPACE_DNS, str(uuid.uuid1()))
        key_list.append(str(uuid_key).replace('-', ''))
    return key_list

if __name__ == '__main__':
    print(generate_key())

Prompt:
Add a blank line in the end

# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-11-30
# Python 3.4

"""

做为 Apple Store App 独立开发者，你要搞限时促销，为你的应用生成激活码（或者优惠券），
使用 Python 如何生成 200 个激活码（或者优惠券）？

"""

import uuid

def generate_key():
    key_list = []
    for i in range(200):
        uuid_key = uuid.uuid3(uuid.NAMESPACE_DNS, str(uuid.uuid1()))
        key_list.append(str(uuid_key).replace('-', ''))
    return key_list

if __name__ == '__main__':
    print(generate_key())


from __future__ import absolute_import, print_function, unicode_literals

from collections import Counter
from streamparse.bolt import Bolt

class WordCounter(Bolt):

    AUTO_ACK = True  # automatically acknowledge tuples after process()
    AUTO_ANCHOR = True  # automatically anchor tuples to current tuple
    AUTO_FAIL = True  # automatically fail tuples when exceptions occur

    def initialize(self, conf, ctx):
        self.counts = Counter()

    def process(self, tup):
        word = tup.values[0]
        self.counts[word] += 1
        self.emit([word, self.counts[word]])
        self.log('%s: %d' % (word, self.counts[word]))

Update quickstart project to use AUTO_*

Update quickstart project to use AUTO_*

Response:
<REPLACE_OLD> Bolt

class <REPLACE_NEW> Bolt

class <REPLACE_END> <INSERT>    AUTO_ACK = True  # automatically acknowledge tuples after process()
    AUTO_ANCHOR = True  # automatically anchor tuples to current tuple
    AUTO_FAIL = True  # automatically fail tuples when exceptions occur

 <INSERT_END> <|endoftext|> from __future__ import absolute_import, print_function, unicode_literals

from collections import Counter
from streamparse.bolt import Bolt

class WordCounter(Bolt):

    AUTO_ACK = True  # automatically acknowledge tuples after process()
    AUTO_ANCHOR = True  # automatically anchor tuples to current tuple
    AUTO_FAIL = True  # automatically fail tuples when exceptions occur

    def initialize(self, conf, ctx):
        self.counts = Counter()

    def process(self, tup):
        word = tup.values[0]
        self.counts[word] += 1
        self.emit([word, self.counts[word]])
        self.log('%s: %d' % (word, self.counts[word]))

Prompt:
Update quickstart project to use AUTO_*

from __future__ import absolute_import, print_function, unicode_literals

from collections import Counter
from streamparse.bolt import Bolt

class WordCounter(Bolt):

    def initialize(self, conf, ctx):
        self.counts = Counter()

    def process(self, tup):
        word = tup.values[0]
        self.counts[word] += 1
        self.emit([word, self.counts[word]])
        self.log('%s: %d' % (word, self.counts[word]))


Response:
<REPLACE_OLD> # pragma: no cover

import <REPLACE_NEW> import <REPLACE_END> <|endoftext|> import warnings

import django

if django.VERSION < (3, 2):
    from feincms3.applications import *  # noqa

    warnings.warn(
        "Django 3.2 will start autodiscovering app configs inside '.apps' modules."
        " We cannot continue using feincms3.apps because the AppsMixin inside this"
        " module can only be loaded after Django initializes all apps."
        " Please change feincms3.apps to feincms3.applications in your code."
        " This compatibility shim will be removed at some point in the future."
        " Sorry for the inconvenience.",
        DeprecationWarning,
        stacklevel=2,
    )

Prompt:
Remove a no cover pragma having no effect (since the pragma only affects the current line)

# pragma: no cover

import warnings

import django

if django.VERSION < (3, 2):
    from feincms3.applications import *  # noqa

    warnings.warn(
        "Django 3.2 will start autodiscovering app configs inside '.apps' modules."
        " We cannot continue using feincms3.apps because the AppsMixin inside this"
        " module can only be loaded after Django initializes all apps."
        " Please change feincms3.apps to feincms3.applications in your code."
        " This compatibility shim will be removed at some point in the future."
        " Sorry for the inconvenience.",
        DeprecationWarning,
        stacklevel=2,
    )


from twisted.cred import checkers, portal
from twisted.protocols import amp
from zope import interface

class AuthenticationLocator(amp.CommandLocator):
    """
    A base class for responder locators that allow users to authenticate.
    """
    credentialInterfaces = []

    def __init__(self, store):
        """
        Initializes an authentication responder locator.

        :param store: The root store.
        """
        self.store = store

        storeCheckers = store.powerupsFor(checkers.ICredentialsChecker)
        self.portal = portal.Portal(Realm(store), storeCheckers)

    def acquireStore(self, userIdentifier):
        """
        Acquires a user store.
        """

@interface.implementer(portal.IRealm)
class Realm(object):
    """
    A realm that produces box receivers for users.
    """
    def __init__(self, getUserByUid):
        self._getUser = getUserByUid

    def requestAvatar(self, uid, mind, *interfaces):
        """
        Attempts to get a lock on the user, then adapts it to ``IBoxReceiver``.
        """
        if amp.IBoxReceiver not in interfaces:
            raise NotImplementedError()

        return self._getUser(uid).addCallback(_gotUser)

def _gotUser(user):
    """
    Adapts the user to ``IBoxReceiver`` and returns a 3-tuple suitable
    as the return value for ``requestAvatar``.
    """
    return amp.IBoxReceiver, amp.IBoxReceiver(user), lambda: None

Response:
<DELETE> exponent.auth import common
from <DELETE_END> <DELETE> twisted.internet import defer
from <DELETE_END> <REPLACE_OLD> interface

def _getUserByIdentifier(rootStore, userIdentifier):
    """
    Gets a user by uid.
    """
    user = common.User.findUnique(rootStore, userIdentifier)
    return defer.succeed(user)

class <REPLACE_NEW> interface

class <REPLACE_END> <|endoftext|> from twisted.cred import checkers, portal
from twisted.protocols import amp
from zope import interface

class AuthenticationLocator(amp.CommandLocator):
    """
    A base class for responder locators that allow users to authenticate.
    """
    credentialInterfaces = []

    def __init__(self, store):
        """
        Initializes an authentication responder locator.

        :param store: The root store.
        """
        self.store = store

        storeCheckers = store.powerupsFor(checkers.ICredentialsChecker)
        self.portal = portal.Portal(Realm(store), storeCheckers)

    def acquireStore(self, userIdentifier):
        """
        Acquires a user store.
        """

@interface.implementer(portal.IRealm)
class Realm(object):
    """
    A realm that produces box receivers for users.
    """
    def __init__(self, getUserByUid):
        self._getUser = getUserByUid

    def requestAvatar(self, uid, mind, *interfaces):
        """
        Attempts to get a lock on the user, then adapts it to ``IBoxReceiver``.
        """
        if amp.IBoxReceiver not in interfaces:
            raise NotImplementedError()

        return self._getUser(uid).addCallback(_gotUser)

def _gotUser(user):
    """
    Adapts the user to ``IBoxReceiver`` and returns a 3-tuple suitable
    as the return value for ``requestAvatar``.
    """
    return amp.IBoxReceiver, amp.IBoxReceiver(user), lambda: None

Prompt:
Remove get user by id nonsense, now exponent.auth.name

from exponent.auth import common
from twisted.cred import checkers, portal
from twisted.internet import defer
from twisted.protocols import amp
from zope import interface

def _getUserByIdentifier(rootStore, userIdentifier):
    """
    Gets a user by uid.
    """
    user = common.User.findUnique(rootStore, userIdentifier)
    return defer.succeed(user)

class AuthenticationLocator(amp.CommandLocator):
    """
    A base class for responder locators that allow users to authenticate.
    """
    credentialInterfaces = []

    def __init__(self, store):
        """
        Initializes an authentication responder locator.

        :param store: The root store.
        """
        self.store = store

        storeCheckers = store.powerupsFor(checkers.ICredentialsChecker)
        self.portal = portal.Portal(Realm(store), storeCheckers)

    def acquireStore(self, userIdentifier):
        """
        Acquires a user store.
        """

@interface.implementer(portal.IRealm)
class Realm(object):
    """
    A realm that produces box receivers for users.
    """
    def __init__(self, getUserByUid):
        self._getUser = getUserByUid

    def requestAvatar(self, uid, mind, *interfaces):
        """
        Attempts to get a lock on the user, then adapts it to ``IBoxReceiver``.
        """
        if amp.IBoxReceiver not in interfaces:
            raise NotImplementedError()

        return self._getUser(uid).addCallback(_gotUser)

def _gotUser(user):
    """
    Adapts the user to ``IBoxReceiver`` and returns a 3-tuple suitable
    as the return value for ``requestAvatar``.
    """
    return amp.IBoxReceiver, amp.IBoxReceiver(user), lambda: None


""" fedmsg-notifications internal API """

import fmn.lib.models

import logging
log = logging.getLogger(__name__)

def recipients(session, config, message):
    """ The main API function.

    Accepts a fedmsg message as an argument.

    Returns a dict mapping context names to lists of recipients.
    """

    res = {}

    for context in session.query(fmn.lib.models.Context).all():
        res[context.name] = recipients_for_context(
            session, config, context, message)

    return res

def recipients_for_context(session, config, context, message):
    """ Returns the recipients for a given fedmsg message and stated context.

    Context may be either the name of a context or an instance of
    fmn.lib.models.Context.
    """

    if isinstance(context, basestring):
        context = session.query(fmn.lib.models.Context)\
            .filter_by(name=context).one()

    return context.recipients(session, config, message)

def load_filters(root='fmn.filters'):
    """ Load the big list of allowed callable filters. """

    module = __import__(root, fromlist=[root.split('.')[0]])

    filters = {}
    for name in dir(module):
        obj = getattr(module, name)
        if not callable(obj):
            continue
        log.info("Found filter %r %r" % (name, obj))
        filters[name] = obj

    return {root: filters}

Response:
<REPLACE_OLD> []
 <REPLACE_NEW> {}
 <REPLACE_END> <REPLACE_OLD> filters.append(obj)

 <REPLACE_NEW> filters[name] = obj

 <REPLACE_END> <REPLACE_OLD> filters
 <REPLACE_NEW> {root: filters}
 <REPLACE_END> <|endoftext|> """ fedmsg-notifications internal API """

import fmn.lib.models

import logging
log = logging.getLogger(__name__)

def recipients(session, config, message):
    """ The main API function.

    Accepts a fedmsg message as an argument.

    Returns a dict mapping context names to lists of recipients.
    """

    res = {}

    for context in session.query(fmn.lib.models.Context).all():
        res[context.name] = recipients_for_context(
            session, config, context, message)

    return res

def recipients_for_context(session, config, context, message):
    """ Returns the recipients for a given fedmsg message and stated context.

    Context may be either the name of a context or an instance of
    fmn.lib.models.Context.
    """

    if isinstance(context, basestring):
        context = session.query(fmn.lib.models.Context)\
            .filter_by(name=context).one()

    return context.recipients(session, config, message)

def load_filters(root='fmn.filters'):
    """ Load the big list of allowed callable filters. """

    module = __import__(root, fromlist=[root.split('.')[0]])

    filters = {}
    for name in dir(module):
        obj = getattr(module, name)
        if not callable(obj):
            continue
        log.info("Found filter %r %r" % (name, obj))
        filters[name] = obj

    return {root: filters}

Prompt:
Restructure the valid_paths list into a dict.

""" fedmsg-notifications internal API """

import fmn.lib.models

import logging
log = logging.getLogger(__name__)

def recipients(session, config, message):
    """ The main API function.

    Accepts a fedmsg message as an argument.

    Returns a dict mapping context names to lists of recipients.
    """

    res = {}

    for context in session.query(fmn.lib.models.Context).all():
        res[context.name] = recipients_for_context(
            session, config, context, message)

    return res

def recipients_for_context(session, config, context, message):
    """ Returns the recipients for a given fedmsg message and stated context.

    Context may be either the name of a context or an instance of
    fmn.lib.models.Context.
    """

    if isinstance(context, basestring):
        context = session.query(fmn.lib.models.Context)\
            .filter_by(name=context).one()

    return context.recipients(session, config, message)

def load_filters(root='fmn.filters'):
    """ Load the big list of allowed callable filters. """

    module = __import__(root, fromlist=[root.split('.')[0]])

    filters = []
    for name in dir(module):
        obj = getattr(module, name)
        if not callable(obj):
            continue
        log.info("Found filter %r %r" % (name, obj))
        filters.append(obj)

    return filters


from setuptools import setup

with open('README.md') as file:
    long_description = file.read()

setup(
    name="chalupas-files",
    version="0.1.0",
    author="Antonin Messinger",
    author_email="antonin.messinger@gmail.com",
    description=" Convert any document",
    long_description=long_description,
    license="MIT License",
    url="https://github.com/Antojitos/chalupas",
    download_url="https://github.com/Antojitos/chalupas/archive/0.1.0.tar.gz",
    keywords=["chalupas", "convert", "document"],
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Web Environment',
        'Framework :: Flask',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Topic :: Internet :: WWW/HTTP',
    ],

    packages=['chalupas'],
    install_requires=[
        'Flask==0.12.3',
        'pypandoc==1.1.3'
    ],

    tests_require=[
        'python-magic==0.4.11',
    ],
    test_suite='tests.main'
)

Response:
<REPLACE_OLD> 'Flask==0.10.1',
 <REPLACE_NEW> 'Flask==0.12.3',
 <REPLACE_END> <|endoftext|> from setuptools import setup

with open('README.md') as file:
    long_description = file.read()

setup(
    name="chalupas-files",
    version="0.1.0",
    author="Antonin Messinger",
    author_email="antonin.messinger@gmail.com",
    description=" Convert any document",
    long_description=long_description,
    license="MIT License",
    url="https://github.com/Antojitos/chalupas",
    download_url="https://github.com/Antojitos/chalupas/archive/0.1.0.tar.gz",
    keywords=["chalupas", "convert", "document"],
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Web Environment',
        'Framework :: Flask',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Topic :: Internet :: WWW/HTTP',
    ],

    packages=['chalupas'],
    install_requires=[
        'Flask==0.12.3',
        'pypandoc==1.1.3'
    ],

    tests_require=[
        'python-magic==0.4.11',
    ],
    test_suite='tests.main'
)

Prompt:
Upgrade to Flask 0.12.3 to fix CVE-2018-1000656

from setuptools import setup

with open('README.md') as file:
    long_description = file.read()

setup(
    name="chalupas-files",
    version="0.1.0",
    author="Antonin Messinger",
    author_email="antonin.messinger@gmail.com",
    description=" Convert any document",
    long_description=long_description,
    license="MIT License",
    url="https://github.com/Antojitos/chalupas",
    download_url="https://github.com/Antojitos/chalupas/archive/0.1.0.tar.gz",
    keywords=["chalupas", "convert", "document"],
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Web Environment',
        'Framework :: Flask',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Topic :: Internet :: WWW/HTTP',
    ],

    packages=['chalupas'],
    install_requires=[
        'Flask==0.10.1',
        'pypandoc==1.1.3'
    ],

    tests_require=[
        'python-magic==0.4.11',
    ],
    test_suite='tests.main'
)