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

from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
import os.path

class UploadedFile(models.Model):
    user = models.ForeignKey(User, verbose_name=u'Käyttäjä')
    description = models.TextField(u'Kuvaus', help_text=u'Lyhyt kuvaus siitä, mihin/missä tiedostoa käytetään.', blank=True)
    file = models.FileField(u'Tiedosto', upload_to='admin_upload/')
    date = models.DateTimeField(u'Aika')

    def __unicode__(self):
        return self.file.name + ' by' + self.user.username + ')'

    class Meta:
        verbose_name=u"tiedosto"
        verbose_name_plural=u"tiedostot"

    def name(self):
        return os.path.basename(self.file.name)

try:
    admin.site.register(UploadedFile)
except:
    pass

Response:
<REPLACE_OLD> admin

class <REPLACE_NEW> admin
import os.path

class <REPLACE_END> <INSERT>
    <INSERT_END> <INSERT>
    <INSERT_END> <REPLACE_OLD> verbose_name_plural=u"tiedostot" <REPLACE_NEW> verbose_name_plural=u"tiedostot"

    def name(self):
        return os.path.basename(self.file.name)

try:
    admin.site.register(UploadedFile)
except:
    pass <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-

from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
import os.path

class UploadedFile(models.Model):
    user = models.ForeignKey(User, verbose_name=u'Käyttäjä')
    description = models.TextField(u'Kuvaus', help_text=u'Lyhyt kuvaus siitä, mihin/missä tiedostoa käytetään.', blank=True)
    file = models.FileField(u'Tiedosto', upload_to='admin_upload/')
    date = models.DateTimeField(u'Aika')

    def __unicode__(self):
        return self.file.name + ' by' + self.user.username + ')'

    class Meta:
        verbose_name=u"tiedosto"
        verbose_name_plural=u"tiedostot"

    def name(self):
        return os.path.basename(self.file.name)

try:
    admin.site.register(UploadedFile)
except:
    pass

Prompt:
admin_upload: Add helper function for getting name from UploadedFile, add model to admin.

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

from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin

class UploadedFile(models.Model):
    user = models.ForeignKey(User, verbose_name=u'Käyttäjä')
    description = models.TextField(u'Kuvaus', help_text=u'Lyhyt kuvaus siitä, mihin/missä tiedostoa käytetään.', blank=True)
    file = models.FileField(u'Tiedosto', upload_to='admin_upload/')
    date = models.DateTimeField(u'Aika')
    def __unicode__(self):
        return self.file.name + ' by' + self.user.username + ')'
    class Meta:
        verbose_name=u"tiedosto"
        verbose_name_plural=u"tiedostot"


from flask import Flask
import relay_api.api.backend as backend

server = Flask(__name__)

backend.init_relays()

@server.route("/relay-api/relays/", methods=["GET"])
def get_all_relays():
    js = backend.get_all_relays()
    return js, 200

@server.route("/relay-api/relays/<relay_name>", methods=["GET"])
def get_relay(relay_name):
    js = backend.get_relay(relay_name)
    if not js:
        return "", 404
    return js, 200

Fix issue with backend import

Fix issue with backend import

Response:
<REPLACE_OLD> relay_api.api.server <REPLACE_NEW> relay_api.api.backend <REPLACE_END> <|endoftext|> from flask import Flask
import relay_api.api.backend as backend

server = Flask(__name__)

backend.init_relays()

@server.route("/relay-api/relays/", methods=["GET"])
def get_all_relays():
    js = backend.get_all_relays()
    return js, 200

@server.route("/relay-api/relays/<relay_name>", methods=["GET"])
def get_relay(relay_name):
    js = backend.get_relay(relay_name)
    if not js:
        return "", 404
    return js, 200

Prompt:
Fix issue with backend import

from flask import Flask
import relay_api.api.server as backend

server = Flask(__name__)

backend.init_relays()

@server.route("/relay-api/relays/", methods=["GET"])
def get_all_relays():
    js = backend.get_all_relays()
    return js, 200

@server.route("/relay-api/relays/<relay_name>", methods=["GET"])
def get_relay(relay_name):
    js = backend.get_relay(relay_name)
    if not js:
        return "", 404
    return js, 200


import re

try:
  import javascript
  import html
except:
  from . import javascript
  from . import html

def expand(string, start, end, extension=None):

  if(re.compile("html|htm|xml").search(extension)):
    return html.expand(string, start, end)

  return javascript.expand(string, start, end)

Response:
<REPLACE_OLD> try:
 <REPLACE_NEW> import re

try:
 <REPLACE_END> <REPLACE_OLD> if(extension in ["html", "htm", "xml"]):
 <REPLACE_NEW> if(re.compile("html|htm|xml").search(extension)):
 <REPLACE_END> <|endoftext|> import re

try:
  import javascript
  import html
except:
  from . import javascript
  from . import html

def expand(string, start, end, extension=None):

  if(re.compile("html|htm|xml").search(extension)):
    return html.expand(string, start, end)

  return javascript.expand(string, start, end)

Prompt:
Use html strategy for any file that has xml/html in file extension. This will will match shtml, xhtml and so on.

try:
  import javascript
  import html
except:
  from . import javascript
  from . import html

def expand(string, start, end, extension=None):

  if(extension in ["html", "htm", "xml"]):
    return html.expand(string, start, end)

  return javascript.expand(string, start, end)


# osm_id: 43950409 name: San Pablo Bay
assert_has_feature(
    14, 2623, 6318, 'water',
    { 'kind': 'bay', 'label_placement': 'yes' })

# osm_id: 360566115 name: Byron strait
assert_has_feature(
    14, 15043, 8311, 'water',
    { 'kind': 'strait', 'label_placement': 'yes' })

# osm_id: -1451065 name: Horsens Fjord
assert_has_feature(
    14, 8645, 5114, 'water',
    { 'kind': 'fjord', 'label_placement': 'yes' })

Add tests for strait and fjord

Add tests for strait and fjord

Response:
<REPLACE_OLD> assert_has_feature(
 <REPLACE_NEW> # osm_id: 43950409 name: San Pablo Bay
assert_has_feature(
 <REPLACE_END> <INSERT> })

# osm_id: 360566115 name: Byron strait
assert_has_feature(
    14, 15043, 8311, 'water',
    { 'kind': 'strait', 'label_placement': 'yes' })

# osm_id: -1451065 name: Horsens Fjord
assert_has_feature(
    14, 8645, 5114, 'water',
    { 'kind': 'fjord', 'label_placement': 'yes' <INSERT_END> <|endoftext|> # osm_id: 43950409 name: San Pablo Bay
assert_has_feature(
    14, 2623, 6318, 'water',
    { 'kind': 'bay', 'label_placement': 'yes' })

# osm_id: 360566115 name: Byron strait
assert_has_feature(
    14, 15043, 8311, 'water',
    { 'kind': 'strait', 'label_placement': 'yes' })

# osm_id: -1451065 name: Horsens Fjord
assert_has_feature(
    14, 8645, 5114, 'water',
    { 'kind': 'fjord', 'label_placement': 'yes' })

Prompt:
Add tests for strait and fjord

assert_has_feature(
    14, 2623, 6318, 'water',
    { 'kind': 'bay', 'label_placement': 'yes' })


from django import VERSION as DJANGO_VERSION
from django import template
from django.conf import settings
if DJANGO_VERSION[0] == 1 and DJANGO_VERSION[1] <= 9:
    from django.core.urlresolvers import reverse
else:
    from django.urls import reverse

register = template.Library()

@register.simple_tag(takes_context=True)
def active_link(context, viewname, css_class=None, strict=None):
    """
    Renders the given CSS class if the request path matches the path of the view.
    :param context: The context where the tag was called. Used to access the request object.
    :param viewname: The name of the view (include namespaces if any).
    :param css_class: The CSS class to render.
    :param strict: If True, the tag will perform an exact match with the request path.
    :return:
    """
    if css_class is None:
        css_class = getattr(settings, 'ACTIVE_LINK_CSS_CLASS', 'active')

    if strict is None:
        strict = getattr(settings, 'ACTIVE_LINK_STRICT', False)

    request = context.get('request')
    if request is None:
        # Can't work without the request object.
        return ''
    path = reverse(viewname)
    if strict:
        active = request.path == path
    else:
        active = request.path.find(path) == 0
    if active:
        return css_class
    return ''

Improve how the active link is checked

Improve how the active link is checked

Response:
<REPLACE_OLD> path in request.path
 <REPLACE_NEW> request.path.find(path) == 0
 <REPLACE_END> <|endoftext|> from django import VERSION as DJANGO_VERSION
from django import template
from django.conf import settings
if DJANGO_VERSION[0] == 1 and DJANGO_VERSION[1] <= 9:
    from django.core.urlresolvers import reverse
else:
    from django.urls import reverse

register = template.Library()

@register.simple_tag(takes_context=True)
def active_link(context, viewname, css_class=None, strict=None):
    """
    Renders the given CSS class if the request path matches the path of the view.
    :param context: The context where the tag was called. Used to access the request object.
    :param viewname: The name of the view (include namespaces if any).
    :param css_class: The CSS class to render.
    :param strict: If True, the tag will perform an exact match with the request path.
    :return:
    """
    if css_class is None:
        css_class = getattr(settings, 'ACTIVE_LINK_CSS_CLASS', 'active')

    if strict is None:
        strict = getattr(settings, 'ACTIVE_LINK_STRICT', False)

    request = context.get('request')
    if request is None:
        # Can't work without the request object.
        return ''
    path = reverse(viewname)
    if strict:
        active = request.path == path
    else:
        active = request.path.find(path) == 0
    if active:
        return css_class
    return ''

Prompt:
Improve how the active link is checked

from django import VERSION as DJANGO_VERSION
from django import template
from django.conf import settings
if DJANGO_VERSION[0] == 1 and DJANGO_VERSION[1] <= 9:
    from django.core.urlresolvers import reverse
else:
    from django.urls import reverse

register = template.Library()

@register.simple_tag(takes_context=True)
def active_link(context, viewname, css_class=None, strict=None):
    """
    Renders the given CSS class if the request path matches the path of the view.
    :param context: The context where the tag was called. Used to access the request object.
    :param viewname: The name of the view (include namespaces if any).
    :param css_class: The CSS class to render.
    :param strict: If True, the tag will perform an exact match with the request path.
    :return:
    """
    if css_class is None:
        css_class = getattr(settings, 'ACTIVE_LINK_CSS_CLASS', 'active')

    if strict is None:
        strict = getattr(settings, 'ACTIVE_LINK_STRICT', False)

    request = context.get('request')
    if request is None:
        # Can't work without the request object.
        return ''
    path = reverse(viewname)
    if strict:
        active = request.path == path
    else:
        active = path in request.path
    if active:
        return css_class
    return ''


from Helpers.string import *

def binop_aexp(commands, env, op, left, right):
    left.compile_vm(commands, env)
    right.compile_vm(commands, env)
    if op == '+':
        value = assemble(Add)
    elif op == '-':
        value = assemble(Sub)
    elif op == '*':
        value = assemble(Mul)
    elif op == '/':
        value = assemble(Div)
    elif op == '%':
        value = assemble(Mod)
    else:
        raise RuntimeError('unknown operator: ' + op)
    commands.append(value)

def int_aexp(commands, env, i):
    commands.append(assemble(Push, i))

def var_aexp(commands, env, name):
    var_type = Environment.get_var_type(env, name)
    var_value = Environment.get_var(env, name)
    if var_type == 'String':
        String.compile_get(commands, env, var_value)
    else:
        commands.append(assemble(Load, var_value))

Response:
<DELETE> 'IntAexp':
        commands.append(assemble(Load, var_value))
    elif var_type == 'Char':
        commands.append(assemble(Load, var_value))
    elif var_type == <DELETE_END> <INSERT>    else:
        commands.append(assemble(Load, var_value))
 <INSERT_END> <|endoftext|> from Helpers.string import *

def binop_aexp(commands, env, op, left, right):
    left.compile_vm(commands, env)
    right.compile_vm(commands, env)
    if op == '+':
        value = assemble(Add)
    elif op == '-':
        value = assemble(Sub)
    elif op == '*':
        value = assemble(Mul)
    elif op == '/':
        value = assemble(Div)
    elif op == '%':
        value = assemble(Mod)
    else:
        raise RuntimeError('unknown operator: ' + op)
    commands.append(value)

def int_aexp(commands, env, i):
    commands.append(assemble(Push, i))

def var_aexp(commands, env, name):
    var_type = Environment.get_var_type(env, name)
    var_value = Environment.get_var(env, name)
    if var_type == 'String':
        String.compile_get(commands, env, var_value)
    else:
        commands.append(assemble(Load, var_value))

Prompt:
Fix compiling problem for runtime variables

from Helpers.string import *

def binop_aexp(commands, env, op, left, right):
    left.compile_vm(commands, env)
    right.compile_vm(commands, env)
    if op == '+':
        value = assemble(Add)
    elif op == '-':
        value = assemble(Sub)
    elif op == '*':
        value = assemble(Mul)
    elif op == '/':
        value = assemble(Div)
    elif op == '%':
        value = assemble(Mod)
    else:
        raise RuntimeError('unknown operator: ' + op)
    commands.append(value)

def int_aexp(commands, env, i):
    commands.append(assemble(Push, i))

def var_aexp(commands, env, name):
    var_type = Environment.get_var_type(env, name)
    var_value = Environment.get_var(env, name)
    if var_type == 'IntAexp':
        commands.append(assemble(Load, var_value))
    elif var_type == 'Char':
        commands.append(assemble(Load, var_value))
    elif var_type == 'String':
        String.compile_get(commands, env, var_value)


from datetime import date, timedelta

class DateWithCalendar(object):
    def __init__(self, calendar_class, date):
        self.calendar = calendar_class
        self.date = date

    def convert_to(self, calendar):
        return calendar.from_date(self.date)

    def __eq__(self, other):
        return self.calendar == other.calendar and self.date == other.date

class ProlepticGregorianCalendar(object):
    def date(self, year, month, day):
        d = date(year, month, day)
        return DateWithCalendar(ProlepticGregorianCalendar, d)

    def from_date(self, date):
        return DateWithCalendar(ProlepticGregorianCalendar, date)

class JulianCalendar(object):
    def date(self, year, month, day):
        d = date(year, month, day)
        d = d + timedelta(days=10)
        return DateWithCalendar(JulianCalendar, d)

Response:
<REPLACE_OLD> date

class <REPLACE_NEW> date, timedelta

class <REPLACE_END> <REPLACE_OLD> date

class <REPLACE_NEW> date

    def convert_to(self, calendar):
        return calendar.from_date(self.date)

    def __eq__(self, other):
        return self.calendar == other.calendar and self.date == other.date

class <REPLACE_END> <REPLACE_OLD> d)

class <REPLACE_NEW> d)

    def from_date(self, date):
        return DateWithCalendar(ProlepticGregorianCalendar, date)

class <REPLACE_END> <INSERT> d = d + timedelta(days=10)
        <INSERT_END> <|endoftext|> from datetime import date, timedelta

class DateWithCalendar(object):
    def __init__(self, calendar_class, date):
        self.calendar = calendar_class
        self.date = date

    def convert_to(self, calendar):
        return calendar.from_date(self.date)

    def __eq__(self, other):
        return self.calendar == other.calendar and self.date == other.date

class ProlepticGregorianCalendar(object):
    def date(self, year, month, day):
        d = date(year, month, day)
        return DateWithCalendar(ProlepticGregorianCalendar, d)

    def from_date(self, date):
        return DateWithCalendar(ProlepticGregorianCalendar, date)

class JulianCalendar(object):
    def date(self, year, month, day):
        d = date(year, month, day)
        d = d + timedelta(days=10)
        return DateWithCalendar(JulianCalendar, d)

Prompt:
Allow conversion from Julian to ProlepticGregorian, also comparison of dates.

from datetime import date

class DateWithCalendar(object):
    def __init__(self, calendar_class, date):
        self.calendar = calendar_class
        self.date = date

class ProlepticGregorianCalendar(object):
    def date(self, year, month, day):
        d = date(year, month, day)
        return DateWithCalendar(ProlepticGregorianCalendar, d)

class JulianCalendar(object):
    def date(self, year, month, day):
        d = date(year, month, day)
        return DateWithCalendar(JulianCalendar, d)


# -*- coding: utf-8 -*-
from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _

from .widgets import AppHookConfigWidget

class AppHookConfigFormField(forms.ModelChoiceField):

    def __init__(self, queryset, empty_label="---------", required=True,
            widget=AppHookConfigWidget, *args, **kwargs):
        super(AppHookConfigFormField, self).__init__(queryset, empty_label,
            required, widget, *args, **kwargs)

class AppHookConfigField(models.ForeignKey):

    def __init__(self, *args, **kwargs):
        kwargs.update({'help_text': _(u'When selecting a value, the form is reloaded to get the updated default')})
        super(AppHookConfigField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        kwargs.update({'form_class': AppHookConfigFormField})
        return super(AppHookConfigField, self).formfield(**kwargs)

Response:
<INSERT> AppHookConfigFormField(forms.ModelChoiceField):

    def __init__(self, queryset, empty_label="---------", required=True,
            widget=AppHookConfigWidget, *args, **kwargs):
        super(AppHookConfigFormField, self).__init__(queryset, empty_label,
            required, widget, *args, **kwargs)

class <INSERT_END> <DELETE> class AppHookConfigFormField(forms.ModelChoiceField):
            widget = AppHookConfigWidget
        <DELETE_END> <|endoftext|> # -*- coding: utf-8 -*-
from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _

from .widgets import AppHookConfigWidget

class AppHookConfigFormField(forms.ModelChoiceField):

    def __init__(self, queryset, empty_label="---------", required=True,
            widget=AppHookConfigWidget, *args, **kwargs):
        super(AppHookConfigFormField, self).__init__(queryset, empty_label,
            required, widget, *args, **kwargs)

class AppHookConfigField(models.ForeignKey):

    def __init__(self, *args, **kwargs):
        kwargs.update({'help_text': _(u'When selecting a value, the form is reloaded to get the updated default')})
        super(AppHookConfigField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        kwargs.update({'form_class': AppHookConfigFormField})
        return super(AppHookConfigField, self).formfield(**kwargs)

Prompt:
Improve the ability for developers to extend or modify

# -*- coding: utf-8 -*-
from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _

from .widgets import AppHookConfigWidget

class AppHookConfigField(models.ForeignKey):

    def __init__(self, *args, **kwargs):
        kwargs.update({'help_text': _(u'When selecting a value, the form is reloaded to get the updated default')})
        super(AppHookConfigField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        class AppHookConfigFormField(forms.ModelChoiceField):
            widget = AppHookConfigWidget
        kwargs.update({'form_class': AppHookConfigFormField})
        return super(AppHookConfigField, self).formfield(**kwargs)


#
# Copyright 2014, NICTA
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(NICTA_BSD)
#

'''Various helpers for doing advanced things with dictionaries.'''

import re

def get_fields(s):
    '''Return a set of field names referenced as formatting keys in the given
    string. I thought there would be an easier way to get this, but I can't
    find one. E.g. get_fields('%(hello)s %(world)s') returns
    set('hello', 'world').'''
    return set(re.findall(r'%\(([^)]+)\)', s))

class Guard(object):
    '''Representation of a condition required for some action. See usage in
    Template.py.'''
    def __init__(self, guard_fn):
        self.guard_fn = guard_fn

    def __call__(self, arg):
        return self.guard_fn(arg)

Response:
<REPLACE_OLD> dictionaries.'''

def <REPLACE_NEW> dictionaries.'''

import re

def <REPLACE_END> <DELETE> class FakeDict(dict):
        def __init__(self):
            super(FakeDict, self).__init__()
            self.referenced = set()
        def __getitem__(self, key):
            self.referenced.add(key)
            <DELETE_END> <REPLACE_OLD> ''
    f = FakeDict()
    s % f # Value deliberately discarded
    return f.referenced

class <REPLACE_NEW> set(re.findall(r'%\(([^)]+)\)', s))

class <REPLACE_END> <|endoftext|> #
# Copyright 2014, NICTA
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(NICTA_BSD)
#

'''Various helpers for doing advanced things with dictionaries.'''

import re

def get_fields(s):
    '''Return a set of field names referenced as formatting keys in the given
    string. I thought there would be an easier way to get this, but I can't
    find one. E.g. get_fields('%(hello)s %(world)s') returns
    set('hello', 'world').'''
    return set(re.findall(r'%\(([^)]+)\)', s))

class Guard(object):
    '''Representation of a condition required for some action. See usage in
    Template.py.'''
    def __init__(self, guard_fn):
        self.guard_fn = guard_fn

    def __call__(self, arg):
        return self.guard_fn(arg)

Prompt:
Support non-string formats in `get_fields`.

This commit rewrites the `get_fields` function to be simpler and more general.
The previous implementation relied on ad hoc dict mocking and only supported
format strings involving string-valued formats ('%(name)s'). From this commit
other formats (e.g. '%(name)04d') are supported. The motivation for this is
upcoming changes to how the DMA pool frames are named.

#
# Copyright 2014, NICTA
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(NICTA_BSD)
#

'''Various helpers for doing advanced things with dictionaries.'''

def get_fields(s):
    '''Return a set of field names referenced as formatting keys in the given
    string. I thought there would be an easier way to get this, but I can't
    find one. E.g. get_fields('%(hello)s %(world)s') returns
    set('hello', 'world').'''
    class FakeDict(dict):
        def __init__(self):
            super(FakeDict, self).__init__()
            self.referenced = set()
        def __getitem__(self, key):
            self.referenced.add(key)
            return ''
    f = FakeDict()
    s % f # Value deliberately discarded
    return f.referenced

class Guard(object):
    '''Representation of a condition required for some action. See usage in
    Template.py.'''
    def __init__(self, guard_fn):
        self.guard_fn = guard_fn

    def __call__(self, arg):
        return self.guard_fn(arg)


VERSION = (0, 9, 0, 'beta', 1)

def get_version():
    try:
        from django.utils.version import get_version as django_get_version
        return django_get_version(VERSION) # pragma: no cover
    except ImportError:
        return ".".join(str(n) for n in VERSION)

Response:
<INSERT>    try:
     <INSERT_END> <INSERT>     <INSERT_END> <INSERT>    except ImportError:
        return ".".join(str(n) for n in VERSION)
 <INSERT_END> <|endoftext|> VERSION = (0, 9, 0, 'beta', 1)

def get_version():
    try:
        from django.utils.version import get_version as django_get_version
        return django_get_version(VERSION) # pragma: no cover
    except ImportError:
        return ".".join(str(n) for n in VERSION)

Prompt:
Fix dependency order issue in get_version

VERSION = (0, 9, 0, 'beta', 1)

def get_version():
    from django.utils.version import get_version as django_get_version
    return django_get_version(VERSION) # pragma: no cover


"""
Convert Google Analytics buckets from Europe/London to UTC
"""
import logging
import copy
from itertools import imap, ifilter
from datetime import timedelta

from backdrop.core.records import Record
from backdrop.core.timeutils import utc

log = logging.getLogger(__name__)

GA_BUCKETS_TO_MIGRATE = [
    "carers_allowance_journey",
    "deposit_foreign_marriage_journey",
    "pay_foreign_marriage_certificates_journey",
    "pay_legalisation_drop_off_journey",
    "pay_legalisation_post_journey",
    "pay_register_birth_abroad_journey",
    "pay_register_death_abroad_journey",
    "lpa_journey",
    "licensing_journey",
]

def fix_timestamp(document):
    """Return a new dict with the _timestamp field fixed
    """
    document = copy.deepcopy(document)
    document['_timestamp'] = document['_timestamp'].replace(tzinfo=None) + \
        timedelta(hours=1)
    return document

def strip_internal_fields(document):
    """Return a new dict with all internal fields removed

    Leaves _timestamp and _id in place
    """
    def allowed_field(key):
        return not key.startswith('_') or key in ['_timestamp', '_id']

    return dict(
        (key, value) for key, value in document.items() if allowed_field(key))

def is_bst(document):
    """Return true if a document looks like it's BST"""
    return document['_timestamp'].hour == 23

def create_record(document):
    """Return a dict with internal fields applied"""
    return Record(document).to_mongo()

def fix_id(document):
    """Return a new dict with the _id field recalculated"""
    def _format(timestamp):
        return to_utc(timestamp).strftime("%Y%m%d%H%M%S")

    def data_id(data_type, timestamp, period):
        """_id generation function copied from backdrop-ga-collector"""
        return base64.urlsafe_b64encode("_".join(
            [data_type, _format(timestamp), period]))

    document = copy.deepcopy(document)
    document['_id'] = data_id(
        document['dataType'], document['_timestamp'],
        document['timeSpan'])

    return document

def up(db):
    for name in GA_BUCKETS_TO_MIGRATE:
        collection = db.get_repository(name)

        documents = collection.find({})

        documents = ifilter(is_bst, documents)
        documents = imap(strip_internal_fields, documents)
        documents = imap(fix_timestamp, documents)
        documents = map(create_record, documents)

        if len(documents) > 0:
            log.info("Convert GA timezone: {0}".format(name))

        map(collection.save, documents)

Add migration to convert GA timezone to UTC

We are ignoring the timezone from GA requests so previous data needs to
be converted to account for this.

See https://www.pivotaltracker.com/story/show/62779118 for details.

Response:
<REPLACE_OLD>  <REPLACE_NEW> """
Convert Google Analytics buckets from Europe/London to UTC
"""
import logging
import copy
from itertools import imap, ifilter
from datetime import timedelta

from backdrop.core.records import Record
from backdrop.core.timeutils import utc

log = logging.getLogger(__name__)

GA_BUCKETS_TO_MIGRATE = [
    "carers_allowance_journey",
    "deposit_foreign_marriage_journey",
    "pay_foreign_marriage_certificates_journey",
    "pay_legalisation_drop_off_journey",
    "pay_legalisation_post_journey",
    "pay_register_birth_abroad_journey",
    "pay_register_death_abroad_journey",
    "lpa_journey",
    "licensing_journey",
]

def fix_timestamp(document):
    """Return a new dict with the _timestamp field fixed
    """
    document = copy.deepcopy(document)
    document['_timestamp'] = document['_timestamp'].replace(tzinfo=None) + \
        timedelta(hours=1)
    return document

def strip_internal_fields(document):
    """Return a new dict with all internal fields removed

    Leaves _timestamp and _id in place
    """
    def allowed_field(key):
        return not key.startswith('_') or key in ['_timestamp', '_id']

    return dict(
        (key, value) for key, value in document.items() if allowed_field(key))

def is_bst(document):
    """Return true if a document looks like it's BST"""
    return document['_timestamp'].hour == 23

def create_record(document):
    """Return a dict with internal fields applied"""
    return Record(document).to_mongo()

def fix_id(document):
    """Return a new dict with the _id field recalculated"""
    def _format(timestamp):
        return to_utc(timestamp).strftime("%Y%m%d%H%M%S")

    def data_id(data_type, timestamp, period):
        """_id generation function copied from backdrop-ga-collector"""
        return base64.urlsafe_b64encode("_".join(
            [data_type, _format(timestamp), period]))

    document = copy.deepcopy(document)
    document['_id'] = data_id(
        document['dataType'], document['_timestamp'],
        document['timeSpan'])

    return document

def up(db):
    for name in GA_BUCKETS_TO_MIGRATE:
        collection = db.get_repository(name)

        documents = collection.find({})

        documents = ifilter(is_bst, documents)
        documents = imap(strip_internal_fields, documents)
        documents = imap(fix_timestamp, documents)
        documents = map(create_record, documents)

        if len(documents) > 0:
            log.info("Convert GA timezone: {0}".format(name))

        map(collection.save, documents)
 <REPLACE_END> <|endoftext|> """
Convert Google Analytics buckets from Europe/London to UTC
"""
import logging
import copy
from itertools import imap, ifilter
from datetime import timedelta

from backdrop.core.records import Record
from backdrop.core.timeutils import utc

log = logging.getLogger(__name__)

GA_BUCKETS_TO_MIGRATE = [
    "carers_allowance_journey",
    "deposit_foreign_marriage_journey",
    "pay_foreign_marriage_certificates_journey",
    "pay_legalisation_drop_off_journey",
    "pay_legalisation_post_journey",
    "pay_register_birth_abroad_journey",
    "pay_register_death_abroad_journey",
    "lpa_journey",
    "licensing_journey",
]

def fix_timestamp(document):
    """Return a new dict with the _timestamp field fixed
    """
    document = copy.deepcopy(document)
    document['_timestamp'] = document['_timestamp'].replace(tzinfo=None) + \
        timedelta(hours=1)
    return document

def strip_internal_fields(document):
    """Return a new dict with all internal fields removed

    Leaves _timestamp and _id in place
    """
    def allowed_field(key):
        return not key.startswith('_') or key in ['_timestamp', '_id']

    return dict(
        (key, value) for key, value in document.items() if allowed_field(key))

def is_bst(document):
    """Return true if a document looks like it's BST"""
    return document['_timestamp'].hour == 23

def create_record(document):
    """Return a dict with internal fields applied"""
    return Record(document).to_mongo()

def fix_id(document):
    """Return a new dict with the _id field recalculated"""
    def _format(timestamp):
        return to_utc(timestamp).strftime("%Y%m%d%H%M%S")

    def data_id(data_type, timestamp, period):
        """_id generation function copied from backdrop-ga-collector"""
        return base64.urlsafe_b64encode("_".join(
            [data_type, _format(timestamp), period]))

    document = copy.deepcopy(document)
    document['_id'] = data_id(
        document['dataType'], document['_timestamp'],
        document['timeSpan'])

    return document

def up(db):
    for name in GA_BUCKETS_TO_MIGRATE:
        collection = db.get_repository(name)

        documents = collection.find({})

        documents = ifilter(is_bst, documents)
        documents = imap(strip_internal_fields, documents)
        documents = imap(fix_timestamp, documents)
        documents = map(create_record, documents)

        if len(documents) > 0:
            log.info("Convert GA timezone: {0}".format(name))

        map(collection.save, documents)

Prompt:
Add migration to convert GA timezone to UTC

We are ignoring the timezone from GA requests so previous data needs to
be converted to account for this.

See https://www.pivotaltracker.com/story/show/62779118 for details.


"""
dialogKit: easy bake dialogs
"""

# determine the environment
haveFL = False
haveVanilla = False
try:
    import FL
    haveFL = True
except ImportError:
    pass
if not haveFL:
    try:
        import vanilla
        haveVanilla = True
    except ImportError:
        pass
# perform the environment specific import
if haveFL:
    from _dkFL import *
elif haveVanilla:
    from _dkVanilla import *
else:
    raise ImportError, 'dialogKit is not available in this environment'

numberVersion = (0, 0, "beta", 1)
version = "0.0.1b"

Response:
<REPLACE_OLD> environment
try:
 <REPLACE_NEW> environment
haveFL = False
haveVanilla = False
try:
 <REPLACE_END> <REPLACE_OLD> haveFL = False
try:
 <REPLACE_NEW> pass
if not haveFL:
    try:
     <REPLACE_END> <REPLACE_OLD> haveVanilla = True
except ImportError:
 <REPLACE_NEW>  <REPLACE_END> <REPLACE_OLD> False
# <REPLACE_NEW> True
    except ImportError:
        pass
# <REPLACE_END> <REPLACE_OLD> *
if <REPLACE_NEW> *
elif <REPLACE_END> <|endoftext|> """
dialogKit: easy bake dialogs
"""

# determine the environment
haveFL = False
haveVanilla = False
try:
    import FL
    haveFL = True
except ImportError:
    pass
if not haveFL:
    try:
        import vanilla
        haveVanilla = True
    except ImportError:
        pass
# perform the environment specific import
if haveFL:
    from _dkFL import *
elif haveVanilla:
    from _dkVanilla import *
else:
    raise ImportError, 'dialogKit is not available in this environment'

numberVersion = (0, 0, "beta", 1)
version = "0.0.1b"

Prompt:
Stop trying imports after something has been successfully loaded.

"""
dialogKit: easy bake dialogs
"""

# determine the environment
try:
    import FL
    haveFL = True
except ImportError:
    haveFL = False
try:
    import vanilla
    haveVanilla = True
except ImportError:
    haveVanilla = False
# perform the environment specific import
if haveFL:
    from _dkFL import *
if haveVanilla:
    from _dkVanilla import *
else:
    raise ImportError, 'dialogKit is not available in this environment'

numberVersion = (0, 0, "beta", 1)
version = "0.0.1b"


__author__ = 'katharine'

import sys
from setuptools import setup, find_packages

requires = [
  'backports.ssl-match-hostname==3.4.0.2',
  'gevent>=1.1b5',
  'gevent-websocket==0.9.3',
  'greenlet==0.4.9',
  'peewee==2.4.7',
  'pygeoip==0.3.2',
  'pypng==0.0.17',
  'python-dateutil==2.4.1',
  'requests==2.5.0',
  'sh==1.09',
  'six==1.9.0',
  'websocket-client==0.31.0',
  'wsgiref==0.1.2',
  'libpebble2==0.0.12',
  'netaddr==0.7.18'
]

setup(name='pypkjs',
      version='3.6',
      description='PebbleKit JS in Python!',
      url='https://github.com/pebble/pypkjs',
      author='Pebble Technology Corporation',
      author_email='katharine@pebble.com',
      license='MIT',
      packages=find_packages(),
      install_requires=requires,
      entry_points={
          'console_scripts': [
            'pypkjs=runner.websocket:run_tool'
          ],
      })

Response:
<REPLACE_OLD> 'netaddr==0.7.18'
]

packages = find_packages()
print packages

setup(name='pypkjs',
 <REPLACE_NEW> 'netaddr==0.7.18'
]

setup(name='pypkjs',
 <REPLACE_END> <REPLACE_OLD> packages=packages,
 <REPLACE_NEW> packages=find_packages(),
 <REPLACE_END> <REPLACE_OLD> },
      zip_safe=True)
 <REPLACE_NEW> })
 <REPLACE_END> <|endoftext|> __author__ = 'katharine'

import sys
from setuptools import setup, find_packages

requires = [
  'backports.ssl-match-hostname==3.4.0.2',
  'gevent>=1.1b5',
  'gevent-websocket==0.9.3',
  'greenlet==0.4.9',
  'peewee==2.4.7',
  'pygeoip==0.3.2',
  'pypng==0.0.17',
  'python-dateutil==2.4.1',
  'requests==2.5.0',
  'sh==1.09',
  'six==1.9.0',
  'websocket-client==0.31.0',
  'wsgiref==0.1.2',
  'libpebble2==0.0.12',
  'netaddr==0.7.18'
]

setup(name='pypkjs',
      version='3.6',
      description='PebbleKit JS in Python!',
      url='https://github.com/pebble/pypkjs',
      author='Pebble Technology Corporation',
      author_email='katharine@pebble.com',
      license='MIT',
      packages=find_packages(),
      install_requires=requires,
      entry_points={
          'console_scripts': [
            'pypkjs=runner.websocket:run_tool'
          ],
      })

Prompt:
Address review comments, remove zip_safe=True because GeoIP

__author__ = 'katharine'

import sys
from setuptools import setup, find_packages

requires = [
  'backports.ssl-match-hostname==3.4.0.2',
  'gevent>=1.1b5',
  'gevent-websocket==0.9.3',
  'greenlet==0.4.9',
  'peewee==2.4.7',
  'pygeoip==0.3.2',
  'pypng==0.0.17',
  'python-dateutil==2.4.1',
  'requests==2.5.0',
  'sh==1.09',
  'six==1.9.0',
  'websocket-client==0.31.0',
  'wsgiref==0.1.2',
  'libpebble2==0.0.12',
  'netaddr==0.7.18'
]

packages = find_packages()
print packages

setup(name='pypkjs',
      version='3.6',
      description='PebbleKit JS in Python!',
      url='https://github.com/pebble/pypkjs',
      author='Pebble Technology Corporation',
      author_email='katharine@pebble.com',
      license='MIT',
      packages=packages,
      install_requires=requires,
      entry_points={
          'console_scripts': [
            'pypkjs=runner.websocket:run_tool'
          ],
      },
      zip_safe=True)


import os
import re

def hdfs_make_qualified(path):
    return path if (re.match(r'[.]*://[.]*', path) or 'CF_HADOOP_DEFAULT_FS' not in os.environ) \
        else os.environ['CF_HADOOP_DEFAULT_FS'] + path

Response:
<REPLACE_OLD> os

def <REPLACE_NEW> os
import re

def <REPLACE_END> <INSERT> (re.match(r'[.]*://[.]*', path) or <INSERT_END> <REPLACE_OLD> os.environ <REPLACE_NEW> os.environ) \
        <REPLACE_END> <|endoftext|> import os
import re

def hdfs_make_qualified(path):
    return path if (re.match(r'[.]*://[.]*', path) or 'CF_HADOOP_DEFAULT_FS' not in os.environ) \
        else os.environ['CF_HADOOP_DEFAULT_FS'] + path

Prompt:
Update python script util to detect if paths are already fully qualified

import os

def hdfs_make_qualified(path):
    return path if 'CF_HADOOP_DEFAULT_FS' not in os.environ else os.environ['CF_HADOOP_DEFAULT_FS'] + path


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

"""python-keystoneclient's pep8 extensions.

In order to make the review process faster and easier for core devs we are
adding some python-keystoneclient specific pep8 checks. This will catch common
errors so that core devs don't have to.

"""

import re

def check_oslo_namespace_imports(logical_line, blank_before, filename):
    oslo_namespace_imports = re.compile(
        r"(((from)|(import))\s+oslo\.)|(from\s+oslo\s+import\s+)")

    if re.match(oslo_namespace_imports, logical_line):
        msg = ("K333: '%s' must be used instead of '%s'.") % (
            logical_line.replace('oslo.', 'oslo_'),
            logical_line)
        yield(0, msg)

def factory(register):
    register(check_oslo_namespace_imports)

Response:
<REPLACE_OLD> r"(((from)|(import))\s+oslo\."
        "((config)|(serialization)|(utils)|(i18n)))|"
        "(from\s+oslo\s+import\s+((config)|(serialization)|(utils)|(i18n)))")

 <REPLACE_NEW> r"(((from)|(import))\s+oslo\.)|(from\s+oslo\s+import\s+)")

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

"""python-keystoneclient's pep8 extensions.

In order to make the review process faster and easier for core devs we are
adding some python-keystoneclient specific pep8 checks. This will catch common
errors so that core devs don't have to.

"""

import re

def check_oslo_namespace_imports(logical_line, blank_before, filename):
    oslo_namespace_imports = re.compile(
        r"(((from)|(import))\s+oslo\.)|(from\s+oslo\s+import\s+)")

    if re.match(oslo_namespace_imports, logical_line):
        msg = ("K333: '%s' must be used instead of '%s'.") % (
            logical_line.replace('oslo.', 'oslo_'),
            logical_line)
        yield(0, msg)

def factory(register):
    register(check_oslo_namespace_imports)

Prompt:
Change hacking check to verify all oslo imports

The hacking check was verifying that specific oslo imports
weren't using the oslo-namespaced package. Since all the oslo
libraries used by keystoneclient are now changed to use the
new package name the hacking check can be simplified.

bp drop-namespace-packages

Change-Id: I6466e857c6eda0add6918e9fb14dc9296ed98600

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

"""python-keystoneclient's pep8 extensions.

In order to make the review process faster and easier for core devs we are
adding some python-keystoneclient specific pep8 checks. This will catch common
errors so that core devs don't have to.

"""

import re

def check_oslo_namespace_imports(logical_line, blank_before, filename):
    oslo_namespace_imports = re.compile(
        r"(((from)|(import))\s+oslo\."
        "((config)|(serialization)|(utils)|(i18n)))|"
        "(from\s+oslo\s+import\s+((config)|(serialization)|(utils)|(i18n)))")

    if re.match(oslo_namespace_imports, logical_line):
        msg = ("K333: '%s' must be used instead of '%s'.") % (
            logical_line.replace('oslo.', 'oslo_'),
            logical_line)
        yield(0, msg)

def factory(register):
    register(check_oslo_namespace_imports)


import os
from setuptools import setup

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
    README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
    name='django-argcache',
    version='0.1',
    license='AGPLv3',
    description='A function-level caching and invalidaton framework for Django.',
    long_description=README,
    url='https://github.com/luac/django-argcache/',
    author='Anthony Lu',
    author_email='lua@mit.edu',
    packages=[
        'argcache',
        'argcache.extras',
    ],
    package_dir={
        'argcache': 'src'
    },
    include_package_data=True,
    install_requires=[
        'django>=1.7',
    ],
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: License :: OSI Approved :: GNU Affero General Public License v3',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ],
)

Fix typo in package description

Fix typo in package description

Response:
<REPLACE_OLD> fraemwork <REPLACE_NEW> framework <REPLACE_END> <|endoftext|> import os
from setuptools import setup

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
    README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
    name='django-argcache',
    version='0.1',
    license='AGPLv3',
    description='A function-level caching and invalidaton framework for Django.',
    long_description=README,
    url='https://github.com/luac/django-argcache/',
    author='Anthony Lu',
    author_email='lua@mit.edu',
    packages=[
        'argcache',
        'argcache.extras',
    ],
    package_dir={
        'argcache': 'src'
    },
    include_package_data=True,
    install_requires=[
        'django>=1.7',
    ],
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: License :: OSI Approved :: GNU Affero General Public License v3',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ],
)

Prompt:
Fix typo in package description

import os
from setuptools import setup

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
    README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
    name='django-argcache',
    version='0.1',
    license='AGPLv3',
    description='A function-level caching and invalidaton fraemwork for Django.',
    long_description=README,
    url='https://github.com/luac/django-argcache/',
    author='Anthony Lu',
    author_email='lua@mit.edu',
    packages=[
        'argcache',
        'argcache.extras',
    ],
    package_dir={
        'argcache': 'src'
    },
    include_package_data=True,
    install_requires=[
        'django>=1.7',
    ],
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: License :: OSI Approved :: GNU Affero General Public License v3',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ],
)


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

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('zerver', '0030_realm_org_type'),
    ]

    operations = [
        migrations.AlterField(
            model_name='userprofile',
            name='avatar_source',
            field=models.CharField(choices=[('G', 'Hosted by Gravatar'), ('U', 'Uploaded by user')], max_length=1, default='G'),
        ),
    ]

Add migration to remove system avatar source.

Fixes the last commit having broken master.

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

from django.db import migrations, models

class Migration(migrations.Migration):

 <INSERT_END> <INSERT>   dependencies = [
        ('zerver', '0030_realm_org_type'),
    ]

    operations = [
        migrations.AlterField(
            model_name='userprofile',
            name='avatar_source',
            field=models.CharField(choices=[('G', 'Hosted by Gravatar'), ('U', 'Uploaded by user')], max_length=1, default='G'),
        ),
    ]
 <INSERT_END> <|endoftext|> # -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('zerver', '0030_realm_org_type'),
    ]

    operations = [
        migrations.AlterField(
            model_name='userprofile',
            name='avatar_source',
            field=models.CharField(choices=[('G', 'Hosted by Gravatar'), ('U', 'Uploaded by user')], max_length=1, default='G'),
        ),
    ]

Prompt:
Add migration to remove system avatar source.

Fixes the last commit having broken master.


# -*- coding: utf-8 -*-
"""
h2/frame_buffer
~~~~~~~~~~~~~~~

A data structure that provides a way to iterate over a byte buffer in terms of
frames.
"""
from hyperframe.frame import Frame

class FrameBuffer(object):
    """
    This is a data structure that expects to act as a buffer for HTTP/2 data
    that allows iteraton in terms of H2 frames.
    """
    def __init__(self, server=False):
        self.data = b''
        self.preamble_len = (
            len(b'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n') if server else 0
        )

    def add_data(self, data):
        """
        Add more data to the frame buffer.

        :param data: A bytestring containing the byte buffer.
        """
        if self.preamble_len:
            data_len = len(data)
            data = data[self.preamble_len:]
            self.preamble_len -= min(data_len, self.preamble_len)

        self.data += data

    def __iter__(self):
        return self

    def next(self):
        if len(self.data) < 9:
            raise StopIteration()

        f, length = Frame.parse_frame_header(self.data[:9])
        if len(self.data) < length + 9:
            raise StopIteration()

        f.parse_body(memoryview(self.data[9:9+length]))
        self.data = self.data[9+length:]
        return f

Define an iterable frame buffer.

Define an iterable frame buffer.

Response:
<REPLACE_OLD>  <REPLACE_NEW> # -*- coding: utf-8 -*-
"""
h2/frame_buffer
~~~~~~~~~~~~~~~

A data structure that provides a way to iterate over a byte buffer in terms of
frames.
"""
from hyperframe.frame import Frame

class FrameBuffer(object):
    """
    This is a data structure that expects to act as a buffer for HTTP/2 data
    that allows iteraton in terms of H2 frames.
    """
    def __init__(self, server=False):
        self.data = b''
        self.preamble_len = (
            len(b'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n') if server else 0
        )

    def add_data(self, data):
        """
        Add more data to the frame buffer.

        :param data: A bytestring containing the byte buffer.
        """
        if self.preamble_len:
            data_len = len(data)
            data = data[self.preamble_len:]
            self.preamble_len -= min(data_len, self.preamble_len)

        self.data += data

    def __iter__(self):
        return self

    def next(self):
        if len(self.data) < 9:
            raise StopIteration()

        f, length = Frame.parse_frame_header(self.data[:9])
        if len(self.data) < length + 9:
            raise StopIteration()

        f.parse_body(memoryview(self.data[9:9+length]))
        self.data = self.data[9+length:]
        return f
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
"""
h2/frame_buffer
~~~~~~~~~~~~~~~

A data structure that provides a way to iterate over a byte buffer in terms of
frames.
"""
from hyperframe.frame import Frame

class FrameBuffer(object):
    """
    This is a data structure that expects to act as a buffer for HTTP/2 data
    that allows iteraton in terms of H2 frames.
    """
    def __init__(self, server=False):
        self.data = b''
        self.preamble_len = (
            len(b'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n') if server else 0
        )

    def add_data(self, data):
        """
        Add more data to the frame buffer.

        :param data: A bytestring containing the byte buffer.
        """
        if self.preamble_len:
            data_len = len(data)
            data = data[self.preamble_len:]
            self.preamble_len -= min(data_len, self.preamble_len)

        self.data += data

    def __iter__(self):
        return self

    def next(self):
        if len(self.data) < 9:
            raise StopIteration()

        f, length = Frame.parse_frame_header(self.data[:9])
        if len(self.data) < length + 9:
            raise StopIteration()

        f.parse_body(memoryview(self.data[9:9+length]))
        self.data = self.data[9+length:]
        return f

Prompt: Define an iterable frame buffer.


#!/usr/bin/python3
import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()

class Member(Base):
    __tablename__ = 'member'

    id = Column(Integer, primary_key=True)
    globalName = Column(String(250), nullable=True)
    nickname = Column(String(250), nullable=True)
    role = Column(String(250), nullable=True)
    points = Column(Integer, nullable=True)

    def __init__(self,id,globalAccountName,serverNickname,role,points):
        self.id = id
        self.globalAccountName = globalAccountName
        self.serverNickname = serverNickname
        self.role = role
        self.points = points

#Display member method.
    def displayMember(self):
        print ("ID:", self.id, "GlobalAccount:", self.globalName, "Nickname:", self.Nickname, "Role:", self.role, "Points:", self.points)

#Example of creating one object, changing value of an object and displaying an object using a method.
'''mem1 = Member(43344454,"larry","doessuck","officer",150)

mem1.globalAccountName="Jack"

mem1.displayMember()'''

engine = create_engine('sqlite:///bayohwoolph.db')

Base.metadata.create_all(engine)

Make globalName nullable for now.

Make globalName nullable for now.

Response:
<REPLACE_OLD> nullable=False)
 <REPLACE_NEW> nullable=True)
 <REPLACE_END> <REPLACE_OLD> create_engine('sqlite:///bayohwoolph.db')

Base.metadata.create_all(engine) <REPLACE_NEW> create_engine('sqlite:///bayohwoolph.db')

Base.metadata.create_all(engine)
 <REPLACE_END> <|endoftext|> #!/usr/bin/python3
import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()

class Member(Base):
    __tablename__ = 'member'

    id = Column(Integer, primary_key=True)
    globalName = Column(String(250), nullable=True)
    nickname = Column(String(250), nullable=True)
    role = Column(String(250), nullable=True)
    points = Column(Integer, nullable=True)

    def __init__(self,id,globalAccountName,serverNickname,role,points):
        self.id = id
        self.globalAccountName = globalAccountName
        self.serverNickname = serverNickname
        self.role = role
        self.points = points

#Display member method.
    def displayMember(self):
        print ("ID:", self.id, "GlobalAccount:", self.globalName, "Nickname:", self.Nickname, "Role:", self.role, "Points:", self.points)

#Example of creating one object, changing value of an object and displaying an object using a method.
'''mem1 = Member(43344454,"larry","doessuck","officer",150)

mem1.globalAccountName="Jack"

mem1.displayMember()'''

engine = create_engine('sqlite:///bayohwoolph.db')

Base.metadata.create_all(engine)

Prompt:
Make globalName nullable for now.

#!/usr/bin/python3
import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()

class Member(Base):
    __tablename__ = 'member'

    id = Column(Integer, primary_key=True)
    globalName = Column(String(250), nullable=False)
    nickname = Column(String(250), nullable=True)
    role = Column(String(250), nullable=True)
    points = Column(Integer, nullable=True)

    def __init__(self,id,globalAccountName,serverNickname,role,points):
        self.id = id
        self.globalAccountName = globalAccountName
        self.serverNickname = serverNickname
        self.role = role
        self.points = points

#Display member method.
    def displayMember(self):
        print ("ID:", self.id, "GlobalAccount:", self.globalName, "Nickname:", self.Nickname, "Role:", self.role, "Points:", self.points)

#Example of creating one object, changing value of an object and displaying an object using a method.
'''mem1 = Member(43344454,"larry","doessuck","officer",150)

mem1.globalAccountName="Jack"

mem1.displayMember()'''

engine = create_engine('sqlite:///bayohwoolph.db')

Base.metadata.create_all(engine)


__doc__ = """
Manipulate audio with an simple and easy high level interface.

See the README file for details, usage info, and a list of gotchas.
"""

from setuptools import setup

setup(
    name='pydub',
    version='0.16.4',
    author='James Robert',
    author_email='jiaaro@gmail.com',
    description='Manipulate audio with an simple and easy high level interface',
    license='MIT',
    keywords='audio sound high-level',
    url='http://pydub.com',
    packages=['pydub'],
    long_description=__doc__,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        "Topic :: Multimedia :: Sound/Audio",
        "Topic :: Multimedia :: Sound/Audio :: Analysis",
        "Topic :: Multimedia :: Sound/Audio :: Conversion",
        "Topic :: Multimedia :: Sound/Audio :: Editors",
        "Topic :: Multimedia :: Sound/Audio :: Mixers",
        "Topic :: Software Development :: Libraries",
        'Topic :: Utilities',
    ]
)

Response:
<REPLACE_OLD> version='0.16.3',
 <REPLACE_NEW> version='0.16.4',
 <REPLACE_END> <|endoftext|> __doc__ = """
Manipulate audio with an simple and easy high level interface.

See the README file for details, usage info, and a list of gotchas.
"""

from setuptools import setup

setup(
    name='pydub',
    version='0.16.4',
    author='James Robert',
    author_email='jiaaro@gmail.com',
    description='Manipulate audio with an simple and easy high level interface',
    license='MIT',
    keywords='audio sound high-level',
    url='http://pydub.com',
    packages=['pydub'],
    long_description=__doc__,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        "Topic :: Multimedia :: Sound/Audio",
        "Topic :: Multimedia :: Sound/Audio :: Analysis",
        "Topic :: Multimedia :: Sound/Audio :: Conversion",
        "Topic :: Multimedia :: Sound/Audio :: Editors",
        "Topic :: Multimedia :: Sound/Audio :: Mixers",
        "Topic :: Software Development :: Libraries",
        'Topic :: Utilities',
    ]
)

Prompt:
Increment version for 24-bit wav bug fix
__doc__ = """
Manipulate audio with an simple and easy high level interface.

See the README file for details, usage info, and a list of gotchas.
"""

from setuptools import setup

setup(
    name='pydub',
    version='0.16.3',
    author='James Robert',
    author_email='jiaaro@gmail.com',
    description='Manipulate audio with an simple and easy high level interface',
    license='MIT',
    keywords='audio sound high-level',
    url='http://pydub.com',
    packages=['pydub'],
    long_description=__doc__,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        "Topic :: Multimedia :: Sound/Audio",
        "Topic :: Multimedia :: Sound/Audio :: Analysis",
        "Topic :: Multimedia :: Sound/Audio :: Conversion",
        "Topic :: Multimedia :: Sound/Audio :: Editors",
        "Topic :: Multimedia :: Sound/Audio :: Mixers",
        "Topic :: Software Development :: Libraries",
        'Topic :: Utilities',
    ]
)


"""
Project

:Authors:
	Berend Klein Haneveld
"""

class Project(object):
	"""
	Project holds the basic information of a project for RegistrationShop
	"""

	def __init__(self, title=None, fixedData=None, movingData=None, isReference=None):
		super(Project, self).__init__()

		self.title = title
		self.fixedData = fixedData
		self.movingData = movingData
		self.isReference = isReference
		self.folder = None
		self.resultData = None
		self.fixedSettings = None
		self.movingSettings = None
		self.multiSettings = None
		self.transformations = None

	def __eq__(self, other):
		if not isinstance(other, Project):
			return False
		return (self.title == other.title
			and self.fixedData == other.fixedData
			and self.movingData == other.movingData
			and self.isReference == other.isReference)

	def __ne__(self, other):
		return not self.__eq__(other)

Response:
<INSERT> None
		self.transformations = <INSERT_END> <|endoftext|> """
Project

:Authors:
	Berend Klein Haneveld
"""

class Project(object):
	"""
	Project holds the basic information of a project for RegistrationShop
	"""

	def __init__(self, title=None, fixedData=None, movingData=None, isReference=None):
		super(Project, self).__init__()

		self.title = title
		self.fixedData = fixedData
		self.movingData = movingData
		self.isReference = isReference
		self.folder = None
		self.resultData = None
		self.fixedSettings = None
		self.movingSettings = None
		self.multiSettings = None
		self.transformations = None

	def __eq__(self, other):
		if not isinstance(other, Project):
			return False
		return (self.title == other.title
			and self.fixedData == other.fixedData
			and self.movingData == other.movingData
			and self.isReference == other.isReference)

	def __ne__(self, other):
		return not self.__eq__(other)

Prompt:
Add transformations property to projects.

"""
Project

:Authors:
	Berend Klein Haneveld
"""

class Project(object):
	"""
	Project holds the basic information of a project for RegistrationShop
	"""

	def __init__(self, title=None, fixedData=None, movingData=None, isReference=None):
		super(Project, self).__init__()

		self.title = title
		self.fixedData = fixedData
		self.movingData = movingData
		self.isReference = isReference
		self.folder = None
		self.resultData = None
		self.fixedSettings = None
		self.movingSettings = None
		self.multiSettings = None

	def __eq__(self, other):
		if not isinstance(other, Project):
			return False
		return (self.title == other.title
			and self.fixedData == other.fixedData
			and self.movingData == other.movingData
			and self.isReference == other.isReference)

	def __ne__(self, other):
		return not self.__eq__(other)


class APIObject(object):

    def __init__(self, client, json_data):
        super(APIObject, self).__init__()
        self.client = client
        self._data = json_data

    def __eq__(self, other):
        if not isinstance(other, APIObject):
            return NotImplemented
        return self.client is other.client and self._data == other._data

    def __ne__(self, other):
        return not (self == other)

    def __getattr__(self, name):
        try:
            return self.__dict__['_data'][name]
        except KeyError:
            raise AttributeError(name)

    def refresh(self):
        self._data = self._fetch()
        return self

    def _fetch(self):
        return self.client.api.get(self.api_path, raw=True)[self._data['type']]

    def __repr__(self):
        return '<API:{data[type]}:{data[id]}>'.format(data=self._data)

Response:
<REPLACE_OLD> self._fetch()

 <REPLACE_NEW> self._fetch()
        return self

 <REPLACE_END> <|endoftext|>
class APIObject(object):

    def __init__(self, client, json_data):
        super(APIObject, self).__init__()
        self.client = client
        self._data = json_data

    def __eq__(self, other):
        if not isinstance(other, APIObject):
            return NotImplemented
        return self.client is other.client and self._data == other._data

    def __ne__(self, other):
        return not (self == other)

    def __getattr__(self, name):
        try:
            return self.__dict__['_data'][name]
        except KeyError:
            raise AttributeError(name)

    def refresh(self):
        self._data = self._fetch()
        return self

    def _fetch(self):
        return self.client.api.get(self.api_path, raw=True)[self._data['type']]

    def __repr__(self):
        return '<API:{data[type]}:{data[id]}>'.format(data=self._data)

Prompt:
Make `refresh` return self for chaining actions

class APIObject(object):

    def __init__(self, client, json_data):
        super(APIObject, self).__init__()
        self.client = client
        self._data = json_data

    def __eq__(self, other):
        if not isinstance(other, APIObject):
            return NotImplemented
        return self.client is other.client and self._data == other._data

    def __ne__(self, other):
        return not (self == other)

    def __getattr__(self, name):
        try:
            return self.__dict__['_data'][name]
        except KeyError:
            raise AttributeError(name)

    def refresh(self):
        self._data = self._fetch()

    def _fetch(self):
        return self.client.api.get(self.api_path, raw=True)[self._data['type']]

    def __repr__(self):
        return '<API:{data[type]}:{data[id]}>'.format(data=self._data)


#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from selenium import webdriver

def before_feature(context, feature):
    #context.browser = webdriver.Firefox()
    context.browser = webdriver.PhantomJS()
    context.browser.set_window_size(1280, 1024)
    context.browser.implicitly_wait(5)
    context.browser.set_page_load_timeout(60) # wait for data
    context.browser.get('http://localhost:4567/')

def after_feature(context, feature):
    context.browser.quit()

def take_screenshot(context):
    context.browser.save_screenshot('/tmp/screenshot.jpeg')

def save_source(context):
    with open('/tmp/source.html', 'w') as out:
        out.write(context.browser.page_source.encode('utf8'))

Response:
<REPLACE_OLD> context.browser.implicitly_wait(10)
 <REPLACE_NEW> context.browser.implicitly_wait(5)
 <REPLACE_END> <REPLACE_OLD> context.browser.set_page_load_timeout(120) <REPLACE_NEW> context.browser.set_page_load_timeout(60) <REPLACE_END> <|endoftext|> #
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from selenium import webdriver

def before_feature(context, feature):
    #context.browser = webdriver.Firefox()
    context.browser = webdriver.PhantomJS()
    context.browser.set_window_size(1280, 1024)
    context.browser.implicitly_wait(5)
    context.browser.set_page_load_timeout(60) # wait for data
    context.browser.get('http://localhost:4567/')

def after_feature(context, feature):
    context.browser.quit()

def take_screenshot(context):
    context.browser.save_screenshot('/tmp/screenshot.jpeg')

def save_source(context):
    with open('/tmp/source.html', 'w') as out:
        out.write(context.browser.page_source.encode('utf8'))

Prompt:
Revert "increasing webdriver timeout on fake-service"

This reverts commit a39a4b40a947db655c84af6eb62d5870cfd8b32c.

#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from selenium import webdriver

def before_feature(context, feature):
    #context.browser = webdriver.Firefox()
    context.browser = webdriver.PhantomJS()
    context.browser.set_window_size(1280, 1024)
    context.browser.implicitly_wait(10)
    context.browser.set_page_load_timeout(120) # wait for data
    context.browser.get('http://localhost:4567/')

def after_feature(context, feature):
    context.browser.quit()

def take_screenshot(context):
    context.browser.save_screenshot('/tmp/screenshot.jpeg')

def save_source(context):
    with open('/tmp/source.html', 'w') as out:
        out.write(context.browser.page_source.encode('utf8'))


from collections import deque
from peewee import *

db = SqliteDatabase(':memory:')

class TreeNode(Model):
    parent = ForeignKeyField('self', backref='children', null=True)
    name = TextField()

    class Meta:
        database = db

    def __str__(self):
        return 'name=%s' % self.name

    def dump(self, _indent=0):
        return ('  ' * _indent + repr(self) + '\n' +
                ''.join(c.dump(_indent + 1) for c in self.children))

if __name__ == '__main__':
    db.create_tables([TreeNode])
    tree = (
        'root', (
            ('node-1', (
                ('sub-1-1', ()),
                ('sub-1-2', ()))),
            ('node-2', (
                ('sub-2-1', (
                    ('sub-sub-2-1-1', ()),
                    ('sub-sub-2-1-2', ()))),
                ('sub-2-2', (
                    ('sub-sub-2-2-1', ()),
                    ('sub-sub-2-2-2', ()))))),
            ('node-3', ()),
            ('node-4', (
                ('sub-4-1', ()),
                ('sub-4-2', ()),
                ('sub-4-3', ()),
                ('sub-4-4', ())))))

    with db.atomic():
        stack = deque([(None, tree)])
        while stack:
            parent, t = stack.pop()
            name, children = t
            node = TreeNode.create(name=name, parent=parent)
            for childdef in children:
                stack.appendleft((node, childdef))

    root = TreeNode.get(name='root')
    print(root.dump())

Add adjacency list example. Compare to SQA's.

[skip ci]

Response:
<REPLACE_OLD>  <REPLACE_NEW> from collections import deque
from peewee import *

db = SqliteDatabase(':memory:')

class TreeNode(Model):
    parent = ForeignKeyField('self', backref='children', null=True)
    name = TextField()

    class Meta:
        database = db

    def __str__(self):
        return 'name=%s' % self.name

    def dump(self, _indent=0):
        return ('  ' * _indent + repr(self) + '\n' +
                ''.join(c.dump(_indent + 1) for c in self.children))

if __name__ == '__main__':
    db.create_tables([TreeNode])
    tree = (
        'root', (
            ('node-1', (
                ('sub-1-1', ()),
                ('sub-1-2', ()))),
            ('node-2', (
                ('sub-2-1', (
                    ('sub-sub-2-1-1', ()),
                    ('sub-sub-2-1-2', ()))),
                ('sub-2-2', (
                    ('sub-sub-2-2-1', ()),
                    ('sub-sub-2-2-2', ()))))),
            ('node-3', ()),
            ('node-4', (
                ('sub-4-1', ()),
                ('sub-4-2', ()),
                ('sub-4-3', ()),
                ('sub-4-4', ())))))

    with db.atomic():
        stack = deque([(None, tree)])
        while stack:
            parent, t = stack.pop()
            name, children = t
            node = TreeNode.create(name=name, parent=parent)
            for childdef in children:
                stack.appendleft((node, childdef))

    root = TreeNode.get(name='root')
    print(root.dump())
 <REPLACE_END> <|endoftext|> from collections import deque
from peewee import *

db = SqliteDatabase(':memory:')

class TreeNode(Model):
    parent = ForeignKeyField('self', backref='children', null=True)
    name = TextField()

    class Meta:
        database = db

    def __str__(self):
        return 'name=%s' % self.name

    def dump(self, _indent=0):
        return ('  ' * _indent + repr(self) + '\n' +
                ''.join(c.dump(_indent + 1) for c in self.children))

if __name__ == '__main__':
    db.create_tables([TreeNode])
    tree = (
        'root', (
            ('node-1', (
                ('sub-1-1', ()),
                ('sub-1-2', ()))),
            ('node-2', (
                ('sub-2-1', (
                    ('sub-sub-2-1-1', ()),
                    ('sub-sub-2-1-2', ()))),
                ('sub-2-2', (
                    ('sub-sub-2-2-1', ()),
                    ('sub-sub-2-2-2', ()))))),
            ('node-3', ()),
            ('node-4', (
                ('sub-4-1', ()),
                ('sub-4-2', ()),
                ('sub-4-3', ()),
                ('sub-4-4', ())))))

    with db.atomic():
        stack = deque([(None, tree)])
        while stack:
            parent, t = stack.pop()
            name, children = t
            node = TreeNode.create(name=name, parent=parent)
            for childdef in children:
                stack.appendleft((node, childdef))

    root = TreeNode.get(name='root')
    print(root.dump())

Prompt:
Add adjacency list example. Compare to SQA's.

[skip ci]


#!/usr/bin/env python

import multiprocessing
import optparse

from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module

from hurricane.utils import run_until_stopped

class ApplicationManager(object):
    @run_until_stopped
    def run(self):
        parser = optparse.OptionParser()
        parser.add_option('--settings', dest='settings')

        options, args = parser.parse_args()
        if not options.settings:
            raise ImproperlyConfigured("You didn't provide a settings module.")
        settings = import_module(options.settings)
        django_settings.configure(settings)

        self.producer_queue = multiprocessing.Queue()

        for producer in settings.PRODUCERS:
            ProducerClass = import_module(producer).Producer
            producer = ProducerClass(settings, self.producer_queue)
            multiprocessing.Process(target=producer.run).start()

        self.receiver_queues = []

        for consumer in settings.CONSUMERS:
            ConsumerClass = import_module(consumer).Consumer
            recv_queue = multiprocessing.Queue()
            consumer = ConsumerClass(settings, recv_queue)
            self.receiver_queues.append(recv_queue)
            multiprocessing.Process(target=consumer.run).start()

        while True:
            item = self.producer_queue.get()
            for recv_queue in self.receiver_queues:
                recv_queue.put(item)

if __name__ == '__main__':
    app = ApplicationManager()
    app.run()

Response:
<INSERT> django.conf import settings as django_settings
from <INSERT_END> <INSERT> django_settings.configure(settings)
        <INSERT_END> <|endoftext|> #!/usr/bin/env python

import multiprocessing
import optparse

from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module

from hurricane.utils import run_until_stopped

class ApplicationManager(object):
    @run_until_stopped
    def run(self):
        parser = optparse.OptionParser()
        parser.add_option('--settings', dest='settings')

        options, args = parser.parse_args()
        if not options.settings:
            raise ImproperlyConfigured("You didn't provide a settings module.")
        settings = import_module(options.settings)
        django_settings.configure(settings)

        self.producer_queue = multiprocessing.Queue()

        for producer in settings.PRODUCERS:
            ProducerClass = import_module(producer).Producer
            producer = ProducerClass(settings, self.producer_queue)
            multiprocessing.Process(target=producer.run).start()

        self.receiver_queues = []

        for consumer in settings.CONSUMERS:
            ConsumerClass = import_module(consumer).Consumer
            recv_queue = multiprocessing.Queue()
            consumer = ConsumerClass(settings, recv_queue)
            self.receiver_queues.append(recv_queue)
            multiprocessing.Process(target=consumer.run).start()

        while True:
            item = self.producer_queue.get()
            for recv_queue in self.receiver_queues:
                recv_queue.put(item)

if __name__ == '__main__':
    app = ApplicationManager()
    app.run()

Prompt:
Configure django correctly when we setup our env

#!/usr/bin/env python

import multiprocessing
import optparse

from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module

from hurricane.utils import run_until_stopped

class ApplicationManager(object):
    @run_until_stopped
    def run(self):
        parser = optparse.OptionParser()
        parser.add_option('--settings', dest='settings')

        options, args = parser.parse_args()
        if not options.settings:
            raise ImproperlyConfigured("You didn't provide a settings module.")
        settings = import_module(options.settings)

        self.producer_queue = multiprocessing.Queue()

        for producer in settings.PRODUCERS:
            ProducerClass = import_module(producer).Producer
            producer = ProducerClass(settings, self.producer_queue)
            multiprocessing.Process(target=producer.run).start()

        self.receiver_queues = []

        for consumer in settings.CONSUMERS:
            ConsumerClass = import_module(consumer).Consumer
            recv_queue = multiprocessing.Queue()
            consumer = ConsumerClass(settings, recv_queue)
            self.receiver_queues.append(recv_queue)
            multiprocessing.Process(target=consumer.run).start()

        while True:
            item = self.producer_queue.get()
            for recv_queue in self.receiver_queues:
                recv_queue.put(item)

if __name__ == '__main__':
    app = ApplicationManager()
    app.run()


from scriptcwl import WorkflowGenerator as WFGenerator

from .utils import CWL_PATH

class WorkflowGenerator(WFGenerator):
    def __init__(self, working_dir=None):
        WFGenerator.__init__(self, steps_dir=CWL_PATH, working_dir=working_dir)

    def save(self, fname, validate=True, wd=True, inline=False, relative=False,
             pack=False, encoding='utf-8'):
        """Save workflow to file

        For nlppln, the default is to use a working directory (and save steps
        using the ``wd`` option).
        """
        super(WorkflowGenerator, self).save(fname,
                                            validate=validate,
                                            wd=wd,
                                            inline=inline,
                                            relative=relative,
                                            pack=pack,
                                            encoding=encoding)

Response:
<REPLACE_OLD> working_dir=None, copy_steps=True):
 <REPLACE_NEW> working_dir=None):
 <REPLACE_END> <REPLACE_OLD> working_dir=working_dir,
                             copy_steps=copy_steps)

 <REPLACE_NEW> working_dir=working_dir)

 <REPLACE_END> <REPLACE_OLD> inline=True, relative=False, validate=True,
             <REPLACE_NEW> validate=True, wd=True, inline=False, relative=False,
             pack=False, <REPLACE_END> <INSERT> use a working directory (and <INSERT_END> <REPLACE_OLD> steps inline.
 <REPLACE_NEW> steps
        using the ``wd`` option).
 <REPLACE_END> <INSERT> validate=validate,
                                            wd=wd,
                                            <INSERT_END> <REPLACE_OLD> validate=validate,
 <REPLACE_NEW> pack=pack,
 <REPLACE_END> <|endoftext|> from scriptcwl import WorkflowGenerator as WFGenerator

from .utils import CWL_PATH

class WorkflowGenerator(WFGenerator):
    def __init__(self, working_dir=None):
        WFGenerator.__init__(self, steps_dir=CWL_PATH, working_dir=working_dir)

    def save(self, fname, validate=True, wd=True, inline=False, relative=False,
             pack=False, encoding='utf-8'):
        """Save workflow to file

        For nlppln, the default is to use a working directory (and save steps
        using the ``wd`` option).
        """
        super(WorkflowGenerator, self).save(fname,
                                            validate=validate,
                                            wd=wd,
                                            inline=inline,
                                            relative=relative,
                                            pack=pack,
                                            encoding=encoding)

Prompt:
Update to use newest (unreleased) scriptcwl options

from scriptcwl import WorkflowGenerator as WFGenerator

from .utils import CWL_PATH

class WorkflowGenerator(WFGenerator):
    def __init__(self, working_dir=None, copy_steps=True):
        WFGenerator.__init__(self, steps_dir=CWL_PATH, working_dir=working_dir,
                             copy_steps=copy_steps)

    def save(self, fname, inline=True, relative=False, validate=True,
             encoding='utf-8'):
        """Save workflow to file

        For nlppln, the default is to save steps inline.
        """
        super(WorkflowGenerator, self).save(fname,
                                            inline=inline,
                                            relative=relative,
                                            validate=validate,
                                            encoding=encoding)


from pkg_resources import iter_entry_points

from spicedham.config import load_config

_plugins = None

def load_plugins():
    """
    If not already loaded, load plugins.
    """
    if _plugins == None
        load_config()
        _plugins = []
        for plugin in iter_entry_points(group='spicedham.classifiers', name=None):
            pluginClass = plugin.load()
            _plugins.append(pluginClass())

def train(tag, training_data, is_spam):
    """
    Calls each plugin's train function.
    """
    for plugin in _plugins:
        plugin.train(tag, training_data, is_spam)

def classify(tag, classification_data):
    """
    Calls each plugin's classify function and averages the results.
    """
    average_score = 0
    total = 0
    for plugin in _plugins:
        value = plugin.classify(tag, classification_data)
        # Skip _plugins which give a score of None
        if value != None:
            total += 1
            average_score += value
    # On rare occasions no _plugins will give scores. If so, return 0
    if total > 0:
        return average_score / total
    else:
        return 0

Fix code which executes on module load.

Fix code which executes on module load.

Response:
<REPLACE_OLD> config

# TODO: Wrap all of this in an object with this in an __init__ function
plugins = []
for <REPLACE_NEW> load_config

_plugins = None

def load_plugins():
    """
    If not already loaded, load plugins.
    """
    if _plugins == None
        load_config()
        _plugins = []
        for <REPLACE_END> <INSERT>         <INSERT_END> <REPLACE_OLD> plugins.append(pluginClass())

def <REPLACE_NEW>         _plugins.append(pluginClass())

def <REPLACE_END> <REPLACE_OLD> plugins:
 <REPLACE_NEW> _plugins:
 <REPLACE_END> <REPLACE_OLD> plugins:
 <REPLACE_NEW> _plugins:
 <REPLACE_END> <REPLACE_OLD> plugins <REPLACE_NEW> _plugins <REPLACE_END> <REPLACE_OLD> plugins <REPLACE_NEW> _plugins <REPLACE_END> <|endoftext|> from pkg_resources import iter_entry_points

from spicedham.config import load_config

_plugins = None

def load_plugins():
    """
    If not already loaded, load plugins.
    """
    if _plugins == None
        load_config()
        _plugins = []
        for plugin in iter_entry_points(group='spicedham.classifiers', name=None):
            pluginClass = plugin.load()
            _plugins.append(pluginClass())

def train(tag, training_data, is_spam):
    """
    Calls each plugin's train function.
    """
    for plugin in _plugins:
        plugin.train(tag, training_data, is_spam)

def classify(tag, classification_data):
    """
    Calls each plugin's classify function and averages the results.
    """
    average_score = 0
    total = 0
    for plugin in _plugins:
        value = plugin.classify(tag, classification_data)
        # Skip _plugins which give a score of None
        if value != None:
            total += 1
            average_score += value
    # On rare occasions no _plugins will give scores. If so, return 0
    if total > 0:
        return average_score / total
    else:
        return 0

Prompt:
Fix code which executes on module load.

from pkg_resources import iter_entry_points

from spicedham.config import config

# TODO: Wrap all of this in an object with this in an __init__ function
plugins = []
for plugin in iter_entry_points(group='spicedham.classifiers', name=None):
    pluginClass = plugin.load()
    plugins.append(pluginClass())

def train(tag, training_data, is_spam):
    """
    Calls each plugin's train function.
    """
    for plugin in plugins:
        plugin.train(tag, training_data, is_spam)

def classify(tag, classification_data):
    """
    Calls each plugin's classify function and averages the results.
    """
    average_score = 0
    total = 0
    for plugin in plugins:
        value = plugin.classify(tag, classification_data)
        # Skip plugins which give a score of None
        if value != None:
            total += 1
            average_score += value
    # On rare occasions no plugins will give scores. If so, return 0
    if total > 0:
        return average_score / total
    else:
        return 0


import json
import logging

if __name__ == "__main__":
    input = sys.argv[1]
    output = sys.argv[2]
    processor = fix_changeline_budget_titles().process(input,output,[])

class fix_changeline_budget_titles(object):

    def process(self,inputs,output):

        out = []

        budgets = {}

        changes_jsons, budget_jsons = inputs

        for line in file(budget_jsons):
            line = json.loads(line.strip())
            budgets["%(year)s/%(code)s" % line] = line['title']

        outfile = file(output,"w")
        changed_num = 0
        for line in file(changes_jsons):
            line = json.loads(line.strip())
            key = "%(year)s/%(budget_code)s" % line
            title = budgets.get(key)
            if title != None and title != line['budget_title']:
                line['budget_title'] = title
                changed_num += 1
            else:
                logging.error("Failed to find title for change with key %s" % key)
            outfile.write(json.dumps(line,sort_keys=True)+"\n")
        print "updated %d entries" % changed_num

Response:
<REPLACE_OLD> json

if <REPLACE_NEW> json
import logging

if <REPLACE_END> <REPLACE_OLD> title = budgets.get("%(year)s/%(budget_code)s" % line)
 <REPLACE_NEW> key = "%(year)s/%(budget_code)s" % line
            title = budgets.get(key)
 <REPLACE_END> <INSERT>        else:
                logging.error("Failed to find title for change with key %s" % key)
 <INSERT_END> <|endoftext|> import json
import logging

if __name__ == "__main__":
    input = sys.argv[1]
    output = sys.argv[2]
    processor = fix_changeline_budget_titles().process(input,output,[])

class fix_changeline_budget_titles(object):

    def process(self,inputs,output):

        out = []

        budgets = {}

        changes_jsons, budget_jsons = inputs

        for line in file(budget_jsons):
            line = json.loads(line.strip())
            budgets["%(year)s/%(code)s" % line] = line['title']

        outfile = file(output,"w")
        changed_num = 0
        for line in file(changes_jsons):
            line = json.loads(line.strip())
            key = "%(year)s/%(budget_code)s" % line
            title = budgets.get(key)
            if title != None and title != line['budget_title']:
                line['budget_title'] = title
                changed_num += 1
            else:
                logging.error("Failed to find title for change with key %s" % key)
            outfile.write(json.dumps(line,sort_keys=True)+"\n")
        print "updated %d entries" % changed_num

Prompt:
Fix bug in changeling title fix - it used to remove some lines on the way...

import json

if __name__ == "__main__":
    input = sys.argv[1]
    output = sys.argv[2]
    processor = fix_changeline_budget_titles().process(input,output,[])

class fix_changeline_budget_titles(object):

    def process(self,inputs,output):

        out = []

        budgets = {}

        changes_jsons, budget_jsons = inputs

        for line in file(budget_jsons):
            line = json.loads(line.strip())
            budgets["%(year)s/%(code)s" % line] = line['title']

        outfile = file(output,"w")
        changed_num = 0
        for line in file(changes_jsons):
            line = json.loads(line.strip())
            title = budgets.get("%(year)s/%(budget_code)s" % line)
            if title != None and title != line['budget_title']:
                line['budget_title'] = title
                changed_num += 1
                outfile.write(json.dumps(line,sort_keys=True)+"\n")
        print "updated %d entries" % changed_num


#! /usr/bin/python

from __future__ import print_function
import sys
import photo.index

idx = photo.index.Index(idxfile=sys.argv[1])
for i in idx:
    print("%s  %s" % (i.md5, i.filename))

Add a script to convert an index to a md5 file.

Response:
<INSERT> #! /usr/bin/python

from __future__ import print_function
import sys
import photo.index

idx = photo.index.Index(idxfile=sys.argv[1])
for i in idx:
 <INSERT_END> <INSERT>   print("%s  %s" % (i.md5, i.filename))
 <INSERT_END> <|endoftext|> #! /usr/bin/python

from __future__ import print_function
import sys
import photo.index

idx = photo.index.Index(idxfile=sys.argv[1])
for i in idx:
    print("%s  %s" % (i.md5, i.filename))

Prompt: Add a script to convert an index to a md5 file.


#!/usr/bin/env python
import os
import socket
import subprocess
import telnetlib

def can_connect(host, port):
    """Check that we can make a connection to Memcached."""
    try:
        c = telnetlib.Telnet(host, port)
    except socket.error:
        return False
    c.close()
    return True

def main():
    if not os.path.exists('/etc/init.d/memcached'):
        return

    hostname = subprocess.check_output('hostname').strip()
    localhost = '127.0.0.1'

    if can_connect(hostname, '11211') or can_connect(localhost, '11211'):
        print 'status ok memcached is reachable'
    else:
        print 'status err memcached is unreachable'

Add rudimentary status check for memcached

Response:
<INSERT> #!/usr/bin/env python
import os
import socket
import subprocess
import telnetlib

def can_connect(host, port):
 <INSERT_END> <INSERT>   """Check that we can make a connection to Memcached."""
    try:
        c = telnetlib.Telnet(host, port)
    except socket.error:
        return False
    c.close()
    return True

def main():
    if not os.path.exists('/etc/init.d/memcached'):
        return

    hostname = subprocess.check_output('hostname').strip()
    localhost = '127.0.0.1'

    if can_connect(hostname, '11211') or can_connect(localhost, '11211'):
        print 'status ok memcached is reachable'
    else:
        print 'status err memcached is unreachable'
 <INSERT_END> <|endoftext|> #!/usr/bin/env python
import os
import socket
import subprocess
import telnetlib

def can_connect(host, port):
    """Check that we can make a connection to Memcached."""
    try:
        c = telnetlib.Telnet(host, port)
    except socket.error:
        return False
    c.close()
    return True

def main():
    if not os.path.exists('/etc/init.d/memcached'):
        return

    hostname = subprocess.check_output('hostname').strip()
    localhost = '127.0.0.1'

    if can_connect(hostname, '11211') or can_connect(localhost, '11211'):
        print 'status ok memcached is reachable'
    else:
        print 'status err memcached is unreachable'

Prompt: Add rudimentary status check for memcached


import json

from django.test import TestCase, Client

class MemeTests(TestCase):

    def test_can_post_to_db(self):
        response = json.loads(self.client.post('/', {'url':'https://foo.bar/baz.gif', 'keywords':'omg, this, is, great'}).content)
        self.assertTrue(response['success'])

Response:
<REPLACE_OLD> from <REPLACE_NEW> import json

from <REPLACE_END> <REPLACE_OLD> TestCase

# Create your tests here.
 <REPLACE_NEW> TestCase, Client

class MemeTests(TestCase):

    def test_can_post_to_db(self):
        response = json.loads(self.client.post('/', {'url':'https://foo.bar/baz.gif', 'keywords':'omg, this, is, great'}).content)
        self.assertTrue(response['success'])

 <REPLACE_END> <|endoftext|> import json

from django.test import TestCase, Client

class MemeTests(TestCase):

    def test_can_post_to_db(self):
        response = json.loads(self.client.post('/', {'url':'https://foo.bar/baz.gif', 'keywords':'omg, this, is, great'}).content)
        self.assertTrue(response['success'])

Prompt:
Add test for posting content to the server

from django.test import TestCase

# Create your tests here.