"""
raven.contrib.celery
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

try:
    from celery.task import task
except ImportError:
    from celery.decorators import task
from celery.signals import task_failure
from raven.base import Client

class CeleryMixin(object):
    def send_encoded(self, message):
        "Errors through celery"
        self.send_raw.delay(message)

    @task(routing_key='sentry')
    def send_raw(self, message):
        return super(CeleryMixin, self).send_encoded(message)

class CeleryClient(CeleryMixin, Client):
    pass

def register_signal(client):
    @task_failure.connect(weak=False)
    def process_failure_signal(sender, task_id, exception, args, kwargs,
                               traceback, einfo, **kw):
        client.captureException(
            exc_info=einfo.exc_info,
            extra={
                'task_id': task_id,
                'task': sender,
                'args': args,
                'kwargs': kwargs,
            })

Response:
<INSERT> @task_failure.connect(weak=False)
    <INSERT_END> <REPLACE_OLD> process_failure_signal(exception, <REPLACE_NEW> process_failure_signal(sender, task_id, exception, args, kwargs,
                               <REPLACE_END> <DELETE> sender, task_id,
                               signal, args, kwargs, <DELETE_END> <DELETE> exc_info = (type(exception), exception, traceback)
        <DELETE_END> <REPLACE_OLD> exc_info=exc_info,
 <REPLACE_NEW> exc_info=einfo.exc_info,
 <REPLACE_END> <REPLACE_OLD> 'sender': <REPLACE_NEW> 'task': <REPLACE_END> <REPLACE_OLD> })
    task_failure.connect(process_failure_signal)
 <REPLACE_NEW> })

 <REPLACE_END> <|endoftext|> """
raven.contrib.celery
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

try:
    from celery.task import task
except ImportError:
    from celery.decorators import task
from celery.signals import task_failure
from raven.base import Client

class CeleryMixin(object):
    def send_encoded(self, message):
        "Errors through celery"
        self.send_raw.delay(message)

    @task(routing_key='sentry')
    def send_raw(self, message):
        return super(CeleryMixin, self).send_encoded(message)

class CeleryClient(CeleryMixin, Client):
    pass

def register_signal(client):
    @task_failure.connect(weak=False)
    def process_failure_signal(sender, task_id, exception, args, kwargs,
                               traceback, einfo, **kw):
        client.captureException(
            exc_info=einfo.exc_info,
            extra={
                'task_id': task_id,
                'task': sender,
                'args': args,
                'kwargs': kwargs,
            })

Prompt:
Fix celery task_failure signal definition

"""
raven.contrib.celery
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

try:
    from celery.task import task
except ImportError:
    from celery.decorators import task
from celery.signals import task_failure
from raven.base import Client

class CeleryMixin(object):
    def send_encoded(self, message):
        "Errors through celery"
        self.send_raw.delay(message)

    @task(routing_key='sentry')
    def send_raw(self, message):
        return super(CeleryMixin, self).send_encoded(message)

class CeleryClient(CeleryMixin, Client):
    pass

def register_signal(client):
    def process_failure_signal(exception, traceback, sender, task_id,
                               signal, args, kwargs, einfo, **kw):
        exc_info = (type(exception), exception, traceback)
        client.captureException(
            exc_info=exc_info,
            extra={
                'task_id': task_id,
                'sender': sender,
                'args': args,
                'kwargs': kwargs,
            })
    task_failure.connect(process_failure_signal)


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

from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt

try:
    from django.http import StreamingHttpResponse as HttpResponse
except ImportError:
    from django.http import HttpResponse

from django.utils.decorators import method_decorator
from sse import Sse

class BaseSseView(View):
    """
    This is a base class for sse streaming.
    """

    def get_last_id(self):
        if "HTTP_LAST_EVENT_ID" in self.request.META:
            return self.request.META['HTTP_LAST_EVENT_ID']
        return None

    def _iterator(self):
        for subiterator in self.iterator():
            for bufferitem in self.sse:
                yield bufferitem

    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        self.sse = Sse()

        self.request = request
        self.args = args
        self.kwargs = kwargs

        response = HttpResponse(self._iterator(), content_type="text/event-stream")
        response['Cache-Control'] = 'no-cache'
        response['Software'] = 'django-sse'
        return response

    def iterator(self):
        """
        This is a source of stream.
        Must be use sentence ``yield`` for flush
        content fon sse object to the client.

        Example:

        def iterator(self):
            counter = 0
            while True:
                self.sse.add_message('foo', 'bar')
                self.sse.add_message('bar', 'foo')
                yield

        """
        raise NotImplementedError

Response:
<REPLACE_OLD> csrf_exempt
from django.http import HttpResponse

try:
 <REPLACE_NEW> csrf_exempt

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

from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt

try:
    from django.http import StreamingHttpResponse as HttpResponse
except ImportError:
    from django.http import HttpResponse

from django.utils.decorators import method_decorator
from sse import Sse

class BaseSseView(View):
    """
    This is a base class for sse streaming.
    """

    def get_last_id(self):
        if "HTTP_LAST_EVENT_ID" in self.request.META:
            return self.request.META['HTTP_LAST_EVENT_ID']
        return None

    def _iterator(self):
        for subiterator in self.iterator():
            for bufferitem in self.sse:
                yield bufferitem

    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        self.sse = Sse()

        self.request = request
        self.args = args
        self.kwargs = kwargs

        response = HttpResponse(self._iterator(), content_type="text/event-stream")
        response['Cache-Control'] = 'no-cache'
        response['Software'] = 'django-sse'
        return response

    def iterator(self):
        """
        This is a source of stream.
        Must be use sentence ``yield`` for flush
        content fon sse object to the client.

        Example:

        def iterator(self):
            counter = 0
            while True:
                self.sse.add_message('foo', 'bar')
                self.sse.add_message('bar', 'foo')
                yield

        """
        raise NotImplementedError

Prompt:
Remove duplicate import. (Thanks to MechanisM)

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

from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse

try:
    from django.http import StreamingHttpResponse as HttpResponse
except ImportError:
    from django.http import HttpResponse

from django.utils.decorators import method_decorator
from sse import Sse

class BaseSseView(View):
    """
    This is a base class for sse streaming.
    """

    def get_last_id(self):
        if "HTTP_LAST_EVENT_ID" in self.request.META:
            return self.request.META['HTTP_LAST_EVENT_ID']
        return None

    def _iterator(self):
        for subiterator in self.iterator():
            for bufferitem in self.sse:
                yield bufferitem

    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        self.sse = Sse()

        self.request = request
        self.args = args
        self.kwargs = kwargs

        response = HttpResponse(self._iterator(), content_type="text/event-stream")
        response['Cache-Control'] = 'no-cache'
        response['Software'] = 'django-sse'
        return response

    def iterator(self):
        """
        This is a source of stream.
        Must be use sentence ``yield`` for flush
        content fon sse object to the client.

        Example:

        def iterator(self):
            counter = 0
            while True:
                self.sse.add_message('foo', 'bar')
                self.sse.add_message('bar', 'foo')
                yield

        """
        raise NotImplementedError


# EXO Convesion Script
# Using specification v1.01
# J.C. Loach (2013)

# Textual replacements
remove = {r"\centering":"", r"newline":"", r"tabular":""};

# Main loop through data file
with open("exo_data.txt") as f_in:
  for line in f_in:
    for i, j in remove.iteritems():
      line = line.replace(i,j)
    line = line.split("&")
    line = [i.strip() for i in line]
    with open("EXO_" + line[0].zfill(3) + "_v1.01.json", 'w') as f_out:
      f_out.write("{\n")
      f_out.write("\n")
      f_out.write("  \"type\":                   \"measurement\",\n")
      f_out.write("\n")
      f_out.write("  \"grouping\":               \"EXO(2008)\",\n")
      f_out.write("\n")

      # Sample

      f_out.write("  \"sample\": {\n")
      f_out.write("    \"m_name\":                 \"" + line[1] + "\",\n")
      f_out.write("    \"m_description\":          \"" + line[1] + "\",\n")
      f_out.write("    \"m_id\":                   \"Table 3 Measurement " + line[0] + "\",\n")
      f_out.write("    \"m_source\":               \"\",\n")
      f_out.write("    \"m_owner\": {\n")
      f_out.write("      \"name\":                   \"\",\n")
      f_out.write("      \"contact\":                \"\"\n")
      f_out.write("    }\n")
      f_out.write("  },\n")
      f_out.write("\n")

      # Measurement

        # ...

      # Data source

        # ...

      f_out.write("}\n")

Add tool for converting EXO data from latex to JSON

Response:
<REPLACE_OLD>  <REPLACE_NEW>
# EXO Convesion Script
# Using specification v1.01
# J.C. Loach (2013)

# Textual replacements
remove = {r"\centering":"", r"newline":"", r"tabular":""};

# Main loop through data file
with open("exo_data.txt") as f_in:
  for line in f_in:
    for i, j in remove.iteritems():
      line = line.replace(i,j)
    line = line.split("&")
    line = [i.strip() for i in line]
    with open("EXO_" + line[0].zfill(3) + "_v1.01.json", 'w') as f_out:
      f_out.write("{\n")
      f_out.write("\n")
      f_out.write("  \"type\":                   \"measurement\",\n")
      f_out.write("\n")
      f_out.write("  \"grouping\":               \"EXO(2008)\",\n")
      f_out.write("\n")

      # Sample

      f_out.write("  \"sample\": {\n")
      f_out.write("    \"m_name\":                 \"" + line[1] + "\",\n")
      f_out.write("    \"m_description\":          \"" + line[1] + "\",\n")
      f_out.write("    \"m_id\":                   \"Table 3 Measurement " + line[0] + "\",\n")
      f_out.write("    \"m_source\":               \"\",\n")
      f_out.write("    \"m_owner\": {\n")
      f_out.write("      \"name\":                   \"\",\n")
      f_out.write("      \"contact\":                \"\"\n")
      f_out.write("    }\n")
      f_out.write("  },\n")
      f_out.write("\n")

      # Measurement

        # ...

      # Data source

        # ...

      f_out.write("}\n")

 <REPLACE_END> <|endoftext|>
# EXO Convesion Script
# Using specification v1.01
# J.C. Loach (2013)

# Textual replacements
remove = {r"\centering":"", r"newline":"", r"tabular":""};

# Main loop through data file
with open("exo_data.txt") as f_in:
  for line in f_in:
    for i, j in remove.iteritems():
      line = line.replace(i,j)
    line = line.split("&")
    line = [i.strip() for i in line]
    with open("EXO_" + line[0].zfill(3) + "_v1.01.json", 'w') as f_out:
      f_out.write("{\n")
      f_out.write("\n")
      f_out.write("  \"type\":                   \"measurement\",\n")
      f_out.write("\n")
      f_out.write("  \"grouping\":               \"EXO(2008)\",\n")
      f_out.write("\n")

      # Sample

      f_out.write("  \"sample\": {\n")
      f_out.write("    \"m_name\":                 \"" + line[1] + "\",\n")
      f_out.write("    \"m_description\":          \"" + line[1] + "\",\n")
      f_out.write("    \"m_id\":                   \"Table 3 Measurement " + line[0] + "\",\n")
      f_out.write("    \"m_source\":               \"\",\n")
      f_out.write("    \"m_owner\": {\n")
      f_out.write("      \"name\":                   \"\",\n")
      f_out.write("      \"contact\":                \"\"\n")
      f_out.write("    }\n")
      f_out.write("  },\n")
      f_out.write("\n")

      # Measurement

        # ...

      # Data source

        # ...

      f_out.write("}\n")

Prompt: Add tool for converting EXO data from latex to JSON


import utils
from os import environ
import os.path

MCDIR = environ.get("MCDIR") or '/mcfs/data/materialscommons'

def for_uid(uidstr):
    pieces = uidstr.split('-')
    path = os.path.join(MCDIR, pieces[1][0:2], pieces[1][2:4])
    utils.mkdirp(path)
    return path

Response:
<REPLACE_OLD> '/mcfs/data'

def <REPLACE_NEW> '/mcfs/data/materialscommons'

def <REPLACE_END> <|endoftext|> import utils
from os import environ
import os.path

MCDIR = environ.get("MCDIR") or '/mcfs/data/materialscommons'

def for_uid(uidstr):
    pieces = uidstr.split('-')
    path = os.path.join(MCDIR, pieces[1][0:2], pieces[1][2:4])
    utils.mkdirp(path)
    return path

Prompt:
Change directory where data is written to.

import utils
from os import environ
import os.path

MCDIR = environ.get("MCDIR") or '/mcfs/data'

def for_uid(uidstr):
    pieces = uidstr.split('-')
    path = os.path.join(MCDIR, pieces[1][0:2], pieces[1][2:4])
    utils.mkdirp(path)
    return path


# Copyright (c) 2012 - 2015 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.

from __future__ import print_function

import pytest

from .. import jenkins_api
from .framework import api_select
from .cfg import ApiType

@pytest.mark.not_apis(ApiType.MOCK, ApiType.SCRIPT)
def test_api_class_repr_job(api_type):
    api = api_select.api(__file__, api_type, login=True)
    job = jenkins_api.ApiJob(api, {}, 'my-job')

    jrd = eval(repr(job))
    assert jrd == {'name': 'my-job', 'dct': {}}

    invocation = jenkins_api.Invocation(job, "http://dummy", 'hello')
    assert repr(invocation) == "Invocation: 'http://dummy' None None"

Test jenkis_api ApiJob and Invocation classes __repr__ methods

Response:
<INSERT> # Copyright (c) 2012 - 2015 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.

from __future__ import print_function

import pytest

from .. import jenkins_api
from .framework import api_select
from .cfg import ApiType

@pytest.mark.not_apis(ApiType.MOCK, ApiType.SCRIPT)
def test_api_class_repr_job(api_type):
 <INSERT_END> <INSERT>   api = api_select.api(__file__, api_type, login=True)
    job = jenkins_api.ApiJob(api, {}, 'my-job')

    jrd = eval(repr(job))
    assert jrd == {'name': 'my-job', 'dct': {}}

    invocation = jenkins_api.Invocation(job, "http://dummy", 'hello')
    assert repr(invocation) == "Invocation: 'http://dummy' None None"

 <INSERT_END> <|endoftext|> # Copyright (c) 2012 - 2015 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.

from __future__ import print_function

import pytest

from .. import jenkins_api
from .framework import api_select
from .cfg import ApiType

@pytest.mark.not_apis(ApiType.MOCK, ApiType.SCRIPT)
def test_api_class_repr_job(api_type):
    api = api_select.api(__file__, api_type, login=True)
    job = jenkins_api.ApiJob(api, {}, 'my-job')

    jrd = eval(repr(job))
    assert jrd == {'name': 'my-job', 'dct': {}}

    invocation = jenkins_api.Invocation(job, "http://dummy", 'hello')
    assert repr(invocation) == "Invocation: 'http://dummy' None None"

Prompt: Test jenkis_api ApiJob and Invocation classes __repr__ methods


# 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.

from st2common.exceptions import StackStormBaseException

class StackStormDBObjectNotFoundError(StackStormBaseException):
    pass

class StackStormDBObjectMalformedError(StackStormBaseException):
    pass

class StackStormDBObjectConflictError(StackStormBaseException):
    """
    Exception that captures a DB object conflict error.
    """
    def __init__(self, message, conflict_id):
        super(StackStormDBObjectConflictError, self).__init__(message)
        self.conflict_id = conflict_id

Response:
<REPLACE_OLD> pass
 <REPLACE_NEW> pass

class StackStormDBObjectConflictError(StackStormBaseException):
    """
    Exception that captures a DB object conflict error.
    """
    def __init__(self, message, conflict_id):
        super(StackStormDBObjectConflictError, self).__init__(message)
        self.conflict_id = conflict_id
 <REPLACE_END> <|endoftext|> # 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.

from st2common.exceptions import StackStormBaseException

class StackStormDBObjectNotFoundError(StackStormBaseException):
    pass

class StackStormDBObjectMalformedError(StackStormBaseException):
    pass

class StackStormDBObjectConflictError(StackStormBaseException):
    """
    Exception that captures a DB object conflict error.
    """
    def __init__(self, message, conflict_id):
        super(StackStormDBObjectConflictError, self).__init__(message)
        self.conflict_id = conflict_id

Prompt:
Add a special exception for capturing object conflicts.

# 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.

from st2common.exceptions import StackStormBaseException

class StackStormDBObjectNotFoundError(StackStormBaseException):
    pass

class StackStormDBObjectMalformedError(StackStormBaseException):
    pass


"""Custom topology example
s1---s2
|   /
|  /
| /
s3

Consist of three fixed core switches, and each core switches will connect to m hosts through n switches.

"""

from mininet.topo import Topo
from optparse import OptionParser

class MyTopo( Topo ):
    "Simple topology example."

#    def __init__( self ):
    def build( self, m=1, n=1 ):
        "Create custom topo."

        # Initialize topology
        #Topo.__init__( self )

        switch_index = 1
        host_index = 1
#        core = ['space']
        switch = ['space']
        host = ['space']

#        parser = OptionParser()
#        parser.add_option("-m", action="store", type="int", dest="m")
#        parser.add_option("-n", action="store", type="int", dest="n")
#        (options, args) = parser,parse_args()
#        print options.m
#        print options.n
        #m = 2
        #n = 2
        CORE_NUMBER = 3

        for i in range(1, CORE_NUMBER+1):
            switch.append(self.addSwitch( 's'+str(switch_index) ))
            switch_index = switch_index + 1
        for k in range(1, CORE_NUMBER+1):
            if (k==CORE_NUMBER):
                self.addLink( switch[k], switch[1] )
            else:
                self.addLink( switch[k], switch[k+1] )

            for i in range(1,m+1):
                for j in range(1,n+1):
                    switch.append(self.addSwitch( 's'+str(switch_index) ))
                    if (j==1):
                        self.addLink( switch[k],switch[switch_index] )
                    else:
                        self.addLink( switch[switch_index-1],switch[switch_index])
                    switch_index = switch_index + 1
                host.append(self.addHost( 'h'+str(host_index)))
                self.addLink( host[host_index], switch[switch_index-1])
                host_index = host_index + 1
        print "total_switches=%u"%(switch_index-1+3)
        print "total_hosts=%u"%(host_index-1)
        print "total_nodes=%u"%(switch_index-1+3+host_index-1)

topos = { 'mytopo': ( lambda m,n:MyTopo(m, n) ) }

Add a custom topology example

Add a custom topology example

Response:
<REPLACE_OLD>  <REPLACE_NEW> """Custom topology example
s1---s2
|   /
|  /
| /
s3

Consist of three fixed core switches, and each core switches will connect to m hosts through n switches.

"""

from mininet.topo import Topo
from optparse import OptionParser

class MyTopo( Topo ):
    "Simple topology example."

#    def __init__( self ):
    def build( self, m=1, n=1 ):
        "Create custom topo."

        # Initialize topology
        #Topo.__init__( self )

        switch_index = 1
        host_index = 1
#        core = ['space']
        switch = ['space']
        host = ['space']

#        parser = OptionParser()
#        parser.add_option("-m", action="store", type="int", dest="m")
#        parser.add_option("-n", action="store", type="int", dest="n")
#        (options, args) = parser,parse_args()
#        print options.m
#        print options.n
        #m = 2
        #n = 2
        CORE_NUMBER = 3

        for i in range(1, CORE_NUMBER+1):
            switch.append(self.addSwitch( 's'+str(switch_index) ))
            switch_index = switch_index + 1
        for k in range(1, CORE_NUMBER+1):
            if (k==CORE_NUMBER):
                self.addLink( switch[k], switch[1] )
            else:
                self.addLink( switch[k], switch[k+1] )

            for i in range(1,m+1):
                for j in range(1,n+1):
                    switch.append(self.addSwitch( 's'+str(switch_index) ))
                    if (j==1):
                        self.addLink( switch[k],switch[switch_index] )
                    else:
                        self.addLink( switch[switch_index-1],switch[switch_index])
                    switch_index = switch_index + 1
                host.append(self.addHost( 'h'+str(host_index)))
                self.addLink( host[host_index], switch[switch_index-1])
                host_index = host_index + 1
        print "total_switches=%u"%(switch_index-1+3)
        print "total_hosts=%u"%(host_index-1)
        print "total_nodes=%u"%(switch_index-1+3+host_index-1)

topos = { 'mytopo': ( lambda m,n:MyTopo(m, n) ) }
 <REPLACE_END> <|endoftext|> """Custom topology example
s1---s2
|   /
|  /
| /
s3

Consist of three fixed core switches, and each core switches will connect to m hosts through n switches.

"""

from mininet.topo import Topo
from optparse import OptionParser

class MyTopo( Topo ):
    "Simple topology example."

#    def __init__( self ):
    def build( self, m=1, n=1 ):
        "Create custom topo."

        # Initialize topology
        #Topo.__init__( self )

        switch_index = 1
        host_index = 1
#        core = ['space']
        switch = ['space']
        host = ['space']

#        parser = OptionParser()
#        parser.add_option("-m", action="store", type="int", dest="m")
#        parser.add_option("-n", action="store", type="int", dest="n")
#        (options, args) = parser,parse_args()
#        print options.m
#        print options.n
        #m = 2
        #n = 2
        CORE_NUMBER = 3

        for i in range(1, CORE_NUMBER+1):
            switch.append(self.addSwitch( 's'+str(switch_index) ))
            switch_index = switch_index + 1
        for k in range(1, CORE_NUMBER+1):
            if (k==CORE_NUMBER):
                self.addLink( switch[k], switch[1] )
            else:
                self.addLink( switch[k], switch[k+1] )

            for i in range(1,m+1):
                for j in range(1,n+1):
                    switch.append(self.addSwitch( 's'+str(switch_index) ))
                    if (j==1):
                        self.addLink( switch[k],switch[switch_index] )
                    else:
                        self.addLink( switch[switch_index-1],switch[switch_index])
                    switch_index = switch_index + 1
                host.append(self.addHost( 'h'+str(host_index)))
                self.addLink( host[host_index], switch[switch_index-1])
                host_index = host_index + 1
        print "total_switches=%u"%(switch_index-1+3)
        print "total_hosts=%u"%(host_index-1)
        print "total_nodes=%u"%(switch_index-1+3+host_index-1)

topos = { 'mytopo': ( lambda m,n:MyTopo(m, n) ) }

Prompt: Add a custom topology example


# -*- encoding: utf-8 -*-
from django import template

register = template.Library()

@register.filter
def scored_by_user(application, user):
    return application.is_scored_by_user(user)

@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '▼'.format(name)
    else:
        return '▲'.format(name)

Response:
<REPLACE_OLD> template

from applications.models import Score

register <REPLACE_NEW> template

register <REPLACE_END> <REPLACE_OLD> template.Library()

@register.filter
def scored_by_user(value, arg):
    try:
        score = Score.objects.get(application=value, user=arg)
     <REPLACE_NEW> template.Library()

@register.filter
def scored_by_user(application, user):
 <REPLACE_END> <REPLACE_OLD> True if score.score else False
    except Score.DoesNotExist:
        return False

@register.simple_tag
def <REPLACE_NEW> application.is_scored_by_user(user)

@register.simple_tag
def <REPLACE_END> <|endoftext|> # -*- encoding: utf-8 -*-
from django import template

register = template.Library()

@register.filter
def scored_by_user(application, user):
    return application.is_scored_by_user(user)

@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '<a href="?order={}">▼</a>'.format(name)
    else:
        return '<a href="?order=-{}">▲</a>'.format(name)

Prompt:
Make scored_by_user filter call model method

Ref #113

# -*- encoding: utf-8 -*-
from django import template

from applications.models import Score

register = template.Library()

@register.filter
def scored_by_user(value, arg):
    try:
        score = Score.objects.get(application=value, user=arg)
        return True if score.score else False
    except Score.DoesNotExist:
        return False

@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '▼'.format(name)
    else:
        return '▲'.format(name)


import multiprocessing
preload_app = True
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
keepalive = 60
timeout = 900
max_requests = 120
# defaults to 30 sec, setting to 5 minutes to fight `GreenletExit`s
graceful_timeout = 5*60
# cryptically, setting forwarded_allow_ips (to the ip of the hqproxy0)
# gets gunicorn to set https on redirects when appropriate. See:
# http://docs.gunicorn.org/en/latest/configure.html#secure-scheme-headers
# http://docs.gunicorn.org/en/latest/configure.html#forwarded-allow-ips
forwarded_allow_ips = '10.176.162.109'

def post_fork(server, worker):
    # hacky way to address gunicorn gevent requests hitting django too early before urls are loaded
    # see: https://github.com/benoitc/gunicorn/issues/527#issuecomment-19601046
    from django.core.urlresolvers import resolve
    resolve('/')

Response:
<REPLACE_OLD> 600
# <REPLACE_NEW> 120
# <REPLACE_END> <|endoftext|> import multiprocessing
preload_app = True
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
keepalive = 60
timeout = 900
max_requests = 120
# defaults to 30 sec, setting to 5 minutes to fight `GreenletExit`s
graceful_timeout = 5*60
# cryptically, setting forwarded_allow_ips (to the ip of the hqproxy0)
# gets gunicorn to set https on redirects when appropriate. See:
# http://docs.gunicorn.org/en/latest/configure.html#secure-scheme-headers
# http://docs.gunicorn.org/en/latest/configure.html#forwarded-allow-ips
forwarded_allow_ips = '10.176.162.109'

def post_fork(server, worker):
    # hacky way to address gunicorn gevent requests hitting django too early before urls are loaded
    # see: https://github.com/benoitc/gunicorn/issues/527#issuecomment-19601046
    from django.core.urlresolvers import resolve
    resolve('/')

Prompt:
Revert "bump gunicorn max_requests to 600"

This reverts commit ffbfe0d6f2ca83346693a788b14562eb332d0cbd.

import multiprocessing
preload_app = True
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
keepalive = 60
timeout = 900
max_requests = 600
# defaults to 30 sec, setting to 5 minutes to fight `GreenletExit`s
graceful_timeout = 5*60
# cryptically, setting forwarded_allow_ips (to the ip of the hqproxy0)
# gets gunicorn to set https on redirects when appropriate. See:
# http://docs.gunicorn.org/en/latest/configure.html#secure-scheme-headers
# http://docs.gunicorn.org/en/latest/configure.html#forwarded-allow-ips
forwarded_allow_ips = '10.176.162.109'

def post_fork(server, worker):
    # hacky way to address gunicorn gevent requests hitting django too early before urls are loaded
    # see: https://github.com/benoitc/gunicorn/issues/527#issuecomment-19601046
    from django.core.urlresolvers import resolve
    resolve('/')


import os

mylang = 'test'
family = 'wikipedia'

custom_path = os.path.expanduser('~/user-config.py')
if os.path.exists(custom_path):
    with open(custom_path, 'r') as f:
        exec(compile(f.read(), custom_path, 'exec'), globals())

# Things that should be non-easily-overridable
usernames['*']['*'] = os.environ['JPY_USER']

Response:
<REPLACE_OLD> 'wikipedia'

# Not defining any extra variables here at all since that causes pywikibot
# to issue a warning about potential misspellings
if os.path.exists(os.path.expanduser('~/user-config.py')):
 <REPLACE_NEW> 'wikipedia'

custom_path = os.path.expanduser('~/user-config.py')
if os.path.exists(custom_path):
 <REPLACE_END> <REPLACE_OLD> open(os.path.expanduser('~/user-config.py'), <REPLACE_NEW> open(custom_path, <REPLACE_END> <REPLACE_OLD> exec(
             compile(f.read(), os.path.expanduser('~/user-config.py'), 'exec'),
             <REPLACE_NEW> exec(compile(f.read(), custom_path, 'exec'), <REPLACE_END> <|endoftext|> import os

mylang = 'test'
family = 'wikipedia'

custom_path = os.path.expanduser('~/user-config.py')
if os.path.exists(custom_path):
    with open(custom_path, 'r') as f:
        exec(compile(f.read(), custom_path, 'exec'), globals())

# Things that should be non-easily-overridable
usernames['*']['*'] = os.environ['JPY_USER']

Prompt:
Revert "Do not introduce extra variables"

Since the 'f' is considered an extra variable and introduces
a warning anyway :( Let's fix this the right way

This reverts commit a03de68fb772d859098327d0e54a219fe4507072.

import os

mylang = 'test'
family = 'wikipedia'

# Not defining any extra variables here at all since that causes pywikibot
# to issue a warning about potential misspellings
if os.path.exists(os.path.expanduser('~/user-config.py')):
    with open(os.path.expanduser('~/user-config.py'), 'r') as f:
        exec(
             compile(f.read(), os.path.expanduser('~/user-config.py'), 'exec'),
             globals())

# Things that should be non-easily-overridable
usernames['*']['*'] = os.environ['JPY_USER']


import numpy

from pysc2.agents import base_agent
from pysc2.lib import actions
from pysc2.lib import features

_PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index
_PLAYER_FRIENDLY = 1
_PLAYER_NEUTRAL = 3  # beacon/minerals
_PLAYER_HOSTILE = 4
_NO_OP = actions.FUNCTIONS.no_op.id
_MOVE_SCREEN = actions.FUNCTIONS.Move_screen.id
_ATTACK_SCREEN = actions.FUNCTIONS.Attack_screen.id
_SELECT_ARMY = actions.FUNCTIONS.select_army.id
_SELECT_POINT = actions.FUNCTIONS.select_point.id
_NOT_QUEUED = [0]
_SELECT_ALL = [0]
_NEW_SELECTION = [0]

class CollectMineralShards(base_agent.BaseAgent):
    """An agent specifically for solving the CollectMineralShards map."""

    def step(self, obs):
        super(CollectMineralShards, self).step(obs)
        player_relative = obs.observation["screen"][_PLAYER_RELATIVE]
        if _MOVE_SCREEN in obs.observation["available_actions"]:
            neutral_y, neutral_x = (player_relative == _PLAYER_NEUTRAL).nonzero()
            player_y, player_x = (player_relative == _PLAYER_FRIENDLY).nonzero()
            if not neutral_y.any() or not player_y.any():
                return actions.FunctionCall(_NO_OP, [])
            player = [int(player_x.mean()), int(player_y.mean())]
            closest, min_dist = None, None
            for p in zip(neutral_x, neutral_y):
                dist = numpy.linalg.norm(numpy.array(player) - numpy.array(p))
                if not min_dist or dist < min_dist:
                    closest, min_dist = p, dist
            return actions.FunctionCall(_MOVE_SCREEN, [_NOT_QUEUED, closest])
        else:
            player_y, player_x = (player_relative == _PLAYER_FRIENDLY).nonzero()
            return actions.FunctionCall(_SELECT_POINT, [_NEW_SELECTION, [player_x[0], player_y[0]]])

Create a new scripted agent: copy from the deepmind one but do not select the two marins, only one

Response:
<REPLACE_OLD>  <REPLACE_NEW> import numpy

from pysc2.agents import base_agent
from pysc2.lib import actions
from pysc2.lib import features

_PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index
_PLAYER_FRIENDLY = 1
_PLAYER_NEUTRAL = 3  # beacon/minerals
_PLAYER_HOSTILE = 4
_NO_OP = actions.FUNCTIONS.no_op.id
_MOVE_SCREEN = actions.FUNCTIONS.Move_screen.id
_ATTACK_SCREEN = actions.FUNCTIONS.Attack_screen.id
_SELECT_ARMY = actions.FUNCTIONS.select_army.id
_SELECT_POINT = actions.FUNCTIONS.select_point.id
_NOT_QUEUED = [0]
_SELECT_ALL = [0]
_NEW_SELECTION = [0]

class CollectMineralShards(base_agent.BaseAgent):
    """An agent specifically for solving the CollectMineralShards map."""

    def step(self, obs):
        super(CollectMineralShards, self).step(obs)
        player_relative = obs.observation["screen"][_PLAYER_RELATIVE]
        if _MOVE_SCREEN in obs.observation["available_actions"]:
            neutral_y, neutral_x = (player_relative == _PLAYER_NEUTRAL).nonzero()
            player_y, player_x = (player_relative == _PLAYER_FRIENDLY).nonzero()
            if not neutral_y.any() or not player_y.any():
                return actions.FunctionCall(_NO_OP, [])
            player = [int(player_x.mean()), int(player_y.mean())]
            closest, min_dist = None, None
            for p in zip(neutral_x, neutral_y):
                dist = numpy.linalg.norm(numpy.array(player) - numpy.array(p))
                if not min_dist or dist < min_dist:
                    closest, min_dist = p, dist
            return actions.FunctionCall(_MOVE_SCREEN, [_NOT_QUEUED, closest])
        else:
            player_y, player_x = (player_relative == _PLAYER_FRIENDLY).nonzero()
            return actions.FunctionCall(_SELECT_POINT, [_NEW_SELECTION, [player_x[0], player_y[0]]])
 <REPLACE_END> <|endoftext|> import numpy

from pysc2.agents import base_agent
from pysc2.lib import actions
from pysc2.lib import features

_PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index
_PLAYER_FRIENDLY = 1
_PLAYER_NEUTRAL = 3  # beacon/minerals
_PLAYER_HOSTILE = 4
_NO_OP = actions.FUNCTIONS.no_op.id
_MOVE_SCREEN = actions.FUNCTIONS.Move_screen.id
_ATTACK_SCREEN = actions.FUNCTIONS.Attack_screen.id
_SELECT_ARMY = actions.FUNCTIONS.select_army.id
_SELECT_POINT = actions.FUNCTIONS.select_point.id
_NOT_QUEUED = [0]
_SELECT_ALL = [0]
_NEW_SELECTION = [0]

class CollectMineralShards(base_agent.BaseAgent):
    """An agent specifically for solving the CollectMineralShards map."""

    def step(self, obs):
        super(CollectMineralShards, self).step(obs)
        player_relative = obs.observation["screen"][_PLAYER_RELATIVE]
        if _MOVE_SCREEN in obs.observation["available_actions"]:
            neutral_y, neutral_x = (player_relative == _PLAYER_NEUTRAL).nonzero()
            player_y, player_x = (player_relative == _PLAYER_FRIENDLY).nonzero()
            if not neutral_y.any() or not player_y.any():
                return actions.FunctionCall(_NO_OP, [])
            player = [int(player_x.mean()), int(player_y.mean())]
            closest, min_dist = None, None
            for p in zip(neutral_x, neutral_y):
                dist = numpy.linalg.norm(numpy.array(player) - numpy.array(p))
                if not min_dist or dist < min_dist:
                    closest, min_dist = p, dist
            return actions.FunctionCall(_MOVE_SCREEN, [_NOT_QUEUED, closest])
        else:
            player_y, player_x = (player_relative == _PLAYER_FRIENDLY).nonzero()
            return actions.FunctionCall(_SELECT_POINT, [_NEW_SELECTION, [player_x[0], player_y[0]]])

Prompt: Create a new scripted agent: copy from the deepmind one but do not select the two marins, only one


from dtest import Tester
from tools import *
from assertions import *

import os, sys, time
from ccmlib.cluster import Cluster

class TestRangeGhosts(Tester):

    def ghosts_test(self):
        """ Check range ghost are correctly removed by the system """
        cluster = self.cluster
        cluster.populate(1).start()
        [node1] = cluster.nodelist()

        time.sleep(.5)
        cursor = self.cql_connection(node1).cursor()
        self.create_ks(cursor, 'ks', 1)
        self.create_cf(cursor, 'cf', gc_grace=0)

        rows = 1000

        for i in xrange(0, rows):
            cursor.execute("UPDATE cf SET c = 'value' WHERE key = k%i" % i)

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows, res

        node1.flush()

        for i in xrange(0, rows/2):
            cursor.execute("DELETE FROM cf WHERE key = k%i" % i)

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows, res

        node1.flush()
        time.sleep(1) # make sure tombstones are collected
        node1.compact()

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows/2, res

Add test to check range ghost are removed

Response:
<REPLACE_OLD>  <REPLACE_NEW> from dtest import Tester
from tools import *
from assertions import *

import os, sys, time
from ccmlib.cluster import Cluster

class TestRangeGhosts(Tester):

    def ghosts_test(self):
        """ Check range ghost are correctly removed by the system """
        cluster = self.cluster
        cluster.populate(1).start()
        [node1] = cluster.nodelist()

        time.sleep(.5)
        cursor = self.cql_connection(node1).cursor()
        self.create_ks(cursor, 'ks', 1)
        self.create_cf(cursor, 'cf', gc_grace=0)

        rows = 1000

        for i in xrange(0, rows):
            cursor.execute("UPDATE cf SET c = 'value' WHERE key = k%i" % i)

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows, res

        node1.flush()

        for i in xrange(0, rows/2):
            cursor.execute("DELETE FROM cf WHERE key = k%i" % i)

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows, res

        node1.flush()
        time.sleep(1) # make sure tombstones are collected
        node1.compact()

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows/2, res
 <REPLACE_END> <|endoftext|> from dtest import Tester
from tools import *
from assertions import *

import os, sys, time
from ccmlib.cluster import Cluster

class TestRangeGhosts(Tester):

    def ghosts_test(self):
        """ Check range ghost are correctly removed by the system """
        cluster = self.cluster
        cluster.populate(1).start()
        [node1] = cluster.nodelist()

        time.sleep(.5)
        cursor = self.cql_connection(node1).cursor()
        self.create_ks(cursor, 'ks', 1)
        self.create_cf(cursor, 'cf', gc_grace=0)

        rows = 1000

        for i in xrange(0, rows):
            cursor.execute("UPDATE cf SET c = 'value' WHERE key = k%i" % i)

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows, res

        node1.flush()

        for i in xrange(0, rows/2):
            cursor.execute("DELETE FROM cf WHERE key = k%i" % i)

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows, res

        node1.flush()
        time.sleep(1) # make sure tombstones are collected
        node1.compact()

        cursor.execute("SELECT * FROM cf LIMIT 10000")
        res = cursor.fetchall()
        assert len(res) == rows/2, res

Prompt: Add test to check range ghost are removed


import sys
import commentjson as json
import os
import argparse
import numpy as np
import copy

sys.path.append('../.')
sys.path.append('.')
from progressbar import ProgressBar

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Replicate nodes, links, divisions and exclusion sets N times, ' \
        'so that the total number of timeframes does not change',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--model', required=True, type=str, dest='model_filename',
                        help='Filename of the json model description')
    parser.add_argument('--output', required=True, type=str, dest='result_filename',
                        help='Filename of the json file that will hold the replicated model')
    parser.add_argument('--num', type=int, dest='num', default=2,
                        help='how many instances of the original model shall be present in the result file')

    args = parser.parse_args()

    print("Loading model file: " + args.model_filename)
    with open(args.model_filename, 'r') as f:
        model = json.load(f)

    segmentationHypotheses = model['segmentationHypotheses']
    # use generator expression instead of list comprehension, we only need it once!
    maxId = max((i['id'] for i in segmentationHypotheses))
    newModel = copy.deepcopy(model)

    for i in range(1, args.num):
        offset = i * (maxId + 1000000) # create random gap in IDs

        for seg in segmentationHypotheses:
            newSeg = copy.deepcopy(seg)
            newSeg['id'] = offset + newSeg['id']
            newModel['segmentationHypotheses'].append(newSeg)

        linkingHypotheses = model['linkingHypotheses']
        for link in linkingHypotheses:
            newLink = copy.deepcopy(link)
            newLink['src'] = offset + newLink['src']
            newLink['dest'] = offset + newLink['dest']
            newModel['linkingHypotheses'].append(newLink)

        if 'exclusions' in model:
            for e in model['exclusions']:
                newExclusion = [x + offset for x in e]
                newModel['exclusions'].append(newExclusion)

        if 'divisions' in model:
            for d in model['divisions']:
                newDiv = copy.deepcopy(d)
                newDiv['parent'] = offset + d['parent']
                newDiv['children'] = [offset + c for c in d['children']]
                newModel['divisions'].append(newDiv)

    with open(args.result_filename, 'w') as f:
        json.dump(newModel, f, indent=4, separators=(',', ': '))

Add script to artificially increase the size of graphs by replicating all nodes and their links

Response:
<REPLACE_OLD>  <REPLACE_NEW> import sys
import commentjson as json
import os
import argparse
import numpy as np
import copy

sys.path.append('../.')
sys.path.append('.')
from progressbar import ProgressBar

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Replicate nodes, links, divisions and exclusion sets N times, ' \
        'so that the total number of timeframes does not change',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--model', required=True, type=str, dest='model_filename',
                        help='Filename of the json model description')
    parser.add_argument('--output', required=True, type=str, dest='result_filename',
                        help='Filename of the json file that will hold the replicated model')
    parser.add_argument('--num', type=int, dest='num', default=2,
                        help='how many instances of the original model shall be present in the result file')

    args = parser.parse_args()

    print("Loading model file: " + args.model_filename)
    with open(args.model_filename, 'r') as f:
        model = json.load(f)

    segmentationHypotheses = model['segmentationHypotheses']
    # use generator expression instead of list comprehension, we only need it once!
    maxId = max((i['id'] for i in segmentationHypotheses))
    newModel = copy.deepcopy(model)

    for i in range(1, args.num):
        offset = i * (maxId + 1000000) # create random gap in IDs

        for seg in segmentationHypotheses:
            newSeg = copy.deepcopy(seg)
            newSeg['id'] = offset + newSeg['id']
            newModel['segmentationHypotheses'].append(newSeg)

        linkingHypotheses = model['linkingHypotheses']
        for link in linkingHypotheses:
            newLink = copy.deepcopy(link)
            newLink['src'] = offset + newLink['src']
            newLink['dest'] = offset + newLink['dest']
            newModel['linkingHypotheses'].append(newLink)

        if 'exclusions' in model:
            for e in model['exclusions']:
                newExclusion = [x + offset for x in e]
                newModel['exclusions'].append(newExclusion)

        if 'divisions' in model:
            for d in model['divisions']:
                newDiv = copy.deepcopy(d)
                newDiv['parent'] = offset + d['parent']
                newDiv['children'] = [offset + c for c in d['children']]
                newModel['divisions'].append(newDiv)

    with open(args.result_filename, 'w') as f:
        json.dump(newModel, f, indent=4, separators=(',', ': '))
 <REPLACE_END> <|endoftext|> import sys
import commentjson as json
import os
import argparse
import numpy as np
import copy

sys.path.append('../.')
sys.path.append('.')
from progressbar import ProgressBar

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Replicate nodes, links, divisions and exclusion sets N times, ' \
        'so that the total number of timeframes does not change',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--model', required=True, type=str, dest='model_filename',
                        help='Filename of the json model description')
    parser.add_argument('--output', required=True, type=str, dest='result_filename',
                        help='Filename of the json file that will hold the replicated model')
    parser.add_argument('--num', type=int, dest='num', default=2,
                        help='how many instances of the original model shall be present in the result file')

    args = parser.parse_args()

    print("Loading model file: " + args.model_filename)
    with open(args.model_filename, 'r') as f:
        model = json.load(f)

    segmentationHypotheses = model['segmentationHypotheses']
    # use generator expression instead of list comprehension, we only need it once!
    maxId = max((i['id'] for i in segmentationHypotheses))
    newModel = copy.deepcopy(model)

    for i in range(1, args.num):
        offset = i * (maxId + 1000000) # create random gap in IDs

        for seg in segmentationHypotheses:
            newSeg = copy.deepcopy(seg)
            newSeg['id'] = offset + newSeg['id']
            newModel['segmentationHypotheses'].append(newSeg)

        linkingHypotheses = model['linkingHypotheses']
        for link in linkingHypotheses:
            newLink = copy.deepcopy(link)
            newLink['src'] = offset + newLink['src']
            newLink['dest'] = offset + newLink['dest']
            newModel['linkingHypotheses'].append(newLink)

        if 'exclusions' in model:
            for e in model['exclusions']:
                newExclusion = [x + offset for x in e]
                newModel['exclusions'].append(newExclusion)

        if 'divisions' in model:
            for d in model['divisions']:
                newDiv = copy.deepcopy(d)
                newDiv['parent'] = offset + d['parent']
                newDiv['children'] = [offset + c for c in d['children']]
                newModel['divisions'].append(newDiv)

    with open(args.result_filename, 'w') as f:
        json.dump(newModel, f, indent=4, separators=(',', ': '))

Prompt: Add script to artificially increase the size of graphs by replicating all nodes and their links


# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.contrib import admin

class IntegrationCredentialAdmin(admin.ModelAdmin):
    search_fields = ("endpoint",)
    list_display = ("endpoint","user",)
    save_on_top = True

Response:
<REPLACE_OLD> ("user","endpoint",)
 <REPLACE_NEW> ("endpoint","user",)
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.contrib import admin

class IntegrationCredentialAdmin(admin.ModelAdmin):
    search_fields = ("endpoint",)
    list_display = ("endpoint","user",)
    save_on_top = True

Prompt:
Change field order at integration credential admin index page

# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.contrib import admin

class IntegrationCredentialAdmin(admin.ModelAdmin):
    search_fields = ("endpoint",)
    list_display = ("user","endpoint",)
    save_on_top = True


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

"""Middleware that provides high-level error handling.

It catches all exceptions from subsequent applications in WSGI pipeline
to hide internal errors from API response.
"""

import webob.dec
import webob.exc

from openstack.common.gettextutils import _LE
from openstack.common import log as logging
from openstack.common.middleware import base

LOG = logging.getLogger(__name__)

class CatchErrorsMiddleware(base.Middleware):

    @webob.dec.wsgify
    def __call__(self, req):
        try:
            response = req.get_response(self.application)
        except Exception:
            LOG.exception(_LE('An error occurred during '
                              'processing the request: %s'))
            response = webob.exc.HTTPInternalServerError()
        return response

Response:
<REPLACE_OLD> _  # noqa
from <REPLACE_NEW> _LE
from <REPLACE_END> <REPLACE_OLD> LOG.exception(_('An <REPLACE_NEW> LOG.exception(_LE('An <REPLACE_END> <INSERT>   <INSERT_END> <|endoftext|> # Copyright (c) 2013 NEC Corporation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""Middleware that provides high-level error handling.

It catches all exceptions from subsequent applications in WSGI pipeline
to hide internal errors from API response.
"""

import webob.dec
import webob.exc

from openstack.common.gettextutils import _LE
from openstack.common import log as logging
from openstack.common.middleware import base

LOG = logging.getLogger(__name__)

class CatchErrorsMiddleware(base.Middleware):

    @webob.dec.wsgify
    def __call__(self, req):
        try:
            response = req.get_response(self.application)
        except Exception:
            LOG.exception(_LE('An error occurred during '
                              'processing the request: %s'))
            response = webob.exc.HTTPInternalServerError()
        return response

Prompt:
Update oslo log messages with translation domains

Update the incubator code to use different domains for log
messages at different levels.

Update the import exceptions setting for hacking to allow
multiple functions to be imported from gettextutils on one
line.

bp log-messages-translation-domain

Change-Id: I6ce0f4a59438612ce74c46b3ee9398bef24c0c19

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

"""Middleware that provides high-level error handling.

It catches all exceptions from subsequent applications in WSGI pipeline
to hide internal errors from API response.
"""

import webob.dec
import webob.exc

from openstack.common.gettextutils import _  # noqa
from openstack.common import log as logging
from openstack.common.middleware import base

LOG = logging.getLogger(__name__)

class CatchErrorsMiddleware(base.Middleware):

    @webob.dec.wsgify
    def __call__(self, req):
        try:
            response = req.get_response(self.application)
        except Exception:
            LOG.exception(_('An error occurred during '
                            'processing the request: %s'))
            response = webob.exc.HTTPInternalServerError()
        return response


import sys
import os
sys.path.append(os.path.abspath(os.path.curdir))

from converter import gml_to_node_edge_list

if __name__ == '__main__':
    in_file = sys.argv[1]
    outfile = sys.argv[2] if len(sys.argv) > 2 else None
    res = gml_to_node_edge_list(in_file, outfile=outfile, routing=True)

Add outfile option to conversion script

Add outfile option to conversion script

Response:
<INSERT> outfile = sys.argv[2] if len(sys.argv) > 2 else None
    <INSERT_END> <INSERT> outfile=outfile, <INSERT_END> <|endoftext|> import sys
import os
sys.path.append(os.path.abspath(os.path.curdir))

from converter import gml_to_node_edge_list

if __name__ == '__main__':
    in_file = sys.argv[1]
    outfile = sys.argv[2] if len(sys.argv) > 2 else None
    res = gml_to_node_edge_list(in_file, outfile=outfile, routing=True)

Prompt:
Add outfile option to conversion script

import sys
import os
sys.path.append(os.path.abspath(os.path.curdir))

from converter import gml_to_node_edge_list

if __name__ == '__main__':
    in_file = sys.argv[1]
    res = gml_to_node_edge_list(in_file, routing=True)


import csv

class Synthesizer():

    def __init__(self):
        self.word_map = {}

        filename = "../../dictionaries/VoxForgeDict"
        for line in csv.reader(open(filename), delimiter=' ', skipinitialspace=True):
            if len(line) > 2:
                self.word_map[line[0]] = line[2:]
        print len(self.word_map)

    def string_to_phonemes(self, string):
        string = string.upper()
        string = string.replace('.','')
        string = string.replace(',','')
        words = string.split()

        result = ""
        for word in words:
            print self.word_map[word]

Add the function for parsing strings to phonemes

Response:
<INSERT> import csv

class Synthesizer():

 <INSERT_END> <INSERT>   def __init__(self):
        self.word_map = {}

        filename = "../../dictionaries/VoxForgeDict"
        for line in csv.reader(open(filename), delimiter=' ', skipinitialspace=True):
            if len(line) > 2:
                self.word_map[line[0]] = line[2:]
        print len(self.word_map)

    def string_to_phonemes(self, string):
        string = string.upper()
        string = string.replace('.','')
        string = string.replace(',','')
        words = string.split()

        result = ""
        for word in words:
            print self.word_map[word]
 <INSERT_END> <|endoftext|> import csv

class Synthesizer():

    def __init__(self):
        self.word_map = {}

        filename = "../../dictionaries/VoxForgeDict"
        for line in csv.reader(open(filename), delimiter=' ', skipinitialspace=True):
            if len(line) > 2:
                self.word_map[line[0]] = line[2:]
        print len(self.word_map)

    def string_to_phonemes(self, string):
        string = string.upper()
        string = string.replace('.','')
        string = string.replace(',','')
        words = string.split()

        result = ""
        for word in words:
            print self.word_map[word]

Prompt: Add the function for parsing strings to phonemes


from Bio import SeqIO
import logging
import unittest

from select_taxa import select_genomes_by_ids
import translate

class Test(unittest.TestCase):

    def setUp(self):
        self.longMessage = True
        logging.root.setLevel(logging.DEBUG)

    def test_translate_genomes(self):
        # Select genomes
        genomes = select_genomes_by_ids(['13305.1']).values()

        # Call translate
        dnafiles, aafiles = translate.translate_genomes(genomes)

        # Verify expected output
        first_header = '13305.1|NC_008253.1|YP_667942.1|None|thr'
        first = next(SeqIO.parse(dnafiles[0], 'fasta'))
        self.assertEqual(first_header, first.id)
        first = next(SeqIO.parse(aafiles[0], 'fasta'))
        self.assertEqual(first_header, first.id)

        # Verify no header appears twice
        headers = [record.id for record in SeqIO.parse(aafiles[0], 'fasta')]
        self.assertEqual(len(headers), len(set(headers)))

    def test_translate_93125_2(self):
        # Select genomes
        genomes = select_genomes_by_ids(['93125.2']).values()

        # Call translate
        aafiles = translate.translate_genomes(genomes)[1]

        # Verify no header appears twice
        headers = [record.id for record in SeqIO.parse(aafiles[0], 'fasta')]
        self.assertEqual(len(headers), len(set(headers)))

Response:
<REPLACE_OLD> first.id)
 <REPLACE_NEW> first.id)

        # Verify no header appears twice
        headers = [record.id for record in SeqIO.parse(aafiles[0], 'fasta')]
        self.assertEqual(len(headers), len(set(headers)))

    def test_translate_93125_2(self):
        # Select genomes
        genomes = select_genomes_by_ids(['93125.2']).values()

        # Call translate
        aafiles = translate.translate_genomes(genomes)[1]

        # Verify no header appears twice
        headers = [record.id for record in SeqIO.parse(aafiles[0], 'fasta')]
        self.assertEqual(len(headers), len(set(headers))) <REPLACE_END> <|endoftext|> from Bio import SeqIO
import logging
import unittest

from select_taxa import select_genomes_by_ids
import translate

class Test(unittest.TestCase):

    def setUp(self):
        self.longMessage = True
        logging.root.setLevel(logging.DEBUG)

    def test_translate_genomes(self):
        # Select genomes
        genomes = select_genomes_by_ids(['13305.1']).values()

        # Call translate
        dnafiles, aafiles = translate.translate_genomes(genomes)

        # Verify expected output
        first_header = '13305.1|NC_008253.1|YP_667942.1|None|thr'
        first = next(SeqIO.parse(dnafiles[0], 'fasta'))
        self.assertEqual(first_header, first.id)
        first = next(SeqIO.parse(aafiles[0], 'fasta'))
        self.assertEqual(first_header, first.id)

        # Verify no header appears twice
        headers = [record.id for record in SeqIO.parse(aafiles[0], 'fasta')]
        self.assertEqual(len(headers), len(set(headers)))

    def test_translate_93125_2(self):
        # Select genomes
        genomes = select_genomes_by_ids(['93125.2']).values()

        # Call translate
        aafiles = translate.translate_genomes(genomes)[1]

        # Verify no header appears twice
        headers = [record.id for record in SeqIO.parse(aafiles[0], 'fasta')]
        self.assertEqual(len(headers), len(set(headers)))

Prompt:
Verify no header appears twice when translating 93125.2
from Bio import SeqIO
import logging
import unittest

from select_taxa import select_genomes_by_ids
import translate

class Test(unittest.TestCase):

    def setUp(self):
        self.longMessage = True
        logging.root.setLevel(logging.DEBUG)

    def test_translate_genomes(self):
        # Select genomes
        genomes = select_genomes_by_ids(['13305.1']).values()

        # Call translate
        dnafiles, aafiles = translate.translate_genomes(genomes)

        # Verify expected output
        first_header = '13305.1|NC_008253.1|YP_667942.1|None|thr'
        first = next(SeqIO.parse(dnafiles[0], 'fasta'))
        self.assertEqual(first_header, first.id)
        first = next(SeqIO.parse(aafiles[0], 'fasta'))
        self.assertEqual(first_header, first.id)


from django.conf.urls import patterns, include, url
from django.core.urlresolvers import reverse_lazy

from MyInfo import views as my_info_views
from django_cas import views as cas_views
from oam_base import views as base_views

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', my_info_views.index, name='index'),
    url(r'^MyInfo/', include('MyInfo.urls', namespace='MyInfo')),
    url(r'^AccountPickup/', include('AccountPickup.urls', namespace='AccountPickup')),
    url(r'^PasswordReset/', include('PasswordReset.urls', namespace='PasswordReset')),

    url(r'^accounts/login/$', cas_views.login, {'next_page': reverse_lazy('AccountPickup:next_step')}, name='CASLogin'),
    url(r'^accounts/logout/$', cas_views.logout, name='CASLogout'),

    url(r'^error/denied/$', base_views.rate_limited, name='rate_limited'),

    url(r'^ajax/', include('ajax.urls')),

    url(r'^admin/', include(admin.site.urls)),
)

handler500 = 'oam_base.views.custom_error'

Response:
<REPLACE_OLD> url(r'^error/denied$', <REPLACE_NEW> url(r'^error/denied/$', <REPLACE_END> <|endoftext|> from django.conf.urls import patterns, include, url
from django.core.urlresolvers import reverse_lazy

from MyInfo import views as my_info_views
from django_cas import views as cas_views
from oam_base import views as base_views

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', my_info_views.index, name='index'),
    url(r'^MyInfo/', include('MyInfo.urls', namespace='MyInfo')),
    url(r'^AccountPickup/', include('AccountPickup.urls', namespace='AccountPickup')),
    url(r'^PasswordReset/', include('PasswordReset.urls', namespace='PasswordReset')),

    url(r'^accounts/login/$', cas_views.login, {'next_page': reverse_lazy('AccountPickup:next_step')}, name='CASLogin'),
    url(r'^accounts/logout/$', cas_views.logout, name='CASLogout'),

    url(r'^error/denied/$', base_views.rate_limited, name='rate_limited'),

    url(r'^ajax/', include('ajax.urls')),

    url(r'^admin/', include(admin.site.urls)),
)

handler500 = 'oam_base.views.custom_error'

Prompt:
Make the ratelimited error URL follow established conventions.

from django.conf.urls import patterns, include, url
from django.core.urlresolvers import reverse_lazy

from MyInfo import views as my_info_views
from django_cas import views as cas_views
from oam_base import views as base_views

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', my_info_views.index, name='index'),
    url(r'^MyInfo/', include('MyInfo.urls', namespace='MyInfo')),
    url(r'^AccountPickup/', include('AccountPickup.urls', namespace='AccountPickup')),
    url(r'^PasswordReset/', include('PasswordReset.urls', namespace='PasswordReset')),

    url(r'^accounts/login/$', cas_views.login, {'next_page': reverse_lazy('AccountPickup:next_step')}, name='CASLogin'),
    url(r'^accounts/logout/$', cas_views.logout, name='CASLogout'),

    url(r'^error/denied$', base_views.rate_limited, name='rate_limited'),

    url(r'^ajax/', include('ajax.urls')),

    url(r'^admin/', include(admin.site.urls)),
)

handler500 = 'oam_base.views.custom_error'


# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-28 16:37
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

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

    operations = [
        migrations.AlterField(
            model_name='video',
            name='mp4',
            field=models.FilePathField(blank=True, match='.*\\.mp4$', null=True, path='videos', recursive=True),
        ),
        migrations.AlterField(
            model_name='video',
            name='ogg',
            field=models.FilePathField(blank=True, match='.*\\.ogv$', null=True, path='videos', recursive=True),
        ),
        migrations.AlterField(
            model_name='video',
            name='webm',
            field=models.FilePathField(blank=True, match='.*\\.webm$', null=True, path='videos', recursive=True),
        ),
    ]

Add migrations for media files

Add migrations for media files

Response:
<REPLACE_OLD>  <REPLACE_NEW> # -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-28 16:37
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

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

    operations = [
        migrations.AlterField(
            model_name='video',
            name='mp4',
            field=models.FilePathField(blank=True, match='.*\\.mp4$', null=True, path='videos', recursive=True),
        ),
        migrations.AlterField(
            model_name='video',
            name='ogg',
            field=models.FilePathField(blank=True, match='.*\\.ogv$', null=True, path='videos', recursive=True),
        ),
        migrations.AlterField(
            model_name='video',
            name='webm',
            field=models.FilePathField(blank=True, match='.*\\.webm$', null=True, path='videos', recursive=True),
        ),
    ]
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-28 16:37
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

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

    operations = [
        migrations.AlterField(
            model_name='video',
            name='mp4',
            field=models.FilePathField(blank=True, match='.*\\.mp4$', null=True, path='videos', recursive=True),
        ),
        migrations.AlterField(
            model_name='video',
            name='ogg',
            field=models.FilePathField(blank=True, match='.*\\.ogv$', null=True, path='videos', recursive=True),
        ),
        migrations.AlterField(
            model_name='video',
            name='webm',
            field=models.FilePathField(blank=True, match='.*\\.webm$', null=True, path='videos', recursive=True),
        ),
    ]

Prompt: Add migrations for media files


from selenium import webdriver
import unittest

class FunctionalTest(unittest.TestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(3)

    def tearDown(self):
        self.browser.quit()

    def test_app_home_title(self):
        self.browser.get('http://localhost:8000/system_maintenance')
        self.assertIn('System Maintenance', self.browser.title)

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

Add simple functional test to test the title of the app's home page

Response:
<INSERT> from selenium import webdriver
import unittest

class FunctionalTest(unittest.TestCase):

 <INSERT_END> <INSERT>   def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(3)

    def tearDown(self):
        self.browser.quit()

    def test_app_home_title(self):
        self.browser.get('http://localhost:8000/system_maintenance')
        self.assertIn('System Maintenance', self.browser.title)

if __name__ == '__main__':
    unittest.main(warnings='ignore')
 <INSERT_END> <|endoftext|> from selenium import webdriver
import unittest

class FunctionalTest(unittest.TestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(3)

    def tearDown(self):
        self.browser.quit()

    def test_app_home_title(self):
        self.browser.get('http://localhost:8000/system_maintenance')
        self.assertIn('System Maintenance', self.browser.title)

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

Prompt: Add simple functional test to test the title of the app's home page


#!/usr/bin/env python
#=========================================================================
#
#  Copyright Insight Software Consortium
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0.txt
#
#  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 hashlib
import argparse
import re
import os

parser = argparse.ArgumentParser( description="Given a list of python wheels, generate a list of hyperlinks to GitHub with sha512 fragment identifier" )
parser.add_argument( '--hash', choices=['md5','sha256', 'sha512'], default='sha512')
parser.add_argument( '-f', '--format', choices=['html','md'], default='html')
parser.add_argument( 'files', metavar="python.whl", type=argparse.FileType(mode='rb'), nargs='+' )

args = parser.parse_args()

for f in args.files:
    name = os.path.basename(f.name)
    #version="1.1.0"
    version = re.match(r'SimpleITK-([0-9]+\.[0-9]+(\.[0-9]+)?(rc[0-9]+)?)', name ).group(1)
    print("version:{0}".format(version))
    if args.hash == "md5":
       hash_value = hashlib.md5(f.read()).hexdigest()
    elif args.hash == "sha256":
       hash_value = hashlib.sha256(f.read()).hexdigest()
    elif args.hash == "sha512":
       hash_value = hashlib.sha512(f.read()).hexdigest()

    tag = "v{0}".format(version)

    #host="SourceForge"
    #url = "https://sourceforge.net/projects/simpleitk/files/SimpleITK/{0}/Python/{1}#{2}={3}".format(version,name,args.hash,hash_value)

    host = "GitHub"
    url = "https://github.com/SimpleITK/SimpleITK/releases/download/{0}/{1}#{2}={3}".format(tag,name,args.hash,hash_value)

    if args.format == 'html':
        print "
{1} (hosted at {2})
".format(url,name,host)
    elif args.format == 'md':
        print "[{1}]({0})".format(url,name)

    f.close()

Add script to generate download links used on simpleitk.org

Response:
<REPLACE_OLD>  <REPLACE_NEW> #!/usr/bin/env python
#=========================================================================
#
#  Copyright Insight Software Consortium
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0.txt
#
#  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 hashlib
import argparse
import re
import os

parser = argparse.ArgumentParser( description="Given a list of python wheels, generate a list of hyperlinks to GitHub with sha512 fragment identifier" )
parser.add_argument( '--hash', choices=['md5','sha256', 'sha512'], default='sha512')
parser.add_argument( '-f', '--format', choices=['html','md'], default='html')
parser.add_argument( 'files', metavar="python.whl", type=argparse.FileType(mode='rb'), nargs='+' )

args = parser.parse_args()

for f in args.files:
    name = os.path.basename(f.name)
    #version="1.1.0"
    version = re.match(r'SimpleITK-([0-9]+\.[0-9]+(\.[0-9]+)?(rc[0-9]+)?)', name ).group(1)
    print("version:{0}".format(version))
    if args.hash == "md5":
       hash_value = hashlib.md5(f.read()).hexdigest()
    elif args.hash == "sha256":
       hash_value = hashlib.sha256(f.read()).hexdigest()
    elif args.hash == "sha512":
       hash_value = hashlib.sha512(f.read()).hexdigest()

    tag = "v{0}".format(version)

    #host="SourceForge"
    #url = "https://sourceforge.net/projects/simpleitk/files/SimpleITK/{0}/Python/{1}#{2}={3}".format(version,name,args.hash,hash_value)

    host = "GitHub"
    url = "https://github.com/SimpleITK/SimpleITK/releases/download/{0}/{1}#{2}={3}".format(tag,name,args.hash,hash_value)

    if args.format == 'html':
        print "<li><a href=\"{0}\" title=\"Click to download {1}\">{1} (hosted at {2})</a></li>".format(url,name,host)
    elif args.format == 'md':
        print "[{1}]({0})".format(url,name)

    f.close()
 <REPLACE_END> <|endoftext|> #!/usr/bin/env python
#=========================================================================
#
#  Copyright Insight Software Consortium
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0.txt
#
#  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 hashlib
import argparse
import re
import os

parser = argparse.ArgumentParser( description="Given a list of python wheels, generate a list of hyperlinks to GitHub with sha512 fragment identifier" )
parser.add_argument( '--hash', choices=['md5','sha256', 'sha512'], default='sha512')
parser.add_argument( '-f', '--format', choices=['html','md'], default='html')
parser.add_argument( 'files', metavar="python.whl", type=argparse.FileType(mode='rb'), nargs='+' )

args = parser.parse_args()

for f in args.files:
    name = os.path.basename(f.name)
    #version="1.1.0"
    version = re.match(r'SimpleITK-([0-9]+\.[0-9]+(\.[0-9]+)?(rc[0-9]+)?)', name ).group(1)
    print("version:{0}".format(version))
    if args.hash == "md5":
       hash_value = hashlib.md5(f.read()).hexdigest()
    elif args.hash == "sha256":
       hash_value = hashlib.sha256(f.read()).hexdigest()
    elif args.hash == "sha512":
       hash_value = hashlib.sha512(f.read()).hexdigest()

    tag = "v{0}".format(version)

    #host="SourceForge"
    #url = "https://sourceforge.net/projects/simpleitk/files/SimpleITK/{0}/Python/{1}#{2}={3}".format(version,name,args.hash,hash_value)

    host = "GitHub"
    url = "https://github.com/SimpleITK/SimpleITK/releases/download/{0}/{1}#{2}={3}".format(tag,name,args.hash,hash_value)

    if args.format == 'html':
        print "<li><a href=\"{0}\" title=\"Click to download {1}\">{1} (hosted at {2})</a></li>".format(url,name,host)
    elif args.format == 'md':
        print "[{1}]({0})".format(url,name)

    f.close()

Prompt: Add script to generate download links used on simpleitk.org


from __future__ import print_function

from datetime import datetime

from django.db.backends import util

import sqlparse

from debug_toolbar.utils import ms_from_timedelta

class PrintQueryWrapper(util.CursorDebugWrapper):
    def execute(self, sql, params=()):
        starttime = datetime.now()
        try:
            return self.cursor.execute(sql, params)
        finally:
            raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
            execution_time = ms_from_timedelta(datetime.now() - starttime)
            formatted_sql = sqlparse.format(raw_sql, reindent=True)
            print('%s [%.2fms]' % (formatted_sql, execution_time))

util.CursorDebugWrapper = PrintQueryWrapper

Response:
<INSERT> __future__ import print_function

from <INSERT_END> <REPLACE_OLD> datetime.now() <REPLACE_NEW> ms_from_timedelta(datetime.now() <REPLACE_END> <REPLACE_OLD> starttime
 <REPLACE_NEW> starttime)
 <REPLACE_END> <REPLACE_OLD> print <REPLACE_NEW> formatted_sql = <REPLACE_END> <REPLACE_OLD> reindent=True),
 <REPLACE_NEW> reindent=True)
 <REPLACE_END> <REPLACE_OLD> print ' <REPLACE_NEW> print('%s <REPLACE_END> <REPLACE_OLD> (ms_from_timedelta(execution_time),)
            print

util.CursorDebugWrapper <REPLACE_NEW> (formatted_sql, execution_time))

util.CursorDebugWrapper <REPLACE_END> <|endoftext|> from __future__ import print_function

from datetime import datetime

from django.db.backends import util

import sqlparse

from debug_toolbar.utils import ms_from_timedelta

class PrintQueryWrapper(util.CursorDebugWrapper):
    def execute(self, sql, params=()):
        starttime = datetime.now()
        try:
            return self.cursor.execute(sql, params)
        finally:
            raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
            execution_time = ms_from_timedelta(datetime.now() - starttime)
            formatted_sql = sqlparse.format(raw_sql, reindent=True)
            print('%s [%.2fms]' % (formatted_sql, execution_time))

util.CursorDebugWrapper = PrintQueryWrapper

Prompt:
Replace print statement by print function.

from datetime import datetime

from django.db.backends import util

import sqlparse

from debug_toolbar.utils import ms_from_timedelta

class PrintQueryWrapper(util.CursorDebugWrapper):
    def execute(self, sql, params=()):
        starttime = datetime.now()
        try:
            return self.cursor.execute(sql, params)
        finally:
            raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
            execution_time = datetime.now() - starttime
            print sqlparse.format(raw_sql, reindent=True),
            print ' [%.2fms]' % (ms_from_timedelta(execution_time),)
            print

util.CursorDebugWrapper = PrintQueryWrapper


# -*- coding: utf-8 -*-
"""
    app.models
    ~~~~~~~~~~

    Provides the SQLAlchemy models
"""
from __future__ import (
    absolute_import, division, print_function, with_statement,
    unicode_literals)

import savalidation.validators as val

from datetime import datetime as dt
from app import db
from savalidation import ValidationMixin

class HDRO(db.Model, ValidationMixin):
    # auto keys
    id = db.Column(db.Integer, primary_key=True)
    utc_created = db.Column(db.DateTime, nullable=False, default=dt.utcnow())
    utc_updated = db.Column(
        db.DateTime, nullable=False, default=dt.utcnow(), onupdate=dt.utcnow())

    # other keys
    rid = db.Column(db.String(16), nullable=False, index=True, unique=True)
    country = db.Column(db.String(32), nullable=False)
    indicator = db.Column(db.String(128), nullable=False)
    value = db.Column(db.Numeric, nullable=False)
    year = db.Column(db.Integer, nullable=False)

    # validation
    val.validates_constraints()

    def __repr__(self):
        return ('<HDRO(%r, %r)>' % (self.country, self.indicator))

Add unique constraint to rid

Add unique constraint to rid

Response:
<REPLACE_OLD> index=True)
 <REPLACE_NEW> index=True, unique=True)
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
"""
    app.models
    ~~~~~~~~~~

    Provides the SQLAlchemy models
"""
from __future__ import (
    absolute_import, division, print_function, with_statement,
    unicode_literals)

import savalidation.validators as val

from datetime import datetime as dt
from app import db
from savalidation import ValidationMixin

class HDRO(db.Model, ValidationMixin):
    # auto keys
    id = db.Column(db.Integer, primary_key=True)
    utc_created = db.Column(db.DateTime, nullable=False, default=dt.utcnow())
    utc_updated = db.Column(
        db.DateTime, nullable=False, default=dt.utcnow(), onupdate=dt.utcnow())

    # other keys
    rid = db.Column(db.String(16), nullable=False, index=True, unique=True)
    country = db.Column(db.String(32), nullable=False)
    indicator = db.Column(db.String(128), nullable=False)
    value = db.Column(db.Numeric, nullable=False)
    year = db.Column(db.Integer, nullable=False)

    # validation
    val.validates_constraints()

    def __repr__(self):
        return ('<HDRO(%r, %r)>' % (self.country, self.indicator))

Prompt:
Add unique constraint to rid
# -*- coding: utf-8 -*-
"""
    app.models
    ~~~~~~~~~~

    Provides the SQLAlchemy models
"""
from __future__ import (
    absolute_import, division, print_function, with_statement,
    unicode_literals)

import savalidation.validators as val

from datetime import datetime as dt
from app import db
from savalidation import ValidationMixin

class HDRO(db.Model, ValidationMixin):
    # auto keys
    id = db.Column(db.Integer, primary_key=True)
    utc_created = db.Column(db.DateTime, nullable=False, default=dt.utcnow())
    utc_updated = db.Column(
        db.DateTime, nullable=False, default=dt.utcnow(), onupdate=dt.utcnow())

    # other keys
    rid = db.Column(db.String(16), nullable=False, index=True)
    country = db.Column(db.String(32), nullable=False)
    indicator = db.Column(db.String(128), nullable=False)
    value = db.Column(db.Numeric, nullable=False)
    year = db.Column(db.Integer, nullable=False)

    # validation
    val.validates_constraints()

    def __repr__(self):
        return ('<HDRO(%r, %r)>' % (self.country, self.indicator))


from . import TestCase

import JsonStats.FetchStats.Plugins
from JsonStats.FetchStats import Fetcher

class TestPluginMount(TestCase):

    def setUp(self):
        # Do stuff that has to happen on every test in this instance
        self.fetcher = Fetcher

        class _example_plugin(Fetcher):
            def __init__(self):
                self.context = 'testplugin'
                self._load_data()
            def _load_data(self):
                self._loaded(True)
            def dump(self):
                return {}
            def dump_json(self):
                return self.json.dumps(self.dump())

        self.example_plugin = _example_plugin

    def test_get_plugins(self):
        """
        Verify that after loading plugins we can see them attached to
        the Mount.
        """
        example_plugin = self.example_plugin()
        discovered = len(self.fetcher.get_plugins())
        assert discovered == 1

Response:
<DELETE> JsonStats.FetchStats.Plugins import *

from <DELETE_END> <INSERT>     class _example_plugin(Fetcher):
            def __init__(self):
                self.context = 'testplugin'
                self._load_data()
            def _load_data(self):
                self._loaded(True)
            def dump(self):
                return {}
            def dump_json(self):
                return self.json.dumps(self.dump())

        self.example_plugin = _example_plugin

    <INSERT_END> <INSERT> example_plugin = self.example_plugin()
        <INSERT_END> <REPLACE_OLD> expected = len(JsonStats.FetchStats.Plugins.__all__)
        self.assertEqual(discovered, expected)
 <REPLACE_NEW> assert discovered == 1
 <REPLACE_END> <|endoftext|> from . import TestCase

import JsonStats.FetchStats.Plugins
from JsonStats.FetchStats import Fetcher

class TestPluginMount(TestCase):

    def setUp(self):
        # Do stuff that has to happen on every test in this instance
        self.fetcher = Fetcher

        class _example_plugin(Fetcher):
            def __init__(self):
                self.context = 'testplugin'
                self._load_data()
            def _load_data(self):
                self._loaded(True)
            def dump(self):
                return {}
            def dump_json(self):
                return self.json.dumps(self.dump())

        self.example_plugin = _example_plugin

    def test_get_plugins(self):
        """
        Verify that after loading plugins we can see them attached to
        the Mount.
        """
        example_plugin = self.example_plugin()
        discovered = len(self.fetcher.get_plugins())
        assert discovered == 1

Prompt:
Fix the plugin mount text. And make it way more intelligent.

from JsonStats.FetchStats.Plugins import *

from . import TestCase

import JsonStats.FetchStats.Plugins
from JsonStats.FetchStats import Fetcher

class TestPluginMount(TestCase):

    def setUp(self):
        # Do stuff that has to happen on every test in this instance
        self.fetcher = Fetcher

    def test_get_plugins(self):
        """
        Verify that after loading plugins we can see them attached to
        the Mount.
        """
        discovered = len(self.fetcher.get_plugins())
        expected = len(JsonStats.FetchStats.Plugins.__all__)
        self.assertEqual(discovered, expected)


#
# -*- coding: utf-8 -*-
#
# This file is part of reclass (http://github.com/madduck/reclass)
#
# Copyright © 2007–13 martin f. krafft <madduck@madduck.net>
# Released under the terms of the Artistic Licence 2.0
#

from output import OutputLoader
from storage import StorageBackendLoader

def get_data(storage_type, nodes_uri, classes_uri, applications_postfix, node):
    storage_class = StorageBackendLoader(storage_type).load()
    storage = storage_class(nodes_uri, classes_uri, applications_postfix)
    if not node:
        ret = storage.inventory()
    else:
        ret = storage.nodeinfo(node)

    return ret

def output(data, fmt, pretty_print=False):
    output_class = OutputLoader(fmt).load()
    outputter = output_class()
    return outputter.dump(data, pretty_print=pretty_print)

Response:
<REPLACE_OLD> node is False:
 <REPLACE_NEW> not node:
 <REPLACE_END> <|endoftext|> #
# -*- coding: utf-8 -*-
#
# This file is part of reclass (http://github.com/madduck/reclass)
#
# Copyright © 2007–13 martin f. krafft <madduck@madduck.net>
# Released under the terms of the Artistic Licence 2.0
#

from output import OutputLoader
from storage import StorageBackendLoader

def get_data(storage_type, nodes_uri, classes_uri, applications_postfix, node):
    storage_class = StorageBackendLoader(storage_type).load()
    storage = storage_class(nodes_uri, classes_uri, applications_postfix)
    if not node:
        ret = storage.inventory()
    else:
        ret = storage.nodeinfo(node)

    return ret

def output(data, fmt, pretty_print=False):
    output_class = OutputLoader(fmt).load()
    outputter = output_class()
    return outputter.dump(data, pretty_print=pretty_print)

Prompt:
Allow node to be None to trigger inventory

Signed-off-by: martin f. krafft <acc3492a66a5949176a2fc8886cf441478ca46a1@madduck.net>

#
# -*- coding: utf-8 -*-
#
# This file is part of reclass (http://github.com/madduck/reclass)
#
# Copyright © 2007–13 martin f. krafft <madduck@madduck.net>
# Released under the terms of the Artistic Licence 2.0
#

from output import OutputLoader
from storage import StorageBackendLoader

def get_data(storage_type, nodes_uri, classes_uri, applications_postfix, node):
    storage_class = StorageBackendLoader(storage_type).load()
    storage = storage_class(nodes_uri, classes_uri, applications_postfix)
    if node is False:
        ret = storage.inventory()
    else:
        ret = storage.nodeinfo(node)

    return ret

def output(data, fmt, pretty_print=False):
    output_class = OutputLoader(fmt).load()
    outputter = output_class()
    return outputter.dump(data, pretty_print=pretty_print)


#!/usr/bin/python

from setuptools import setup

setup(name="catsnap",
      version="6.0.0",
      description="catalog and store images",
      author="Erin Call",
      author_email="hello@erincall.com",
      url="https://github.com/ErinCall/",
      packages=['catsnap',
                'catsnap.document',
                'catsnap.config',
                'catsnap.batch'],
      install_requires=[
          "Flask==0.9",
          "gunicorn==0.14.6",
          "boto==2.5.2",
          "requests==0.13.2",
          "argparse==1.2.1",
          "psycopg2==2.4.6",
          "sqlalchemy==0.8.0b2",
          "yoyo-migrations==4.1.6",
          "wand==0.3.3",
          "celery==3.1.16",
          "redis==2.10.3",
          "gevent==1.1b5",
          "Flask-Sockets==0.1",
          "PyYAML==3.11",

          "mock==1.0.1",
          "nose==1.1.2",
          "splinter==0.5.3",
          "bcrypt==1.1.1",
      ],
      )

Response:
<REPLACE_OLD> "gevent==1.0.2",
 <REPLACE_NEW> "gevent==1.1b5",
 <REPLACE_END> <|endoftext|> #!/usr/bin/python

from setuptools import setup

setup(name="catsnap",
      version="6.0.0",
      description="catalog and store images",
      author="Erin Call",
      author_email="hello@erincall.com",
      url="https://github.com/ErinCall/",
      packages=['catsnap',
                'catsnap.document',
                'catsnap.config',
                'catsnap.batch'],
      install_requires=[
          "Flask==0.9",
          "gunicorn==0.14.6",
          "boto==2.5.2",
          "requests==0.13.2",
          "argparse==1.2.1",
          "psycopg2==2.4.6",
          "sqlalchemy==0.8.0b2",
          "yoyo-migrations==4.1.6",
          "wand==0.3.3",
          "celery==3.1.16",
          "redis==2.10.3",
          "gevent==1.1b5",
          "Flask-Sockets==0.1",
          "PyYAML==3.11",

          "mock==1.0.1",
          "nose==1.1.2",
          "splinter==0.5.3",
          "bcrypt==1.1.1",
      ],
      )

Prompt:
Upgrade to a newer gevent for OSX Yosemity compat

See https://github.com/gevent/gevent/issues/656

#!/usr/bin/python

from setuptools import setup

setup(name="catsnap",
      version="6.0.0",
      description="catalog and store images",
      author="Erin Call",
      author_email="hello@erincall.com",
      url="https://github.com/ErinCall/",
      packages=['catsnap',
                'catsnap.document',
                'catsnap.config',
                'catsnap.batch'],
      install_requires=[
          "Flask==0.9",
          "gunicorn==0.14.6",
          "boto==2.5.2",
          "requests==0.13.2",
          "argparse==1.2.1",
          "psycopg2==2.4.6",
          "sqlalchemy==0.8.0b2",
          "yoyo-migrations==4.1.6",
          "wand==0.3.3",
          "celery==3.1.16",
          "redis==2.10.3",
          "gevent==1.0.2",
          "Flask-Sockets==0.1",
          "PyYAML==3.11",

          "mock==1.0.1",
          "nose==1.1.2",
          "splinter==0.5.3",
          "bcrypt==1.1.1",
      ],
      )


# Copyright 2013 Russell Heilling
import logging

from google.appengine.api import users

from pulldb import base
from pulldb import session
from pulldb.models.users import User

class Profile(session.SessionHandler):
  def get(self):
    app_user = users.get_current_user()
    template_values = self.base_template_values()
    template_values.update({
        'user': user_key(app_user).get(),
    })
    template = self.templates.get_template('users_profile.html')
    self.response.write(template.render(template_values))

def user_key(app_user=users.get_current_user(), create=True):
  logging.debug("Looking up user key for: %r", app_user)
  key = None
  user = User.query(User.userid == app_user.user_id()).get()
  if user:
    key = user.key
  elif create:
    logging.info('Adding user to datastore: %s', app_user.nickname())
    user = User(userid=app_user.user_id(),
                nickname=app_user.nickname())
    user.put()
    key = user.key
  return user.key

app = base.create_app([
    ('/users/me', Profile),
])

Add logging to track down a bug

Add logging to track down a bug

Response:
<INSERT>  logging.debug("Looking up user key for: %r", app_user)
 <INSERT_END> <|endoftext|> # Copyright 2013 Russell Heilling
import logging

from google.appengine.api import users

from pulldb import base
from pulldb import session
from pulldb.models.users import User

class Profile(session.SessionHandler):
  def get(self):
    app_user = users.get_current_user()
    template_values = self.base_template_values()
    template_values.update({
        'user': user_key(app_user).get(),
    })
    template = self.templates.get_template('users_profile.html')
    self.response.write(template.render(template_values))

def user_key(app_user=users.get_current_user(), create=True):
  logging.debug("Looking up user key for: %r", app_user)
  key = None
  user = User.query(User.userid == app_user.user_id()).get()
  if user:
    key = user.key
  elif create:
    logging.info('Adding user to datastore: %s', app_user.nickname())
    user = User(userid=app_user.user_id(),
                nickname=app_user.nickname())
    user.put()
    key = user.key
  return user.key

app = base.create_app([
    ('/users/me', Profile),
])

Prompt:
Add logging to track down a bug

# Copyright 2013 Russell Heilling
import logging

from google.appengine.api import users

from pulldb import base
from pulldb import session
from pulldb.models.users import User

class Profile(session.SessionHandler):
  def get(self):
    app_user = users.get_current_user()
    template_values = self.base_template_values()
    template_values.update({
        'user': user_key(app_user).get(),
    })
    template = self.templates.get_template('users_profile.html')
    self.response.write(template.render(template_values))

def user_key(app_user=users.get_current_user(), create=True):
  key = None
  user = User.query(User.userid == app_user.user_id()).get()
  if user:
    key = user.key
  elif create:
    logging.info('Adding user to datastore: %s', app_user.nickname())
    user = User(userid=app_user.user_id(),
                nickname=app_user.nickname())
    user.put()
    key = user.key
  return user.key

app = base.create_app([
    ('/users/me', Profile),
])