Add NFD_NFC to unicode normalization comparison.

--- iscc_bench/metaid/shortnorm.py
+++ iscc_bench/metaid/shortnorm.py
@@ -14,6 +14,7 @@
     nfkc = unicodedata.normalize('NFKC', s)
     nfkd = unicodedata.normalize('NFKD', s)
     nfd_nfkc = unicodedata.normalize('NFKC', nfd)
+    nfd_nfc = unicodedata.normalize('NFC', nfd)

     print('UTF-8 length of normalized strings:\n')
     print(f'NFC: {len(nfc.encode("utf8"))}')
@@ -21,6 +22,7 @@
     print(f'NFKC: {len(nfkc.encode("utf8"))}')
     print(f'NFKD: {len(nfkd.encode("utf8"))}')
     print(f'NFD_NFKC: {len(nfd_nfkc.encode("utf8"))}')
+    print(f'NFD_NFC: {len(nfd_nfc.encode("utf8"))}')

 if __name__ == '__main__':

<|original_code|>
# -*- coding: utf-8 -*-
import unicodedata

def shortest_normalization_form():
    """
    Find unicode normalization that generates shortest utf8 encoded text.

    Result NFKC
    """
    s = 'Iñtërnâtiônàlizætiøn☃ and string escaping are ticky   things'
    nfc = unicodedata.normalize('NFC', s)
    nfd = unicodedata.normalize('NFD', s)
    nfkc = unicodedata.normalize('NFKC', s)
    nfkd = unicodedata.normalize('NFKD', s)
    nfd_nfkc = unicodedata.normalize('NFKC', nfd)

    print('UTF-8 length of normalized strings:\n')
    print(f'NFC: {len(nfc.encode("utf8"))}')
    print(f'NFD: {len(nfd.encode("utf8"))}')
    print(f'NFKC: {len(nfkc.encode("utf8"))}')
    print(f'NFKD: {len(nfkd.encode("utf8"))}')
    print(f'NFD_NFKC: {len(nfd_nfkc.encode("utf8"))}')

if __name__ == '__main__':
    shortest_normalization_form()

<|edits_diff|>
--- iscc_bench/metaid/shortnorm.py
+++ iscc_bench/metaid/shortnorm.py
@@ -14,6 +14,7 @@
     nfkc = unicodedata.normalize('NFKC', s)
     nfkd = unicodedata.normalize('NFKD', s)
     nfd_nfkc = unicodedata.normalize('NFKC', nfd)
+    nfd_nfc = unicodedata.normalize('NFC', nfd)

     print('UTF-8 length of normalized strings:\n')
     print(f'NFC: {len(nfc.encode("utf8"))}')
<|current_version|>
# -*- coding: utf-8 -*-
import unicodedata

def shortest_normalization_form():
    """
    Find unicode normalization that generates shortest utf8 encoded text.

    Result NFKC
    """
    s = 'Iñtërnâtiônàlizætiøn☃ and string escaping are ticky   things'
    nfc = unicodedata.normalize('NFC', s)
    nfd = unicodedata.normalize('NFD', s)
    nfkc = unicodedata.normalize('NFKC', s)
    nfkd = unicodedata.normalize('NFKD', s)
    nfd_nfkc = unicodedata.normalize('NFKC', nfd)
    nfd_nfc = unicodedata.normalize('NFC', nfd)

    print('UTF-8 length of normalized strings:\n')
    print(f'NFC: {len(nfc.encode("utf8"))}')
    print(f'NFD: {len(nfd.encode("utf8"))}')
    print(f'NFKC: {len(nfkc.encode("utf8"))}')
    print(f'NFKD: {len(nfkd.encode("utf8"))}')
    print(f'NFD_NFKC: {len(nfd_nfkc.encode("utf8"))}')

if __name__ == '__main__':
    shortest_normalization_form()

<|next_version|>
# -*- coding: utf-8 -*-
import unicodedata

def shortest_normalization_form():
    """
    Find unicode normalization that generates shortest utf8 encoded text.

    Result NFKC
    """
    s = 'Iñtërnâtiônàlizætiøn☃ and string escaping are ticky   things'
    nfc = unicodedata.normalize('NFC', s)
    nfd = unicodedata.normalize('NFD', s)
    nfkc = unicodedata.normalize('NFKC', s)
    nfkd = unicodedata.normalize('NFKD', s)
    nfd_nfkc = unicodedata.normalize('NFKC', nfd)
    nfd_nfc = unicodedata.normalize('NFC', nfd)

    print('UTF-8 length of normalized strings:\n')
    print(f'NFC: {len(nfc.encode("utf8"))}')
    print(f'NFD: {len(nfd.encode("utf8"))}')
    print(f'NFKC: {len(nfkc.encode("utf8"))}')
    print(f'NFKD: {len(nfkd.encode("utf8"))}')
    print(f'NFD_NFKC: {len(nfd_nfkc.encode("utf8"))}')
    print(f'NFD_NFC: {len(nfd_nfc.encode("utf8"))}')

if __name__ == '__main__':
    shortest_normalization_form()


Add cache headers to self-repair page

Add cache headers to self-repair page

--- normandy/selfrepair/views.py
+++ normandy/selfrepair/views.py
@@ -1,9 +1,12 @@
+from django.conf import settings
 from django.shortcuts import render
+from django.views.decorators.cache import cache_control

 from normandy.base.decorators import short_circuit_middlewares

 @short_circuit_middlewares
+@cache_control(public=True, max_age=settings.API_CACHE_TIME)
 def repair(request, locale):
     return render(request, 'selfrepair/repair.html', {
         'locale': locale,

<|original_code|>
from django.shortcuts import render

from normandy.base.decorators import short_circuit_middlewares

@short_circuit_middlewares
def repair(request, locale):
    return render(request, 'selfrepair/repair.html', {
        'locale': locale,
    })

<|edits_diff|>
--- normandy/selfrepair/views.py
+++ normandy/selfrepair/views.py
@@ -1,4 +1,6 @@
+from django.conf import settings
 from django.shortcuts import render
+from django.views.decorators.cache import cache_control

 from normandy.base.decorators import short_circuit_middlewares

<|current_version|>
from django.conf import settings
from django.shortcuts import render
from django.views.decorators.cache import cache_control

from normandy.base.decorators import short_circuit_middlewares

@short_circuit_middlewares
def repair(request, locale):
    return render(request, 'selfrepair/repair.html', {
        'locale': locale,
    })

<|next_version|>
from django.conf import settings
from django.shortcuts import render
from django.views.decorators.cache import cache_control

from normandy.base.decorators import short_circuit_middlewares

@short_circuit_middlewares
@cache_control(public=True, max_age=settings.API_CACHE_TIME)
def repair(request, locale):
    return render(request, 'selfrepair/repair.html', {
        'locale': locale,
    })


Add field short_url on flatpages model

Add field short_url on flatpages model

--- opps/flatpages/models.py
+++ opps/flatpages/models.py
@@ -16,6 +16,10 @@
         max_length=150,
         unique=True,
     )
+    short_url = models.URLField(
+        _("Short URL"),
+        null=True, blank=False,
+    )
     show_in_menu = models.BooleanField(_(u"Show in menu?"), default=False)
     main_image = models.ForeignKey(
         'images.Image',
@@ -26,6 +30,10 @@
     content = models.TextField(_(u"Content"))
     order = models.IntegerField(_(u"Order"), default=0)

+    def get_absolute_url(self):
+        return "/page/{0}".format(self.slug)
+    get_absolute_url.short_description = 'URL'
+
     def __unicode__(self):
         return u"{0} - {1}".format(self.site.name, self.slug)

<|original_code|>
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from googl.short import GooglUrlShort

from opps.core.models import Publishable, BaseConfig

class FlatPage(Publishable):
    title = models.CharField(_(u"Title"), max_length=140, db_index=True)
    headline = models.TextField(_(u"Headline"), blank=True, null=True)
    slug = models.SlugField(
        _(u"URL"),
        db_index=True,
        max_length=150,
        unique=True,
    )
    show_in_menu = models.BooleanField(_(u"Show in menu?"), default=False)
    main_image = models.ForeignKey(
        'images.Image',
        null=True, blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_(u'Main Image'),
    )
    content = models.TextField(_(u"Content"))
    order = models.IntegerField(_(u"Order"), default=0)

    def __unicode__(self):
        return u"{0} - {1}".format(self.site.name, self.slug)

class FlatPageConfig(BaseConfig):
    """
    Default implementation
    """
    pass

<|edits_diff|>
--- opps/flatpages/models.py
+++ opps/flatpages/models.py
@@ -15,6 +15,10 @@
         db_index=True,
         max_length=150,
         unique=True,
+    )
+    short_url = models.URLField(
+        _("Short URL"),
+        null=True, blank=False,
     )
     show_in_menu = models.BooleanField(_(u"Show in menu?"), default=False)
     main_image = models.ForeignKey(
<|current_version|>
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from googl.short import GooglUrlShort

from opps.core.models import Publishable, BaseConfig

class FlatPage(Publishable):
    title = models.CharField(_(u"Title"), max_length=140, db_index=True)
    headline = models.TextField(_(u"Headline"), blank=True, null=True)
    slug = models.SlugField(
        _(u"URL"),
        db_index=True,
        max_length=150,
        unique=True,
    )
    short_url = models.URLField(
        _("Short URL"),
        null=True, blank=False,
    )
    show_in_menu = models.BooleanField(_(u"Show in menu?"), default=False)
    main_image = models.ForeignKey(
        'images.Image',
        null=True, blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_(u'Main Image'),
    )
    content = models.TextField(_(u"Content"))
    order = models.IntegerField(_(u"Order"), default=0)

    def __unicode__(self):
        return u"{0} - {1}".format(self.site.name, self.slug)

class FlatPageConfig(BaseConfig):
    """
    Default implementation
    """
    pass

<|next_version|>
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from googl.short import GooglUrlShort

from opps.core.models import Publishable, BaseConfig

class FlatPage(Publishable):
    title = models.CharField(_(u"Title"), max_length=140, db_index=True)
    headline = models.TextField(_(u"Headline"), blank=True, null=True)
    slug = models.SlugField(
        _(u"URL"),
        db_index=True,
        max_length=150,
        unique=True,
    )
    short_url = models.URLField(
        _("Short URL"),
        null=True, blank=False,
    )
    show_in_menu = models.BooleanField(_(u"Show in menu?"), default=False)
    main_image = models.ForeignKey(
        'images.Image',
        null=True, blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_(u'Main Image'),
    )
    content = models.TextField(_(u"Content"))
    order = models.IntegerField(_(u"Order"), default=0)

    def get_absolute_url(self):
        return "/page/{0}".format(self.slug)
    get_absolute_url.short_description = 'URL'

    def __unicode__(self):
        return u"{0} - {1}".format(self.site.name, self.slug)

class FlatPageConfig(BaseConfig):
    """
    Default implementation
    """
    pass


Update scraper to account for new fields

--- txlege84/core/management/commands/updateconveningtimes.py
+++ txlege84/core/management/commands/updateconveningtimes.py
@@ -1,8 +1,10 @@
 from django.core.management.base import BaseCommand
+from django.utils import timezone

 from core.models import ConveneTime
 from legislators.models import Chamber

+from dateutil.parser import parse
 import requests

@@ -20,11 +22,16 @@
                             '/SessionTime/{}SessTime.js'.format(chamber))

         time_string = page.text.strip()[16:-3]
+        status, time = time_string.split(' until ')
+        time = timezone.make_aware(
+            parse(time.replace(' noon', '')), timezone.get_default_timezone())

         ConveneTime.objects.update_or_create(
             chamber=Chamber.objects.get(name='Texas {}'.format(chamber)),
             defaults={
                 'time_string': time_string,
+                'status': status,
+                'time': time,
             }
         )

<|original_code|>
from django.core.management.base import BaseCommand

from core.models import ConveneTime
from legislators.models import Chamber

import requests

class Command(BaseCommand):
    help = u'Scrape TLO for convening times.'

    def handle(self, *args, **kwargs):
        self.update_time('House')
        self.update_time('Senate')

    def update_time(self, chamber):
        self.stdout.write(u'Updating {} convening time...'.format(chamber))

        page = requests.get('http://www.capitol.state.tx.us/tlodocs'
                            '/SessionTime/{}SessTime.js'.format(chamber))

        time_string = page.text.strip()[16:-3]

        ConveneTime.objects.update_or_create(
            chamber=Chamber.objects.get(name='Texas {}'.format(chamber)),
            defaults={
                'time_string': time_string,
            }
        )

        self.stdout.write(u'Now set to: {}'.format(time_string))

<|edits_diff|>
--- txlege84/core/management/commands/updateconveningtimes.py
+++ txlege84/core/management/commands/updateconveningtimes.py
@@ -1,8 +1,10 @@
 from django.core.management.base import BaseCommand
+from django.utils import timezone

 from core.models import ConveneTime
 from legislators.models import Chamber

+from dateutil.parser import parse
 import requests

@@ -20,6 +22,9 @@
                             '/SessionTime/{}SessTime.js'.format(chamber))

         time_string = page.text.strip()[16:-3]
+        status, time = time_string.split(' until ')
+        time = timezone.make_aware(
+            parse(time.replace(' noon', '')), timezone.get_default_timezone())

         ConveneTime.objects.update_or_create(
             chamber=Chamber.objects.get(name='Texas {}'.format(chamber)),
<|current_version|>
from django.core.management.base import BaseCommand
from django.utils import timezone

from core.models import ConveneTime
from legislators.models import Chamber

from dateutil.parser import parse
import requests

class Command(BaseCommand):
    help = u'Scrape TLO for convening times.'

    def handle(self, *args, **kwargs):
        self.update_time('House')
        self.update_time('Senate')

    def update_time(self, chamber):
        self.stdout.write(u'Updating {} convening time...'.format(chamber))

        page = requests.get('http://www.capitol.state.tx.us/tlodocs'
                            '/SessionTime/{}SessTime.js'.format(chamber))

        time_string = page.text.strip()[16:-3]
        status, time = time_string.split(' until ')
        time = timezone.make_aware(
            parse(time.replace(' noon', '')), timezone.get_default_timezone())

        ConveneTime.objects.update_or_create(
            chamber=Chamber.objects.get(name='Texas {}'.format(chamber)),
            defaults={
                'time_string': time_string,
            }
        )

        self.stdout.write(u'Now set to: {}'.format(time_string))

<|next_version|>
from django.core.management.base import BaseCommand
from django.utils import timezone

from core.models import ConveneTime
from legislators.models import Chamber

from dateutil.parser import parse
import requests

class Command(BaseCommand):
    help = u'Scrape TLO for convening times.'

    def handle(self, *args, **kwargs):
        self.update_time('House')
        self.update_time('Senate')

    def update_time(self, chamber):
        self.stdout.write(u'Updating {} convening time...'.format(chamber))

        page = requests.get('http://www.capitol.state.tx.us/tlodocs'
                            '/SessionTime/{}SessTime.js'.format(chamber))

        time_string = page.text.strip()[16:-3]
        status, time = time_string.split(' until ')
        time = timezone.make_aware(
            parse(time.replace(' noon', '')), timezone.get_default_timezone())

        ConveneTime.objects.update_or_create(
            chamber=Chamber.objects.get(name='Texas {}'.format(chamber)),
            defaults={
                'time_string': time_string,
                'status': status,
                'time': time,
            }
        )

        self.stdout.write(u'Now set to: {}'.format(time_string))


Fix failing TestMarketplace test by ensuring vanilla authentication and authorization

--- mkt/api/tests/test_base.py
+++ mkt/api/tests/test_base.py
@@ -1,4 +1,5 @@
 from tastypie import http
+from tastypie.authentication import Authentication
 from tastypie.authorization import Authorization
 from test_utils import RequestFactory

@@ -9,7 +10,11 @@
 class TestMarketplace(TestCase):
     def setUp(self):
         self.resource = MarketplaceResource()
+
+        # Ensure that we have proper authentication and authorization.
+        self.resource._meta.authentication = Authentication()
         self.resource._meta.authorization = Authorization()
+
         self.request = RequestFactory().post('/')

     def test_form_encoded(self):

<|original_code|>
from tastypie import http
from tastypie.authorization import Authorization
from test_utils import RequestFactory

from amo.tests import TestCase
from mkt.api.base import MarketplaceResource

class TestMarketplace(TestCase):
    def setUp(self):
        self.resource = MarketplaceResource()
        self.resource._meta.authorization = Authorization()
        self.request = RequestFactory().post('/')

    def test_form_encoded(self):
        """
        Regression test of bug #858403: ensure that a 400 (and not 500) is
        raised when an unsupported Content-Type header is passed to an API
        endpoint.
        """
        self.request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        with self.assertImmediate(http.HttpBadRequest):
            self.resource.dispatch('list', self.request)

<|edits_diff|>
--- mkt/api/tests/test_base.py
+++ mkt/api/tests/test_base.py
@@ -1,4 +1,5 @@
 from tastypie import http
+from tastypie.authentication import Authentication
 from tastypie.authorization import Authorization
 from test_utils import RequestFactory

@@ -9,6 +10,9 @@
 class TestMarketplace(TestCase):
     def setUp(self):
         self.resource = MarketplaceResource()
+
+        # Ensure that we have proper authentication and authorization.
+        self.resource._meta.authentication = Authentication()
         self.resource._meta.authorization = Authorization()
         self.request = RequestFactory().post('/')

<|current_version|>
from tastypie import http
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from test_utils import RequestFactory

from amo.tests import TestCase
from mkt.api.base import MarketplaceResource

class TestMarketplace(TestCase):
    def setUp(self):
        self.resource = MarketplaceResource()

        # Ensure that we have proper authentication and authorization.
        self.resource._meta.authentication = Authentication()
        self.resource._meta.authorization = Authorization()
        self.request = RequestFactory().post('/')

    def test_form_encoded(self):
        """
        Regression test of bug #858403: ensure that a 400 (and not 500) is
        raised when an unsupported Content-Type header is passed to an API
        endpoint.
        """
        self.request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        with self.assertImmediate(http.HttpBadRequest):
            self.resource.dispatch('list', self.request)

<|next_version|>
from tastypie import http
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from test_utils import RequestFactory

from amo.tests import TestCase
from mkt.api.base import MarketplaceResource

class TestMarketplace(TestCase):
    def setUp(self):
        self.resource = MarketplaceResource()

        # Ensure that we have proper authentication and authorization.
        self.resource._meta.authentication = Authentication()
        self.resource._meta.authorization = Authorization()

        self.request = RequestFactory().post('/')

    def test_form_encoded(self):
        """
        Regression test of bug #858403: ensure that a 400 (and not 500) is
        raised when an unsupported Content-Type header is passed to an API
        endpoint.
        """
        self.request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        with self.assertImmediate(http.HttpBadRequest):
            self.resource.dispatch('list', self.request)


Implement __str__ for proper printing in admin

--- poll/models.py
+++ poll/models.py
@@ -7,6 +7,9 @@
     date_added = models.DateTimeField(auto_now=True)
     date_modified = models.DateTimeField(auto_now_add=True)

+    def __str__(self):
+        return str(self.id) + ". " + self.heading
+

 class Question(models.Model):
     text = models.TextField()
@@ -14,12 +17,18 @@
     date_added = models.DateTimeField(auto_now=True)
     date_modified = models.DateTimeField(auto_now_add=True)

+    def __str__(self):
+        return str(self.id) + ". " + self.text
+

 class Choice(models.Model):
     text = models.TextField()
     question = models.ForeignKey(Question)
     date_added = models.DateTimeField(auto_now=True)
     date_modified = models.DateTimeField(auto_now_add=True)
+
+    def __str__(self):
+        return str(self.id) + ". " + self.text

 class Session(models.Model):

<|original_code|>
from django.db import models

class QuestionGroup(models.Model):
    heading = models.TextField()
    text = models.TextField(blank=True)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

class Question(models.Model):
    text = models.TextField()
    question_group = models.ForeignKey(QuestionGroup)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

class Choice(models.Model):
    text = models.TextField()
    question = models.ForeignKey(Question)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

class Session(models.Model):
    name = models.TextField(blank=True)
    ip = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now=True)
    date_submitted = models.DateTimeField(null=True)

class Response(models.Model):
    choice = models.ForeignKey(Choice)
    session = models.ForeignKey(Session)
    value = models.IntegerField()
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

<|edits_diff|>
--- poll/models.py
+++ poll/models.py
@@ -7,12 +7,18 @@
     date_added = models.DateTimeField(auto_now=True)
     date_modified = models.DateTimeField(auto_now_add=True)

+    def __str__(self):
+        return str(self.id) + ". " + self.heading
+

 class Question(models.Model):
     text = models.TextField()
     question_group = models.ForeignKey(QuestionGroup)
     date_added = models.DateTimeField(auto_now=True)
     date_modified = models.DateTimeField(auto_now_add=True)
+
+    def __str__(self):
+        return str(self.id) + ". " + self.text

 class Choice(models.Model):
<|current_version|>
from django.db import models

class QuestionGroup(models.Model):
    heading = models.TextField()
    text = models.TextField(blank=True)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.id) + ". " + self.heading

class Question(models.Model):
    text = models.TextField()
    question_group = models.ForeignKey(QuestionGroup)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.id) + ". " + self.text

class Choice(models.Model):
    text = models.TextField()
    question = models.ForeignKey(Question)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

class Session(models.Model):
    name = models.TextField(blank=True)
    ip = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now=True)
    date_submitted = models.DateTimeField(null=True)

class Response(models.Model):
    choice = models.ForeignKey(Choice)
    session = models.ForeignKey(Session)
    value = models.IntegerField()
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

<|next_version|>
from django.db import models

class QuestionGroup(models.Model):
    heading = models.TextField()
    text = models.TextField(blank=True)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.id) + ". " + self.heading

class Question(models.Model):
    text = models.TextField()
    question_group = models.ForeignKey(QuestionGroup)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.id) + ". " + self.text

class Choice(models.Model):
    text = models.TextField()
    question = models.ForeignKey(Question)
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.id) + ". " + self.text

class Session(models.Model):
    name = models.TextField(blank=True)
    ip = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now=True)
    date_submitted = models.DateTimeField(null=True)

class Response(models.Model):
    choice = models.ForeignKey(Choice)
    session = models.ForeignKey(Session)
    value = models.IntegerField()
    date_added = models.DateTimeField(auto_now=True)
    date_modified = models.DateTimeField(auto_now_add=True)


Add error if missing root

Add error if missing root

--- run.py
+++ run.py
@@ -1,6 +1,11 @@
 import argparse
+import os

 from app import app
+
+
+if os.geteuid() != 0:
+    raise OSError("Must be run as root")

 parser = argparse.ArgumentParser()
 parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False)

<|original_code|>
import argparse

from app import app

parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False)
parser.add_argument('-p', '--port', action='store', dest='port', default=5000, type=int)
params = parser.parse_args()

app.run(debug=params.debug, port=params.port, host='0.0.0.0')
<|edits_diff|>
--- run.py
+++ run.py
@@ -1,4 +1,5 @@
 import argparse
+import os

 from app import app

<|current_version|>
import argparse
import os

from app import app

parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False)
parser.add_argument('-p', '--port', action='store', dest='port', default=5000, type=int)
params = parser.parse_args()

app.run(debug=params.debug, port=params.port, host='0.0.0.0')
<|next_version|>
import argparse
import os

from app import app

if os.geteuid() != 0:
    raise OSError("Must be run as root")

parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False)
parser.add_argument('-p', '--port', action='store', dest='port', default=5000, type=int)
params = parser.parse_args()

app.run(debug=params.debug, port=params.port, host='0.0.0.0')


Add new boolean field MetaBase.active

Add new boolean field MetaBase.active

--- comics/meta/base.py
+++ comics/meta/base.py
@@ -9,6 +9,7 @@
     url = None

     # Default values
+    active = True
     start_date = None
     end_date = None
     rights = ''
@@ -29,6 +30,7 @@
                 slug=self.slug,
                 language=self.language,
                 url=self.url)
+        comic.active = self.active
         comic.start_date = self._get_date(self.start_date)
         comic.end_date = self._get_date(self.end_date)
         comic.rights = self.rights

<|original_code|>
import datetime as dt

from comics.core.models import Comic

class MetaBase(object):
    # Required values
    name = None
    language = None
    url = None

    # Default values
    start_date = None
    end_date = None
    rights = ''

    @property
    def slug(self):
        return self.__module__.split('.')[-1]

    def create_comic(self):
        if Comic.objects.filter(slug=self.slug).count():
            comic = Comic.objects.get(slug=self.slug)
            comic.name = self.name
            comic.language = self.language
            comic.url = self.url
        else:
            comic = Comic(
                name=self.name,
                slug=self.slug,
                language=self.language,
                url=self.url)
        comic.start_date = self._get_date(self.start_date)
        comic.end_date = self._get_date(self.end_date)
        comic.rights = self.rights
        comic.save()

    def _get_date(self, date):
        if date is None:
            return None
        return dt.datetime.strptime(date, '%Y-%m-%d').date()

<|edits_diff|>
--- comics/meta/base.py
+++ comics/meta/base.py
@@ -9,6 +9,7 @@
     url = None

     # Default values
+    active = True
     start_date = None
     end_date = None
     rights = ''
<|current_version|>
import datetime as dt

from comics.core.models import Comic

class MetaBase(object):
    # Required values
    name = None
    language = None
    url = None

    # Default values
    active = True
    start_date = None
    end_date = None
    rights = ''

    @property
    def slug(self):
        return self.__module__.split('.')[-1]

    def create_comic(self):
        if Comic.objects.filter(slug=self.slug).count():
            comic = Comic.objects.get(slug=self.slug)
            comic.name = self.name
            comic.language = self.language
            comic.url = self.url
        else:
            comic = Comic(
                name=self.name,
                slug=self.slug,
                language=self.language,
                url=self.url)
        comic.start_date = self._get_date(self.start_date)
        comic.end_date = self._get_date(self.end_date)
        comic.rights = self.rights
        comic.save()

    def _get_date(self, date):
        if date is None:
            return None
        return dt.datetime.strptime(date, '%Y-%m-%d').date()

<|next_version|>
import datetime as dt

from comics.core.models import Comic

class MetaBase(object):
    # Required values
    name = None
    language = None
    url = None

    # Default values
    active = True
    start_date = None
    end_date = None
    rights = ''

    @property
    def slug(self):
        return self.__module__.split('.')[-1]

    def create_comic(self):
        if Comic.objects.filter(slug=self.slug).count():
            comic = Comic.objects.get(slug=self.slug)
            comic.name = self.name
            comic.language = self.language
            comic.url = self.url
        else:
            comic = Comic(
                name=self.name,
                slug=self.slug,
                language=self.language,
                url=self.url)
        comic.active = self.active
        comic.start_date = self._get_date(self.start_date)
        comic.end_date = self._get_date(self.end_date)
        comic.rights = self.rights
        comic.save()

    def _get_date(self, date):
        if date is None:
            return None
        return dt.datetime.strptime(date, '%Y-%m-%d').date()


Add CBO column to cnes professional

Add CBO column to cnes professional

--- app/models/cnes_professional.py
+++ app/models/cnes_professional.py
@@ -10,6 +10,7 @@
     state         = Column(String(2), primary_key=True)
     municipality  = Column(String(7), primary_key=True)
     cnes          = Column(String(7), primary_key=True)
+    cbo           = Column(String(2), primary_key=True)

     @classmethod
     def dimensions(cls):
@@ -20,6 +21,7 @@
             'microregion',
             'state',
             'municipality',
+            'cbo',
         ]

     @classmethod

<|original_code|>
from sqlalchemy import Column, Integer, String, func
from app import db

class CnesProfessional(db.Model):
    __tablename__ = 'cnes_professional'
    year          = Column(Integer, primary_key=True)
    region        = Column(String(1), primary_key=True)
    mesoregion    = Column(String(4), primary_key=True)
    microregion   = Column(String(5), primary_key=True)
    state         = Column(String(2), primary_key=True)
    municipality  = Column(String(7), primary_key=True)
    cnes          = Column(String(7), primary_key=True)

    @classmethod
    def dimensions(cls):
        return [
            'year',
            'region',
            'mesoregion',
            'microregion',
            'state',
            'municipality',
        ]

    @classmethod
    def aggregate(cls, value):
        return {
            'professionals': func.count(cls.cnes)
        }[value]

    @classmethod
    def values(cls):
        return ['professionals']

<|edits_diff|>
--- app/models/cnes_professional.py
+++ app/models/cnes_professional.py
@@ -10,6 +10,7 @@
     state         = Column(String(2), primary_key=True)
     municipality  = Column(String(7), primary_key=True)
     cnes          = Column(String(7), primary_key=True)
+    cbo           = Column(String(2), primary_key=True)

     @classmethod
     def dimensions(cls):
<|current_version|>
from sqlalchemy import Column, Integer, String, func
from app import db

class CnesProfessional(db.Model):
    __tablename__ = 'cnes_professional'
    year          = Column(Integer, primary_key=True)
    region        = Column(String(1), primary_key=True)
    mesoregion    = Column(String(4), primary_key=True)
    microregion   = Column(String(5), primary_key=True)
    state         = Column(String(2), primary_key=True)
    municipality  = Column(String(7), primary_key=True)
    cnes          = Column(String(7), primary_key=True)
    cbo           = Column(String(2), primary_key=True)

    @classmethod
    def dimensions(cls):
        return [
            'year',
            'region',
            'mesoregion',
            'microregion',
            'state',
            'municipality',
        ]

    @classmethod
    def aggregate(cls, value):
        return {
            'professionals': func.count(cls.cnes)
        }[value]

    @classmethod
    def values(cls):
        return ['professionals']

<|next_version|>
from sqlalchemy import Column, Integer, String, func
from app import db

class CnesProfessional(db.Model):
    __tablename__ = 'cnes_professional'
    year          = Column(Integer, primary_key=True)
    region        = Column(String(1), primary_key=True)
    mesoregion    = Column(String(4), primary_key=True)
    microregion   = Column(String(5), primary_key=True)
    state         = Column(String(2), primary_key=True)
    municipality  = Column(String(7), primary_key=True)
    cnes          = Column(String(7), primary_key=True)
    cbo           = Column(String(2), primary_key=True)

    @classmethod
    def dimensions(cls):
        return [
            'year',
            'region',
            'mesoregion',
            'microregion',
            'state',
            'municipality',
            'cbo',
        ]

    @classmethod
    def aggregate(cls, value):
        return {
            'professionals': func.count(cls.cnes)
        }[value]

    @classmethod
    def values(cls):
        return ['professionals']


Use flush and fsync to ensure data is written to disk

--- Main.py
+++ Main.py
@@ -1,5 +1,6 @@
 """Main Module of PDF Splitter"""
 import argparse
+import os

 from PyPDF2 import PdfFileWriter

@@ -35,5 +36,7 @@
         output_filename = '{0:05}.pdf'.format(idx)
         with open(output_filename, 'wb') as output_file:
             pdf_writer.write(output_file)
+            output_file.flush()
+            os.fsync(output_file.fileno())

     map(lambda f: f.close, opened_files)

<|original_code|>
"""Main Module of PDF Splitter"""
import argparse

from PyPDF2 import PdfFileWriter

from Util import all_pdf_files_in_directory, split_on_condition, concat_pdf_pages

parser = \
    argparse.ArgumentParser(
        description='Split all the pages of multiple PDF files in a directory by document number'
    )
parser.add_argument(
    'directory',
    metavar='PATH',
    type=str,
    help='path to a directory'
)

def width_greater_than_height(page):
    box = page.mediaBox
    return box.getWidth() > box.getHeight()

if __name__ == '__main__':
    args = parser.parse_args()
    all_pdf_files = all_pdf_files_in_directory(args.directory)
    opened_files = map(lambda path: open(path, 'rb'), all_pdf_files)
    all_pages = concat_pdf_pages(opened_files)

    for idx, pages in enumerate(split_on_condition(all_pages, predicate=width_greater_than_height), start=1):
        pdf_writer = PdfFileWriter()
        map(pdf_writer.addPage, pages)

        output_filename = '{0:05}.pdf'.format(idx)
        with open(output_filename, 'wb') as output_file:
            pdf_writer.write(output_file)

    map(lambda f: f.close, opened_files)

<|edits_diff|>
--- Main.py
+++ Main.py
@@ -1,5 +1,6 @@
 """Main Module of PDF Splitter"""
 import argparse
+import os

 from PyPDF2 import PdfFileWriter

<|current_version|>
"""Main Module of PDF Splitter"""
import argparse
import os

from PyPDF2 import PdfFileWriter

from Util import all_pdf_files_in_directory, split_on_condition, concat_pdf_pages

parser = \
    argparse.ArgumentParser(
        description='Split all the pages of multiple PDF files in a directory by document number'
    )
parser.add_argument(
    'directory',
    metavar='PATH',
    type=str,
    help='path to a directory'
)

def width_greater_than_height(page):
    box = page.mediaBox
    return box.getWidth() > box.getHeight()

if __name__ == '__main__':
    args = parser.parse_args()
    all_pdf_files = all_pdf_files_in_directory(args.directory)
    opened_files = map(lambda path: open(path, 'rb'), all_pdf_files)
    all_pages = concat_pdf_pages(opened_files)

    for idx, pages in enumerate(split_on_condition(all_pages, predicate=width_greater_than_height), start=1):
        pdf_writer = PdfFileWriter()
        map(pdf_writer.addPage, pages)

        output_filename = '{0:05}.pdf'.format(idx)
        with open(output_filename, 'wb') as output_file:
            pdf_writer.write(output_file)

    map(lambda f: f.close, opened_files)

<|next_version|>
"""Main Module of PDF Splitter"""
import argparse
import os

from PyPDF2 import PdfFileWriter

from Util import all_pdf_files_in_directory, split_on_condition, concat_pdf_pages

parser = \
    argparse.ArgumentParser(
        description='Split all the pages of multiple PDF files in a directory by document number'
    )
parser.add_argument(
    'directory',
    metavar='PATH',
    type=str,
    help='path to a directory'
)

def width_greater_than_height(page):
    box = page.mediaBox
    return box.getWidth() > box.getHeight()

if __name__ == '__main__':
    args = parser.parse_args()
    all_pdf_files = all_pdf_files_in_directory(args.directory)
    opened_files = map(lambda path: open(path, 'rb'), all_pdf_files)
    all_pages = concat_pdf_pages(opened_files)

    for idx, pages in enumerate(split_on_condition(all_pages, predicate=width_greater_than_height), start=1):
        pdf_writer = PdfFileWriter()
        map(pdf_writer.addPage, pages)

        output_filename = '{0:05}.pdf'.format(idx)
        with open(output_filename, 'wb') as output_file:
            pdf_writer.write(output_file)
            output_file.flush()
            os.fsync(output_file.fileno())

    map(lambda f: f.close, opened_files)


Read variable data for qf_bv

Read variable data for qf_bv

--- qfbv.py
+++ qfbv.py
@@ -1,4 +1,5 @@
 from config import *
+import re

 class QFBV:
 	def preamble(self):
@@ -17,3 +18,8 @@

 	pass

+	def read_variable(self, expr1):
+		string, = expr1
+		regex = "round_([0-9]+)_match_([0-9]+)_slot_([0-9]+)"
+		result = re.match(regex, string)
+		return int(result.group(1)), int(result.group(2)), int(result.group(3))

<|original_code|>
from config import *

class QFBV:
	def preamble(self):
		print "(set-logic QF_BV)"

		print ""

		# Enumerate all the variables, for each match round.
		for i in range(NUMROUNDS):
			for j in range(NUMMATCHES):
				for k in range(NUMSLOTS):
					print "(declare-fun {0} () (_ BitVec {1}))".format(self.project(i, j, k), TEAMBITS)

	def project(self, x, y, z):
		return "round_{0}_match_{1}_slot_{2}".format(x, y, z)

	pass

<|edits_diff|>
--- qfbv.py
+++ qfbv.py
@@ -1,4 +1,5 @@
 from config import *
+import re

 class QFBV:
 	def preamble(self):
<|current_version|>
from config import *
import re

class QFBV:
	def preamble(self):
		print "(set-logic QF_BV)"

		print ""

		# Enumerate all the variables, for each match round.
		for i in range(NUMROUNDS):
			for j in range(NUMMATCHES):
				for k in range(NUMSLOTS):
					print "(declare-fun {0} () (_ BitVec {1}))".format(self.project(i, j, k), TEAMBITS)

	def project(self, x, y, z):
		return "round_{0}_match_{1}_slot_{2}".format(x, y, z)

	pass

<|next_version|>
from config import *
import re

class QFBV:
	def preamble(self):
		print "(set-logic QF_BV)"

		print ""

		# Enumerate all the variables, for each match round.
		for i in range(NUMROUNDS):
			for j in range(NUMMATCHES):
				for k in range(NUMSLOTS):
					print "(declare-fun {0} () (_ BitVec {1}))".format(self.project(i, j, k), TEAMBITS)

	def project(self, x, y, z):
		return "round_{0}_match_{1}_slot_{2}".format(x, y, z)

	pass

	def read_variable(self, expr1):
		string, = expr1
		regex = "round_([0-9]+)_match_([0-9]+)_slot_([0-9]+)"
		result = re.match(regex, string)
		return int(result.group(1)), int(result.group(2)), int(result.group(3))


Allow schedule edition by supervisors

[schedule] Allow schedule edition by supervisors

--- zou/app/blueprints/crud/schedule_item.py
+++ zou/app/blueprints/crud/schedule_item.py
@@ -1,6 +1,8 @@
 from zou.app.models.schedule_item import ScheduleItem

 from .base import BaseModelResource, BaseModelsResource
+
+from zou.app.services import user_service

 class ScheduleItemsResource(BaseModelsResource):
@@ -12,6 +14,9 @@
     def __init__(self):
         BaseModelResource.__init__(self, ScheduleItem)

+    def check_update_permissions(self, instance, data):
+        return user_service.check_manager_project_access(instance["project_id"])
+
     def update_data(self, data, instance_id):
         if isinstance(data.get("man_days", None), str):
             data.pop("man_days", None)

<|original_code|>
from zou.app.models.schedule_item import ScheduleItem

from .base import BaseModelResource, BaseModelsResource

class ScheduleItemsResource(BaseModelsResource):
    def __init__(self):
        BaseModelsResource.__init__(self, ScheduleItem)

class ScheduleItemResource(BaseModelResource):
    def __init__(self):
        BaseModelResource.__init__(self, ScheduleItem)

    def update_data(self, data, instance_id):
        if isinstance(data.get("man_days", None), str):
            data.pop("man_days", None)

        for field in self.protected_fields:
            data.pop(field, None)

        return data

<|edits_diff|>
--- zou/app/blueprints/crud/schedule_item.py
+++ zou/app/blueprints/crud/schedule_item.py
@@ -1,6 +1,8 @@
 from zou.app.models.schedule_item import ScheduleItem

 from .base import BaseModelResource, BaseModelsResource
+
+from zou.app.services import user_service

 class ScheduleItemsResource(BaseModelsResource):
<|current_version|>
from zou.app.models.schedule_item import ScheduleItem

from .base import BaseModelResource, BaseModelsResource

from zou.app.services import user_service

class ScheduleItemsResource(BaseModelsResource):
    def __init__(self):
        BaseModelsResource.__init__(self, ScheduleItem)

class ScheduleItemResource(BaseModelResource):
    def __init__(self):
        BaseModelResource.__init__(self, ScheduleItem)

    def update_data(self, data, instance_id):
        if isinstance(data.get("man_days", None), str):
            data.pop("man_days", None)

        for field in self.protected_fields:
            data.pop(field, None)

        return data

<|next_version|>
from zou.app.models.schedule_item import ScheduleItem

from .base import BaseModelResource, BaseModelsResource

from zou.app.services import user_service

class ScheduleItemsResource(BaseModelsResource):
    def __init__(self):
        BaseModelsResource.__init__(self, ScheduleItem)

class ScheduleItemResource(BaseModelResource):
    def __init__(self):
        BaseModelResource.__init__(self, ScheduleItem)

    def check_update_permissions(self, instance, data):
        return user_service.check_manager_project_access(instance["project_id"])

    def update_data(self, data, instance_id):
        if isinstance(data.get("man_days", None), str):
            data.pop("man_days", None)

        for field in self.protected_fields:
            data.pop(field, None)

        return data


Fix 404 when no path in URL

Fix 404 when no path in URL

--- ditto/multitenancy/middleware.py
+++ ditto/multitenancy/middleware.py
@@ -1,6 +1,7 @@
 from django.conf import settings
 from django.conf.urls import patterns, include, url
 from django.conf.urls.static import static
+from django.views.generic import RedirectView

 class FakeTenant(object):
@@ -26,6 +27,10 @@
     return tuple(
         patterns(
             '',
+            (r'^$', RedirectView.as_view(
+                pattern_name='ditto:home',
+                permanent=True,
+            )),
             url(r'^%s/' % tenant_slug, include('network_urls')),
             url(r'^main/', include('multitenancy.urls', namespace="ditto")),
         ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))

<|original_code|>
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static

class FakeTenant(object):
    is_main =  lambda self: False
    is_configured = lambda self: True
    id = 'di'

    def chat_host(self):
        if settings.DEBUG:
            return 'network1.localhost'
        return 'network1.ditto.technology'

# NOTE: this MUST come first in the middleware order
class CurrentTenantMiddleware(object):
    def process_request(self, request):
        request.tenant = FakeTenant()
        request.urlconf = _get_urls('di')

def _get_urls(tenant_slug):
    # Note, need 'tuple' here otherwise url stuff blows up
    return tuple(
        patterns(
            '',
            url(r'^%s/' % tenant_slug, include('network_urls')),
            url(r'^main/', include('multitenancy.urls', namespace="ditto")),
        ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))

<|edits_diff|>
--- ditto/multitenancy/middleware.py
+++ ditto/multitenancy/middleware.py
@@ -1,6 +1,7 @@
 from django.conf import settings
 from django.conf.urls import patterns, include, url
 from django.conf.urls.static import static
+from django.views.generic import RedirectView

 class FakeTenant(object):
<|current_version|>
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.views.generic import RedirectView

class FakeTenant(object):
    is_main =  lambda self: False
    is_configured = lambda self: True
    id = 'di'

    def chat_host(self):
        if settings.DEBUG:
            return 'network1.localhost'
        return 'network1.ditto.technology'

# NOTE: this MUST come first in the middleware order
class CurrentTenantMiddleware(object):
    def process_request(self, request):
        request.tenant = FakeTenant()
        request.urlconf = _get_urls('di')

def _get_urls(tenant_slug):
    # Note, need 'tuple' here otherwise url stuff blows up
    return tuple(
        patterns(
            '',
            url(r'^%s/' % tenant_slug, include('network_urls')),
            url(r'^main/', include('multitenancy.urls', namespace="ditto")),
        ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))

<|next_version|>
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.views.generic import RedirectView

class FakeTenant(object):
    is_main =  lambda self: False
    is_configured = lambda self: True
    id = 'di'

    def chat_host(self):
        if settings.DEBUG:
            return 'network1.localhost'
        return 'network1.ditto.technology'

# NOTE: this MUST come first in the middleware order
class CurrentTenantMiddleware(object):
    def process_request(self, request):
        request.tenant = FakeTenant()
        request.urlconf = _get_urls('di')

def _get_urls(tenant_slug):
    # Note, need 'tuple' here otherwise url stuff blows up
    return tuple(
        patterns(
            '',
            (r'^$', RedirectView.as_view(
                pattern_name='ditto:home',
                permanent=True,
            )),
            url(r'^%s/' % tenant_slug, include('network_urls')),
            url(r'^main/', include('multitenancy.urls', namespace="ditto")),
        ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))


Add display for running states

Add display for running states

--- AnnotationToXMLConverter/AnnotationToXMLConverter.py
+++ AnnotationToXMLConverter/AnnotationToXMLConverter.py
@@ -1,5 +1,7 @@
 import os
+import time
 from TextFileReader import *
+

 def main():
     # get the base directory
@@ -8,6 +10,7 @@
     # counter for percentage print
     stage_counter = 0
     total_stage = len(os.listdir(base_directory + "/Annotation"))
+    start_time = time.time()

     for filename in os.listdir(base_directory + "/Annotation"):
         # print the percentage.
@@ -31,6 +34,11 @@
         write_xml_tag(base_directory + "/XML/" + concatenate_extension(base_filename, "xml"),
                       concatenate_extension(base_filename, "jpg"), image_size, annotation_data)

+    end_time = time.time()
+    print()
+    print("%d annotations converted into xml. Total running time: %lf secs." % (total_stage, end_time - start_time))

+
+# main function
 if __name__ == "__main__":
     main()

<|original_code|>
import os
from TextFileReader import *

def main():
    # get the base directory
    base_directory = os.getcwd()

    # counter for percentage print
    stage_counter = 0
    total_stage = len(os.listdir(base_directory + "/Annotation"))

    for filename in os.listdir(base_directory + "/Annotation"):
        # print the percentage.
        stage_counter += 1
        print(stage_counter, "/", total_stage, end=" ", sep=" ")
        print("(", int(stage_counter / total_stage * 100), "%)", sep="")

        # check the given file is a valid txt file.
        if not filename.endswith(".txt"):
            continue

        # get filename without .txt extension
        base_filename = truncate_extension(filename, 3)

        # read data from the file
        image_size = read_image_size(base_directory + "/Image/" + concatenate_extension(base_filename, "jpg"))
        annotation_data = read_annotation_data(base_directory + "/Annotation/"
                                               + concatenate_extension(base_filename, "txt"), image_size)

        # write the xml file
        write_xml_tag(base_directory + "/XML/" + concatenate_extension(base_filename, "xml"),
                      concatenate_extension(base_filename, "jpg"), image_size, annotation_data)

if __name__ == "__main__":
    main()
<|edits_diff|>
--- AnnotationToXMLConverter/AnnotationToXMLConverter.py
+++ AnnotationToXMLConverter/AnnotationToXMLConverter.py
@@ -1,5 +1,7 @@
 import os
+import time
 from TextFileReader import *
+

 def main():
     # get the base directory
@@ -8,6 +10,7 @@
     # counter for percentage print
     stage_counter = 0
     total_stage = len(os.listdir(base_directory + "/Annotation"))
+    start_time = time.time()

     for filename in os.listdir(base_directory + "/Annotation"):
         # print the percentage.
@@ -31,6 +34,9 @@
         write_xml_tag(base_directory + "/XML/" + concatenate_extension(base_filename, "xml"),
                       concatenate_extension(base_filename, "jpg"), image_size, annotation_data)

+    end_time = time.time()
+    print()
+    print("%d annotations converted into xml. Total running time: %lf secs." % (total_stage, end_time - start_time))

 if __name__ == "__main__":
     main()
<|current_version|>
import os
import time
from TextFileReader import *

def main():
    # get the base directory
    base_directory = os.getcwd()

    # counter for percentage print
    stage_counter = 0
    total_stage = len(os.listdir(base_directory + "/Annotation"))
    start_time = time.time()

    for filename in os.listdir(base_directory + "/Annotation"):
        # print the percentage.
        stage_counter += 1
        print(stage_counter, "/", total_stage, end=" ", sep=" ")
        print("(", int(stage_counter / total_stage * 100), "%)", sep="")

        # check the given file is a valid txt file.
        if not filename.endswith(".txt"):
            continue

        # get filename without .txt extension
        base_filename = truncate_extension(filename, 3)

        # read data from the file
        image_size = read_image_size(base_directory + "/Image/" + concatenate_extension(base_filename, "jpg"))
        annotation_data = read_annotation_data(base_directory + "/Annotation/"
                                               + concatenate_extension(base_filename, "txt"), image_size)

        # write the xml file
        write_xml_tag(base_directory + "/XML/" + concatenate_extension(base_filename, "xml"),
                      concatenate_extension(base_filename, "jpg"), image_size, annotation_data)

    end_time = time.time()
    print()
    print("%d annotations converted into xml. Total running time: %lf secs." % (total_stage, end_time - start_time))

if __name__ == "__main__":
    main()
<|next_version|>
import os
import time
from TextFileReader import *

def main():
    # get the base directory
    base_directory = os.getcwd()

    # counter for percentage print
    stage_counter = 0
    total_stage = len(os.listdir(base_directory + "/Annotation"))
    start_time = time.time()

    for filename in os.listdir(base_directory + "/Annotation"):
        # print the percentage.
        stage_counter += 1
        print(stage_counter, "/", total_stage, end=" ", sep=" ")
        print("(", int(stage_counter / total_stage * 100), "%)", sep="")

        # check the given file is a valid txt file.
        if not filename.endswith(".txt"):
            continue

        # get filename without .txt extension
        base_filename = truncate_extension(filename, 3)

        # read data from the file
        image_size = read_image_size(base_directory + "/Image/" + concatenate_extension(base_filename, "jpg"))
        annotation_data = read_annotation_data(base_directory + "/Annotation/"
                                               + concatenate_extension(base_filename, "txt"), image_size)

        # write the xml file
        write_xml_tag(base_directory + "/XML/" + concatenate_extension(base_filename, "xml"),
                      concatenate_extension(base_filename, "jpg"), image_size, annotation_data)

    end_time = time.time()
    print()
    print("%d annotations converted into xml. Total running time: %lf secs." % (total_stage, end_time - start_time))

# main function
if __name__ == "__main__":
    main()


Send episode_done=True from local human agent

--- parlai/agents/local_human/local_human.py
+++ parlai/agents/local_human/local_human.py
@@ -15,6 +15,7 @@
     def __init__(self, opt, shared=None):
         super().__init__(opt)
         self.id = 'localHuman'
+        self.done = False

     def observe(self, msg):
         print(display_messages([msg]))
@@ -24,4 +25,11 @@
         reply = {}
         reply['id'] = self.getID()
         reply['text'] = input("Enter Your Reply: ")
+        if reply_text == '[DONE]':
+            reply['episode_done'] = True
+            self.done = True
+        reply['text'] = reply_text
         return reply
+
+    def epoch_done(self):
+        return self.done

<|original_code|>
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
"""Agent does gets the local keyboard input in the act() function.
   Example: python examples/eval_model.py -m local_human -t babi:Task1k:1 -dt valid
"""

from parlai.core.agents import Agent
from parlai.core.worlds import display_messages

class LocalHumanAgent(Agent):

    def __init__(self, opt, shared=None):
        super().__init__(opt)
        self.id = 'localHuman'

    def observe(self, msg):
        print(display_messages([msg]))

    def act(self):
        obs = self.observation
        reply = {}
        reply['id'] = self.getID()
        reply['text'] = input("Enter Your Reply: ")
        return reply

<|edits_diff|>
--- parlai/agents/local_human/local_human.py
+++ parlai/agents/local_human/local_human.py
@@ -15,6 +15,7 @@
     def __init__(self, opt, shared=None):
         super().__init__(opt)
         self.id = 'localHuman'
+        self.done = False

     def observe(self, msg):
         print(display_messages([msg]))
@@ -24,4 +25,8 @@
         reply = {}
         reply['id'] = self.getID()
         reply['text'] = input("Enter Your Reply: ")
+        if reply_text == '[DONE]':
+            reply['episode_done'] = True
+            self.done = True
+        reply['text'] = reply_text
         return reply
<|current_version|>
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
"""Agent does gets the local keyboard input in the act() function.
   Example: python examples/eval_model.py -m local_human -t babi:Task1k:1 -dt valid
"""

from parlai.core.agents import Agent
from parlai.core.worlds import display_messages

class LocalHumanAgent(Agent):

    def __init__(self, opt, shared=None):
        super().__init__(opt)
        self.id = 'localHuman'
        self.done = False

    def observe(self, msg):
        print(display_messages([msg]))

    def act(self):
        obs = self.observation
        reply = {}
        reply['id'] = self.getID()
        reply['text'] = input("Enter Your Reply: ")
        if reply_text == '[DONE]':
            reply['episode_done'] = True
            self.done = True
        reply['text'] = reply_text
        return reply

<|next_version|>
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
"""Agent does gets the local keyboard input in the act() function.
   Example: python examples/eval_model.py -m local_human -t babi:Task1k:1 -dt valid
"""

from parlai.core.agents import Agent
from parlai.core.worlds import display_messages

class LocalHumanAgent(Agent):

    def __init__(self, opt, shared=None):
        super().__init__(opt)
        self.id = 'localHuman'
        self.done = False

    def observe(self, msg):
        print(display_messages([msg]))

    def act(self):
        obs = self.observation
        reply = {}
        reply['id'] = self.getID()
        reply['text'] = input("Enter Your Reply: ")
        if reply_text == '[DONE]':
            reply['episode_done'] = True
            self.done = True
        reply['text'] = reply_text
        return reply

    def epoch_done(self):
        return self.done


Set max threads for MKL.

Set max threads for MKL.

--- code/python/knub/thesis/topic_model.py
+++ code/python/knub/thesis/topic_model.py
@@ -1,7 +1,9 @@
 import logging, gensim, bz2
+import mkl
 from knub.thesis.util.memory import limit_memory

 logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
+mkl.set_num_threads(8)

 def main():
     logging.info("Starting Wikipedia LDA")

<|original_code|>
import logging, gensim, bz2
from knub.thesis.util.memory import limit_memory

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

def main():
    logging.info("Starting Wikipedia LDA")
    # limit memory to 32 GB
    limit_memory(32000)

    id2word = gensim.corpora.Dictionary.load_from_text(bz2.BZ2File("/data/wikipedia/2016-06-21/gensim_wordids.txt.bz2"))
    mm = gensim.corpora.MmCorpus("/data/wikipedia/2016-06-21/gensim_tfidf.mm")
    print mm
    lda = gensim.models.ldamodel.LdaModel(corpus=mm, num_topics=100, id2word=id2word, chunksize=10000, passes=1)
    # lda = gensim.models.ldamodel.LdaModel(corpus=mm, num_topics=100, id2word=id2word, workers=3)
    lda.save("/data/wikipedia/2016-06-21/topics.model")
    lda.print_topics()
    logging.info("Finished Wikipedia LDA")

if __name__ == "__main__":
    main()
<|edits_diff|>
--- code/python/knub/thesis/topic_model.py
+++ code/python/knub/thesis/topic_model.py
@@ -1,4 +1,5 @@
 import logging, gensim, bz2
+import mkl
 from knub.thesis.util.memory import limit_memory

 logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
<|current_version|>
import logging, gensim, bz2
import mkl
from knub.thesis.util.memory import limit_memory

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

def main():
    logging.info("Starting Wikipedia LDA")
    # limit memory to 32 GB
    limit_memory(32000)

    id2word = gensim.corpora.Dictionary.load_from_text(bz2.BZ2File("/data/wikipedia/2016-06-21/gensim_wordids.txt.bz2"))
    mm = gensim.corpora.MmCorpus("/data/wikipedia/2016-06-21/gensim_tfidf.mm")
    print mm
    lda = gensim.models.ldamodel.LdaModel(corpus=mm, num_topics=100, id2word=id2word, chunksize=10000, passes=1)
    # lda = gensim.models.ldamodel.LdaModel(corpus=mm, num_topics=100, id2word=id2word, workers=3)
    lda.save("/data/wikipedia/2016-06-21/topics.model")
    lda.print_topics()
    logging.info("Finished Wikipedia LDA")

if __name__ == "__main__":
    main()
<|next_version|>
import logging, gensim, bz2
import mkl
from knub.thesis.util.memory import limit_memory

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
mkl.set_num_threads(8)

def main():
    logging.info("Starting Wikipedia LDA")
    # limit memory to 32 GB
    limit_memory(32000)

    id2word = gensim.corpora.Dictionary.load_from_text(bz2.BZ2File("/data/wikipedia/2016-06-21/gensim_wordids.txt.bz2"))
    mm = gensim.corpora.MmCorpus("/data/wikipedia/2016-06-21/gensim_tfidf.mm")
    print mm
    lda = gensim.models.ldamodel.LdaModel(corpus=mm, num_topics=100, id2word=id2word, chunksize=10000, passes=1)
    # lda = gensim.models.ldamodel.LdaModel(corpus=mm, num_topics=100, id2word=id2word, workers=3)
    lda.save("/data/wikipedia/2016-06-21/topics.model")
    lda.print_topics()
    logging.info("Finished Wikipedia LDA")

if __name__ == "__main__":
    main()


Add methods for Documentation Endpoints

Add methods for Documentation Endpoints

Signed-off-by: Huang Yaming <ce2ec9fa26f071590d1a68b9e7447b51f2c76084@gmail.com>

--- gerrit/documentation.py
+++ gerrit/documentation.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-

 URLS = {
+    'SEARCH': 'Documentation/?q=%(keyword)s',
 }

@@ -13,3 +14,8 @@
     def __init__(self, gerrit):
         self.gerrit = gerrit
         self.gerrit.URLS.update(URLS)
+
+    def search(self, keyword):
+        url = self.gerrit.url('SEARCH', keyword=keyword)
+        r = Request(method='GET', url=url, auth=self.gerrit.auth)
+        return self.gerrit.dispatch(r)

<|original_code|>
# -*- coding: utf-8 -*-

URLS = {
}

class Documentation(object):
    """ This class provide documentation-related methods
    Documentation related REST endpoints:
    https://gerrit-review.googlesource.com/Documentation/rest-api-documentation.html
    """

    def __init__(self, gerrit):
        self.gerrit = gerrit
        self.gerrit.URLS.update(URLS)

<|edits_diff|>
--- gerrit/documentation.py
+++ gerrit/documentation.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-

 URLS = {
+    'SEARCH': 'Documentation/?q=%(keyword)s',
 }

<|current_version|>
# -*- coding: utf-8 -*-

URLS = {
    'SEARCH': 'Documentation/?q=%(keyword)s',
}

class Documentation(object):
    """ This class provide documentation-related methods
    Documentation related REST endpoints:
    https://gerrit-review.googlesource.com/Documentation/rest-api-documentation.html
    """

    def __init__(self, gerrit):
        self.gerrit = gerrit
        self.gerrit.URLS.update(URLS)

<|next_version|>
# -*- coding: utf-8 -*-

URLS = {
    'SEARCH': 'Documentation/?q=%(keyword)s',
}

class Documentation(object):
    """ This class provide documentation-related methods
    Documentation related REST endpoints:
    https://gerrit-review.googlesource.com/Documentation/rest-api-documentation.html
    """

    def __init__(self, gerrit):
        self.gerrit = gerrit
        self.gerrit.URLS.update(URLS)

    def search(self, keyword):
        url = self.gerrit.url('SEARCH', keyword=keyword)
        r = Request(method='GET', url=url, auth=self.gerrit.auth)
        return self.gerrit.dispatch(r)


Use Fake redis for tests.

Use Fake redis for tests.

--- test/services/tv_remote/test_service.py
+++ test/services/tv_remote/test_service.py
@@ -1,3 +1,5 @@
+import os
+
 from roku import Roku

 from app.core.messaging import Receiver
@@ -8,11 +10,13 @@
 class TestRokuScanner(object):
     @classmethod
     def setup_class(cls):
+        os.environ["USE_FAKE_REDIS"] = "TRUE"
         cls.service_manager = ServiceManager(None)
         cls.service_manager.start_services(["messaging"])

     @classmethod
     def teardown_class(cls):
+        del os.environ["USE_FAKE_REDIS"]
         cls.service_manager.stop()

     def test_basic_discovery(self):

<|original_code|>
from roku import Roku

from app.core.messaging import Receiver
from app.core.servicemanager import ServiceManager
from app.services.tv_remote.service import RokuScanner, RokuTV

class TestRokuScanner(object):
    @classmethod
    def setup_class(cls):
        cls.service_manager = ServiceManager(None)
        cls.service_manager.start_services(["messaging"])

    @classmethod
    def teardown_class(cls):
        cls.service_manager.stop()

    def test_basic_discovery(self):
        roku1 = Roku("abc")
        scanner = RokuScanner("/devices", scan_interval=10)
        scanner.discover_devices = lambda: [roku1]
        scanner.get_device_id = lambda: "deviceid"
        scanner.start()

        receiver = Receiver("/devices")
        msg = receiver.receive()
        expected = {
            "deviceid": {
                "device_id": "deviceid",
                "device_command_queue": "devices/tv/command",
                "device_commands": RokuTV(None, None).read_commands()
            }
        }
        assert msg == expected

<|edits_diff|>
--- test/services/tv_remote/test_service.py
+++ test/services/tv_remote/test_service.py
@@ -1,3 +1,5 @@
+import os
+
 from roku import Roku

 from app.core.messaging import Receiver
@@ -8,6 +10,7 @@
 class TestRokuScanner(object):
     @classmethod
     def setup_class(cls):
+        os.environ["USE_FAKE_REDIS"] = "TRUE"
         cls.service_manager = ServiceManager(None)
         cls.service_manager.start_services(["messaging"])

<|current_version|>
import os

from roku import Roku

from app.core.messaging import Receiver
from app.core.servicemanager import ServiceManager
from app.services.tv_remote.service import RokuScanner, RokuTV

class TestRokuScanner(object):
    @classmethod
    def setup_class(cls):
        os.environ["USE_FAKE_REDIS"] = "TRUE"
        cls.service_manager = ServiceManager(None)
        cls.service_manager.start_services(["messaging"])

    @classmethod
    def teardown_class(cls):
        cls.service_manager.stop()

    def test_basic_discovery(self):
        roku1 = Roku("abc")
        scanner = RokuScanner("/devices", scan_interval=10)
        scanner.discover_devices = lambda: [roku1]
        scanner.get_device_id = lambda: "deviceid"
        scanner.start()

        receiver = Receiver("/devices")
        msg = receiver.receive()
        expected = {
            "deviceid": {
                "device_id": "deviceid",
                "device_command_queue": "devices/tv/command",
                "device_commands": RokuTV(None, None).read_commands()
            }
        }
        assert msg == expected

<|next_version|>
import os

from roku import Roku

from app.core.messaging import Receiver
from app.core.servicemanager import ServiceManager
from app.services.tv_remote.service import RokuScanner, RokuTV

class TestRokuScanner(object):
    @classmethod
    def setup_class(cls):
        os.environ["USE_FAKE_REDIS"] = "TRUE"
        cls.service_manager = ServiceManager(None)
        cls.service_manager.start_services(["messaging"])

    @classmethod
    def teardown_class(cls):
        del os.environ["USE_FAKE_REDIS"]
        cls.service_manager.stop()

    def test_basic_discovery(self):
        roku1 = Roku("abc")
        scanner = RokuScanner("/devices", scan_interval=10)
        scanner.discover_devices = lambda: [roku1]
        scanner.get_device_id = lambda: "deviceid"
        scanner.start()

        receiver = Receiver("/devices")
        msg = receiver.receive()
        expected = {
            "deviceid": {
                "device_id": "deviceid",
                "device_command_queue": "devices/tv/command",
                "device_commands": RokuTV(None, None).read_commands()
            }
        }
        assert msg == expected


Add tests for disabled sympification of vectors

--- tests/vec_test.py
+++ tests/vec_test.py
@@ -1,4 +1,6 @@
 """Tests for vectors."""
+
+import pytest

 from sympy import sympify

@@ -26,3 +28,7 @@
         assert i == v_ab
         assert str(i) == str_ref
         assert repr(i) == repr_ref
+
+        # Vectors should not be sympified.
+        with pytest.raises(TypeError):
+            sympify(i)

<|original_code|>
"""Tests for vectors."""

from sympy import sympify

from drudge import Vec

def test_vecs_has_basic_properties():
    """Tests the basic properties of vector instances."""

    base = Vec('v')
    v_ab = Vec('v', indices=['a', 'b'])
    v_ab_1 = base['a', 'b']
    v_ab_2 = (base['a'])['b']

    indices_ref = (sympify('a'), sympify('b'))
    hash_ref = hash(v_ab)
    str_ref = 'v[a, b]'
    repr_ref = "Vec('v', (a, b))"

    for i in [v_ab, v_ab_1, v_ab_2]:
        assert i.label == base.label
        assert i.base == base
        assert i.indices == indices_ref
        assert hash(i) == hash_ref
        assert i == v_ab
        assert str(i) == str_ref
        assert repr(i) == repr_ref

<|edits_diff|>
--- tests/vec_test.py
+++ tests/vec_test.py
@@ -1,4 +1,6 @@
 """Tests for vectors."""
+
+import pytest

 from sympy import sympify

<|current_version|>
"""Tests for vectors."""

import pytest

from sympy import sympify

from drudge import Vec

def test_vecs_has_basic_properties():
    """Tests the basic properties of vector instances."""

    base = Vec('v')
    v_ab = Vec('v', indices=['a', 'b'])
    v_ab_1 = base['a', 'b']
    v_ab_2 = (base['a'])['b']

    indices_ref = (sympify('a'), sympify('b'))
    hash_ref = hash(v_ab)
    str_ref = 'v[a, b]'
    repr_ref = "Vec('v', (a, b))"

    for i in [v_ab, v_ab_1, v_ab_2]:
        assert i.label == base.label
        assert i.base == base
        assert i.indices == indices_ref
        assert hash(i) == hash_ref
        assert i == v_ab
        assert str(i) == str_ref
        assert repr(i) == repr_ref

<|next_version|>
"""Tests for vectors."""

import pytest

from sympy import sympify

from drudge import Vec

def test_vecs_has_basic_properties():
    """Tests the basic properties of vector instances."""

    base = Vec('v')
    v_ab = Vec('v', indices=['a', 'b'])
    v_ab_1 = base['a', 'b']
    v_ab_2 = (base['a'])['b']

    indices_ref = (sympify('a'), sympify('b'))
    hash_ref = hash(v_ab)
    str_ref = 'v[a, b]'
    repr_ref = "Vec('v', (a, b))"

    for i in [v_ab, v_ab_1, v_ab_2]:
        assert i.label == base.label
        assert i.base == base
        assert i.indices == indices_ref
        assert hash(i) == hash_ref
        assert i == v_ab
        assert str(i) == str_ref
        assert repr(i) == repr_ref

        # Vectors should not be sympified.
        with pytest.raises(TypeError):
            sympify(i)


Add 1 level depth and also categories fields to employee serializer

--- employees/serializers.py
+++ employees/serializers.py
@@ -5,6 +5,7 @@
 class EmployeeSerializer(serializers.ModelSerializer):
     class Meta:
         model = Employee
+        depth = 1
         fields = ('pk',
                   'username',
                   'email',
@@ -16,6 +17,7 @@
                   'current_month_score',
                   'level',
                   'score',
+                  'categories',
                   'is_active',
                   'last_login')

<|original_code|>
from .models import Employee
from rest_framework import serializers

class EmployeeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk',
                  'username',
                  'email',
                  'first_name',
                  'last_name',
                  'role',
                  'skype_id',
                  'last_month_score',
                  'current_month_score',
                  'level',
                  'score',
                  'is_active',
                  'last_login')

class EmployeeListSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk',
                  'username',
                  'email',
                  'first_name',
                  'last_name',
                  'level',
                  'avatar',
                  'score')

class EmployeeAvatarSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk', 'avatar')

<|edits_diff|>
--- employees/serializers.py
+++ employees/serializers.py
@@ -5,6 +5,7 @@
 class EmployeeSerializer(serializers.ModelSerializer):
     class Meta:
         model = Employee
+        depth = 1
         fields = ('pk',
                   'username',
                   'email',
<|current_version|>
from .models import Employee
from rest_framework import serializers

class EmployeeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        depth = 1
        fields = ('pk',
                  'username',
                  'email',
                  'first_name',
                  'last_name',
                  'role',
                  'skype_id',
                  'last_month_score',
                  'current_month_score',
                  'level',
                  'score',
                  'is_active',
                  'last_login')

class EmployeeListSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk',
                  'username',
                  'email',
                  'first_name',
                  'last_name',
                  'level',
                  'avatar',
                  'score')

class EmployeeAvatarSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk', 'avatar')

<|next_version|>
from .models import Employee
from rest_framework import serializers

class EmployeeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        depth = 1
        fields = ('pk',
                  'username',
                  'email',
                  'first_name',
                  'last_name',
                  'role',
                  'skype_id',
                  'last_month_score',
                  'current_month_score',
                  'level',
                  'score',
                  'categories',
                  'is_active',
                  'last_login')

class EmployeeListSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk',
                  'username',
                  'email',
                  'first_name',
                  'last_name',
                  'level',
                  'avatar',
                  'score')

class EmployeeAvatarSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('pk', 'avatar')


Make exceptions available at top-level netdumplings module

--- netdumplings/__init__.py
+++ netdumplings/__init__.py
@@ -1,6 +1,9 @@
 from .dumpling import Dumpling, DumplingDriver
 from .dumplingchef import DumplingChef
 from .dumplingeater import DumplingEater
+from .exceptions import (
+    InvalidDumpling, InvalidDumplingPayload, NetDumplingsError,
+)
 from .dumplinghub import DumplingHub
 from .dumplingkitchen import DumplingKitchen
 from ._version import __version__
@@ -13,5 +16,8 @@
     DumplingEater,
     DumplingHub,
     DumplingKitchen,
+    InvalidDumpling,
+    InvalidDumplingPayload,
+    NetDumplingsError,
     __version__,
 )

<|original_code|>
from .dumpling import Dumpling, DumplingDriver
from .dumplingchef import DumplingChef
from .dumplingeater import DumplingEater
from .dumplinghub import DumplingHub
from .dumplingkitchen import DumplingKitchen
from ._version import __version__

# Workaround to avoid F401 "imported but unused" linter errors.
(
    Dumpling,
    DumplingDriver,
    DumplingChef,
    DumplingEater,
    DumplingHub,
    DumplingKitchen,
    __version__,
)

<|edits_diff|>
--- netdumplings/__init__.py
+++ netdumplings/__init__.py
@@ -1,6 +1,9 @@
 from .dumpling import Dumpling, DumplingDriver
 from .dumplingchef import DumplingChef
 from .dumplingeater import DumplingEater
+from .exceptions import (
+    InvalidDumpling, InvalidDumplingPayload, NetDumplingsError,
+)
 from .dumplinghub import DumplingHub
 from .dumplingkitchen import DumplingKitchen
 from ._version import __version__
<|current_version|>
from .dumpling import Dumpling, DumplingDriver
from .dumplingchef import DumplingChef
from .dumplingeater import DumplingEater
from .exceptions import (
    InvalidDumpling, InvalidDumplingPayload, NetDumplingsError,
)
from .dumplinghub import DumplingHub
from .dumplingkitchen import DumplingKitchen
from ._version import __version__

# Workaround to avoid F401 "imported but unused" linter errors.
(
    Dumpling,
    DumplingDriver,
    DumplingChef,
    DumplingEater,
    DumplingHub,
    DumplingKitchen,
    __version__,
)

<|next_version|>
from .dumpling import Dumpling, DumplingDriver
from .dumplingchef import DumplingChef
from .dumplingeater import DumplingEater
from .exceptions import (
    InvalidDumpling, InvalidDumplingPayload, NetDumplingsError,
)
from .dumplinghub import DumplingHub
from .dumplingkitchen import DumplingKitchen
from ._version import __version__

# Workaround to avoid F401 "imported but unused" linter errors.
(
    Dumpling,
    DumplingDriver,
    DumplingChef,
    DumplingEater,
    DumplingHub,
    DumplingKitchen,
    InvalidDumpling,
    InvalidDumplingPayload,
    NetDumplingsError,
    __version__,
)


Test how cut_by_number handles whitespace

--- test/unit_test/test_cut_number.py
+++ test/unit_test/test_cut_number.py
@@ -18,5 +18,9 @@
         assert cut_by_number("Text", 1) == ["Text"]
         assert cut_by_number("This text has five words", 5) == \
                ["This ", "text ", "has ", "five ", "words"]
+
+    def test_cut_by_number_spacing(self):
         assert cut_by_number("Hanging space ", 2) == ["Hanging ", "space "]
+        assert cut_by_number("Other  whitespace\n is\tfine!\n\n", 4) == \
+               ["Other  ", "whitespace\n ", "is\t", "fine!\n\n"]

<|original_code|>
from lexos.processors.prepare.cutter import split_keep_whitespace, \
    count_words, cut_by_number

class TestCutByNumbers:
    def test_split_keep_whitespace(self):
        assert split_keep_whitespace("Test string") == ["Test", " ", "string"]
        assert split_keep_whitespace("Test") == ["Test"]
        assert split_keep_whitespace(" ") == ["", " ", ""]  # intended?
        assert split_keep_whitespace("") == [""]

    def test_count_words(self):
        assert count_words(["word", "word", " ", "not", "word"]) == 4
        assert count_words(['\n', '\t', ' ', '', '\u3000', "word"]) == 1
        assert count_words([""]) == 0

    def test_cut_by_number_normal(self):
        assert cut_by_number("Text", 1) == ["Text"]
        assert cut_by_number("This text has five words", 5) == \
               ["This ", "text ", "has ", "five ", "words"]
        assert cut_by_number("Hanging space ", 2) == ["Hanging ", "space "]

<|edits_diff|>
--- test/unit_test/test_cut_number.py
+++ test/unit_test/test_cut_number.py
@@ -18,5 +18,7 @@
         assert cut_by_number("Text", 1) == ["Text"]
         assert cut_by_number("This text has five words", 5) == \
                ["This ", "text ", "has ", "five ", "words"]
+
+    def test_cut_by_number_spacing(self):
         assert cut_by_number("Hanging space ", 2) == ["Hanging ", "space "]

<|current_version|>
from lexos.processors.prepare.cutter import split_keep_whitespace, \
    count_words, cut_by_number

class TestCutByNumbers:
    def test_split_keep_whitespace(self):
        assert split_keep_whitespace("Test string") == ["Test", " ", "string"]
        assert split_keep_whitespace("Test") == ["Test"]
        assert split_keep_whitespace(" ") == ["", " ", ""]  # intended?
        assert split_keep_whitespace("") == [""]

    def test_count_words(self):
        assert count_words(["word", "word", " ", "not", "word"]) == 4
        assert count_words(['\n', '\t', ' ', '', '\u3000', "word"]) == 1
        assert count_words([""]) == 0

    def test_cut_by_number_normal(self):
        assert cut_by_number("Text", 1) == ["Text"]
        assert cut_by_number("This text has five words", 5) == \
               ["This ", "text ", "has ", "five ", "words"]

    def test_cut_by_number_spacing(self):
        assert cut_by_number("Hanging space ", 2) == ["Hanging ", "space "]

<|next_version|>
from lexos.processors.prepare.cutter import split_keep_whitespace, \
    count_words, cut_by_number

class TestCutByNumbers:
    def test_split_keep_whitespace(self):
        assert split_keep_whitespace("Test string") == ["Test", " ", "string"]
        assert split_keep_whitespace("Test") == ["Test"]
        assert split_keep_whitespace(" ") == ["", " ", ""]  # intended?
        assert split_keep_whitespace("") == [""]

    def test_count_words(self):
        assert count_words(["word", "word", " ", "not", "word"]) == 4
        assert count_words(['\n', '\t', ' ', '', '\u3000', "word"]) == 1
        assert count_words([""]) == 0

    def test_cut_by_number_normal(self):
        assert cut_by_number("Text", 1) == ["Text"]
        assert cut_by_number("This text has five words", 5) == \
               ["This ", "text ", "has ", "five ", "words"]

    def test_cut_by_number_spacing(self):
        assert cut_by_number("Hanging space ", 2) == ["Hanging ", "space "]
        assert cut_by_number("Other  whitespace\n is\tfine!\n\n", 4) == \
               ["Other  ", "whitespace\n ", "is\t", "fine!\n\n"]


Create url enter Process WebSocket

Create url enter Process WebSocket

--- mining/urls.py
+++ mining/urls.py
@@ -1,9 +1,11 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 from .views import MainHandler, ProcessHandler, DashboardHandler
+from .views import ProcessWebSocket

 INCLUDE_URLS = [
+    (r"/process/(?P<slug>[\w-]+).ws", ProcessWebSocket),
     (r"/process/(?P<slug>[\w-]+).json", ProcessHandler),
     (r"/dashboard/(?P<slug>[\w-]+)", DashboardHandler),
     (r"/", MainHandler),

<|original_code|>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .views import MainHandler, ProcessHandler, DashboardHandler

INCLUDE_URLS = [
    (r"/process/(?P<slug>[\w-]+).json", ProcessHandler),
    (r"/dashboard/(?P<slug>[\w-]+)", DashboardHandler),
    (r"/", MainHandler),
]

<|edits_diff|>
--- mining/urls.py
+++ mining/urls.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 from .views import MainHandler, ProcessHandler, DashboardHandler
+from .views import ProcessWebSocket

 INCLUDE_URLS = [
<|current_version|>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .views import MainHandler, ProcessHandler, DashboardHandler
from .views import ProcessWebSocket

INCLUDE_URLS = [
    (r"/process/(?P<slug>[\w-]+).json", ProcessHandler),
    (r"/dashboard/(?P<slug>[\w-]+)", DashboardHandler),
    (r"/", MainHandler),
]

<|next_version|>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .views import MainHandler, ProcessHandler, DashboardHandler
from .views import ProcessWebSocket

INCLUDE_URLS = [
    (r"/process/(?P<slug>[\w-]+).ws", ProcessWebSocket),
    (r"/process/(?P<slug>[\w-]+).json", ProcessHandler),
    (r"/dashboard/(?P<slug>[\w-]+)", DashboardHandler),
    (r"/", MainHandler),
]


Add text to selection grid

Add text to selection grid

--- falmer/content/models/selection_grid.py
+++ falmer/content/models/selection_grid.py
@@ -3,6 +3,7 @@
 from wagtail.core.fields import StreamField
 from wagtail.admin.edit_handlers import TabbedInterface, StreamFieldPanel, ObjectList

+from falmer.content import components
 from falmer.content.blocks import HeroImageBlock, FalmerImageChooserBlock
 from falmer.content.models.core import Page

@@ -20,6 +21,7 @@
 class SelectionGridPage(Page):
     body = StreamField([
         ('heading_hero', HeroImageBlock()),
+        components.text.to_pair(),
         ('selection_grid', blocks.ListBlock(GridItem)),
     ])

<|original_code|>
from wagtail.core import blocks
from wagtail.core.blocks import RichTextBlock
from wagtail.core.fields import StreamField
from wagtail.admin.edit_handlers import TabbedInterface, StreamFieldPanel, ObjectList

from falmer.content.blocks import HeroImageBlock, FalmerImageChooserBlock
from falmer.content.models.core import Page

class GridItem(blocks.StructBlock):
    title = blocks.CharBlock(required=True)
    link = blocks.URLBlock()
    image = FalmerImageChooserBlock()
    description = RichTextBlock(required=False)

    class Meta:
        icon = 'item'

class SelectionGridPage(Page):
    body = StreamField([
        ('heading_hero', HeroImageBlock()),
        ('selection_grid', blocks.ListBlock(GridItem)),
    ])

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]

    edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Content'),
        ObjectList(Page.promote_panels, heading='Promote'),
        ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
    ])

    type_fields = (
        'body',
    )

<|edits_diff|>
--- falmer/content/models/selection_grid.py
+++ falmer/content/models/selection_grid.py
@@ -3,6 +3,7 @@
 from wagtail.core.fields import StreamField
 from wagtail.admin.edit_handlers import TabbedInterface, StreamFieldPanel, ObjectList

+from falmer.content import components
 from falmer.content.blocks import HeroImageBlock, FalmerImageChooserBlock
 from falmer.content.models.core import Page

<|current_version|>
from wagtail.core import blocks
from wagtail.core.blocks import RichTextBlock
from wagtail.core.fields import StreamField
from wagtail.admin.edit_handlers import TabbedInterface, StreamFieldPanel, ObjectList

from falmer.content import components
from falmer.content.blocks import HeroImageBlock, FalmerImageChooserBlock
from falmer.content.models.core import Page

class GridItem(blocks.StructBlock):
    title = blocks.CharBlock(required=True)
    link = blocks.URLBlock()
    image = FalmerImageChooserBlock()
    description = RichTextBlock(required=False)

    class Meta:
        icon = 'item'

class SelectionGridPage(Page):
    body = StreamField([
        ('heading_hero', HeroImageBlock()),
        ('selection_grid', blocks.ListBlock(GridItem)),
    ])

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]

    edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Content'),
        ObjectList(Page.promote_panels, heading='Promote'),
        ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
    ])

    type_fields = (
        'body',
    )

<|next_version|>
from wagtail.core import blocks
from wagtail.core.blocks import RichTextBlock
from wagtail.core.fields import StreamField
from wagtail.admin.edit_handlers import TabbedInterface, StreamFieldPanel, ObjectList

from falmer.content import components
from falmer.content.blocks import HeroImageBlock, FalmerImageChooserBlock
from falmer.content.models.core import Page

class GridItem(blocks.StructBlock):
    title = blocks.CharBlock(required=True)
    link = blocks.URLBlock()
    image = FalmerImageChooserBlock()
    description = RichTextBlock(required=False)

    class Meta:
        icon = 'item'

class SelectionGridPage(Page):
    body = StreamField([
        ('heading_hero', HeroImageBlock()),
        components.text.to_pair(),
        ('selection_grid', blocks.ListBlock(GridItem)),
    ])

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]

    edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Content'),
        ObjectList(Page.promote_panels, heading='Promote'),
        ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
    ])

    type_fields = (
        'body',
    )


Integrate whitenoise with the Django application

This allows Django to serve static files in production.

--- craigomatic/wsgi.py
+++ craigomatic/wsgi.py
@@ -9,8 +9,11 @@

 from django.core.wsgi import get_wsgi_application

+from whitenoise.django import DjangoWhiteNoise
+
 SITE_ROOT = dirname(dirname(abspath(__file__)))
 path.append(SITE_ROOT)

 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "craigomatic.settings")
 application = get_wsgi_application()
+application = DjangoWhiteNoise(application)

<|original_code|>
"""
WSGI config for craigomatic project.

It exposes the WSGI callable as a module-level variable named ``application``.
"""
import os
from os.path import abspath, dirname
from sys import path

from django.core.wsgi import get_wsgi_application

SITE_ROOT = dirname(dirname(abspath(__file__)))
path.append(SITE_ROOT)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "craigomatic.settings")
application = get_wsgi_application()

<|edits_diff|>
--- craigomatic/wsgi.py
+++ craigomatic/wsgi.py
@@ -9,6 +9,8 @@

 from django.core.wsgi import get_wsgi_application

+from whitenoise.django import DjangoWhiteNoise
+
 SITE_ROOT = dirname(dirname(abspath(__file__)))
 path.append(SITE_ROOT)

<|current_version|>
"""
WSGI config for craigomatic project.

It exposes the WSGI callable as a module-level variable named ``application``.
"""
import os
from os.path import abspath, dirname
from sys import path

from django.core.wsgi import get_wsgi_application

from whitenoise.django import DjangoWhiteNoise

SITE_ROOT = dirname(dirname(abspath(__file__)))
path.append(SITE_ROOT)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "craigomatic.settings")
application = get_wsgi_application()

<|next_version|>
"""
WSGI config for craigomatic project.

It exposes the WSGI callable as a module-level variable named ``application``.
"""
import os
from os.path import abspath, dirname
from sys import path

from django.core.wsgi import get_wsgi_application

from whitenoise.django import DjangoWhiteNoise

SITE_ROOT = dirname(dirname(abspath(__file__)))
path.append(SITE_ROOT)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "craigomatic.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)


Fix for graphene ui on debug mode

Fix for graphene ui on debug mode

--- src/office/views.py
+++ src/office/views.py
@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.http import JsonResponse
 from django.utils.decorators import method_decorator
 from django.utils.translation import ugettext_lazy as _
@@ -17,6 +18,9 @@
     """

     def wrap(request, *args, **kwargs):
+        if settings.DEBUG:
+            if request.user.is_authenticated():
+                return func(request, *args, **kwargs)
         try:
             auth_tuple = JSONWebTokenAuthentication().authenticate(request)
         except APIException as e:

<|original_code|>
from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from graphene_django.views import GraphQLView
from rest_framework import status
from rest_framework.exceptions import APIException
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

def check_jwt_decorator(func):
    """
    Check JWT Token by using DRF Authentication class.
    Returns UNAUTHORIZED response if headers don't contain alive token.

    :param func:
    :return:
    """

    def wrap(request, *args, **kwargs):
        try:
            auth_tuple = JSONWebTokenAuthentication().authenticate(request)
        except APIException as e:
            return JsonResponse({'details': str(e)}, status=e.status_code)
        except Exception as e:
            raise e
        if auth_tuple is None:
            return JsonResponse({'details': _('Unauthorized user')},
                                status=status.HTTP_401_UNAUTHORIZED)
        request.user, request.auth = auth_tuple
        return func(request, *args, **kwargs)

    return wrap

class DRFAuthenticatedGraphQLView(GraphQLView):
    """
    Extended default GraphQLView.
    """

    @method_decorator(check_jwt_decorator)
    def dispatch(self, request, *args, **kwargs):
        return super(DRFAuthenticatedGraphQLView, self).dispatch(
            request, *args, **kwargs)

<|edits_diff|>
--- src/office/views.py
+++ src/office/views.py
@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.http import JsonResponse
 from django.utils.decorators import method_decorator
 from django.utils.translation import ugettext_lazy as _
<|current_version|>
from django.conf import settings
from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from graphene_django.views import GraphQLView
from rest_framework import status
from rest_framework.exceptions import APIException
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

def check_jwt_decorator(func):
    """
    Check JWT Token by using DRF Authentication class.
    Returns UNAUTHORIZED response if headers don't contain alive token.

    :param func:
    :return:
    """

    def wrap(request, *args, **kwargs):
        try:
            auth_tuple = JSONWebTokenAuthentication().authenticate(request)
        except APIException as e:
            return JsonResponse({'details': str(e)}, status=e.status_code)
        except Exception as e:
            raise e
        if auth_tuple is None:
            return JsonResponse({'details': _('Unauthorized user')},
                                status=status.HTTP_401_UNAUTHORIZED)
        request.user, request.auth = auth_tuple
        return func(request, *args, **kwargs)

    return wrap

class DRFAuthenticatedGraphQLView(GraphQLView):
    """
    Extended default GraphQLView.
    """

    @method_decorator(check_jwt_decorator)
    def dispatch(self, request, *args, **kwargs):
        return super(DRFAuthenticatedGraphQLView, self).dispatch(
            request, *args, **kwargs)

<|next_version|>
from django.conf import settings
from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from graphene_django.views import GraphQLView
from rest_framework import status
from rest_framework.exceptions import APIException
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

def check_jwt_decorator(func):
    """
    Check JWT Token by using DRF Authentication class.
    Returns UNAUTHORIZED response if headers don't contain alive token.

    :param func:
    :return:
    """

    def wrap(request, *args, **kwargs):
        if settings.DEBUG:
            if request.user.is_authenticated():
                return func(request, *args, **kwargs)
        try:
            auth_tuple = JSONWebTokenAuthentication().authenticate(request)
        except APIException as e:
            return JsonResponse({'details': str(e)}, status=e.status_code)
        except Exception as e:
            raise e
        if auth_tuple is None:
            return JsonResponse({'details': _('Unauthorized user')},
                                status=status.HTTP_401_UNAUTHORIZED)
        request.user, request.auth = auth_tuple
        return func(request, *args, **kwargs)

    return wrap

class DRFAuthenticatedGraphQLView(GraphQLView):
    """
    Extended default GraphQLView.
    """

    @method_decorator(check_jwt_decorator)
    def dispatch(self, request, *args, **kwargs):
        return super(DRFAuthenticatedGraphQLView, self).dispatch(
            request, *args, **kwargs)