import time

from simpleflow import (
    activity,
    Workflow,
)

@activity.with_attributes(task_list='quickstart')
def increment(x):
    return x + 1

@activity.with_attributes(task_list='quickstart')
def double(x):
    return x * 2

@activity.with_attributes(task_list='quickstart', version='example')
def delay(t, x):
    time.sleep(t)
    return x

class BasicWorkflow(Workflow):
    name = 'basic'
    version = 'example'

    def run(self, x, t=30):
        y = self.submit(increment, x)
        yy = self.submit(delay, t, y)
        z = self.submit(double, yy)

        print '({x} + 1) * 2 = {result}'.format(
            x=x,
            result=z.result)
        return z.result

Update example: add a delay task

Update example: add a delay task

Response:
<REPLACE_OLD> from <REPLACE_NEW> import time

from <REPLACE_END> <REPLACE_OLD> 2

class <REPLACE_NEW> 2

@activity.with_attributes(task_list='quickstart', version='example')
def delay(t, x):
    time.sleep(t)
    return x

class <REPLACE_END> <REPLACE_OLD> x):
 <REPLACE_NEW> x, t=30):
 <REPLACE_END> <INSERT> yy = self.submit(delay, t, y)
        <INSERT_END> <REPLACE_OLD> y)

 <REPLACE_NEW> yy)

 <REPLACE_END> <|endoftext|> import time

from simpleflow import (
    activity,
    Workflow,
)

@activity.with_attributes(task_list='quickstart')
def increment(x):
    return x + 1

@activity.with_attributes(task_list='quickstart')
def double(x):
    return x * 2

@activity.with_attributes(task_list='quickstart', version='example')
def delay(t, x):
    time.sleep(t)
    return x

class BasicWorkflow(Workflow):
    name = 'basic'
    version = 'example'

    def run(self, x, t=30):
        y = self.submit(increment, x)
        yy = self.submit(delay, t, y)
        z = self.submit(double, yy)

        print '({x} + 1) * 2 = {result}'.format(
            x=x,
            result=z.result)
        return z.result

Prompt:
Update example: add a delay task

from simpleflow import (
    activity,
    Workflow,
)

@activity.with_attributes(task_list='quickstart')
def increment(x):
    return x + 1

@activity.with_attributes(task_list='quickstart')
def double(x):
    return x * 2

class BasicWorkflow(Workflow):
    name = 'basic'
    version = 'example'

    def run(self, x):
        y = self.submit(increment, x)
        z = self.submit(double, y)

        print '({x} + 1) * 2 = {result}'.format(
            x=x,
            result=z.result)
        return z.result


# -*- coding: utf-8 -*-
"""
Created on Sat Feb 27 22:01:37 2016

@author: ORCHISAMA
"""

#calculate LPC coefficients from sound file
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

def autocorr(x):
    n = len(x)
    variance = np.var(x)
    x = x - np.mean(x)
    r = np.correlate(x, x, mode = 'full')[-n:] #n numbers from last index (l-n to l)
    result = r/(variance*(np.arange(n, 0, -1)))
    return result

def createSymmetricMatrix(acf,p):
    R = np.empty((p,p))
    for i in range(p):
        for j in range(p):
            R[i,j] = acf[np.abs(i-j)]
    return R

def lpc(s,fs,p):

    #divide into segments of 25 ms with overlap of 10ms
    nSamples = np.int32(0.025*fs)
    overlap = np.int32(0.01*fs)
    nFrames = np.int32(np.ceil(len(s)/(nSamples-overlap)))

    #zero padding to make signal length long enough to have nFrames
    padding = ((nSamples-overlap)*nFrames) - len(s)
    if padding > 0:
        signal = np.append(s, np.zeros(padding))
    else:
        signal = s
    segment = np.empty((nSamples, nFrames))
    start = 0
    for i in range(nFrames):
        segment[:,i] = signal[start:start+nSamples]
        start = (nSamples-overlap)*i

    #calculate LPC with Yule-Walker
    lpc_coeffs = np.empty((p, nFrames))
    for i in range(nFrames):
        acf = autocorr(segment[:,i])
#        plt.figure(1)
#        plt.plot(acf)
#        plt.xlabel('lags')
#        plt.ylabel('Autocorrelation coefficients')
#        plt.axis([0, np.size(acf), -1, 1])
#        plt.title('Autocorrelation function')
#        break
        r = -acf[1:p+1].T
        R = createSymmetricMatrix(acf,p)
        lpc_coeffs[:,i] = np.dot(np.linalg.inv(R),r)
        lpc_coeffs[:,i] = lpc_coeffs[:,i]/np.max(np.abs(lpc_coeffs[:,i]))

    return lpc_coeffs

Add program to calculate Linear Prediction Coefficients

Response:
<REPLACE_OLD>  <REPLACE_NEW> # -*- coding: utf-8 -*-
"""
Created on Sat Feb 27 22:01:37 2016

@author: ORCHISAMA
"""

#calculate LPC coefficients from sound file
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

def autocorr(x):
    n = len(x)
    variance = np.var(x)
    x = x - np.mean(x)
    r = np.correlate(x, x, mode = 'full')[-n:] #n numbers from last index (l-n to l)
    result = r/(variance*(np.arange(n, 0, -1)))
    return result

def createSymmetricMatrix(acf,p):
    R = np.empty((p,p))
    for i in range(p):
        for j in range(p):
            R[i,j] = acf[np.abs(i-j)]
    return R

def lpc(s,fs,p):

    #divide into segments of 25 ms with overlap of 10ms
    nSamples = np.int32(0.025*fs)
    overlap = np.int32(0.01*fs)
    nFrames = np.int32(np.ceil(len(s)/(nSamples-overlap)))

    #zero padding to make signal length long enough to have nFrames
    padding = ((nSamples-overlap)*nFrames) - len(s)
    if padding > 0:
        signal = np.append(s, np.zeros(padding))
    else:
        signal = s
    segment = np.empty((nSamples, nFrames))
    start = 0
    for i in range(nFrames):
        segment[:,i] = signal[start:start+nSamples]
        start = (nSamples-overlap)*i

    #calculate LPC with Yule-Walker
    lpc_coeffs = np.empty((p, nFrames))
    for i in range(nFrames):
        acf = autocorr(segment[:,i])
#        plt.figure(1)
#        plt.plot(acf)
#        plt.xlabel('lags')
#        plt.ylabel('Autocorrelation coefficients')
#        plt.axis([0, np.size(acf), -1, 1])
#        plt.title('Autocorrelation function')
#        break
        r = -acf[1:p+1].T
        R = createSymmetricMatrix(acf,p)
        lpc_coeffs[:,i] = np.dot(np.linalg.inv(R),r)
        lpc_coeffs[:,i] = lpc_coeffs[:,i]/np.max(np.abs(lpc_coeffs[:,i]))

    return lpc_coeffs
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
"""
Created on Sat Feb 27 22:01:37 2016

@author: ORCHISAMA
"""

#calculate LPC coefficients from sound file
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

def autocorr(x):
    n = len(x)
    variance = np.var(x)
    x = x - np.mean(x)
    r = np.correlate(x, x, mode = 'full')[-n:] #n numbers from last index (l-n to l)
    result = r/(variance*(np.arange(n, 0, -1)))
    return result

def createSymmetricMatrix(acf,p):
    R = np.empty((p,p))
    for i in range(p):
        for j in range(p):
            R[i,j] = acf[np.abs(i-j)]
    return R

def lpc(s,fs,p):

    #divide into segments of 25 ms with overlap of 10ms
    nSamples = np.int32(0.025*fs)
    overlap = np.int32(0.01*fs)
    nFrames = np.int32(np.ceil(len(s)/(nSamples-overlap)))

    #zero padding to make signal length long enough to have nFrames
    padding = ((nSamples-overlap)*nFrames) - len(s)
    if padding > 0:
        signal = np.append(s, np.zeros(padding))
    else:
        signal = s
    segment = np.empty((nSamples, nFrames))
    start = 0
    for i in range(nFrames):
        segment[:,i] = signal[start:start+nSamples]
        start = (nSamples-overlap)*i

    #calculate LPC with Yule-Walker
    lpc_coeffs = np.empty((p, nFrames))
    for i in range(nFrames):
        acf = autocorr(segment[:,i])
#        plt.figure(1)
#        plt.plot(acf)
#        plt.xlabel('lags')
#        plt.ylabel('Autocorrelation coefficients')
#        plt.axis([0, np.size(acf), -1, 1])
#        plt.title('Autocorrelation function')
#        break
        r = -acf[1:p+1].T
        R = createSymmetricMatrix(acf,p)
        lpc_coeffs[:,i] = np.dot(np.linalg.inv(R),r)
        lpc_coeffs[:,i] = lpc_coeffs[:,i]/np.max(np.abs(lpc_coeffs[:,i]))

    return lpc_coeffs

Prompt: Add program to calculate Linear Prediction Coefficients


# -*- coding: utf-8 -*-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

import unittest2

from st2common.util.payload import PayloadLookup

__all__ = [
    'PayloadLookupTestCase'
]

class PayloadLookupTestCase(unittest2.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.payload = PayloadLookup({
            'pikachu': "Has no ears",
            'charmander': "Plays with fire",
        })
        super(PayloadLookupTestCase, cls).setUpClass()

    def test_get_key(self):
        self.assertEqual(self.payload.get_value('trigger.pikachu'), ["Has no ears"])
        self.assertEqual(self.payload.get_value('trigger.charmander'), ["Plays with fire"])

    def test_explicitly_get_multiple_keys(self):
        self.assertEqual(self.payload.get_value('trigger.pikachu[*]'), ["Has no ears"])
        self.assertEqual(self.payload.get_value('trigger.charmander[*]'), ["Plays with fire"])

    def test_get_nonexistent_key(self):
        self.assertIsNone(self.payload.get_value('trigger.squirtle'))

Add tests for new payload module

Add tests for new payload module

Response:
<REPLACE_OLD>  <REPLACE_NEW> # -*- coding: utf-8 -*-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

import unittest2

from st2common.util.payload import PayloadLookup

__all__ = [
    'PayloadLookupTestCase'
]

class PayloadLookupTestCase(unittest2.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.payload = PayloadLookup({
            'pikachu': "Has no ears",
            'charmander': "Plays with fire",
        })
        super(PayloadLookupTestCase, cls).setUpClass()

    def test_get_key(self):
        self.assertEqual(self.payload.get_value('trigger.pikachu'), ["Has no ears"])
        self.assertEqual(self.payload.get_value('trigger.charmander'), ["Plays with fire"])

    def test_explicitly_get_multiple_keys(self):
        self.assertEqual(self.payload.get_value('trigger.pikachu[*]'), ["Has no ears"])
        self.assertEqual(self.payload.get_value('trigger.charmander[*]'), ["Plays with fire"])

    def test_get_nonexistent_key(self):
        self.assertIsNone(self.payload.get_value('trigger.squirtle'))
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

import unittest2

from st2common.util.payload import PayloadLookup

__all__ = [
    'PayloadLookupTestCase'
]

class PayloadLookupTestCase(unittest2.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.payload = PayloadLookup({
            'pikachu': "Has no ears",
            'charmander': "Plays with fire",
        })
        super(PayloadLookupTestCase, cls).setUpClass()

    def test_get_key(self):
        self.assertEqual(self.payload.get_value('trigger.pikachu'), ["Has no ears"])
        self.assertEqual(self.payload.get_value('trigger.charmander'), ["Plays with fire"])

    def test_explicitly_get_multiple_keys(self):
        self.assertEqual(self.payload.get_value('trigger.pikachu[*]'), ["Has no ears"])
        self.assertEqual(self.payload.get_value('trigger.charmander[*]'), ["Plays with fire"])

    def test_get_nonexistent_key(self):
        self.assertIsNone(self.payload.get_value('trigger.squirtle'))

Prompt: Add tests for new payload module


VERSION = (0, 5, 6, 'alpha', 0)

def get_version():
    version = '%s.%s' % (VERSION[0], VERSION[1])
    if VERSION[2]:
        version = '%s.%s' % (version, VERSION[2])
    if VERSION[3:] == ('alpha', 0):
        version = '%s pre-alpha' % version
    else:
        if VERSION[3] != 'final':
            version = '%s %s %s' % (version, VERSION[3], VERSION[4])
    #from django.utils.version import get_svn_revision
    #svn_rev = get_svn_revision()
    #if svn_rev != u'SVN-unknown':
    #    version = "%s %s" % (version, svn_rev)
    return version

Mark dojango as 0.5.6 alpha

Mark dojango as 0.5.6 alpha

Response:
<REPLACE_OLD> 5, 'final', <REPLACE_NEW> 6, 'alpha', <REPLACE_END> <|endoftext|> VERSION = (0, 5, 6, 'alpha', 0)

def get_version():
    version = '%s.%s' % (VERSION[0], VERSION[1])
    if VERSION[2]:
        version = '%s.%s' % (version, VERSION[2])
    if VERSION[3:] == ('alpha', 0):
        version = '%s pre-alpha' % version
    else:
        if VERSION[3] != 'final':
            version = '%s %s %s' % (version, VERSION[3], VERSION[4])
    #from django.utils.version import get_svn_revision
    #svn_rev = get_svn_revision()
    #if svn_rev != u'SVN-unknown':
    #    version = "%s %s" % (version, svn_rev)
    return version

Prompt:
Mark dojango as 0.5.6 alpha

VERSION = (0, 5, 5, 'final', 0)

def get_version():
    version = '%s.%s' % (VERSION[0], VERSION[1])
    if VERSION[2]:
        version = '%s.%s' % (version, VERSION[2])
    if VERSION[3:] == ('alpha', 0):
        version = '%s pre-alpha' % version
    else:
        if VERSION[3] != 'final':
            version = '%s %s %s' % (version, VERSION[3], VERSION[4])
    #from django.utils.version import get_svn_revision
    #svn_rev = get_svn_revision()
    #if svn_rev != u'SVN-unknown':
    #    version = "%s %s" % (version, svn_rev)
    return version


from django.conf.urls import patterns, url

from sitecontent import views

urlpatterns = patterns('',
    url("^feeds/(?P<format>.*)$",
        "sitecontent.views.blog_post_feed_richtext_filters", name="blog_post_feed_richtext_filters"),
)

Use feeds instead of rss

Use feeds instead of rss

Response:
<REPLACE_OLD> url("^rss/(?P<format>.*)$",
 <REPLACE_NEW> url("^feeds/(?P<format>.*)$",
 <REPLACE_END> <|endoftext|> from django.conf.urls import patterns, url

from sitecontent import views

urlpatterns = patterns('',
    url("^feeds/(?P<format>.*)$",
        "sitecontent.views.blog_post_feed_richtext_filters", name="blog_post_feed_richtext_filters"),
)

Prompt:
Use feeds instead of rss

from django.conf.urls import patterns, url

from sitecontent import views

urlpatterns = patterns('',
    url("^rss/(?P<format>.*)$",
        "sitecontent.views.blog_post_feed_richtext_filters", name="blog_post_feed_richtext_filters"),
)


import setuptools

REQUIREMENTS = [
    "docopt==0.6.1",
    "feedparser==5.1.3",
    "jabberbot==0.15",
    "xmpppy==0.5.0rc1",
]

if __name__ == "__main__":
    setuptools.setup(
        name="dudebot",
        version="0.0.6",
        author="Sujay Mansingh",
        author_email="sujay.mansingh@gmail.com",
        packages=setuptools.find_packages(),
        package_data={
            "dudebot": ["README.rst"]
        },
        scripts=[],
        url="https://github.com/sujaymansingh/dudebot",
        license="LICENSE.txt",
        description="A really simple framework for chatroom bots",
        long_description="View the github page (https://github.com/sujaymansingh/dudebot) for more details.",
        install_requires=REQUIREMENTS
    )

Response:
<REPLACE_OLD> long_description=open("README.rst").read(),
 <REPLACE_NEW> long_description="View the github page (https://github.com/sujaymansingh/dudebot) for more details.",
 <REPLACE_END> <|endoftext|> import setuptools

REQUIREMENTS = [
    "docopt==0.6.1",
    "feedparser==5.1.3",
    "jabberbot==0.15",
    "xmpppy==0.5.0rc1",
]

if __name__ == "__main__":
    setuptools.setup(
        name="dudebot",
        version="0.0.6",
        author="Sujay Mansingh",
        author_email="sujay.mansingh@gmail.com",
        packages=setuptools.find_packages(),
        package_data={
            "dudebot": ["README.rst"]
        },
        scripts=[],
        url="https://github.com/sujaymansingh/dudebot",
        license="LICENSE.txt",
        description="A really simple framework for chatroom bots",
        long_description="View the github page (https://github.com/sujaymansingh/dudebot) for more details.",
        install_requires=REQUIREMENTS
    )

Prompt:
Use a placeholder string instead of a README.

Until I work out why README.rst isn't being included, use this.

import setuptools

REQUIREMENTS = [
    "docopt==0.6.1",
    "feedparser==5.1.3",
    "jabberbot==0.15",
    "xmpppy==0.5.0rc1",
]

if __name__ == "__main__":
    setuptools.setup(
        name="dudebot",
        version="0.0.6",
        author="Sujay Mansingh",
        author_email="sujay.mansingh@gmail.com",
        packages=setuptools.find_packages(),
        package_data={
            "dudebot": ["README.rst"]
        },
        scripts=[],
        url="https://github.com/sujaymansingh/dudebot",
        license="LICENSE.txt",
        description="A really simple framework for chatroom bots",
        long_description=open("README.rst").read(),
        install_requires=REQUIREMENTS
    )


"""
Default settings for the ``mezzanine.twitter`` app. Each of these can be
overridden in your project's settings module, just like regular
Django settings. The ``editable`` argument for each controls whether
the setting is editable via Django's admin.

Thought should be given to how a setting is actually used before
making it editable, as it may be inappropriate - for example settings
that are only read during startup shouldn't be editable, since changing
them would require an application reload.
"""

from django.utils.translation import ugettext_lazy as _

from mezzanine.conf import register_setting
from mezzanine.twitter import QUERY_TYPE_CHOICES, QUERY_TYPE_SEARCH

register_setting(
    name="TWITTER_DEFAULT_QUERY_TYPE",
    label=_("Default Twitter Query Type"),
    description=_("Type of query that will be used to retrieve tweets for "
        "the default Twitter feed."),
    editable=True,
    default=QUERY_TYPE_SEARCH,
    choices=QUERY_TYPE_CHOICES,
)

register_setting(
    name="TWITTER_DEFAULT_QUERY",
    label=_("Default Twitter Query"),
    description=_("Twitter query to use for the default query type."),
    editable=True,
    default="django mezzanine",
)

register_setting(
    name="TWITTER_DEFAULT_NUM_TWEETS",
    label=_("Default Number of Tweets"),
    description=_("Number of tweets to display in the default Twitter feed."),
    editable=True,
    default=3,
)

Response:
<REPLACE_OLD> default="#django",
)

register_setting(
 <REPLACE_NEW> default="django mezzanine",
)

register_setting(
 <REPLACE_END> <|endoftext|> """
Default settings for the ``mezzanine.twitter`` app. Each of these can be
overridden in your project's settings module, just like regular
Django settings. The ``editable`` argument for each controls whether
the setting is editable via Django's admin.

Thought should be given to how a setting is actually used before
making it editable, as it may be inappropriate - for example settings
that are only read during startup shouldn't be editable, since changing
them would require an application reload.
"""

from django.utils.translation import ugettext_lazy as _

from mezzanine.conf import register_setting
from mezzanine.twitter import QUERY_TYPE_CHOICES, QUERY_TYPE_SEARCH

register_setting(
    name="TWITTER_DEFAULT_QUERY_TYPE",
    label=_("Default Twitter Query Type"),
    description=_("Type of query that will be used to retrieve tweets for "
        "the default Twitter feed."),
    editable=True,
    default=QUERY_TYPE_SEARCH,
    choices=QUERY_TYPE_CHOICES,
)

register_setting(
    name="TWITTER_DEFAULT_QUERY",
    label=_("Default Twitter Query"),
    description=_("Twitter query to use for the default query type."),
    editable=True,
    default="django mezzanine",
)

register_setting(
    name="TWITTER_DEFAULT_NUM_TWEETS",
    label=_("Default Number of Tweets"),
    description=_("Number of tweets to display in the default Twitter feed."),
    editable=True,
    default=3,
)

Prompt:
Update the default twitter query since it's been flooded by movie tweets.

"""
Default settings for the ``mezzanine.twitter`` app. Each of these can be
overridden in your project's settings module, just like regular
Django settings. The ``editable`` argument for each controls whether
the setting is editable via Django's admin.

Thought should be given to how a setting is actually used before
making it editable, as it may be inappropriate - for example settings
that are only read during startup shouldn't be editable, since changing
them would require an application reload.
"""

from django.utils.translation import ugettext_lazy as _

from mezzanine.conf import register_setting
from mezzanine.twitter import QUERY_TYPE_CHOICES, QUERY_TYPE_SEARCH

register_setting(
    name="TWITTER_DEFAULT_QUERY_TYPE",
    label=_("Default Twitter Query Type"),
    description=_("Type of query that will be used to retrieve tweets for "
        "the default Twitter feed."),
    editable=True,
    default=QUERY_TYPE_SEARCH,
    choices=QUERY_TYPE_CHOICES,
)

register_setting(
    name="TWITTER_DEFAULT_QUERY",
    label=_("Default Twitter Query"),
    description=_("Twitter query to use for the default query type."),
    editable=True,
    default="#django",
)

register_setting(
    name="TWITTER_DEFAULT_NUM_TWEETS",
    label=_("Default Number of Tweets"),
    description=_("Number of tweets to display in the default Twitter feed."),
    editable=True,
    default=3,
)


# Copyright 2015 The Swarming Authors. All rights reserved.
# Use of this source code is governed by the Apache v2.0 license that can be
# found in the LICENSE file.

"""Android specific utility functions.

This file serves as an API to bot_config.py. bot_config.py can be replaced on
the server to allow additional server-specific functionality.
"""

import collections
import logging
import os

from adb import adb_commands_safe
from adb import adb_protocol
from adb import common
from adb import high

# Master switch that can easily be temporarily increased to INFO or even DEBUG
# when needed by simply pushing a new tainted swarming server version. This
# helps quickly debugging issues. On the other hand, even INFO level is quite
# verbose so keep it at WARNING by default.
LEVEL = logging.WARNING
adb_commands_safe._LOG.setLevel(LEVEL)
adb_protocol._LOG.setLevel(LEVEL)
common._LOG.setLevel(LEVEL)
high._LOG.setLevel(LEVEL)

def initialize(pub_key, priv_key):
  return high.Initialize(pub_key, priv_key)

def get_devices(bot):
  return high.GetDevices(
      'swarming', 10000, 10000, on_error=bot.post_error if bot else None,
      as_root=True)

def close_devices(devices):
  return high.CloseDevices(devices)

def kill_adb():
  return adb_commands_safe.KillADB()

Response:
<REPLACE_OLD> high

def <REPLACE_NEW> adb_protocol
from adb import common
from adb import high

# Master switch that can easily be temporarily increased to INFO or even DEBUG
# when needed by simply pushing a new tainted swarming server version. This
# helps quickly debugging issues. On the other hand, even INFO level is quite
# verbose so keep it at WARNING by default.
LEVEL = logging.WARNING
adb_commands_safe._LOG.setLevel(LEVEL)
adb_protocol._LOG.setLevel(LEVEL)
common._LOG.setLevel(LEVEL)
high._LOG.setLevel(LEVEL)

def <REPLACE_END> <REPLACE_OLD> high.CloseDevices(devices)
 <REPLACE_NEW> high.CloseDevices(devices)

def kill_adb():
  return adb_commands_safe.KillADB()
 <REPLACE_END> <|endoftext|> # Copyright 2015 The Swarming Authors. All rights reserved.
# Use of this source code is governed by the Apache v2.0 license that can be
# found in the LICENSE file.

"""Android specific utility functions.

This file serves as an API to bot_config.py. bot_config.py can be replaced on
the server to allow additional server-specific functionality.
"""

import collections
import logging
import os

from adb import adb_commands_safe
from adb import adb_protocol
from adb import common
from adb import high

# Master switch that can easily be temporarily increased to INFO or even DEBUG
# when needed by simply pushing a new tainted swarming server version. This
# helps quickly debugging issues. On the other hand, even INFO level is quite
# verbose so keep it at WARNING by default.
LEVEL = logging.WARNING
adb_commands_safe._LOG.setLevel(LEVEL)
adb_protocol._LOG.setLevel(LEVEL)
common._LOG.setLevel(LEVEL)
high._LOG.setLevel(LEVEL)

def initialize(pub_key, priv_key):
  return high.Initialize(pub_key, priv_key)

def get_devices(bot):
  return high.GetDevices(
      'swarming', 10000, 10000, on_error=bot.post_error if bot else None,
      as_root=True)

def close_devices(devices):
  return high.CloseDevices(devices)

def kill_adb():
  return adb_commands_safe.KillADB()

Prompt:
Add kill_adb() and increase python-adb logging to WARNING.

It gives a master switch that can easily be temporarily increased to INFO or
even DEBUG when needed by simply pushing a new tainted swarming server version.
This helps quickly debugging issues. On the other hand, even INFO level is quite
verbose so keep it at WARNING by default.

Adding kill_adb() is useful, since it's better to forcibly kill adb upfront in
on_after_task() than try to kill it after trying USB enumeration then killing
adb then enumerating again.

R=stip@chromium.org
BUG=chromium:525873

Review URL: https://codereview.chromium.org/1430073003

# Copyright 2015 The Swarming Authors. All rights reserved.
# Use of this source code is governed by the Apache v2.0 license that can be
# found in the LICENSE file.

"""Android specific utility functions.

This file serves as an API to bot_config.py. bot_config.py can be replaced on
the server to allow additional server-specific functionality.
"""

import collections
import logging
import os

from adb import adb_commands_safe
from adb import high

def initialize(pub_key, priv_key):
  return high.Initialize(pub_key, priv_key)

def get_devices(bot):
  return high.GetDevices(
      'swarming', 10000, 10000, on_error=bot.post_error if bot else None,
      as_root=True)

def close_devices(devices):
  return high.CloseDevices(devices)


#!/usr/bin/python2

"""
packet_loss.py: Simulates packet loss by dropping all packets with a
probability of 25%.
"""

import random

from pox.core import core
import pox.openflow.libopenflow_01 as of

def packet_in(event):
    if random.random() >= 0.25:
        msg = of.ofp_packet_out(data = event.ofp)
        msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))
        event.connection.send(msg)

def launch():
    core.openflow.addListenerByName("PacketIn", packet_in)

Fix bug in packet loss

Fix bug in packet loss

Response:
<REPLACE_OLD> packet_in(event):.
 <REPLACE_NEW> packet_in(event):
 <REPLACE_END> <REPLACE_OLD> conn.send(event.connection)

def <REPLACE_NEW> event.connection.send(msg)

def <REPLACE_END> <|endoftext|> #!/usr/bin/python2

"""
packet_loss.py: Simulates packet loss by dropping all packets with a
probability of 25%.
"""

import random

from pox.core import core
import pox.openflow.libopenflow_01 as of

def packet_in(event):
    if random.random() >= 0.25:
        msg = of.ofp_packet_out(data = event.ofp)
        msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))
        event.connection.send(msg)

def launch():
    core.openflow.addListenerByName("PacketIn", packet_in)

Prompt:
Fix bug in packet loss

#!/usr/bin/python2

"""
packet_loss.py: Simulates packet loss by dropping all packets with a
probability of 25%.
"""

import random

from pox.core import core
import pox.openflow.libopenflow_01 as of

def packet_in(event):.
    if random.random() >= 0.25:
        msg = of.ofp_packet_out(data = event.ofp)
        msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))
        conn.send(event.connection)

def launch():
    core.openflow.addListenerByName("PacketIn", packet_in)


#!/usr/bin/python

import argparse
import os
import struct
import sys

CP_STRUCT_SIZES = { 0xa:3 }

###############
### CLASSES ###
###############
class MyParser(argparse.ArgumentParser):
    def error(self, message):
        sys.stderr.write('error: %s\n' % message)
        self.print_help()
        sys.exit(2)

###################
### SUBROUTINES ###
###################
def lenCpStruct(tag):
  if tag in CP_STRUCT_SIZES:
    return CP_STRUCT_SIZES[tag]
  else:
    return -1

############
### MAIN ###
############
parser = MyParser('Run bytecode in jjvm')
parser.add_argument('path', help='path to class')
args = parser.parse_args()

with open(args.path, "rb") as c:
  c.seek(8)
  cpCount = struct.unpack(">H", c.read(2))[0] - 1

  print "Constant pool count: %d" % cpCount;

  while cpCount >= 0:
    cpTag = ord(c.read(1))

    print "Got tag: %d" % cpTag
    cpStructSize = lenCpStruct(cpTag)

    if cpStructSize < 0:
      print "ERROR: cpStructSize %d for tag %d" % (cpStructSize, cpTag)
      sys.exit(1)

    print "Size: %d" % cpStructSize

    cpCount -= 1
    c.seek(cpStructSize, os.SEEK_CUR)

Response:
<REPLACE_OLD> sys

###############
### <REPLACE_NEW> sys

CP_STRUCT_SIZES = { 0xa:3 }

###############
### <REPLACE_END> <REPLACE_OLD> == 0xa:
 <REPLACE_NEW> in CP_STRUCT_SIZES:
 <REPLACE_END> <REPLACE_OLD> 3
 <REPLACE_NEW> CP_STRUCT_SIZES[tag]
 <REPLACE_END> <|endoftext|> #!/usr/bin/python

import argparse
import os
import struct
import sys

CP_STRUCT_SIZES = { 0xa:3 }

###############
### CLASSES ###
###############
class MyParser(argparse.ArgumentParser):
    def error(self, message):
        sys.stderr.write('error: %s\n' % message)
        self.print_help()
        sys.exit(2)

###################
### SUBROUTINES ###
###################
def lenCpStruct(tag):
  if tag in CP_STRUCT_SIZES:
    return CP_STRUCT_SIZES[tag]
  else:
    return -1

############
### MAIN ###
############
parser = MyParser('Run bytecode in jjvm')
parser.add_argument('path', help='path to class')
args = parser.parse_args()

with open(args.path, "rb") as c:
  c.seek(8)
  cpCount = struct.unpack(">H", c.read(2))[0] - 1

  print "Constant pool count: %d" % cpCount;

  while cpCount >= 0:
    cpTag = ord(c.read(1))

    print "Got tag: %d" % cpTag
    cpStructSize = lenCpStruct(cpTag)

    if cpStructSize < 0:
      print "ERROR: cpStructSize %d for tag %d" % (cpStructSize, cpTag)
      sys.exit(1)

    print "Size: %d" % cpStructSize

    cpCount -= 1
    c.seek(cpStructSize, os.SEEK_CUR)

Prompt:
Use constants dictionary in lenCpStruct()

#!/usr/bin/python

import argparse
import os
import struct
import sys

###############
### CLASSES ###
###############
class MyParser(argparse.ArgumentParser):
    def error(self, message):
        sys.stderr.write('error: %s\n' % message)
        self.print_help()
        sys.exit(2)

###################
### SUBROUTINES ###
###################
def lenCpStruct(tag):
  if tag == 0xa:
    return 3
  else:
    return -1

############
### MAIN ###
############
parser = MyParser('Run bytecode in jjvm')
parser.add_argument('path', help='path to class')
args = parser.parse_args()

with open(args.path, "rb") as c:
  c.seek(8)
  cpCount = struct.unpack(">H", c.read(2))[0] - 1

  print "Constant pool count: %d" % cpCount;

  while cpCount >= 0:
    cpTag = ord(c.read(1))

    print "Got tag: %d" % cpTag
    cpStructSize = lenCpStruct(cpTag)

    if cpStructSize < 0:
      print "ERROR: cpStructSize %d for tag %d" % (cpStructSize, cpTag)
      sys.exit(1)

    print "Size: %d" % cpStructSize

    cpCount -= 1
    c.seek(cpStructSize, os.SEEK_CUR)


# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-08 10:23
from __future__ import unicode_literals

from django.db import migrations

from corehq.blobs import get_blob_db
from corehq.sql_db.operations import HqRunPython

FIXTURE_BUCKET = 'domain-fixtures'

def rm_blobdb_domain_fixtures(apps, schema_editor):
    get_blob_db().delete(bucket=FIXTURE_BUCKET)

def noop_reverse_migration(apps, schema_editor):
    pass

class Migration(migrations.Migration):

    dependencies = [
        ('fixtures', '0001_initial'),
    ]

    operations = [
        HqRunPython(rm_blobdb_domain_fixtures, noop_reverse_migration),
    ]

Add migration to delete existing cache values

Response:
<INSERT> # -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-08 10:23
from __future__ import unicode_literals

from django.db import migrations

from corehq.blobs import get_blob_db
from corehq.sql_db.operations import HqRunPython

FIXTURE_BUCKET = 'domain-fixtures'

def rm_blobdb_domain_fixtures(apps, schema_editor):
 <INSERT_END> <INSERT>   get_blob_db().delete(bucket=FIXTURE_BUCKET)

def noop_reverse_migration(apps, schema_editor):
    pass

class Migration(migrations.Migration):

    dependencies = [
        ('fixtures', '0001_initial'),
    ]

    operations = [
        HqRunPython(rm_blobdb_domain_fixtures, noop_reverse_migration),
    ]
 <INSERT_END> <|endoftext|> # -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-08 10:23
from __future__ import unicode_literals

from django.db import migrations

from corehq.blobs import get_blob_db
from corehq.sql_db.operations import HqRunPython

FIXTURE_BUCKET = 'domain-fixtures'

def rm_blobdb_domain_fixtures(apps, schema_editor):
    get_blob_db().delete(bucket=FIXTURE_BUCKET)

def noop_reverse_migration(apps, schema_editor):
    pass

class Migration(migrations.Migration):

    dependencies = [
        ('fixtures', '0001_initial'),
    ]

    operations = [
        HqRunPython(rm_blobdb_domain_fixtures, noop_reverse_migration),
    ]

Prompt: Add migration to delete existing cache values


from django.core.management.base import BaseCommand
from django.core import serializers

from data_log import models
import json

class Command(BaseCommand):
    help = 'Create Data Log Report fixtures'

    def handle(self, *args, **kwargs):
        self.stdout.write(self.style.HTTP_INFO('Creating fixtures for Data Log Reports...'))
        JSONSerializer = serializers.get_serializer("json")
        j = JSONSerializer()
        data = []
        models_to_serialize = [
            models.LevelReport,
            models.SummonReport,
            models.MagicShopRefreshReport,
            models.MagicBoxCraftingReport,
            models.WishReport,
            models.RuneCraftingReport
        ]

        pks = []
        for model in models_to_serialize:
            self.stdout.write(self.style.WARNING(model.__name__))
            serialized_data = json.loads(j.serialize(model.objects.order_by('-generated_on')[:100]))
            pks += [d['pk'] for d in serialized_data]
            data += serialized_data

        self.stdout.write(self.style.WARNING(models.Report.__name__))
        reports = json.loads(j.serialize(models.Report.objects.order_by('-generated_on')[:100]))

        self.stdout.write(self.style.HTTP_INFO("Finishing special reports..."))
        reports += json.loads(j.serialize(models.Report.objects.filter(pk__in=pks)))

        data = reports + data

        self.stdout.write(self.style.HTTP_INFO('Saving fixtures to file'))
        with open("fixture_reports.json", "w+") as f:
            json.dump(data, f)

        self.stdout.write(self.style.SUCCESS('Done!'))

Fix data log fixture foreign keys

Fix data log fixture foreign keys

Response:
<INSERT> pks = []
        <INSERT_END> <INSERT> serialized_data = json.loads(j.serialize(model.objects.order_by('-generated_on')[:100]))
            pks += [d['pk'] for d in serialized_data]
            <INSERT_END> <REPLACE_OLD> json.loads(j.serialize(model.objects.order_by('-generated_on')[:100]))
 <REPLACE_NEW> serialized_data
 <REPLACE_END> <INSERT> reports = json.loads(j.serialize(models.Report.objects.order_by('-generated_on')[:100]))

        self.stdout.write(self.style.HTTP_INFO("Finishing special reports..."))
        reports += json.loads(j.serialize(models.Report.objects.filter(pk__in=pks)))

        <INSERT_END> <REPLACE_OLD> += json.loads(j.serialize(models.Report.objects.order_by('-generated_on')[:1000]))

 <REPLACE_NEW> = reports + data

        self.stdout.write(self.style.HTTP_INFO('Saving fixtures to file'))
 <REPLACE_END> <|endoftext|> from django.core.management.base import BaseCommand
from django.core import serializers

from data_log import models
import json

class Command(BaseCommand):
    help = 'Create Data Log Report fixtures'

    def handle(self, *args, **kwargs):
        self.stdout.write(self.style.HTTP_INFO('Creating fixtures for Data Log Reports...'))
        JSONSerializer = serializers.get_serializer("json")
        j = JSONSerializer()
        data = []
        models_to_serialize = [
            models.LevelReport,
            models.SummonReport,
            models.MagicShopRefreshReport,
            models.MagicBoxCraftingReport,
            models.WishReport,
            models.RuneCraftingReport
        ]

        pks = []
        for model in models_to_serialize:
            self.stdout.write(self.style.WARNING(model.__name__))
            serialized_data = json.loads(j.serialize(model.objects.order_by('-generated_on')[:100]))
            pks += [d['pk'] for d in serialized_data]
            data += serialized_data

        self.stdout.write(self.style.WARNING(models.Report.__name__))
        reports = json.loads(j.serialize(models.Report.objects.order_by('-generated_on')[:100]))

        self.stdout.write(self.style.HTTP_INFO("Finishing special reports..."))
        reports += json.loads(j.serialize(models.Report.objects.filter(pk__in=pks)))

        data = reports + data

        self.stdout.write(self.style.HTTP_INFO('Saving fixtures to file'))
        with open("fixture_reports.json", "w+") as f:
            json.dump(data, f)

        self.stdout.write(self.style.SUCCESS('Done!'))

Prompt:
Fix data log fixture foreign keys

from django.core.management.base import BaseCommand
from django.core import serializers

from data_log import models
import json

class Command(BaseCommand):
    help = 'Create Data Log Report fixtures'

    def handle(self, *args, **kwargs):
        self.stdout.write(self.style.HTTP_INFO('Creating fixtures for Data Log Reports...'))
        JSONSerializer = serializers.get_serializer("json")
        j = JSONSerializer()
        data = []
        models_to_serialize = [
            models.LevelReport,
            models.SummonReport,
            models.MagicShopRefreshReport,
            models.MagicBoxCraftingReport,
            models.WishReport,
            models.RuneCraftingReport
        ]

        for model in models_to_serialize:
            self.stdout.write(self.style.WARNING(model.__name__))
            data += json.loads(j.serialize(model.objects.order_by('-generated_on')[:100]))

        self.stdout.write(self.style.WARNING(models.Report.__name__))
        data += json.loads(j.serialize(models.Report.objects.order_by('-generated_on')[:1000]))

        with open("fixture_reports.json", "w+") as f:
            json.dump(data, f)

        self.stdout.write(self.style.SUCCESS('Done!'))


#! /usr/bin/env python
#
# Copyright (c) 2011 Red Hat, Inc.
#
# This software is licensed to you under the GNU Lesser General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (LGPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of LGPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt.
#
# Jeff Ortel <jortel@redhat.com>
#

"""
Provides a debugging agent that loads configuration and plugins
from standard locations.  But, does not need to run as root
since it does use /var directories.
IMPORTANT: be sure the installed daemon is stopped.
"""

import os
import time

from gofer.agent import logutil

class TestAgent:

    ROOT = '/tmp/gofer'

    def start(self):
        self.mkdir()
        logutil.LOGDIR = self.ROOT

        from gofer.agent.main import PluginLoader, Agent, AgentLock, eager
        from gofer.rmi.store import PendingQueue

        AgentLock.PATH = os.path.join(self.ROOT, 'gofer.pid')
        PendingQueue.ROOT = os.path.join(self.ROOT, 'messaging/pending')
        self.mkdir(PendingQueue.ROOT)

        pl = PluginLoader()
        plugins = pl.load(eager())
        agent = Agent(plugins)
        agent.start(False)
        print 'Agent: started'
        while True:
            time.sleep(10)
            print 'Agent: sleeping...'

    def mkdir(self, path=ROOT):
        if not os.path.exists(path):
            os.makedirs(path)
        return path

if __name__ == '__main__':
    agent = TestAgent()
    agent.start()
    print 'Done'

Add for debugging w/o running as root.

Add for debugging w/o running as root.

Response:
<REPLACE_OLD>  <REPLACE_NEW> #! /usr/bin/env python
#
# Copyright (c) 2011 Red Hat, Inc.
#
# This software is licensed to you under the GNU Lesser General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (LGPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of LGPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt.
#
# Jeff Ortel <jortel@redhat.com>
#

"""
Provides a debugging agent that loads configuration and plugins
from standard locations.  But, does not need to run as root
since it does use /var directories.
IMPORTANT: be sure the installed daemon is stopped.
"""

import os
import time

from gofer.agent import logutil

class TestAgent:

    ROOT = '/tmp/gofer'

    def start(self):
        self.mkdir()
        logutil.LOGDIR = self.ROOT

        from gofer.agent.main import PluginLoader, Agent, AgentLock, eager
        from gofer.rmi.store import PendingQueue

        AgentLock.PATH = os.path.join(self.ROOT, 'gofer.pid')
        PendingQueue.ROOT = os.path.join(self.ROOT, 'messaging/pending')
        self.mkdir(PendingQueue.ROOT)

        pl = PluginLoader()
        plugins = pl.load(eager())
        agent = Agent(plugins)
        agent.start(False)
        print 'Agent: started'
        while True:
            time.sleep(10)
            print 'Agent: sleeping...'

    def mkdir(self, path=ROOT):
        if not os.path.exists(path):
            os.makedirs(path)
        return path

if __name__ == '__main__':
    agent = TestAgent()
    agent.start()
    print 'Done' <REPLACE_END> <|endoftext|> #! /usr/bin/env python
#
# Copyright (c) 2011 Red Hat, Inc.
#
# This software is licensed to you under the GNU Lesser General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (LGPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of LGPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt.
#
# Jeff Ortel <jortel@redhat.com>
#

"""
Provides a debugging agent that loads configuration and plugins
from standard locations.  But, does not need to run as root
since it does use /var directories.
IMPORTANT: be sure the installed daemon is stopped.
"""

import os
import time

from gofer.agent import logutil

class TestAgent:

    ROOT = '/tmp/gofer'

    def start(self):
        self.mkdir()
        logutil.LOGDIR = self.ROOT

        from gofer.agent.main import PluginLoader, Agent, AgentLock, eager
        from gofer.rmi.store import PendingQueue

        AgentLock.PATH = os.path.join(self.ROOT, 'gofer.pid')
        PendingQueue.ROOT = os.path.join(self.ROOT, 'messaging/pending')
        self.mkdir(PendingQueue.ROOT)

        pl = PluginLoader()
        plugins = pl.load(eager())
        agent = Agent(plugins)
        agent.start(False)
        print 'Agent: started'
        while True:
            time.sleep(10)
            print 'Agent: sleeping...'

    def mkdir(self, path=ROOT):
        if not os.path.exists(path):
            os.makedirs(path)
        return path

if __name__ == '__main__':
    agent = TestAgent()
    agent.start()
    print 'Done'

Prompt: Add for debugging w/o running as root.


import unittest
import numpy as np
import numpy.testing as test
from word2gauss.words import Vocabulary, iter_pairs

DTYPE = np.float32

class TestIterPairs(unittest.TestCase):
    def test_iter_pairs(self):
        np.random.seed(1234)
        vocab = Vocabulary({'zero': 0, 'one': 1, 'two': 2})

        actual = list(iter_pairs(['zero one two', 'one two zero'],
            vocab, batch_size=2, nsamples=1))
        expected = np.array([[0, 1, 0, 2, 0],
                            [0, 1, 1, 1, 1],
                            [0, 2, 0, 0, 0],
                            [0, 2, 0, 2, 1],
                            [1, 2, 1, 0, 0],
                            [1, 2, 1, 2, 1],
                            [1, 2, 1, 1, 0],
                            [1, 2, 1, 2, 1],
                            [1, 0, 1, 2, 0],
                            [1, 0, 2, 0, 1],
                            [2, 0, 2, 2, 0],
                            [2, 0, 0, 0, 1]], dtype=DTYPE)
        self.assertEqual(len(actual), 1)
        self.assertTrue(np.all(actual[0] == expected))

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

Add a test for iter_pairs

Add a test for iter_pairs

Response:
<REPLACE_OLD>  <REPLACE_NEW>
import unittest
import numpy as np
import numpy.testing as test
from word2gauss.words import Vocabulary, iter_pairs

DTYPE = np.float32

class TestIterPairs(unittest.TestCase):
    def test_iter_pairs(self):
        np.random.seed(1234)
        vocab = Vocabulary({'zero': 0, 'one': 1, 'two': 2})

        actual = list(iter_pairs(['zero one two', 'one two zero'],
            vocab, batch_size=2, nsamples=1))
        expected = np.array([[0, 1, 0, 2, 0],
                            [0, 1, 1, 1, 1],
                            [0, 2, 0, 0, 0],
                            [0, 2, 0, 2, 1],
                            [1, 2, 1, 0, 0],
                            [1, 2, 1, 2, 1],
                            [1, 2, 1, 1, 0],
                            [1, 2, 1, 2, 1],
                            [1, 0, 1, 2, 0],
                            [1, 0, 2, 0, 1],
                            [2, 0, 2, 2, 0],
                            [2, 0, 0, 0, 1]], dtype=DTYPE)
        self.assertEqual(len(actual), 1)
        self.assertTrue(np.all(actual[0] == expected))

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

 <REPLACE_END> <|endoftext|>
import unittest
import numpy as np
import numpy.testing as test
from word2gauss.words import Vocabulary, iter_pairs

DTYPE = np.float32

class TestIterPairs(unittest.TestCase):
    def test_iter_pairs(self):
        np.random.seed(1234)
        vocab = Vocabulary({'zero': 0, 'one': 1, 'two': 2})

        actual = list(iter_pairs(['zero one two', 'one two zero'],
            vocab, batch_size=2, nsamples=1))
        expected = np.array([[0, 1, 0, 2, 0],
                            [0, 1, 1, 1, 1],
                            [0, 2, 0, 0, 0],
                            [0, 2, 0, 2, 1],
                            [1, 2, 1, 0, 0],
                            [1, 2, 1, 2, 1],
                            [1, 2, 1, 1, 0],
                            [1, 2, 1, 2, 1],
                            [1, 0, 1, 2, 0],
                            [1, 0, 2, 0, 1],
                            [2, 0, 2, 2, 0],
                            [2, 0, 0, 0, 1]], dtype=DTYPE)
        self.assertEqual(len(actual), 1)
        self.assertTrue(np.all(actual[0] == expected))

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

Prompt: Add a test for iter_pairs


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

import sys
from traceback import format_exception

from pyramid.decorator import reify
from pyramid.httpexceptions import HTTPInternalServerError
from pyramid.interfaces import IRequestFactory

from ines.convert import force_string
from ines.middlewares import Middleware
from ines.utils import format_error_to_json

class LoggingMiddleware(Middleware):
    name = 'logging'

    @property
    def request_factory(self):
        return self.config.registry.queryUtility(IRequestFactory)

    @reify
    def api_name(self):
        return self.settings.get('logging_api_name') or 'logging'

    def __call__(self, environ, start_response):
        try:
            for chunk in self.application(environ, start_response):
                yield chunk
        except (BaseException, Exception) as error:
            type_, value, tb = sys.exc_info()
            message = ''.join(format_exception(type_, value, tb))

            # Save / log error
            request = self.request_factory(environ)
            request.registry = self.config.registry

            try:
                small_message = '%s: %s' % (error.__class__.__name__, force_string(error))
            except (BaseException, Exception):
                small_message = error

            try:
                getattr(request.api, self.api_name).log_critical(
                    'internal_server_error',
                    str(small_message))
            except (BaseException, Exception):
                print message

            internal_server_error = HTTPInternalServerError()
            headers = [('Content-type', 'application/json')]
            start_response(internal_server_error.status, headers)
            yield format_error_to_json(internal_server_error, request=request)

Set log with small message

Set log with small message

Response:
<INSERT> ines.convert import force_string
from <INSERT_END> <REPLACE_OLD> Exception):
 <REPLACE_NEW> Exception) as error:
 <REPLACE_END> <REPLACE_OLD> error <REPLACE_NEW> message <REPLACE_END> <REPLACE_OLD> message = error.split()[-1]
                getattr(request.api, self.api_name).log_critical('internal_server_error', message)
 <REPLACE_NEW> small_message = '%s: %s' % (error.__class__.__name__, force_string(error))
 <REPLACE_END> <INSERT> small_message = error

            try:
                getattr(request.api, self.api_name).log_critical(
                    'internal_server_error',
                    str(small_message))
            except (BaseException, Exception):
                <INSERT_END> <REPLACE_OLD> error

 <REPLACE_NEW> message

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

import sys
from traceback import format_exception

from pyramid.decorator import reify
from pyramid.httpexceptions import HTTPInternalServerError
from pyramid.interfaces import IRequestFactory

from ines.convert import force_string
from ines.middlewares import Middleware
from ines.utils import format_error_to_json

class LoggingMiddleware(Middleware):
    name = 'logging'

    @property
    def request_factory(self):
        return self.config.registry.queryUtility(IRequestFactory)

    @reify
    def api_name(self):
        return self.settings.get('logging_api_name') or 'logging'

    def __call__(self, environ, start_response):
        try:
            for chunk in self.application(environ, start_response):
                yield chunk
        except (BaseException, Exception) as error:
            type_, value, tb = sys.exc_info()
            message = ''.join(format_exception(type_, value, tb))

            # Save / log error
            request = self.request_factory(environ)
            request.registry = self.config.registry

            try:
                small_message = '%s: %s' % (error.__class__.__name__, force_string(error))
            except (BaseException, Exception):
                small_message = error

            try:
                getattr(request.api, self.api_name).log_critical(
                    'internal_server_error',
                    str(small_message))
            except (BaseException, Exception):
                print message

            internal_server_error = HTTPInternalServerError()
            headers = [('Content-type', 'application/json')]
            start_response(internal_server_error.status, headers)
            yield format_error_to_json(internal_server_error, request=request)

Prompt:
Set log with small message

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

import sys
from traceback import format_exception

from pyramid.decorator import reify
from pyramid.httpexceptions import HTTPInternalServerError
from pyramid.interfaces import IRequestFactory

from ines.middlewares import Middleware
from ines.utils import format_error_to_json

class LoggingMiddleware(Middleware):
    name = 'logging'

    @property
    def request_factory(self):
        return self.config.registry.queryUtility(IRequestFactory)

    @reify
    def api_name(self):
        return self.settings.get('logging_api_name') or 'logging'

    def __call__(self, environ, start_response):
        try:
            for chunk in self.application(environ, start_response):
                yield chunk
        except (BaseException, Exception):
            type_, value, tb = sys.exc_info()
            error = ''.join(format_exception(type_, value, tb))

            # Save / log error
            request = self.request_factory(environ)
            request.registry = self.config.registry

            try:
                message = error.split()[-1]
                getattr(request.api, self.api_name).log_critical('internal_server_error', message)
            except (BaseException, Exception):
                print error

            internal_server_error = HTTPInternalServerError()
            headers = [('Content-type', 'application/json')]
            start_response(internal_server_error.status, headers)
            yield format_error_to_json(internal_server_error, request=request)


from django import forms

from .models import Account

class AccountForm(forms.ModelForm):
    class Meta:
        model = Account
        fields = ('name', 'desc', 'address_one',
                  'address_two', 'city', 'state', 'phone',
        )
        widgets = {
            'name': forms.TextInput(
                attrs={
                    'placeholder':'Company',
                    'class':'col-md-12 form-control'
                }
            ),
            'desc': forms.Textarea(
                attrs={
                    'placeholder':'Enter a description',
                    'class':'form-control'
                }
            ),
            'address_one': forms.TextInput(
                attrs={
                    'placeholder':'Street Address',
                    'class':'gi-form-addr form-control'
                }
            ),
            'address_two': forms.TextInput(
                attrs={
                    'placeholder':'Suite, PO, etc',
                    'class':'gi-form-addr form-control'
                }
            ),
            'city': forms.TextInput(
                attrs={
                    'placeholder':'City',
                    'class':'gi-form-addr form-control'
                }
            ),
            'state': forms.TextInput(
                attrs={
                    'placeholder':'State',
                    'class':'gi-form-addr form-control'
                }
            ),
            'phone': forms.TextInput(
                attrs={
                    'placeholder':'Phone',
                    'class':'gi-form-addr form-control'
                }
            ),
        }

Create the Account Detail Page - Part II > New Account - Create Form

Response:
<REPLACE_OLD>  <REPLACE_NEW> from django import forms

from .models import Account

class AccountForm(forms.ModelForm):
    class Meta:
        model = Account
        fields = ('name', 'desc', 'address_one',
                  'address_two', 'city', 'state', 'phone',
        )
        widgets = {
            'name': forms.TextInput(
                attrs={
                    'placeholder':'Company',
                    'class':'col-md-12 form-control'
                }
            ),
            'desc': forms.Textarea(
                attrs={
                    'placeholder':'Enter a description',
                    'class':'form-control'
                }
            ),
            'address_one': forms.TextInput(
                attrs={
                    'placeholder':'Street Address',
                    'class':'gi-form-addr form-control'
                }
            ),
            'address_two': forms.TextInput(
                attrs={
                    'placeholder':'Suite, PO, etc',
                    'class':'gi-form-addr form-control'
                }
            ),
            'city': forms.TextInput(
                attrs={
                    'placeholder':'City',
                    'class':'gi-form-addr form-control'
                }
            ),
            'state': forms.TextInput(
                attrs={
                    'placeholder':'State',
                    'class':'gi-form-addr form-control'
                }
            ),
            'phone': forms.TextInput(
                attrs={
                    'placeholder':'Phone',
                    'class':'gi-form-addr form-control'
                }
            ),
        }
 <REPLACE_END> <|endoftext|> from django import forms

from .models import Account

class AccountForm(forms.ModelForm):
    class Meta:
        model = Account
        fields = ('name', 'desc', 'address_one',
                  'address_two', 'city', 'state', 'phone',
        )
        widgets = {
            'name': forms.TextInput(
                attrs={
                    'placeholder':'Company',
                    'class':'col-md-12 form-control'
                }
            ),
            'desc': forms.Textarea(
                attrs={
                    'placeholder':'Enter a description',
                    'class':'form-control'
                }
            ),
            'address_one': forms.TextInput(
                attrs={
                    'placeholder':'Street Address',
                    'class':'gi-form-addr form-control'
                }
            ),
            'address_two': forms.TextInput(
                attrs={
                    'placeholder':'Suite, PO, etc',
                    'class':'gi-form-addr form-control'
                }
            ),
            'city': forms.TextInput(
                attrs={
                    'placeholder':'City',
                    'class':'gi-form-addr form-control'
                }
            ),
            'state': forms.TextInput(
                attrs={
                    'placeholder':'State',
                    'class':'gi-form-addr form-control'
                }
            ),
            'phone': forms.TextInput(
                attrs={
                    'placeholder':'Phone',
                    'class':'gi-form-addr form-control'
                }
            ),
        }

Prompt: Create the Account Detail Page - Part II > New Account - Create Form


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

from django.views.generic.detail import DetailView
from django.views.generic.list import ListView

from opps.article.models import Post

class OppsList(ListView):

    context_object_name = "context"

    @property
    def template_name(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return 'channel/{0}.html'.format(long_slug)

    @property
    def queryset(self):
        if not self.kwargs.get('channel__long_slug'):
            return Post.objects.filter(channel__homepage=True).all()
        return Post.objects.filter(
                channel__long_slug=self.kwargs['channel__long_slug']).all()

class OppsDetail(DetailView):

    context_object_name = "context"

    @property
    def template_name(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return 'article/{0}/{1}.html'.format(long_slug, self.kwargs['slug'])

    @property
    def queryset(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return Post.objects.filter(channel__long_slug=long_slug,
                slug=self.kwargs['slug']).all()

Response:
<REPLACE_OLD> return 'article/{0}/{1}.html'.format(
 <REPLACE_NEW> long_slug = self.kwargs.get('channel__long_slug', 'home')
 <REPLACE_END> <REPLACE_OLD>         self.kwargs['channel__long_slug'], <REPLACE_NEW> return 'article/{0}/{1}.html'.format(long_slug, <REPLACE_END> <|endoftext|> #!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.views.generic.detail import DetailView
from django.views.generic.list import ListView

from opps.article.models import Post

class OppsList(ListView):

    context_object_name = "context"

    @property
    def template_name(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return 'channel/{0}.html'.format(long_slug)

    @property
    def queryset(self):
        if not self.kwargs.get('channel__long_slug'):
            return Post.objects.filter(channel__homepage=True).all()
        return Post.objects.filter(
                channel__long_slug=self.kwargs['channel__long_slug']).all()

class OppsDetail(DetailView):

    context_object_name = "context"

    @property
    def template_name(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return 'article/{0}/{1}.html'.format(long_slug, self.kwargs['slug'])

    @property
    def queryset(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return Post.objects.filter(channel__long_slug=long_slug,
                slug=self.kwargs['slug']).all()

Prompt:
Fix template name on entry home page (/) on detail page

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

from django.views.generic.detail import DetailView
from django.views.generic.list import ListView

from opps.article.models import Post

class OppsList(ListView):

    context_object_name = "context"

    @property
    def template_name(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return 'channel/{0}.html'.format(long_slug)

    @property
    def queryset(self):
        if not self.kwargs.get('channel__long_slug'):
            return Post.objects.filter(channel__homepage=True).all()
        return Post.objects.filter(
                channel__long_slug=self.kwargs['channel__long_slug']).all()

class OppsDetail(DetailView):

    context_object_name = "context"

    @property
    def template_name(self):
        return 'article/{0}/{1}.html'.format(
                self.kwargs['channel__long_slug'], self.kwargs['slug'])

    @property
    def queryset(self):
        long_slug = self.kwargs.get('channel__long_slug', 'home')
        return Post.objects.filter(channel__long_slug=long_slug,
                slug=self.kwargs['slug']).all()


# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-11-03 20:56
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import journal.models

class Migration(migrations.Migration):

    dependencies = [
        ('journal', '0034_migrate_issue_types'),
        ('core', '0037_journal_xsl_files'),

    ]

    operations = [
        migrations.AddField(
            model_name='journal',
            name='xsl',
            field=models.ForeignKey(default=journal.models.default_xsl, on_delete=django.db.models.deletion.SET_DEFAULT, to='core.XSLFile'),
            preserve_default=False,
        ),
    ]

Fix migration tree for journal 0035

Fix migration tree for journal 0035

Response:
<INSERT>        ('core', '0037_journal_xsl_files'),

 <INSERT_END> <|endoftext|> # -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-11-03 20:56
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import journal.models

class Migration(migrations.Migration):

    dependencies = [
        ('journal', '0034_migrate_issue_types'),
        ('core', '0037_journal_xsl_files'),

    ]

    operations = [
        migrations.AddField(
            model_name='journal',
            name='xsl',
            field=models.ForeignKey(default=journal.models.default_xsl, on_delete=django.db.models.deletion.SET_DEFAULT, to='core.XSLFile'),
            preserve_default=False,
        ),
    ]

Prompt:
Fix migration tree for journal 0035

# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-11-03 20:56
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import journal.models

class Migration(migrations.Migration):

    dependencies = [
        ('journal', '0034_migrate_issue_types'),
    ]

    operations = [
        migrations.AddField(
            model_name='journal',
            name='xsl',
            field=models.ForeignKey(default=journal.models.default_xsl, on_delete=django.db.models.deletion.SET_DEFAULT, to='core.XSLFile'),
            preserve_default=False,
        ),
    ]


from django.conf import settings
from purl import Template
import requests

from .models import SimilarResponse

API_URL = Template("http://developer.echonest.com/api/v4/artist/similar"
                   "?api_key=%s&results=100&name={name}"
                   % settings.ECHONEST_API_KEY)

def get_similar_from_api(name):
    url = API_URL.expand({'name': name})
    r = requests.get(str(url))
    r.raise_for_status()
    return SimilarResponse.objects.create(name=name, response=r.json())

def get_similar_from_db(name):
    return SimilarResponse.objects.get(normalized_name=name.upper())

def get_similar(name):
    try:
        response = get_similar_from_db(name)
    except SimilarResponse.DoesNotExist:
        response = get_similar_from_api(name)
    return response.artist_names

Fix bug in The Echo Nest API call

Fix bug in The Echo Nest API call

Response:
<REPLACE_OLD> requests.get(url)
 <REPLACE_NEW> requests.get(str(url))
 <REPLACE_END> <|endoftext|> from django.conf import settings
from purl import Template
import requests

from .models import SimilarResponse

API_URL = Template("http://developer.echonest.com/api/v4/artist/similar"
                   "?api_key=%s&results=100&name={name}"
                   % settings.ECHONEST_API_KEY)

def get_similar_from_api(name):
    url = API_URL.expand({'name': name})
    r = requests.get(str(url))
    r.raise_for_status()
    return SimilarResponse.objects.create(name=name, response=r.json())

def get_similar_from_db(name):
    return SimilarResponse.objects.get(normalized_name=name.upper())

def get_similar(name):
    try:
        response = get_similar_from_db(name)
    except SimilarResponse.DoesNotExist:
        response = get_similar_from_api(name)
    return response.artist_names

Prompt:
Fix bug in The Echo Nest API call

from django.conf import settings
from purl import Template
import requests

from .models import SimilarResponse

API_URL = Template("http://developer.echonest.com/api/v4/artist/similar"
                   "?api_key=%s&results=100&name={name}"
                   % settings.ECHONEST_API_KEY)

def get_similar_from_api(name):
    url = API_URL.expand({'name': name})
    r = requests.get(url)
    r.raise_for_status()
    return SimilarResponse.objects.create(name=name, response=r.json())

def get_similar_from_db(name):
    return SimilarResponse.objects.get(normalized_name=name.upper())

def get_similar(name):
    try:
        response = get_similar_from_db(name)
    except SimilarResponse.DoesNotExist:
        response = get_similar_from_api(name)
    return response.artist_names


import os
import imp

_formula_cache = {}

_default_search_path = [os.path.join(os.path.dirname(__file__), "..", "Formula")]

class FormulaManager:
    @staticmethod
    def _find(name, search_path=[]):
        file_path = ""
        for path in search_path + default_search_path:
            if os.path.exists(os.path.join(path, name + ".py")):
                file_path = os.path.join(path, name + ".py")
        return file_path

    @staticmethod
    def get(name, search_path=[]):
        file_path = ""

        #name can be a path
        if os.path.isfile(name):
            file_path = name

        name = os.path.splitext(os.path.basename(file_path))[0]

        if _formula_cache.has_key(name):
            return _formula_cache[name]
        else:
            if not file_path:
                file_path = FormulaManager._find(name, search_path)

            formula = imp.load_source(name, file_path)
            _formula_cache[name] = formula

            return formula

Implement class for managing formulas

Implement class for managing formulas

Response:
<REPLACE_OLD>  <REPLACE_NEW> import os
import imp

_formula_cache = {}

_default_search_path = [os.path.join(os.path.dirname(__file__), "..", "Formula")]

class FormulaManager:
    @staticmethod
    def _find(name, search_path=[]):
        file_path = ""
        for path in search_path + default_search_path:
            if os.path.exists(os.path.join(path, name + ".py")):
                file_path = os.path.join(path, name + ".py")
        return file_path

    @staticmethod
    def get(name, search_path=[]):
        file_path = ""

        #name can be a path
        if os.path.isfile(name):
            file_path = name

        name = os.path.splitext(os.path.basename(file_path))[0]

        if _formula_cache.has_key(name):
            return _formula_cache[name]
        else:
            if not file_path:
                file_path = FormulaManager._find(name, search_path)

            formula = imp.load_source(name, file_path)
            _formula_cache[name] = formula

            return formula

         <REPLACE_END> <|endoftext|> import os
import imp

_formula_cache = {}

_default_search_path = [os.path.join(os.path.dirname(__file__), "..", "Formula")]

class FormulaManager:
    @staticmethod
    def _find(name, search_path=[]):
        file_path = ""
        for path in search_path + default_search_path:
            if os.path.exists(os.path.join(path, name + ".py")):
                file_path = os.path.join(path, name + ".py")
        return file_path

    @staticmethod
    def get(name, search_path=[]):
        file_path = ""

        #name can be a path
        if os.path.isfile(name):
            file_path = name

        name = os.path.splitext(os.path.basename(file_path))[0]

        if _formula_cache.has_key(name):
            return _formula_cache[name]
        else:
            if not file_path:
                file_path = FormulaManager._find(name, search_path)

            formula = imp.load_source(name, file_path)
            _formula_cache[name] = formula

            return formula

Prompt: Implement class for managing formulas


from rest_framework import serializers as ser

from api.base.serializers import (
    JSONAPISerializer, LinksField, IDField, TypeField
)
from api.base.utils import absolute_reverse

class LicenseSerializer(JSONAPISerializer):
    filterable_fields = frozenset([
        'name',
        'id',
    ])
    non_anonymized_fields = ['type']
    id = IDField(source='_id', read_only=True)
    type = TypeField()
    name = ser.CharField(required=True, help_text='License name')
    text = ser.CharField(required=True, help_text='Full text of the license')
    url = ser.URLField(required=False, help_text='URL for the license')
    required_fields = ser.ListField(source='properties', read_only=True,
                                    help_text='Fields required for this license (provided to help front-end validators)')
    links = LinksField({'self': 'get_absolute_url'})

    class Meta:
        type_ = 'licenses'

    def get_absolute_url(self, obj):
        return absolute_reverse('licenses:license-detail', kwargs={
            'license_id': obj._id,
            'version': self.context['request'].parser_context['kwargs']['version']
        })

Add url to the license api serializer

Add url to the license api serializer

Response:
<INSERT> the license')
    url = ser.URLField(required=False, help_text='URL for <INSERT_END> <|endoftext|> from rest_framework import serializers as ser

from api.base.serializers import (
    JSONAPISerializer, LinksField, IDField, TypeField
)
from api.base.utils import absolute_reverse

class LicenseSerializer(JSONAPISerializer):
    filterable_fields = frozenset([
        'name',
        'id',
    ])
    non_anonymized_fields = ['type']
    id = IDField(source='_id', read_only=True)
    type = TypeField()
    name = ser.CharField(required=True, help_text='License name')
    text = ser.CharField(required=True, help_text='Full text of the license')
    url = ser.URLField(required=False, help_text='URL for the license')
    required_fields = ser.ListField(source='properties', read_only=True,
                                    help_text='Fields required for this license (provided to help front-end validators)')
    links = LinksField({'self': 'get_absolute_url'})

    class Meta:
        type_ = 'licenses'

    def get_absolute_url(self, obj):
        return absolute_reverse('licenses:license-detail', kwargs={
            'license_id': obj._id,
            'version': self.context['request'].parser_context['kwargs']['version']
        })

Prompt:
Add url to the license api serializer

from rest_framework import serializers as ser

from api.base.serializers import (
    JSONAPISerializer, LinksField, IDField, TypeField
)
from api.base.utils import absolute_reverse

class LicenseSerializer(JSONAPISerializer):
    filterable_fields = frozenset([
        'name',
        'id',
    ])
    non_anonymized_fields = ['type']
    id = IDField(source='_id', read_only=True)
    type = TypeField()
    name = ser.CharField(required=True, help_text='License name')
    text = ser.CharField(required=True, help_text='Full text of the license')
    required_fields = ser.ListField(source='properties', read_only=True,
                                    help_text='Fields required for this license (provided to help front-end validators)')
    links = LinksField({'self': 'get_absolute_url'})

    class Meta:
        type_ = 'licenses'

    def get_absolute_url(self, obj):
        return absolute_reverse('licenses:license-detail', kwargs={
            'license_id': obj._id,
            'version': self.context['request'].parser_context['kwargs']['version']
        })


from setuptools import setup, find_packages

__version__ = '0.2.1'
__pkg_name__ = 'textsift'

setup(
    name = __pkg_name__,
    version = __version__,
    description = 'Text modelling framework',
    author='Andrew Chisholm',
    packages = find_packages(),
    license = 'MIT',
    url = 'https://github.com/wikilinks/sift',
    scripts = [
        'scripts/download-wikipedia'
    ],
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Console',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
        'Topic :: Text Processing :: Linguistic'
    ],
    install_requires = [
        "ujson",
        "numpy",
        "pattern",
        "gensim",
        "msgpack-python"
    ],
    test_suite = __pkg_name__ + '.test'
)

Response:
<REPLACE_OLD> '0.2.0'
__pkg_name__ <REPLACE_NEW> '0.2.1'
__pkg_name__ <REPLACE_END> <DELETE> 'scripts/sift',
        <DELETE_END> <|endoftext|> from setuptools import setup, find_packages

__version__ = '0.2.1'
__pkg_name__ = 'textsift'

setup(
    name = __pkg_name__,
    version = __version__,
    description = 'Text modelling framework',
    author='Andrew Chisholm',
    packages = find_packages(),
    license = 'MIT',
    url = 'https://github.com/wikilinks/sift',
    scripts = [
        'scripts/download-wikipedia'
    ],
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Console',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
        'Topic :: Text Processing :: Linguistic'
    ],
    install_requires = [
        "ujson",
        "numpy",
        "pattern",
        "gensim",
        "msgpack-python"
    ],
    test_suite = __pkg_name__ + '.test'
)

Prompt:
Remove all sift cli script command from package

from setuptools import setup, find_packages

__version__ = '0.2.0'
__pkg_name__ = 'textsift'

setup(
    name = __pkg_name__,
    version = __version__,
    description = 'Text modelling framework',
    author='Andrew Chisholm',
    packages = find_packages(),
    license = 'MIT',
    url = 'https://github.com/wikilinks/sift',
    scripts = [
        'scripts/sift',
        'scripts/download-wikipedia'
    ],
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Console',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
        'Topic :: Text Processing :: Linguistic'
    ],
    install_requires = [
        "ujson",
        "numpy",
        "pattern",
        "gensim",
        "msgpack-python"
    ],
    test_suite = __pkg_name__ + '.test'
)


__version__ = '1.6.0'
__author__ = 'Cameron Higby-Naquin'

Response:
<REPLACE_OLD> '1.5.2'
__author__ <REPLACE_NEW> '1.6.0'
__author__ <REPLACE_END> <|endoftext|> __version__ = '1.6.0'
__author__ = 'Cameron Higby-Naquin'

Prompt:
Increment minor version for new feature release.

__version__ = '1.5.2'
__author__ = 'Cameron Higby-Naquin'


from twisted.words.protocols import irc

class HeufyBotConnection(irc.IRC):
    def __init__(self, protocol):
        self.protocol = protocol
        self.nick = "PyHeufyBot"  # TODO This will be set by a configuration at some point
        self.ident = "PyHeufyBot"  # TODO This will be set by a configuration at some point
        self.gecos = "PyHeufyBot IRC Bot"  # TODO This will be set by a configuration at some point
        self.channels = {}
        self.usermodes = {}

    def connectionMade(self):
        self.cmdNICK(self.nick)
        self.cmdUSER(self.ident, self.gecos)

    def connectionLost(self, reason=""):
        print reason

    def dataReceived(self, data):
        print data

    def sendMessage(self, command, *parameter_list, **prefix):
        print command, " ".join(parameter_list)
        irc.IRC.sendMessage(self, command, *parameter_list, **prefix)

    def cmdNICK(self, nick):
        self.sendMessage("NICK", nick)

    def cmdUSER(self, ident, gecos):
        # RFC2812 allows usermodes to be set, but this isn't implemented much in IRCds at all.
        # Pass 0 for usermodes instead.
        self.sendMessage("USER", ident, "0", "*", ":{}".format(gecos))

Response:
<REPLACE_OLD> point

 <REPLACE_NEW> point
        self.channels = {}
        self.usermodes = {}

 <REPLACE_END> <|endoftext|> from twisted.words.protocols import irc

class HeufyBotConnection(irc.IRC):
    def __init__(self, protocol):
        self.protocol = protocol
        self.nick = "PyHeufyBot"  # TODO This will be set by a configuration at some point
        self.ident = "PyHeufyBot"  # TODO This will be set by a configuration at some point
        self.gecos = "PyHeufyBot IRC Bot"  # TODO This will be set by a configuration at some point
        self.channels = {}
        self.usermodes = {}

    def connectionMade(self):
        self.cmdNICK(self.nick)
        self.cmdUSER(self.ident, self.gecos)

    def connectionLost(self, reason=""):
        print reason

    def dataReceived(self, data):
        print data

    def sendMessage(self, command, *parameter_list, **prefix):
        print command, " ".join(parameter_list)
        irc.IRC.sendMessage(self, command, *parameter_list, **prefix)

    def cmdNICK(self, nick):
        self.sendMessage("NICK", nick)

    def cmdUSER(self, ident, gecos):
        # RFC2812 allows usermodes to be set, but this isn't implemented much in IRCds at all.
        # Pass 0 for usermodes instead.
        self.sendMessage("USER", ident, "0", "*", ":{}".format(gecos))

Prompt:
Add dictionaries for channels and usermodes

from twisted.words.protocols import irc

class HeufyBotConnection(irc.IRC):
    def __init__(self, protocol):
        self.protocol = protocol
        self.nick = "PyHeufyBot"  # TODO This will be set by a configuration at some point
        self.ident = "PyHeufyBot"  # TODO This will be set by a configuration at some point
        self.gecos = "PyHeufyBot IRC Bot"  # TODO This will be set by a configuration at some point

    def connectionMade(self):
        self.cmdNICK(self.nick)
        self.cmdUSER(self.ident, self.gecos)

    def connectionLost(self, reason=""):
        print reason

    def dataReceived(self, data):
        print data

    def sendMessage(self, command, *parameter_list, **prefix):
        print command, " ".join(parameter_list)
        irc.IRC.sendMessage(self, command, *parameter_list, **prefix)

    def cmdNICK(self, nick):
        self.sendMessage("NICK", nick)

    def cmdUSER(self, ident, gecos):
        # RFC2812 allows usermodes to be set, but this isn't implemented much in IRCds at all.
        # Pass 0 for usermodes instead.
        self.sendMessage("USER", ident, "0", "*", ":{}".format(gecos))


# -*- encoding: utf-8 *-*
#!/usr/bin/env python
import os
import sys
from glob import glob
from setuptools import setup, Extension
from setuptools.command.sdist import sdist
hashindex_sources = ['darc/hashindex.pyx', 'darc/_hashindex.c']

try:
    from Cython.Distutils import build_ext
    import Cython.Compiler.Main as cython_compiler
    class Sdist(sdist):
        def __init__(self, *args, **kwargs):
            for src in glob('darc/*.pyx'):
                print 'src', src
                cython_compiler.compile(glob('darc/*.pyx'),
                                        cython_compiler.default_options)
            sdist.__init__(self, *args, **kwargs)

        def run(self):
            sdist.run(self)
            self.filelist.append('darc/hashindex.c', 'darc/hashindex.h')

except ImportError:
    hashindex_sources[0] = hashindex_sources[0].replace('.pyx', '.c')
    from setuptools.command.build_ext import build_ext
    Sdist = sdist
    if not os.path.exists('darc/hashindex.c'):
        raise ImportError('The GIT version of darc needs Cython. Install Cython or use a released version')

dependencies = ['pycrypto', 'msgpack-python', 'pbkdf2.py', 'xattr', 'paramiko']
if sys.version_info < (2, 7):
    dependencies.append('argparse')

setup(name='darc',
      version='0.1',
      author='Jonas Borgström',
      author_email='jonas@borgstrom.se',
      url='http://github.com/jborg/darc/',
      packages=['darc'],
      cmdclass = {'build_ext': build_ext, 'sdist': Sdist},
      ext_modules=[
      Extension('darc._speedups', ['darc/_speedups.c']),
      Extension('darc.hashindex', hashindex_sources)],
      install_requires=dependencies,
      entry_points = {
        'console_scripts': [
            'darc = darc.archiver:main',
        ]
    })

Include Cython output in sdist

Include Cython output in sdist

Response:
<INSERT> os
import <INSERT_END> <INSERT> glob import glob
from <INSERT_END> <INSERT> setuptools.command.sdist import sdist
hashindex_sources = ['darc/hashindex.pyx', 'darc/_hashindex.c']

try:
    from <INSERT_END> <REPLACE_OLD> build_ext

dependencies <REPLACE_NEW> build_ext
    import Cython.Compiler.Main as cython_compiler
    class Sdist(sdist):
        def __init__(self, *args, **kwargs):
            for src in glob('darc/*.pyx'):
                print 'src', src
                cython_compiler.compile(glob('darc/*.pyx'),
                                        cython_compiler.default_options)
            sdist.__init__(self, *args, **kwargs)

        def run(self):
            sdist.run(self)
            self.filelist.append('darc/hashindex.c', 'darc/hashindex.h')

except ImportError:
    hashindex_sources[0] = hashindex_sources[0].replace('.pyx', '.c')
    from setuptools.command.build_ext import build_ext
    Sdist = sdist
    if not os.path.exists('darc/hashindex.c'):
        raise ImportError('The GIT version of darc needs Cython. Install Cython or use a released version')

dependencies <REPLACE_END> <REPLACE_OLD> 'paramiko', 'Pyrex', 'Cython']
if <REPLACE_NEW> 'paramiko']
if <REPLACE_END> <INSERT> url='http://github.com/jborg/darc/',
      <INSERT_END> <REPLACE_OLD> build_ext},
 <REPLACE_NEW> build_ext, 'sdist': Sdist},
 <REPLACE_END> <DELETE>              <DELETE_END> <REPLACE_OLD> ['darc/hashindex.pyx', 'darc/_hashindex.c'])],
 <REPLACE_NEW> hashindex_sources)],
 <REPLACE_END> <|endoftext|> # -*- encoding: utf-8 *-*
#!/usr/bin/env python
import os
import sys
from glob import glob
from setuptools import setup, Extension
from setuptools.command.sdist import sdist
hashindex_sources = ['darc/hashindex.pyx', 'darc/_hashindex.c']

try:
    from Cython.Distutils import build_ext
    import Cython.Compiler.Main as cython_compiler
    class Sdist(sdist):
        def __init__(self, *args, **kwargs):
            for src in glob('darc/*.pyx'):
                print 'src', src
                cython_compiler.compile(glob('darc/*.pyx'),
                                        cython_compiler.default_options)
            sdist.__init__(self, *args, **kwargs)

        def run(self):
            sdist.run(self)
            self.filelist.append('darc/hashindex.c', 'darc/hashindex.h')

except ImportError:
    hashindex_sources[0] = hashindex_sources[0].replace('.pyx', '.c')
    from setuptools.command.build_ext import build_ext
    Sdist = sdist
    if not os.path.exists('darc/hashindex.c'):
        raise ImportError('The GIT version of darc needs Cython. Install Cython or use a released version')

dependencies = ['pycrypto', 'msgpack-python', 'pbkdf2.py', 'xattr', 'paramiko']
if sys.version_info < (2, 7):
    dependencies.append('argparse')

setup(name='darc',
      version='0.1',
      author='Jonas Borgström',
      author_email='jonas@borgstrom.se',
      url='http://github.com/jborg/darc/',
      packages=['darc'],
      cmdclass = {'build_ext': build_ext, 'sdist': Sdist},
      ext_modules=[
      Extension('darc._speedups', ['darc/_speedups.c']),
      Extension('darc.hashindex', hashindex_sources)],
      install_requires=dependencies,
      entry_points = {
        'console_scripts': [
            'darc = darc.archiver:main',
        ]
    })

Prompt:
Include Cython output in sdist

# -*- encoding: utf-8 *-*
#!/usr/bin/env python
import sys
from setuptools import setup, Extension
from Cython.Distutils import build_ext

dependencies = ['pycrypto', 'msgpack-python', 'pbkdf2.py', 'xattr', 'paramiko', 'Pyrex', 'Cython']
if sys.version_info < (2, 7):
    dependencies.append('argparse')

setup(name='darc',
      version='0.1',
      author='Jonas Borgström',
      author_email='jonas@borgstrom.se',
      packages=['darc'],
      cmdclass = {'build_ext': build_ext},
      ext_modules=[
      Extension('darc._speedups', ['darc/_speedups.c']),
                   Extension('darc.hashindex', ['darc/hashindex.pyx', 'darc/_hashindex.c'])],
      install_requires=dependencies,
      entry_points = {
        'console_scripts': [
            'darc = darc.archiver:main',
        ]
    })


# Licensed under an MIT open source license - see LICENSE
from __future__ import print_function, absolute_import, division

class TurbuStatTestingWarning(Warning):
    '''
    Turbustat.statistics warning for untested methods.
    '''

class TurbuStatMetricWarning(Warning):
    '''
    Turbustat.statistics warning for misusing a distance metric.
    '''

Response:
<REPLACE_OLD> ''' <REPLACE_NEW> '''

class TurbuStatMetricWarning(Warning):
    '''
    Turbustat.statistics warning for misusing a distance metric.
    '''
 <REPLACE_END> <|endoftext|> # Licensed under an MIT open source license - see LICENSE
from __future__ import print_function, absolute_import, division

class TurbuStatTestingWarning(Warning):
    '''
    Turbustat.statistics warning for untested methods.
    '''

class TurbuStatMetricWarning(Warning):
    '''
    Turbustat.statistics warning for misusing a distance metric.
    '''

Prompt:
Add warning for where a distance metric is being misused

# Licensed under an MIT open source license - see LICENSE
from __future__ import print_function, absolute_import, division

class TurbuStatTestingWarning(Warning):
    '''
    Turbustat.statistics warning for untested methods.
    '''


import packages.project as project
import packages.primitive as primitive
import packages.utils as utils
import packages.processing
import packages.io
import argparse
from matplotlib import pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
from scipy.stats import norm,kstest,skewtest,kurtosistest,normaltest

compareToGt = False

itmin=0
itmax=3

################################################################################
## Command line parsing
parser = argparse.ArgumentParser(description='Collect full run statistics.')
parser.add_argument('projectdir')

args = parser.parse_args()

projectdir = args.projectdir
if projectdir[-1] == '/':
    projectdir = projectdir[:-1]

projectname  = projectdir.split('/')[-1]
cloudfile    = projectdir+'/cloud.ply'
cloud        = packages.io.readPointCloudFromPly(cloudfile)

print 'Processing project ', projectname

sigma_ref = 1.

if compareToGt:
    projectfile  = projectdir+'/gt/'+projectname+'.prj'
    gtlinesfile  = projectdir+'/gt/primitives.csv'
    gtassignfile = projectdir+'/gt/points_primitives.csv'

    project  = project.PyProject(projectfile)
    gtlines  = primitive.readPrimitivesFromFile(gtlinesfile)
    gtassign = packages.io.readPointAssignementFromFiles(gtassignfile)

    gtlines  = packages.processing.removeUnassignedPrimitives(gtlines, gtassign)
    gtassign = packages.processing.removeUnassignedPoint(gtlines, gtassign)

    ############################################################################
    ## Process noise
    sigma_ref = project.kernels[0].stdev()
    gtDistrib   = utils.distanceToPrimitives(cloud, gtassign,   gtlines)
    print "Ground truth sigma ", np.sqrt(np.var(gtDistrib)) / sigma_ref

for it in range(itmin, itmax):
    print "Processing iteration",it

    linesfile_it  = projectdir+'/primitives_merged_it'+str(it)+'.csv'
    assignfile_it = projectdir+'/points_primitives_it'+str(it)+'.csv'

    ################################################################################
    ## Reading input files
    lines_it  = primitive.readPrimitivesFromFile(linesfile_it)
    assign_it = packages.io.readPointAssignementFromFiles(assignfile_it)

    lines_it  = packages.processing.removeUnassignedPrimitives(lines_it, assign_it)
    assign_it = packages.processing.removeUnassignedPoint(lines_it, assign_it)

    ################################################################################
    ## Process noise

    # Compute the distance between each point and its assigned primitive
    distrib_it = utils.distanceToPrimitives(cloud, assign_it, lines_it)
    print "Estimated sigma ", np.sqrt(np.var(distrib_it)) / sigma_ref

Add a new script processing different iterations of a run and computing statistics

Response:
<REPLACE_OLD>  <REPLACE_NEW> import packages.project as project
import packages.primitive as primitive
import packages.utils as utils
import packages.processing
import packages.io
import argparse
from matplotlib import pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
from scipy.stats import norm,kstest,skewtest,kurtosistest,normaltest

compareToGt = False

itmin=0
itmax=3

################################################################################
## Command line parsing
parser = argparse.ArgumentParser(description='Collect full run statistics.')
parser.add_argument('projectdir')

args = parser.parse_args()

projectdir = args.projectdir
if projectdir[-1] == '/':
    projectdir = projectdir[:-1]

projectname  = projectdir.split('/')[-1]
cloudfile    = projectdir+'/cloud.ply'
cloud        = packages.io.readPointCloudFromPly(cloudfile)

print 'Processing project ', projectname

sigma_ref = 1.

if compareToGt:
    projectfile  = projectdir+'/gt/'+projectname+'.prj'
    gtlinesfile  = projectdir+'/gt/primitives.csv'
    gtassignfile = projectdir+'/gt/points_primitives.csv'

    project  = project.PyProject(projectfile)
    gtlines  = primitive.readPrimitivesFromFile(gtlinesfile)
    gtassign = packages.io.readPointAssignementFromFiles(gtassignfile)

    gtlines  = packages.processing.removeUnassignedPrimitives(gtlines, gtassign)
    gtassign = packages.processing.removeUnassignedPoint(gtlines, gtassign)

    ############################################################################
    ## Process noise
    sigma_ref = project.kernels[0].stdev()
    gtDistrib   = utils.distanceToPrimitives(cloud, gtassign,   gtlines)
    print "Ground truth sigma ", np.sqrt(np.var(gtDistrib)) / sigma_ref

for it in range(itmin, itmax):
    print "Processing iteration",it

    linesfile_it  = projectdir+'/primitives_merged_it'+str(it)+'.csv'
    assignfile_it = projectdir+'/points_primitives_it'+str(it)+'.csv'

    ################################################################################
    ## Reading input files
    lines_it  = primitive.readPrimitivesFromFile(linesfile_it)
    assign_it = packages.io.readPointAssignementFromFiles(assignfile_it)

    lines_it  = packages.processing.removeUnassignedPrimitives(lines_it, assign_it)
    assign_it = packages.processing.removeUnassignedPoint(lines_it, assign_it)

    ################################################################################
    ## Process noise

    # Compute the distance between each point and its assigned primitive
    distrib_it = utils.distanceToPrimitives(cloud, assign_it, lines_it)
    print "Estimated sigma ", np.sqrt(np.var(distrib_it)) / sigma_ref

 <REPLACE_END> <|endoftext|> import packages.project as project
import packages.primitive as primitive
import packages.utils as utils
import packages.processing
import packages.io
import argparse
from matplotlib import pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
from scipy.stats import norm,kstest,skewtest,kurtosistest,normaltest

compareToGt = False

itmin=0
itmax=3

################################################################################
## Command line parsing
parser = argparse.ArgumentParser(description='Collect full run statistics.')
parser.add_argument('projectdir')

args = parser.parse_args()

projectdir = args.projectdir
if projectdir[-1] == '/':
    projectdir = projectdir[:-1]

projectname  = projectdir.split('/')[-1]
cloudfile    = projectdir+'/cloud.ply'
cloud        = packages.io.readPointCloudFromPly(cloudfile)

print 'Processing project ', projectname

sigma_ref = 1.

if compareToGt:
    projectfile  = projectdir+'/gt/'+projectname+'.prj'
    gtlinesfile  = projectdir+'/gt/primitives.csv'
    gtassignfile = projectdir+'/gt/points_primitives.csv'

    project  = project.PyProject(projectfile)
    gtlines  = primitive.readPrimitivesFromFile(gtlinesfile)
    gtassign = packages.io.readPointAssignementFromFiles(gtassignfile)

    gtlines  = packages.processing.removeUnassignedPrimitives(gtlines, gtassign)
    gtassign = packages.processing.removeUnassignedPoint(gtlines, gtassign)

    ############################################################################
    ## Process noise
    sigma_ref = project.kernels[0].stdev()
    gtDistrib   = utils.distanceToPrimitives(cloud, gtassign,   gtlines)
    print "Ground truth sigma ", np.sqrt(np.var(gtDistrib)) / sigma_ref

for it in range(itmin, itmax):
    print "Processing iteration",it

    linesfile_it  = projectdir+'/primitives_merged_it'+str(it)+'.csv'
    assignfile_it = projectdir+'/points_primitives_it'+str(it)+'.csv'

    ################################################################################
    ## Reading input files
    lines_it  = primitive.readPrimitivesFromFile(linesfile_it)
    assign_it = packages.io.readPointAssignementFromFiles(assignfile_it)

    lines_it  = packages.processing.removeUnassignedPrimitives(lines_it, assign_it)
    assign_it = packages.processing.removeUnassignedPoint(lines_it, assign_it)

    ################################################################################
    ## Process noise

    # Compute the distance between each point and its assigned primitive
    distrib_it = utils.distanceToPrimitives(cloud, assign_it, lines_it)
    print "Estimated sigma ", np.sqrt(np.var(distrib_it)) / sigma_ref

Prompt: Add a new script processing different iterations of a run and computing statistics