commit
stringlengths
40
40
old_file
stringlengths
4
150
new_file
stringlengths
4
150
old_contents
stringlengths
0
3.26k
new_contents
stringlengths
1
4.43k
subject
stringlengths
15
501
message
stringlengths
15
4.06k
lang
stringclasses
4 values
license
stringclasses
13 values
repos
stringlengths
5
91.5k
diff
stringlengths
0
4.35k
1160a10a3d78eee3be61d760849e70e645272355
analytical/__init__.py
analytical/__init__.py
""" Analytics service integration for Django ======================================== The django-analytical application integrates analytics services into a Django_ project. See the ``docs`` directory for more information. .. _Django: http://www.djangoproject.com/ """ __author__ = "Joost Cassee" __email__ = "joost@cassee.net" __version__ = "0.9.0" __copyright__ = "Copyright (C) 2011 Joost Cassee" __license__ = "MIT License"
""" Analytics service integration for Django ======================================== The django-analytical application integrates analytics services into a Django_ project. See the ``docs`` directory for more information. .. _Django: http://www.djangoproject.com/ """ __author__ = "Joost Cassee" __email__ = "joost@cassee.net" __version__ = "0.9.0" __copyright__ = "Copyright (C) 2011 Joost Cassee and others" __license__ = "MIT License"
Add 'and others' to copyright
Add 'and others' to copyright
Python
mit
jcassee/django-analytical,ericdwang/django-analytical,machtfit/django-analytical,apocquet/django-analytical,bittner/django-analytical,ChristosChristofidis/django-analytical,pjdelport/django-analytical
--- +++ @@ -11,5 +11,5 @@ __author__ = "Joost Cassee" __email__ = "joost@cassee.net" __version__ = "0.9.0" -__copyright__ = "Copyright (C) 2011 Joost Cassee" +__copyright__ = "Copyright (C) 2011 Joost Cassee and others" __license__ = "MIT License"
576dc66d2826759e05d55d5ffbef446825a62481
designatedashboard/__init__.py
designatedashboard/__init__.py
# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import pbr.version __version__ = pbr.version.VersionInfo( 'designatedashboard').version_string()
# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import pbr.version __version__ = pbr.version.VersionInfo( 'designate-dashboard').version_string()
Fix package name in init.py
Fix package name in init.py Change-Id: Ib20efd224de709d493d98cfd9ab5dad6005779de
Python
apache-2.0
openstack/designate-dashboard,openstack/designate-dashboard,openstack/designate-dashboard
--- +++ @@ -16,4 +16,4 @@ __version__ = pbr.version.VersionInfo( - 'designatedashboard').version_string() + 'designate-dashboard').version_string()
b2a977a7285cbe832350492b967213b5261ad6b4
flask_app/tasks.py
flask_app/tasks.py
from __future__ import absolute_import import functools import os import sys import logbook from celery import Celery from celery.signals import after_setup_logger, after_setup_task_logger from .app import create_app _logger = logbook.Logger(__name__) queue = Celery('tasks', broker='redis://localhost') queue.conf.update( CELERY_TASK_SERIALIZER='json', CELERY_ACCEPT_CONTENT=['json'], # Ignore other content CELERY_RESULT_SERIALIZER='json', CELERY_ENABLE_UTC=True, ) def setup_log(**args): logbook.SyslogHandler().push_application() logbook.StreamHandler(sys.stderr, bubble=True).push_application() APP = None def needs_app_context(f): @functools.wraps(f) def wrapper(*args, **kwargs): global APP if APP is None: APP = create_app() with APP.app_context(): return f(*args, **kwargs) return wrapper after_setup_logger.connect(setup_log) after_setup_task_logger.connect(setup_log)
from __future__ import absolute_import import functools import os import sys import logging import logging.handlers import logbook from celery import Celery from celery.signals import after_setup_logger, after_setup_task_logger from celery.log import redirect_stdouts_to_logger from .app import create_app _logger = logbook.Logger(__name__) queue = Celery('tasks', broker='redis://localhost') queue.conf.update( CELERY_TASK_SERIALIZER='json', CELERY_ACCEPT_CONTENT=['json'], # Ignore other content CELERY_RESULT_SERIALIZER='json', CELERY_ENABLE_UTC=True, ) def setup_log(**args): logbook.SyslogHandler().push_application() logbook.StreamHandler(sys.stderr, bubble=True).push_application() redirect_stdouts_to_logger(args['logger']) # logs to local syslog if os.path.exists('/dev/log'): h = logging.handlers.SysLogHandler('/dev/log') else: h = logging.handlers.SysLogHandler() h.setLevel(args['loglevel']) formatter = logging.Formatter(logging.BASIC_FORMAT) h.setFormatter(formatter) args['logger'].addHandler(h) APP = None def needs_app_context(f): @functools.wraps(f) def wrapper(*args, **kwargs): global APP if APP is None: APP = create_app() with APP.app_context(): return f(*args, **kwargs) return wrapper after_setup_logger.connect(setup_log) after_setup_task_logger.connect(setup_log)
Fix celery logging in deployment
Fix celery logging in deployment
Python
mit
getslash/mailboxer,getslash/mailboxer,getslash/mailboxer,vmalloc/mailboxer,vmalloc/mailboxer,vmalloc/mailboxer,Infinidat/lanister,Infinidat/lanister
--- +++ @@ -4,10 +4,13 @@ import os import sys +import logging +import logging.handlers import logbook from celery import Celery from celery.signals import after_setup_logger, after_setup_task_logger +from celery.log import redirect_stdouts_to_logger from .app import create_app @@ -25,6 +28,15 @@ def setup_log(**args): logbook.SyslogHandler().push_application() logbook.StreamHandler(sys.stderr, bubble=True).push_application() + redirect_stdouts_to_logger(args['logger']) # logs to local syslog + if os.path.exists('/dev/log'): + h = logging.handlers.SysLogHandler('/dev/log') + else: + h = logging.handlers.SysLogHandler() + h.setLevel(args['loglevel']) + formatter = logging.Formatter(logging.BASIC_FORMAT) + h.setFormatter(formatter) + args['logger'].addHandler(h) APP = None
16256c57de5b12b2a1ef148d2ba15db2dfce7407
foundry/settings_dev.py
foundry/settings_dev.py
from foundry.settings import * #FOUNDRY['layers'] = ('basic',) FOUNDRY['layers'] = ('web', 'basic',) #FOUNDRY['layers'] = ('mid', 'basic',) #FOUNDRY['layers'] = ('smart', 'mid', 'basic',) compute_settings(sys.modules[__name__])
from foundry.settings import * #FOUNDRY['layers'] = ('basic',) #FOUNDRY['layers'] = ('smart', 'basic',) FOUNDRY['layers'] = ('web', 'basic',) CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', } }
Disable caching in development mode
Disable caching in development mode
Python
bsd-3-clause
praekelt/jmbo-foundry,praekelt/jmbo-foundry,praekelt/jmbo-foundry
--- +++ @@ -1,9 +1,11 @@ from foundry.settings import * #FOUNDRY['layers'] = ('basic',) +#FOUNDRY['layers'] = ('smart', 'basic',) FOUNDRY['layers'] = ('web', 'basic',) -#FOUNDRY['layers'] = ('mid', 'basic',) -#FOUNDRY['layers'] = ('smart', 'mid', 'basic',) - -compute_settings(sys.modules[__name__]) +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } +}
796f9ff27f579557237c48196eb50d40269c6840
glitch/__main__.py
glitch/__main__.py
from . import config from . import apikeys import argparse import logging parser = argparse.ArgumentParser(description="Invoke the Infinite Glitch server(s)") parser.add_argument("server", help="Server to invoke", choices=["main", "renderer"], nargs="?", default="main") parser.add_argument("-l", "--log", help="Logging level", type=lambda x: x.upper(), choices=logging._nameToLevel, # NAUGHTY default="INFO") parser.add_argument("--dev", help="Dev mode (no logins)", action='store_true') arguments = parser.parse_args() log = logging.getLogger(__name__) logging.basicConfig(level=getattr(logging, arguments.log), format='%(asctime)s:%(levelname)s:%(name)s:%(message)s') if arguments.server == "renderer": from . import renderer renderer.run() # doesn't return else: from . import server server.run(disable_logins=arguments.dev) # doesn't return
from . import config from . import apikeys import argparse # Hack: Allow "python -m glitch database" to be the same as "glitch.database" import sys if len(sys.argv) > 1 and sys.argv[1] == "database": from . import database import clize sys.exit(clize.run(*database.commands, args=sys.argv[1:])) import logging parser = argparse.ArgumentParser(description="Invoke the Infinite Glitch server(s)") parser.add_argument("server", help="Server to invoke", choices=["main", "renderer"], nargs="?", default="main") parser.add_argument("-l", "--log", help="Logging level", type=lambda x: x.upper(), choices=logging._nameToLevel, # NAUGHTY default="INFO") parser.add_argument("--dev", help="Dev mode (no logins)", action='store_true') arguments = parser.parse_args() log = logging.getLogger(__name__) logging.basicConfig(level=getattr(logging, arguments.log), format='%(asctime)s:%(levelname)s:%(name)s:%(message)s') if arguments.server == "renderer": from . import renderer renderer.run() # doesn't return else: from . import server server.run(disable_logins=arguments.dev) # doesn't return
Allow 'python -m glitch database' as well as with a dot
Allow 'python -m glitch database' as well as with a dot
Python
artistic-2.0
MikeiLL/appension,MikeiLL/appension,Rosuav/appension,Rosuav/appension,MikeiLL/appension,MikeiLL/appension,Rosuav/appension,Rosuav/appension
--- +++ @@ -1,6 +1,13 @@ from . import config from . import apikeys import argparse + +# Hack: Allow "python -m glitch database" to be the same as "glitch.database" +import sys +if len(sys.argv) > 1 and sys.argv[1] == "database": + from . import database + import clize + sys.exit(clize.run(*database.commands, args=sys.argv[1:])) import logging parser = argparse.ArgumentParser(description="Invoke the Infinite Glitch server(s)")
452b48b9313af8126052a32230e789dff2c69df7
frontui/data.py
frontui/data.py
""" Data layer """ # pylint: disable=line-too-long import json import os from frontui.models import ChecklistInfo class DataProvider: """ Data provider (objects, questions, etc) """ def __init__(self): self.data_dir = './frontui/app_data' self.checklists_dir = self.data_dir + '/checklists' self.objects = list() self.checklist = ChecklistInfo() def add_object(self, obj): """ Add object to collection """ self.objects.append(obj) def save_checklist(self, obj_num, obj_date, obj_dict): """ Save checklist data """ obj_json = json.dumps(obj_dict, sort_keys=True, indent=4) filedir = self.checklists_dir + '/' + obj_num if not os.path.exists(filedir): os.makedirs(filedir) filename = obj_date + '.json' with open(filedir + '/' + filename, 'w', encoding='utf8') as file: file.write(obj_json) return
""" Data layer """ # pylint: disable=line-too-long import json import os from frontui.models import ChecklistInfo class DataProvider: """ Data provider (objects, questions, etc) """ def __init__(self): self.data_dir = './frontui/app_data' self.checklists_dir = self.data_dir + '/checklists' self.objects = list() self.checklist = ChecklistInfo() def add_object(self, obj): """ Add object to collection """ self.objects.append(obj) def save_checklist(self, obj_num, obj_date, obj_dict): """ Save checklist data """ obj_json = json.dumps(obj_dict, sort_keys=True, indent=4, ensure_ascii=False) filedir = self.checklists_dir + '/' + obj_num if not os.path.exists(filedir): os.makedirs(filedir) filename = obj_date + '.json' with open(filedir + '/' + filename, 'w', encoding='utf8') as file: file.write(obj_json) return
Fix non ascii symbols in json
Fix non ascii symbols in json
Python
mit
nixxa/SecretShopper,nixxa/SecretShopper,nixxa/SecretShopper
--- +++ @@ -21,7 +21,7 @@ def save_checklist(self, obj_num, obj_date, obj_dict): """ Save checklist data """ - obj_json = json.dumps(obj_dict, sort_keys=True, indent=4) + obj_json = json.dumps(obj_dict, sort_keys=True, indent=4, ensure_ascii=False) filedir = self.checklists_dir + '/' + obj_num if not os.path.exists(filedir): os.makedirs(filedir)
0d572d60522ae0e80105330981a66bc541434b99
rip/filter_operators.py
rip/filter_operators.py
EQUALS = 'equals' GT = 'gt' LT = 'lt' OPERATOR_SEPARATOR = '__' REVERSE_ORDER = '-' ALL_OPERATORS = {EQUALS: 1, GT: 1, LT: 1} def split_to_field_and_filter_type(filter_name): filter_split = filter_name.split(OPERATOR_SEPARATOR) filter_type = filter_split[-1] if len(filter_split) > 0 else None if filter_type in ALL_OPERATORS: return OPERATOR_SEPARATOR.join(filter_split[:-1]), filter_type else: return filter_name, None def split_to_field_and_order_type(field_name_with_operator): if field_name_with_operator.startswith(REVERSE_ORDER): return field_name_with_operator[1:], REVERSE_ORDER else: return field_name_with_operator, None def transform_to_list(val): if isinstance(val, (list, tuple)): return val else: return [val]
EQUALS = 'equals' GT = 'gt' LT = 'lt' IN = 'in' OPERATOR_SEPARATOR = '__' REVERSE_ORDER = '-' ALL_OPERATORS = {EQUALS: 1, GT: 1, LT: 1, IN: 1} def split_to_field_and_filter_type(filter_name): filter_split = filter_name.split(OPERATOR_SEPARATOR) filter_type = filter_split[-1] if len(filter_split) > 0 else None if filter_type in ALL_OPERATORS: return OPERATOR_SEPARATOR.join(filter_split[:-1]), filter_type else: return filter_name, None def split_to_field_and_order_type(field_name_with_operator): if field_name_with_operator.startswith(REVERSE_ORDER): return field_name_with_operator[1:], REVERSE_ORDER else: return field_name_with_operator, None def transform_to_list(val): if isinstance(val, (list, tuple)): return val else: return [val]
Support __in as operator for backwards comp
Support __in as operator for backwards comp
Python
mit
Aplopio/rip,Aplopio/django_rip
--- +++ @@ -2,11 +2,12 @@ EQUALS = 'equals' GT = 'gt' LT = 'lt' +IN = 'in' OPERATOR_SEPARATOR = '__' REVERSE_ORDER = '-' -ALL_OPERATORS = {EQUALS: 1, GT: 1, LT: 1} +ALL_OPERATORS = {EQUALS: 1, GT: 1, LT: 1, IN: 1} def split_to_field_and_filter_type(filter_name):
dc6819f67a5f348d260c36c496bc9d116a875ef7
backend/backend/serializers.py
backend/backend/serializers.py
from rest_framework import serializers from .models import Animal class AnimalSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Animal fields = ('id', 'name', 'dob', 'gender', 'active', 'own', 'father', 'mother')
from rest_framework import serializers from .models import Animal class AnimalSerializer(serializers.ModelSerializer): class Meta: model = Animal fields = ('id', 'name', 'dob', 'gender', 'active', 'own', 'father', 'mother')
Change sanitizer to normal model sanitizer, so it sends ids of parents.
Change sanitizer to normal model sanitizer, so it sends ids of parents.
Python
apache-2.0
mmlado/animal_pairing,mmlado/animal_pairing
--- +++ @@ -1,7 +1,7 @@ from rest_framework import serializers from .models import Animal -class AnimalSerializer(serializers.HyperlinkedModelSerializer): +class AnimalSerializer(serializers.ModelSerializer): class Meta: model = Animal fields = ('id', 'name', 'dob', 'gender', 'active', 'own', 'father', 'mother')
988cac30eeb3ca9ee25378581371e5ea61faec3e
paypal/exceptions.py
paypal/exceptions.py
from oscar.apps.payment.exceptions import PaymentError class PayPalError(PaymentError): pass
try: from oscar.apps.payment.exceptions import PaymentError except ImportError: class PaymentError(Exception): pass class PayPalError(PaymentError): pass
Make gateway importable without django-oscar installed.
Make gateway importable without django-oscar installed.
Python
bsd-3-clause
vintasoftware/django-oscar-paypal,ZachGoldberg/django-oscar-paypal,bharling/django-oscar-worldpay,britco/django-oscar-paypal,st8st8/django-oscar-paypal,evonove/django-oscar-paypal,embedded1/django-oscar-paypal,bharling/django-oscar-worldpay,FedeDR/django-oscar-paypal,django-oscar/django-oscar-paypal,django-oscar/django-oscar-paypal,nfletton/django-oscar-paypal,enodyt/django-oscar-paypal,embedded1/django-oscar-paypal,ZachGoldberg/django-oscar-paypal,st8st8/django-oscar-paypal,nfletton/django-oscar-paypal,lpakula/django-oscar-paypal,lpakula/django-oscar-paypal,lpakula/django-oscar-paypal,ZachGoldberg/django-oscar-paypal,vintasoftware/django-oscar-paypal,enodyt/django-oscar-paypal,evonove/django-oscar-paypal,nfletton/django-oscar-paypal,FedeDR/django-oscar-paypal,phedoreanu/django-oscar-paypal,phedoreanu/django-oscar-paypal,embedded1/django-oscar-paypal,enodyt/django-oscar-paypal,bharling/django-oscar-worldpay,bharling/django-oscar-worldpay,vintasoftware/django-oscar-paypal,phedoreanu/django-oscar-paypal,britco/django-oscar-paypal,django-oscar/django-oscar-paypal,evonove/django-oscar-paypal,britco/django-oscar-paypal,st8st8/django-oscar-paypal,FedeDR/django-oscar-paypal
--- +++ @@ -1,5 +1,8 @@ -from oscar.apps.payment.exceptions import PaymentError - +try: + from oscar.apps.payment.exceptions import PaymentError +except ImportError: + class PaymentError(Exception): + pass class PayPalError(PaymentError): pass
8fa0c30cce8d47344ea66a26d4d627fe12c46ee9
pombola/settings/south_africa.py
pombola/settings/south_africa.py
import re from .base import * from .south_africa_base import * INSTALLED_APPS = insert_after(INSTALLED_APPS, 'markitup', 'pombola.' + COUNTRY_APP) INSTALLED_APPS += OPTIONAL_APPS # This is needed by the speeches application MIDDLEWARE_CLASSES += ( 'pombola.middleware.FakeInstanceMiddleware', ) ENABLED_FEATURES = make_enabled_features(INSTALLED_APPS, ALL_OPTIONAL_APPS)
import re from .base import * from .south_africa_base import * HAYSTACK_CONNECTIONS['default']['EXCLUDED_INDEXES'] = ['pombola.search.search_indexes.PlaceIndex'] INSTALLED_APPS = insert_after(INSTALLED_APPS, 'markitup', 'pombola.' + COUNTRY_APP) INSTALLED_APPS += OPTIONAL_APPS # This is needed by the speeches application MIDDLEWARE_CLASSES += ( 'pombola.middleware.FakeInstanceMiddleware', ) ENABLED_FEATURES = make_enabled_features(INSTALLED_APPS, ALL_OPTIONAL_APPS)
Add PlaceIndex to the Haystack EXCLUDED_INDEXES
ZA: Add PlaceIndex to the Haystack EXCLUDED_INDEXES This was a mistake in the earlier rearrangement of the settings modules; PlaceIndex needed to be added to Haystack EXCLUDED_INDEXES in the south_africa module as well as tests_south_africa.
Python
agpl-3.0
hzj123/56th,mysociety/pombola,geoffkilpin/pombola,patricmutwiri/pombola,mysociety/pombola,ken-muturi/pombola,patricmutwiri/pombola,patricmutwiri/pombola,hzj123/56th,hzj123/56th,hzj123/56th,geoffkilpin/pombola,patricmutwiri/pombola,ken-muturi/pombola,mysociety/pombola,mysociety/pombola,ken-muturi/pombola,hzj123/56th,geoffkilpin/pombola,hzj123/56th,patricmutwiri/pombola,mysociety/pombola,geoffkilpin/pombola,ken-muturi/pombola,mysociety/pombola,ken-muturi/pombola,geoffkilpin/pombola,geoffkilpin/pombola,patricmutwiri/pombola,ken-muturi/pombola
--- +++ @@ -2,6 +2,8 @@ from .base import * from .south_africa_base import * + +HAYSTACK_CONNECTIONS['default']['EXCLUDED_INDEXES'] = ['pombola.search.search_indexes.PlaceIndex'] INSTALLED_APPS = insert_after(INSTALLED_APPS, 'markitup',
cbacb4148eba442a5d2b178721bf5805d31fdf8d
disposable_email_checker/__init__.py
disposable_email_checker/__init__.py
from django.conf import settings import re import sys class DisposableEmailChecker(): """ Check if an email is from a disposable email service """ def __init__(self): self.emails = [line.strip() for line in open(settings.DISPOSABLE_EMAIL_DOMAINS)] def chunk(l,n): return (l[i:i+n] for i in xrange(0, len(l), n)) def is_disposable(self, email): for email_group in self.chunk(self.emails, 20): regex = "(.*" + ")|(.*".join(email_group) + ")" if re.match(regex, email): return True return False
from django.conf import settings import re import sys class DisposableEmailChecker(): """ Check if an email is from a disposable email service """ def __init__(self): self.emails = [line.strip() for line in open(settings.DISPOSABLE_EMAIL_DOMAINS)] def chunk(self,l,n): return (l[i:i+n] for i in xrange(0, len(l), n)) def is_disposable(self, email): for email_group in self.chunk(self.emails, 20): regex = "(.*" + ")|(.*".join(email_group) + ")" if re.match(regex, email): return True return False
Fix bug in chunk arguments
Fix bug in chunk arguments
Python
bsd-3-clause
aaronbassett/DisposableEmailChecker
--- +++ @@ -12,7 +12,7 @@ def __init__(self): self.emails = [line.strip() for line in open(settings.DISPOSABLE_EMAIL_DOMAINS)] - def chunk(l,n): + def chunk(self,l,n): return (l[i:i+n] for i in xrange(0, len(l), n)) def is_disposable(self, email):
8a28dee1bc3ca8ec83705cc431768ef18be7798c
segments/virtual_env.py
segments/virtual_env.py
import os def add_virtual_env_segment(): env = os.getenv('VIRTUAL_ENV') if env is None: return env_name = os.path.basename(env) bg = Color.VIRTUAL_ENV_BG fg = Color.VIRTUAL_ENV_FG powerline.append(' %s ' % env_name, fg, bg) add_virtual_env_segment()
import os def add_virtual_env_segment(): env = os.getenv('VIRTUAL_ENV') or os.getenv('CONDA_ENV_PATH') if env is None: return env_name = os.path.basename(env) bg = Color.VIRTUAL_ENV_BG fg = Color.VIRTUAL_ENV_FG powerline.append(' %s ' % env_name, fg, bg) add_virtual_env_segment()
Allow venv segment to be from Anaconda
Allow venv segment to be from Anaconda
Python
mit
banga/powerline-shell,tswsl1989/powerline-shell,paulhybryant/powerline-shell,b-ryan/powerline-shell,rbanffy/powerline-shell,b-ryan/powerline-shell,Menci/powerline-shell,iKrishneel/powerline-shell,milkbikis/powerline-shell,paulhybryant/powerline-shell,torbjornvatn/powerline-shell,banga/powerline-shell,bitIO/powerline-shell,LeonardoGentile/powerline-shell,ceholden/powerline-shell
--- +++ @@ -1,7 +1,7 @@ import os def add_virtual_env_segment(): - env = os.getenv('VIRTUAL_ENV') + env = os.getenv('VIRTUAL_ENV') or os.getenv('CONDA_ENV_PATH') if env is None: return
4262e9fa6b67d56c33202ce05d6a1128338ebf7f
zipline/gens/brokers/__init__.py
zipline/gens/brokers/__init__.py
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from ib_broker import IBBroker __all__ = ["IBBroker"]
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from .ib_broker import IBBroker __all__ = ["IBBroker"]
Fix ib_broker import from brokers
Fix ib_broker import from brokers
Python
apache-2.0
Scapogo/zipline,florentchandelier/zipline,florentchandelier/zipline,Scapogo/zipline
--- +++ @@ -11,6 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ib_broker import IBBroker +from .ib_broker import IBBroker __all__ = ["IBBroker"]
6b762607914e1c79bc05f7e8d5cdbe6c6d7a49e4
hiro/patches.py
hiro/patches.py
""" patched builtin time classes for use by :class:`hiro.Timeline` """ import abc from datetime import date as realdate from datetime import datetime as realdatetime import time import six class DatetimeMeta(abc.ABCMeta): """ meta class to allow interaction between :class:`datetime.datetime` objects create inside the :class:`hiro.Timeline` with those created outside it. """ def __instancecheck__(cls, instance): return isinstance(instance, realdatetime) class DateMeta(type): """ meta class to allow interaction between :class:`datetime.date` objects create inside the :class:`hiro.Timeline` with those created outside it. """ def __instancecheck__(cls, instance): return isinstance(instance, realdate) @six.add_metaclass(DatetimeMeta) class Datetime(realdatetime): """ used to patch :class:`datetime.datetime` to follow the rules of the parent :class:`hiro.Timeline` """ @classmethod def now(cls, tz=None): return cls.fromtimestamp(time.time(), tz) @classmethod def utcnow(cls): return cls.fromtimestamp(time.mktime(time.gmtime())) @six.add_metaclass(DateMeta) class Date(realdate): """ used to patch :class:`datetime.date` to follow the rules of the parent :class:`hiro.Timeline` """ __metaclass__ = DateMeta @classmethod def today(cls): return cls.fromtimestamp(time.time())
""" patched builtin time classes for use by :class:`hiro.Timeline` """ import abc from datetime import date as realdate from datetime import datetime as realdatetime import time import six class DatetimeMeta(abc.ABCMeta): """ meta class to allow interaction between :class:`datetime.datetime` objects create inside the :class:`hiro.Timeline` with those created outside it. """ def __instancecheck__(cls, instance): return isinstance(instance, realdatetime) class DateMeta(type): """ meta class to allow interaction between :class:`datetime.date` objects create inside the :class:`hiro.Timeline` with those created outside it. """ def __instancecheck__(cls, instance): return isinstance(instance, realdate) @six.add_metaclass(DatetimeMeta) class Datetime(realdatetime): """ used to patch :class:`datetime.datetime` to follow the rules of the parent :class:`hiro.Timeline` """ @classmethod def now(cls, tz=None): return cls.fromtimestamp(time.time(), tz) @classmethod def utcnow(cls): return cls.utcfromtimestamp(time.time()) @six.add_metaclass(DateMeta) class Date(realdate): """ used to patch :class:`datetime.date` to follow the rules of the parent :class:`hiro.Timeline` """ __metaclass__ = DateMeta @classmethod def today(cls): return cls.fromtimestamp(time.time())
Fix issue with daylight saving time + utcnow
Fix issue with daylight saving time + utcnow Fixes issue #2
Python
mit
alisaifee/hiro,alisaifee/hiro
--- +++ @@ -39,7 +39,7 @@ @classmethod def utcnow(cls): - return cls.fromtimestamp(time.mktime(time.gmtime())) + return cls.utcfromtimestamp(time.time()) @six.add_metaclass(DateMeta) class Date(realdate):
3d91950735d8b42e030f6f479a32369804e90ac0
gaphas/picklers.py
gaphas/picklers.py
""" Some extra picklers needed to gracefully dump and load a canvas. """ import copyreg import types import cairo from future import standard_library standard_library.install_aliases() # Allow instancemethod to be pickled: def construct_instancemethod(funcname, self, clazz): func = getattr(clazz, funcname) return types.MethodType(func, self) def reduce_instancemethod(im): return ( construct_instancemethod, (im.__func__.__name__, im.__self__, im.__self__.__class__), ) copyreg.pickle(types.MethodType, reduce_instancemethod, construct_instancemethod) # Allow cairo.Matrix to be pickled: def construct_cairo_matrix(*args): return cairo.Matrix(*args) def reduce_cairo_matrix(m): return construct_cairo_matrix, tuple(m) copyreg.pickle(cairo.Matrix, reduce_cairo_matrix, construct_cairo_matrix)
""" Some extra picklers needed to gracefully dump and load a canvas. """ import copyreg import types import cairo from future import standard_library standard_library.install_aliases() # Allow cairo.Matrix to be pickled: def construct_cairo_matrix(*args): return cairo.Matrix(*args) def reduce_cairo_matrix(m): return construct_cairo_matrix, tuple(m) copyreg.pickle(cairo.Matrix, reduce_cairo_matrix, construct_cairo_matrix)
Remove ununsed pickle code for instance methods
Remove ununsed pickle code for instance methods
Python
lgpl-2.1
amolenaar/gaphas
--- +++ @@ -10,23 +10,6 @@ standard_library.install_aliases() - -# Allow instancemethod to be pickled: -def construct_instancemethod(funcname, self, clazz): - func = getattr(clazz, funcname) - return types.MethodType(func, self) - - -def reduce_instancemethod(im): - return ( - construct_instancemethod, - (im.__func__.__name__, im.__self__, im.__self__.__class__), - ) - - -copyreg.pickle(types.MethodType, reduce_instancemethod, construct_instancemethod) - - # Allow cairo.Matrix to be pickled: def construct_cairo_matrix(*args): return cairo.Matrix(*args)
aa6d6e59be8c0b8577517bd16de3e75de7f0e570
project_name/urls.py
project_name/urls.py
"""{{project_name}} URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ from django.conf.urls import include, url from django.contrib import admin from django.conf import settings from django.views.generic import TemplateView urlpatterns = [ url(settings.ADMIN_URL, include(admin.site.urls)), url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"), url(r'^users/', include('users.urls')), ]
# -*- coding: utf-8 -*- from django.conf.urls import include, url from django.contrib import admin from django.conf import settings from django.views.generic import TemplateView from django.conf.urls.static import static from django.views import defaults as default_views urlpatterns = [ url(settings.ADMIN_URL, include(admin.site.urls)), url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"), url(r'^users/', include('users.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG: # This allows the error pages to be debugged during development, just visit # these url in browser to see how these error pages look like. urlpatterns += [ url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception("Bad Request!")}), url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception("Permissin Denied")}), url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception("Page not Found")}), url(r'^500/$', default_views.server_error), ]
Improve url patterns structure, enable debugging common error pages while debugging
Improve url patterns structure, enable debugging common error pages while debugging
Python
mit
Nikola-K/django-template,Nikola-K/django-template
--- +++ @@ -1,25 +1,24 @@ -"""{{project_name}} URL Configuration +# -*- coding: utf-8 -*- -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/1.8/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') -Including another URLconf - 1. Add an import: from blog import urls as blog_urls - 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) -""" from django.conf.urls import include, url from django.contrib import admin from django.conf import settings from django.views.generic import TemplateView +from django.conf.urls.static import static +from django.views import defaults as default_views urlpatterns = [ url(settings.ADMIN_URL, include(admin.site.urls)), url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"), url(r'^users/', include('users.urls')), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +if settings.DEBUG: + # This allows the error pages to be debugged during development, just visit + # these url in browser to see how these error pages look like. + urlpatterns += [ + url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception("Bad Request!")}), + url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception("Permissin Denied")}), + url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception("Page not Found")}), + url(r'^500/$', default_views.server_error), + ]
a4a139e4476fefe431e6561bd0ef950cb74c0db4
htpt/buffers.py
htpt/buffers.py
from constants import * class Buffer: """Stores data, buffers it and sends it to the Framer""" def __init__(self): self.buffer = [] self.callback = None def attach(self, callback): self.callback = callback def addData(self, data): # we can't add all the data, there's not enough space if len(self.buffer) + len(data) > BUFFER_SIZE: # compute remaining space buffer_space_rem = BUFFER_SIZE - len(self.buffer) self.buffer.append(data[:buffer_space_rem]) data = data[buffer_space_rem:] # flush the buffer self.flushBuffer() # repeat till we have no data self.addData(data) else: self.buffer.append(data) def flushBuffer(self): self.callback(self.buffer) self.buffer = []
from constants import * class Buffer: """Stores data, buffers it and sends it to the Framer""" def __init__(self): self.buffer = [] self.callback = None def attach(self, callback): self.callback = callback def addData(self, data): # we can't add all the data, there's not enough space if len(self.buffer) + len(data) > BUFFER_SIZE: # compute remaining space buffer_space_rem = BUFFER_SIZE - len(self.buffer) self.buffer.append(data[:buffer_space_rem]) data = data[buffer_space_rem:] # flush the buffer self.flushBuffer() # repeat till we have no data self.addData(data) else: self.buffer.append(data) def flushBuffer(self): self.callback(self.buffer) self.buffer = []
Change indentation to 2 spaces
Change indentation to 2 spaces
Python
mit
gsathya/htpt,gsathya/htpt
--- +++ @@ -1,30 +1,30 @@ from constants import * class Buffer: - """Stores data, buffers it and sends it to the Framer""" - def __init__(self): - self.buffer = [] - self.callback = None + """Stores data, buffers it and sends it to the Framer""" + def __init__(self): + self.buffer = [] + self.callback = None - def attach(self, callback): - self.callback = callback + def attach(self, callback): + self.callback = callback - def addData(self, data): - # we can't add all the data, there's not enough space - if len(self.buffer) + len(data) > BUFFER_SIZE: - # compute remaining space - buffer_space_rem = BUFFER_SIZE - len(self.buffer) - self.buffer.append(data[:buffer_space_rem]) - data = data[buffer_space_rem:] + def addData(self, data): + # we can't add all the data, there's not enough space + if len(self.buffer) + len(data) > BUFFER_SIZE: + # compute remaining space + buffer_space_rem = BUFFER_SIZE - len(self.buffer) + self.buffer.append(data[:buffer_space_rem]) + data = data[buffer_space_rem:] - # flush the buffer - self.flushBuffer() + # flush the buffer + self.flushBuffer() - # repeat till we have no data - self.addData(data) - else: - self.buffer.append(data) + # repeat till we have no data + self.addData(data) + else: + self.buffer.append(data) - def flushBuffer(self): - self.callback(self.buffer) - self.buffer = [] + def flushBuffer(self): + self.callback(self.buffer) + self.buffer = []
ee7a49fa7094160f27993adb25fb2d98db518cb9
pinax/wiki/urls.py
pinax/wiki/urls.py
import os from django.conf.urls import patterns, url from .conf import settings from .views import index, page, edit, file_download, file_upload urlpatterns = patterns( "", url(r"^file-download/(\d+)/([^/]+)$", file_download, name="pinax_wiki_file_download"), url(r"^file-upload/$", file_upload, name="pinax_wiki_file_upload") ) for binder in settings.PINAX_WIKI_BINDERS: urlpatterns += patterns( "", url(os.path.join(binder.root, r"$"), index, {"binder": binder}, name=binder.index_url_name), url(os.path.join(binder.root, r"(?P<slug>[^/]+)/$"), page, {"binder": binder}, name=binder.page_url_name), url(os.path.join(binder.root, r"(?P<slug>[^/]+)/edit/$"), edit, {"binder": binder}, name=binder.edit_url_name), )
import os from django.conf.urls import url from .conf import settings from .views import index, page, edit, file_download, file_upload urlpatterns = [ url(r"^file-download/(\d+)/([^/]+)$", file_download, name="pinax_wiki_file_download"), url(r"^file-upload/$", file_upload, name="pinax_wiki_file_upload") ] for binder in settings.PINAX_WIKI_BINDERS: urlpatterns += [ url(os.path.join(binder.root, r"$"), index, {"binder": binder}, name=binder.index_url_name), url(os.path.join(binder.root, r"(?P<slug>[^/]+)/$"), page, {"binder": binder}, name=binder.page_url_name), url(os.path.join(binder.root, r"(?P<slug>[^/]+)/edit/$"), edit, {"binder": binder}, name=binder.edit_url_name), ]
Fix for patterns() being deprecated and now removed in Django 1.10
Fix for patterns() being deprecated and now removed in Django 1.10
Python
mit
pinax/pinax-wiki
--- +++ @@ -1,20 +1,18 @@ import os -from django.conf.urls import patterns, url +from django.conf.urls import url from .conf import settings from .views import index, page, edit, file_download, file_upload -urlpatterns = patterns( - "", +urlpatterns = [ url(r"^file-download/(\d+)/([^/]+)$", file_download, name="pinax_wiki_file_download"), url(r"^file-upload/$", file_upload, name="pinax_wiki_file_upload") -) +] for binder in settings.PINAX_WIKI_BINDERS: - urlpatterns += patterns( - "", + urlpatterns += [ url(os.path.join(binder.root, r"$"), index, {"binder": binder}, name=binder.index_url_name), url(os.path.join(binder.root, r"(?P<slug>[^/]+)/$"), page, {"binder": binder}, name=binder.page_url_name), url(os.path.join(binder.root, r"(?P<slug>[^/]+)/edit/$"), edit, {"binder": binder}, name=binder.edit_url_name), - ) + ]
c9534dfb1b2aaa8cb4aaee3a3471ac39d956e5b7
plugins/spotify.py
plugins/spotify.py
from plugins.util import command, get_url import json import re SPOTIFY_URI_REGEX = r"(?<=spotify:)(?:track|album|artist):[a-zA-Z0-9]{22}" ENDPOINT = "https://api.spotify.com/v1/{0}s/{1}" @command() def spotify(m): """Retrieve information about a Spotify URI.""" spotify_uris = re.findall(SPOTIFY_URI_REGEX, m.body) for spotify_uri in spotify_uris: try: type, id = _parse_spotify_uri(spotify_uri) except ValueError: m.bot.logger.error("Invalid Spotify URI: " + spotify_uri) else: req = get_url(m, ENDPOINT.format(type, id)) if req: blob = json.loads(req) if type == "track" or type == "album": m.bot.private_message(m.location, '"{0}" by {1} - {2}' .format(blob["name"], blob["artists"][0]["name"], blob["external_urls"]["spotify"])) else: m.bot.private_message(m.location, "{0} - {1}" .format(blob["name"], blob["external_urls"]["spotify"])) def _parse_spotify_uri(s): """Parse the type and ID from a Spotify URI.""" [type, id] = s.split(':') return type, id
from plugins.util import command, get_url import json import re SPOTIFY_URI_REGEX = r"(?<=spotify:)(?:track|album|artist):[a-zA-Z0-9]{22}" ENDPOINT = "https://api.spotify.com/v1/{0}s/{1}" @command() def spotify(m): """Retrieve information about a Spotify URI.""" spotify_uris = re.findall(SPOTIFY_URI_REGEX, m.body) for spotify_uri in spotify_uris: try: type, id = _parse_spotify_uri(spotify_uri) except ValueError: m.bot.logger.error("Invalid Spotify URI: " + spotify_uri) else: req = get_url(m, ENDPOINT.format(type, id)) if req: blob = json.loads(req) if type == "track" or type == "album": m.bot.private_message(m.location, '"{0}" by {1}' .format(blob["name"], blob["artists"][0]["name"])) else: m.bot.private_message(m.location, blob["name"]) def _parse_spotify_uri(s): """Parse the type and ID from a Spotify URI.""" [type, id] = s.split(':') return type, id
Remove URL from Spotify response
Remove URL from Spotify response
Python
mit
molly/GorillaBot,molly/GorillaBot,quanticle/GorillaBot,quanticle/GorillaBot
--- +++ @@ -19,12 +19,10 @@ if req: blob = json.loads(req) if type == "track" or type == "album": - m.bot.private_message(m.location, '"{0}" by {1} - {2}' - .format(blob["name"], blob["artists"][0]["name"], - blob["external_urls"]["spotify"])) + m.bot.private_message(m.location, '"{0}" by {1}' + .format(blob["name"], blob["artists"][0]["name"])) else: - m.bot.private_message(m.location, "{0} - {1}" - .format(blob["name"], blob["external_urls"]["spotify"])) + m.bot.private_message(m.location, blob["name"]) def _parse_spotify_uri(s): """Parse the type and ID from a Spotify URI."""
794868448bc9740bc76f9c3381ff75385f72c769
kinetic_widget/admin.py
kinetic_widget/admin.py
from django.contrib import admin from kinetic_widget.models import * admin.site.register(TestWidgetSimple) admin.site.register(TestWidgetMulti)
from django.contrib import admin from django.http import HttpResponse from django.conf.urls import url, patterns from django.shortcuts import render_to_response, render, get_object_or_404, redirect from kinetic_widget.models import * class TestWidgetSimpleAdmin(admin.ModelAdmin): def get_urls(self): urls = super(TestWidgetSimpleAdmin, self).get_urls() my_urls = patterns('', url(r'^(?P<id>\d+)/json/$', self.admin_site.admin_view(self.get_json), name='json-simple'), ) return my_urls + urls def get_json(self, request, id): inst = get_object_or_404(self.model, pk=id) return HttpResponse(inst.jeden, mimetype='application/json') class TestWidgetMultiAdmin(admin.ModelAdmin): pass admin.site.register(TestWidgetSimple, TestWidgetSimpleAdmin) admin.site.register(TestWidgetMulti, TestWidgetMultiAdmin)
Test Widget: added support for displaying raw json
Test Widget: added support for displaying raw json
Python
bsd-2-clause
knaperek/gits,knaperek/gits,knaperek/gits
--- +++ @@ -1,6 +1,24 @@ from django.contrib import admin +from django.http import HttpResponse +from django.conf.urls import url, patterns +from django.shortcuts import render_to_response, render, get_object_or_404, redirect from kinetic_widget.models import * -admin.site.register(TestWidgetSimple) -admin.site.register(TestWidgetMulti) +class TestWidgetSimpleAdmin(admin.ModelAdmin): + def get_urls(self): + urls = super(TestWidgetSimpleAdmin, self).get_urls() + my_urls = patterns('', + url(r'^(?P<id>\d+)/json/$', self.admin_site.admin_view(self.get_json), name='json-simple'), + ) + return my_urls + urls + + def get_json(self, request, id): + inst = get_object_or_404(self.model, pk=id) + return HttpResponse(inst.jeden, mimetype='application/json') + +class TestWidgetMultiAdmin(admin.ModelAdmin): + pass + +admin.site.register(TestWidgetSimple, TestWidgetSimpleAdmin) +admin.site.register(TestWidgetMulti, TestWidgetMultiAdmin)
b6eaabd47e98d51e4392c5419a59a75a0db45bf1
geotrek/core/tests/test_forms.py
geotrek/core/tests/test_forms.py
from django.conf import settings from django.test import TestCase from unittest import skipIf from geotrek.core.factories import TrailFactory from geotrek.authent.factories import UserFactory from geotrek.core.forms import TrailForm @skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only') class TopologyFormTest(TestCase): def test_save_form_when_topology_has_not_changed(self): user = UserFactory() topo = TrailFactory() form = TrailForm(instance=topo, user=user) self.assertEqual(topo, form.instance) form.cleaned_data = {'topology': topo} form.save() self.assertEqual(topo, form.instance)
from django.conf import settings from django.test import TestCase from unittest import skipIf from geotrek.core.factories import TrailFactory, PathFactory from geotrek.authent.factories import UserFactory from geotrek.core.forms import TrailForm, PathForm @skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only') class TopologyFormTest(TestCase): def test_save_form_when_topology_has_not_changed(self): user = UserFactory() topo = TrailFactory() form = TrailForm(instance=topo, user=user) self.assertEqual(topo, form.instance) form.cleaned_data = {'topology': topo} form.save() self.assertEqual(topo, form.instance) class PathFormTest(TestCase): def test_overlapping_path(self): user = UserFactory() PathFactory.create(geom='SRID=4326;LINESTRING(3 45, 3 46)') # Just intersecting form1 = PathForm( user=user, data={'geom': '{"geom": "LINESTRING(2.5 45.5, 3.5 45.5)", "snap": [null, null]}'} ) self.assertTrue(form1.is_valid(), str(form1.errors)) # Overlapping form2 = PathForm( user=user, data={'geom': '{"geom": "LINESTRING(3 45.5, 3 46.5)", "snap": [null, null]}'} ) self.assertFalse(form2.is_valid(), str(form2.errors))
Add tests for path overlapping check
Add tests for path overlapping check
Python
bsd-2-clause
makinacorpus/Geotrek,GeotrekCE/Geotrek-admin,makinacorpus/Geotrek,makinacorpus/Geotrek,GeotrekCE/Geotrek-admin,makinacorpus/Geotrek,GeotrekCE/Geotrek-admin,GeotrekCE/Geotrek-admin
--- +++ @@ -3,9 +3,9 @@ from unittest import skipIf -from geotrek.core.factories import TrailFactory +from geotrek.core.factories import TrailFactory, PathFactory from geotrek.authent.factories import UserFactory -from geotrek.core.forms import TrailForm +from geotrek.core.forms import TrailForm, PathForm @skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only') @@ -18,3 +18,21 @@ form.cleaned_data = {'topology': topo} form.save() self.assertEqual(topo, form.instance) + + +class PathFormTest(TestCase): + def test_overlapping_path(self): + user = UserFactory() + PathFactory.create(geom='SRID=4326;LINESTRING(3 45, 3 46)') + # Just intersecting + form1 = PathForm( + user=user, + data={'geom': '{"geom": "LINESTRING(2.5 45.5, 3.5 45.5)", "snap": [null, null]}'} + ) + self.assertTrue(form1.is_valid(), str(form1.errors)) + # Overlapping + form2 = PathForm( + user=user, + data={'geom': '{"geom": "LINESTRING(3 45.5, 3 46.5)", "snap": [null, null]}'} + ) + self.assertFalse(form2.is_valid(), str(form2.errors))
cef2fbc059c5c9f55e4379e1963b4b974d09b7fb
statbot/__init__.py
statbot/__init__.py
# # __init__.py # # statbot - Store Discord records for later analysis # Copyright (c) 2017 Ammon Smith # # statbot is available free of charge under the terms of the MIT # License. You are free to redistribute and/or modify it under those # terms. It is distributed in the hopes that it will be useful, but # WITHOUT ANY WARRANTY. See the LICENSE file for more details. # from . import client, config, util __all__ = [ '__version__', 'client', 'config', 'util', ] __version__ = '0.3.0'
# # __init__.py # # statbot - Store Discord records for later analysis # Copyright (c) 2017 Ammon Smith # # statbot is available free of charge under the terms of the MIT # License. You are free to redistribute and/or modify it under those # terms. It is distributed in the hopes that it will be useful, but # WITHOUT ANY WARRANTY. See the LICENSE file for more details. # from . import client, config, util __all__ = [ '__version__', 'client', 'config', 'util', ] __version__ = '0.4.0'
Bump statbot version to 0.4.0
Bump statbot version to 0.4.0
Python
mit
strinking/statbot,strinking/statbot
--- +++ @@ -19,4 +19,4 @@ 'util', ] -__version__ = '0.3.0' +__version__ = '0.4.0'
6392e2d9487d5718d13f73f87797ad142ff14e50
src/zeit/find/cli.py
src/zeit/find/cli.py
from argparse import ArgumentParser from gocept.runner import once from zeit.find import search, elastic def parse(): parser = ArgumentParser(description='Elasticsearch debug client') parser.add_argument('-f', '--fulltext', help='Fulltext search term') parser.add_argument('-a', '--authors', help='Search author name') return vars(parser.parse_args()) @once(principal='zope.manager') def search_solr(): args = parse() query = search.query(**args) print('using query: {}'.format(query)) response = search.search(query) print('got {} results'.format(len(response))) @once(principal='zope.manager') def search_elastic(): args = parse() query = elastic.query(**args) print('using query: {}'.format(query)) response = elastic.search(query) print('got {} results'.format(response.hits))
from argparse import ArgumentParser from gocept.runner import once from logging import getLogger from operator import itemgetter from zeit.cms.interfaces import ICMSContent from zeit.find import search, elastic log = getLogger(__name__) def parse(): parser = ArgumentParser(description='Elasticsearch debug client') parser.add_argument('conditions', nargs='+', help='Search conditions') parser.add_argument( '-v', '--verbose', action='store_true', help='Report query & results') args = parser.parse_args() conditions = dict([c.split(':', 1) for c in args.conditions]) return args, conditions def perform_search(module, get_id): args, conditions = parse() query = module.query(**conditions) if args.verbose: log.info('using query: {}'.format(query)) response = module.search(query) log.info('got {} results'.format(response.hits)) if args.verbose: for idx, item in enumerate(response): log.info('#{}: {}'.format(idx, get_id(item))) @once(principal='zope.manager') def search_solr(): perform_search(search, itemgetter('uniqueId')) @once(principal='zope.manager') def search_elastic(): perform_search(elastic, lambda item: ICMSContent(item).uniqueId)
Allow search script to report the query & results.
TMS-240: Allow search script to report the query & results. In addition search conditions are now specified using a <field>:<term> notation: $ work/zope/bin/search-solr --verbose "authors:Klaus Mustermann" $ work/zope/bin/search-elastic --verbose "fulltext:Klaus Lage"
Python
bsd-3-clause
ZeitOnline/zeit.find,ZeitOnline/zeit.find
--- +++ @@ -1,28 +1,41 @@ from argparse import ArgumentParser from gocept.runner import once +from logging import getLogger +from operator import itemgetter +from zeit.cms.interfaces import ICMSContent from zeit.find import search, elastic + + +log = getLogger(__name__) def parse(): parser = ArgumentParser(description='Elasticsearch debug client') - parser.add_argument('-f', '--fulltext', help='Fulltext search term') - parser.add_argument('-a', '--authors', help='Search author name') - return vars(parser.parse_args()) + parser.add_argument('conditions', nargs='+', help='Search conditions') + parser.add_argument( + '-v', '--verbose', action='store_true', help='Report query & results') + args = parser.parse_args() + conditions = dict([c.split(':', 1) for c in args.conditions]) + return args, conditions + + +def perform_search(module, get_id): + args, conditions = parse() + query = module.query(**conditions) + if args.verbose: + log.info('using query: {}'.format(query)) + response = module.search(query) + log.info('got {} results'.format(response.hits)) + if args.verbose: + for idx, item in enumerate(response): + log.info('#{}: {}'.format(idx, get_id(item))) @once(principal='zope.manager') def search_solr(): - args = parse() - query = search.query(**args) - print('using query: {}'.format(query)) - response = search.search(query) - print('got {} results'.format(len(response))) + perform_search(search, itemgetter('uniqueId')) @once(principal='zope.manager') def search_elastic(): - args = parse() - query = elastic.query(**args) - print('using query: {}'.format(query)) - response = elastic.search(query) - print('got {} results'.format(response.hits)) + perform_search(elastic, lambda item: ICMSContent(item).uniqueId)
8ef82138d513630f5d83adef6233c6a9386019a1
main.py
main.py
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2014 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 """What is more common: FFFFUUUU, or FFUUUUU, or FFFFFUUU, etc.?""" import pdb from googleapiclient.discovery import build mykey = open('apikey.txt', 'r').read().splitlines()[0] mycx = '001893756405173909803:zmyrda2qwcc' service = build("customsearch", "v1", developerKey=mykey) n = 3 # Max number of Fs or Us. M = [[None] * (n+1)] * (n+1) for i in range(1, n+1): for j in range(1, n+1): query = ("f" * i) + ("u" * j) res = service.cse().list(q=query, cx=mycx).execute() c = int(res['searchInformation']['totalResults']) M[i][j] = c print M
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2014 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 """What is more common: FFFFUUUU, or FFUUUUU, or FFFFFUUU, etc.?""" import pdb from googleapiclient.discovery import build mykey = open('apikey.txt', 'r').read().splitlines()[0] mycx = '001893756405173909803:zmyrda2qwcc' service = build("customsearch", "v1", developerKey=mykey) n = 3 # Max number of Fs or Us. M = [] T = [] for i in range(n): M.append([]) T.append([]) for j in range(n): query = ("f" * (i+1)) + ("u" * (j+1)) res = service.cse().list(q=query, cx=mycx).execute() c = int(res['searchInformation']['totalResults']) M[i].append(c) T[i].append(query) print M print T
Fix problem with repeating rows. Good data on 3x3.
Fix problem with repeating rows. Good data on 3x3.
Python
apache-2.0
zimolzak/ffuu,zimolzak/ffuu
--- +++ @@ -18,13 +18,18 @@ service = build("customsearch", "v1", developerKey=mykey) n = 3 # Max number of Fs or Us. -M = [[None] * (n+1)] * (n+1) +M = [] +T = [] -for i in range(1, n+1): - for j in range(1, n+1): - query = ("f" * i) + ("u" * j) +for i in range(n): + M.append([]) + T.append([]) + for j in range(n): + query = ("f" * (i+1)) + ("u" * (j+1)) res = service.cse().list(q=query, cx=mycx).execute() c = int(res['searchInformation']['totalResults']) - M[i][j] = c + M[i].append(c) + T[i].append(query) print M +print T
a83949ef067a5302bd1bb1f428c40c1c244b9f0d
main.py
main.py
from createCollection import createCollection from ObjectFactories.albumFactory import AlbumFactory from ObjectFactories.bookFactory import BookFactory from ObjectFactories.itemFactory import ItemFactory from ObjectFactories.movieFactory import MovieFactory def main(): createCollection('agarner','books') item = ItemFactory.createItem('item1','','') print(item.name) album = AlbumFactory.createAlbum('album1','','','artist1') print(album.name) book = BookFactory.createBook('book1','','','author1') print(book.name) movie = MovieFactory.createMovie('movie1','','','director1') print(movie.name) if __name__ == '__main__': main()
from createCollection import createCollection from ObjectFactories.ItemFactory import ItemFactory from DataObjects.Collection import Collection import datetime import json def main(): #createCollection('agarner','books') now = datetime.datetime.now() items = [] for i in range(0,10): item = ItemFactory.factory('item', [i, 'item' + str(i), now, now]) print(item.name) items.append(item) itemCollection = Collection('Items', 'agarner', items) print itemCollection.toJSON() if __name__ == '__main__': main()
Implement export data to json test
Implement export data to json test
Python
apache-2.0
AmosGarner/PyInventory
--- +++ @@ -1,21 +1,19 @@ from createCollection import createCollection -from ObjectFactories.albumFactory import AlbumFactory -from ObjectFactories.bookFactory import BookFactory -from ObjectFactories.itemFactory import ItemFactory -from ObjectFactories.movieFactory import MovieFactory +from ObjectFactories.ItemFactory import ItemFactory +from DataObjects.Collection import Collection +import datetime +import json def main(): - createCollection('agarner','books') - - item = ItemFactory.createItem('item1','','') - print(item.name) - album = AlbumFactory.createAlbum('album1','','','artist1') - print(album.name) - book = BookFactory.createBook('book1','','','author1') - print(book.name) - movie = MovieFactory.createMovie('movie1','','','director1') - print(movie.name) - + #createCollection('agarner','books') + now = datetime.datetime.now() + items = [] + for i in range(0,10): + item = ItemFactory.factory('item', [i, 'item' + str(i), now, now]) + print(item.name) + items.append(item) + itemCollection = Collection('Items', 'agarner', items) + print itemCollection.toJSON() if __name__ == '__main__': main()
cd5802850fab20648748b4be4a47ad4cc050c32d
tests/test_fields/common_tests.py
tests/test_fields/common_tests.py
from unittest import TestCase from lie2me import Field class CommonTests(object): def get_instance(self): return self.Field() def test_submitting_empty_value_on_required_field_returns_error(self): field = self.get_instance() field.required = True value, error = field.submit(field.empty_value()) self.assertTrue(error) def test_submitting_empty_value_on_optional_field_does_not_return_error(self): field = self.get_instance() field.required = False value, error = field.submit(field.empty_value()) self.assertFalse(error) def test_field_is_required_by_default(self): field = self.get_instance() value, error = field.submit(field.empty_value()) self.assertTrue(error) def test_field_with_default_is_not_required(self): field = self.get_instance() field.default = self.valid_default value, error = field.submit(field.empty_value()) self.assertTrue(value) self.assertFalse(error) def test_field_instance_can_overwrite_specific_messages(self): field = self.get_instance() field.messages = {'required': 'Lorem ipsum'} value, error = field.submit(None) self.assertIn('Lorem ipsum', str(error))
from unittest import TestCase from lie2me import Field class CommonTests(object): def get_instance(self): return self.Field() def test_submitting_empty_value_on_required_field_returns_error(self): field = self.get_instance() field.required = True value, error = field.submit(field.empty_value()) self.assertTrue(error) def test_submitting_empty_value_on_optional_field_does_not_return_error(self): field = self.get_instance() field.required = False value, error = field.submit(field.empty_value()) self.assertFalse(error) def test_field_is_required_by_default(self): field = self.get_instance() value, error = field.submit(field.empty_value()) self.assertTrue(error) def test_field_with_default_is_not_required(self): field = self.get_instance() field.default = self.valid_default value, error = field.submit(field.empty_value()) self.assertFalse(error) def test_field_instance_can_overwrite_specific_messages(self): field = self.get_instance() field.messages = {'required': 'Lorem ipsum'} value, error = field.submit(None) self.assertIn('Lorem ipsum', str(error))
Fix detail in one of the common tests
Fix detail in one of the common tests The value returned by the submit will not necessarily be truish.
Python
mit
hugollm/lie2me,hugollm/lie2me
--- +++ @@ -28,7 +28,6 @@ field = self.get_instance() field.default = self.valid_default value, error = field.submit(field.empty_value()) - self.assertTrue(value) self.assertFalse(error) def test_field_instance_can_overwrite_specific_messages(self):
2306478f67a93e27dd9d7d397f97e3641df3516a
ipython_startup.py
ipython_startup.py
import scipy as sp import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D
from __future__ import division from __future__ import absolute_import import scipy as sp import itertools as it import functools as ft import operator as op import sys import sympy # Plotting import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.pyplot import subplots from matplotlib.pyplot import show as pltshow # and import some common functions into the global namespace from scipy.linalg import norm from scipy import sin, cos, tan, log, pi, sqrt, exp, mean from math import atan2, acos from sympy import Rational as sRat from sympy import pretty as spretty
Add lots of useful default imports to ipython
Add lots of useful default imports to ipython
Python
cc0-1.0
davidshepherd7/dotfiles,davidshepherd7/dotfiles,davidshepherd7/dotfiles,davidshepherd7/dotfiles,davidshepherd7/dotfiles
--- +++ @@ -1,3 +1,24 @@ +from __future__ import division +from __future__ import absolute_import + import scipy as sp +import itertools as it +import functools as ft +import operator as op +import sys +import sympy + + +# Plotting import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D +from matplotlib.pyplot import subplots +from matplotlib.pyplot import show as pltshow + + +# and import some common functions into the global namespace +from scipy.linalg import norm +from scipy import sin, cos, tan, log, pi, sqrt, exp, mean +from math import atan2, acos +from sympy import Rational as sRat +from sympy import pretty as spretty
109085a9f5f6eded6ea2afe1f6aabaf183980d7c
scripts/jenkins/cloud/ansible/roles/heat-generator/files/dns-update.py
scripts/jenkins/cloud/ansible/roles/heat-generator/files/dns-update.py
#!/usr/bin/env python import argparse import yaml def parse_commandline(): parser = argparse.ArgumentParser() parser.add_argument( "--dns-servers", metavar="NAME", help="A list of nameservers", nargs="+", default=[]) parser.add_argument( "--ntp-servers", metavar="NAME", help="A list of ntp servers", nargs="+", default=[]) return parser.parse_args() if __name__ == "__main__": options = parse_commandline() print(options) with open('cloudConfig.yml') as f: data = yaml.load(f.read(), Loader=yaml.SafeLoader) data['cloud']['dns-settings'] = dict(nameservers=options.dns_servers) data['cloud']['ntp-servers'] = options.ntp_servers with open('cloudConfig.yml', 'w') as f: f.write(yaml.safe_dump(data, default_flow_style=False))
#!/usr/bin/env python import argparse import yaml def parse_commandline(): parser = argparse.ArgumentParser() parser.add_argument( "--dns-servers", metavar="NAME", help="A list of nameservers", nargs="+", default=[]) parser.add_argument( "--ntp-servers", metavar="NAME", help="A list of ntp servers", nargs="+", default=[]) parser.add_argument( "--cloud-config", metavar="FILE", help="The cloudConfig.yml FILE", default="cloudConfig.yml") return parser.parse_args() if __name__ == "__main__": options = parse_commandline() print(options) with open(options.cloud_config) as f: data = yaml.load(f.read(), Loader=yaml.SafeLoader) data['cloud']['dns-settings'] = dict(nameservers=options.dns_servers) data['cloud']['ntp-servers'] = options.ntp_servers with open(options.cloud_config, 'w') as f: f.write(yaml.safe_dump(data, default_flow_style=False))
Add option for name and path of cloudConfig.yml file
Add option for name and path of cloudConfig.yml file This change adds a command line option to the dns script to specify the name and location of the `cloudConfig.yml` file. Signed-off-by: Nicolas Bock <4ad6fd604400c7892c7a2cb53bf674987bcaa405@suse.com>
Python
apache-2.0
aspiers/automation,SUSE-Cloud/automation,gosipyan/automation,gosipyan/automation,gosipyan/automation,gosipyan/automation,SUSE-Cloud/automation,aspiers/automation,aspiers/automation,aspiers/automation,SUSE-Cloud/automation,SUSE-Cloud/automation
--- +++ @@ -19,6 +19,11 @@ help="A list of ntp servers", nargs="+", default=[]) + parser.add_argument( + "--cloud-config", + metavar="FILE", + help="The cloudConfig.yml FILE", + default="cloudConfig.yml") return parser.parse_args() @@ -26,11 +31,11 @@ options = parse_commandline() print(options) - with open('cloudConfig.yml') as f: + with open(options.cloud_config) as f: data = yaml.load(f.read(), Loader=yaml.SafeLoader) data['cloud']['dns-settings'] = dict(nameservers=options.dns_servers) data['cloud']['ntp-servers'] = options.ntp_servers - with open('cloudConfig.yml', 'w') as f: + with open(options.cloud_config, 'w') as f: f.write(yaml.safe_dump(data, default_flow_style=False))
58ae075463518e477185816094eb83f42ce5b77c
gcloud/bigquery/__init__.py
gcloud/bigquery/__init__.py
# Copyright 2015 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Google Cloud BigQuery API wrapper. The main concepts with this API are: - :class:`gcloud.bigquery.dataset.Dataset` represents an collection of tables. - :class:`gcloud.bigquery.table.Table` represents a single "relation". """ from gcloud.bigquery.client import Client from gcloud.bigquery.connection import SCOPE from gcloud.bigquery.dataset import Dataset
# Copyright 2015 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Google Cloud BigQuery API wrapper. The main concepts with this API are: - :class:`gcloud.bigquery.dataset.Dataset` represents an collection of tables. - :class:`gcloud.bigquery.table.Table` represents a single "relation". """ from gcloud.bigquery.client import Client from gcloud.bigquery.connection import SCOPE from gcloud.bigquery.dataset import Dataset from gcloud.bigquery.table import SchemaField from gcloud.bigquery.table import Table
Add public API entties from 'bigquery.table'.
Add public API entties from 'bigquery.table'.
Python
apache-2.0
CyrusBiotechnology/gcloud-python,tseaver/google-cloud-python,Fkawala/gcloud-python,waprin/gcloud-python,jonparrott/gcloud-python,EugenePig/gcloud-python,dhermes/google-cloud-python,tswast/google-cloud-python,thesandlord/gcloud-python,tswast/google-cloud-python,EugenePig/gcloud-python,jbuberel/gcloud-python,dhermes/google-cloud-python,calpeyser/google-cloud-python,tseaver/gcloud-python,dhermes/gcloud-python,dhermes/google-cloud-python,tseaver/google-cloud-python,jgeewax/gcloud-python,tswast/google-cloud-python,waprin/google-cloud-python,GoogleCloudPlatform/gcloud-python,jonparrott/google-cloud-python,tseaver/google-cloud-python,vj-ug/gcloud-python,quom/google-cloud-python,googleapis/google-cloud-python,tseaver/gcloud-python,tartavull/google-cloud-python,daspecster/google-cloud-python,quom/google-cloud-python,dhermes/gcloud-python,jonparrott/google-cloud-python,googleapis/google-cloud-python,Fkawala/gcloud-python,jbuberel/gcloud-python,elibixby/gcloud-python,VitalLabs/gcloud-python,waprin/gcloud-python,GoogleCloudPlatform/gcloud-python,CyrusBiotechnology/gcloud-python,jonparrott/gcloud-python,jgeewax/gcloud-python,vj-ug/gcloud-python,VitalLabs/gcloud-python,waprin/google-cloud-python,thesandlord/gcloud-python,daspecster/google-cloud-python,elibixby/gcloud-python,tartavull/google-cloud-python,calpeyser/google-cloud-python
--- +++ @@ -24,3 +24,5 @@ from gcloud.bigquery.client import Client from gcloud.bigquery.connection import SCOPE from gcloud.bigquery.dataset import Dataset +from gcloud.bigquery.table import SchemaField +from gcloud.bigquery.table import Table
661baf5e280f64824bf983b710c54efccb93a41a
oscar/apps/wishlists/forms.py
oscar/apps/wishlists/forms.py
# -*- coding: utf-8 -*- from django import forms from django.db.models import get_model from django.forms.models import inlineformset_factory WishList = get_model('wishlists', 'WishList') Line = get_model('wishlists', 'Line') class WishListForm(forms.ModelForm): def __init__(self, user, *args, **kwargs): super(WishListForm, self).__init__(*args, **kwargs) self.instance.owner = user class Meta: model = WishList fields = ('name', ) LineFormset = inlineformset_factory(WishList, Line, fields=('quantity', ), extra=0, can_delete=False)
# -*- coding: utf-8 -*- from django import forms from django.db.models import get_model from django.forms.models import inlineformset_factory, fields_for_model WishList = get_model('wishlists', 'WishList') Line = get_model('wishlists', 'Line') class WishListForm(forms.ModelForm): def __init__(self, user, *args, **kwargs): super(WishListForm, self).__init__(*args, **kwargs) self.instance.owner = user class Meta: model = WishList fields = ('name', ) class WishListLineForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(WishListLineForm, self).__init__(*args, **kwargs) self.fields['quantity'].widget.attrs['size'] = 2 LineFormset = inlineformset_factory( WishList, Line, fields=('quantity', ), form=WishListLineForm, extra=0, can_delete=False)
Set size on wishlist line quantity form field
Set size on wishlist line quantity form field This doesn't actually work since there is an overriding CSS style. When issue #851 is resolved, this should start working.
Python
bsd-3-clause
sasha0/django-oscar,nickpack/django-oscar,elliotthill/django-oscar,DrOctogon/unwash_ecom,josesanch/django-oscar,bnprk/django-oscar,kapari/django-oscar,marcoantoniooliveira/labweb,solarissmoke/django-oscar,kapt/django-oscar,nickpack/django-oscar,machtfit/django-oscar,jlmadurga/django-oscar,marcoantoniooliveira/labweb,Bogh/django-oscar,adamend/django-oscar,machtfit/django-oscar,WillisXChen/django-oscar,QLGu/django-oscar,itbabu/django-oscar,Bogh/django-oscar,anentropic/django-oscar,amirrpp/django-oscar,makielab/django-oscar,jinnykoo/wuyisj.com,faratro/django-oscar,pasqualguerrero/django-oscar,jmt4/django-oscar,DrOctogon/unwash_ecom,monikasulik/django-oscar,vovanbo/django-oscar,amirrpp/django-oscar,QLGu/django-oscar,WillisXChen/django-oscar,Jannes123/django-oscar,thechampanurag/django-oscar,jinnykoo/wuyisj,michaelkuty/django-oscar,bschuon/django-oscar,sonofatailor/django-oscar,QLGu/django-oscar,sasha0/django-oscar,josesanch/django-oscar,spartonia/django-oscar,amirrpp/django-oscar,django-oscar/django-oscar,bnprk/django-oscar,WillisXChen/django-oscar,sonofatailor/django-oscar,ahmetdaglarbas/e-commerce,binarydud/django-oscar,nickpack/django-oscar,MatthewWilkes/django-oscar,WadeYuChen/django-oscar,itbabu/django-oscar,faratro/django-oscar,itbabu/django-oscar,monikasulik/django-oscar,manevant/django-oscar,ahmetdaglarbas/e-commerce,django-oscar/django-oscar,kapt/django-oscar,jinnykoo/wuyisj.com,Idematica/django-oscar,mexeniz/django-oscar,WadeYuChen/django-oscar,anentropic/django-oscar,dongguangming/django-oscar,thechampanurag/django-oscar,rocopartners/django-oscar,pdonadeo/django-oscar,jlmadurga/django-oscar,mexeniz/django-oscar,manevant/django-oscar,solarissmoke/django-oscar,jmt4/django-oscar,solarissmoke/django-oscar,binarydud/django-oscar,michaelkuty/django-oscar,machtfit/django-oscar,vovanbo/django-oscar,ahmetdaglarbas/e-commerce,dongguangming/django-oscar,nickpack/django-oscar,solarissmoke/django-oscar,taedori81/django-oscar,manevant/django-oscar,monikasulik/django-oscar,okfish/django-oscar,saadatqadri/django-oscar,anentropic/django-oscar,eddiep1101/django-oscar,pasqualguerrero/django-oscar,itbabu/django-oscar,lijoantony/django-oscar,pdonadeo/django-oscar,binarydud/django-oscar,faratro/django-oscar,marcoantoniooliveira/labweb,lijoantony/django-oscar,taedori81/django-oscar,michaelkuty/django-oscar,nfletton/django-oscar,makielab/django-oscar,elliotthill/django-oscar,okfish/django-oscar,jinnykoo/wuyisj,WillisXChen/django-oscar,mexeniz/django-oscar,jlmadurga/django-oscar,ademuk/django-oscar,john-parton/django-oscar,michaelkuty/django-oscar,taedori81/django-oscar,kapari/django-oscar,django-oscar/django-oscar,pdonadeo/django-oscar,okfish/django-oscar,MatthewWilkes/django-oscar,jmt4/django-oscar,Jannes123/django-oscar,okfish/django-oscar,sonofatailor/django-oscar,jinnykoo/wuyisj.com,saadatqadri/django-oscar,lijoantony/django-oscar,pdonadeo/django-oscar,adamend/django-oscar,jinnykoo/christmas,rocopartners/django-oscar,makielab/django-oscar,rocopartners/django-oscar,QLGu/django-oscar,thechampanurag/django-oscar,kapari/django-oscar,ka7eh/django-oscar,pasqualguerrero/django-oscar,eddiep1101/django-oscar,monikasulik/django-oscar,MatthewWilkes/django-oscar,Idematica/django-oscar,django-oscar/django-oscar,nfletton/django-oscar,pasqualguerrero/django-oscar,ka7eh/django-oscar,lijoantony/django-oscar,sonofatailor/django-oscar,thechampanurag/django-oscar,bschuon/django-oscar,Jannes123/django-oscar,mexeniz/django-oscar,binarydud/django-oscar,vovanbo/django-oscar,marcoantoniooliveira/labweb,jlmadurga/django-oscar,jinnykoo/wuyisj,bschuon/django-oscar,ademuk/django-oscar,saadatqadri/django-oscar,eddiep1101/django-oscar,ademuk/django-oscar,Jannes123/django-oscar,nfletton/django-oscar,faratro/django-oscar,ka7eh/django-oscar,DrOctogon/unwash_ecom,vovanbo/django-oscar,WillisXChen/django-oscar,Bogh/django-oscar,taedori81/django-oscar,jinnykoo/wuyisj.com,john-parton/django-oscar,amirrpp/django-oscar,elliotthill/django-oscar,ka7eh/django-oscar,nfletton/django-oscar,Idematica/django-oscar,john-parton/django-oscar,josesanch/django-oscar,jmt4/django-oscar,jinnykoo/christmas,jinnykoo/wuyisj,WadeYuChen/django-oscar,Bogh/django-oscar,adamend/django-oscar,kapari/django-oscar,spartonia/django-oscar,kapt/django-oscar,rocopartners/django-oscar,dongguangming/django-oscar,eddiep1101/django-oscar,adamend/django-oscar,jinnykoo/christmas,bnprk/django-oscar,bschuon/django-oscar,bnprk/django-oscar,john-parton/django-oscar,sasha0/django-oscar,sasha0/django-oscar,makielab/django-oscar,ahmetdaglarbas/e-commerce,WillisXChen/django-oscar,spartonia/django-oscar,WadeYuChen/django-oscar,ademuk/django-oscar,saadatqadri/django-oscar,anentropic/django-oscar,MatthewWilkes/django-oscar,dongguangming/django-oscar,manevant/django-oscar,spartonia/django-oscar
--- +++ @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django import forms from django.db.models import get_model -from django.forms.models import inlineformset_factory +from django.forms.models import inlineformset_factory, fields_for_model WishList = get_model('wishlists', 'WishList') Line = get_model('wishlists', 'Line') @@ -18,5 +18,13 @@ fields = ('name', ) -LineFormset = inlineformset_factory(WishList, Line, fields=('quantity', ), - extra=0, can_delete=False) +class WishListLineForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super(WishListLineForm, self).__init__(*args, **kwargs) + self.fields['quantity'].widget.attrs['size'] = 2 + + +LineFormset = inlineformset_factory( + WishList, Line, fields=('quantity', ), form=WishListLineForm, + extra=0, can_delete=False)
e5322958f14b2428b74de726476fd98adae8c454
app.py
app.py
from flask import Flask, render_template, request, redirect import requests import pandas as pd from datetime import datetime from bokeh.plotting import figure, output_notebook, output_file, save app = Flask(__name__) @app.route('/') def main(): return redirect('/index') @app.route('/index', methods=['GET', 'POST']) def index(): if request.method == 'GET': return render_template('index.html') else: pitcher = request.form['pitcher'] image_file = pitcher.lower() image_file = image_file.split() image_file = '_'.join(image_file) + '.png' return render_template('results.html', image_file = image_file) if __name__ == '__main__': app.run(port=33508)
from flask import Flask, render_template, request, redirect import requests import pandas as pd from datetime import datetime from bokeh.plotting import figure, output_notebook, output_file, save app = Flask(__name__) # @app.route('/') # def main(): # return redirect('/index') @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'GET': return render_template('index.html') else: pitcher = request.form['pitcher'] image_file = pitcher.lower() image_file = image_file.split() image_file = '_'.join(image_file) + '.png' return render_template('results.html', image_file = image_file) if __name__ == '__main__': app.run(port=33508)
Remove redirect to avoid Chrome privacy error
Remove redirect to avoid Chrome privacy error
Python
mit
gsganden/pitcher-reports,gsganden/pitcher-reports
--- +++ @@ -6,11 +6,11 @@ app = Flask(__name__) -@app.route('/') -def main(): - return redirect('/index') +# @app.route('/') +# def main(): +# return redirect('/index') -@app.route('/index', methods=['GET', 'POST']) +@app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'GET': return render_template('index.html')
5c64fe29690e2471aef20473592f0dcebac4eff8
tests/_support/contextualized.py
tests/_support/contextualized.py
from invoke import ctask @ctask def go(ctx): return ctx @ctask def run(ctx): ctx.run('x')
from invoke import ctask @ctask def go(ctx): return ctx @ctask def run(ctx): ctx.run('false')
Tweak a test so it fails more usefully when mocking doesn't work, heh
Tweak a test so it fails more usefully when mocking doesn't work, heh
Python
bsd-2-clause
kejbaly2/invoke,frol/invoke,pyinvoke/invoke,singingwolfboy/invoke,pfmoore/invoke,mattrobenolt/invoke,tyewang/invoke,mkusz/invoke,mattrobenolt/invoke,mkusz/invoke,kejbaly2/invoke,frol/invoke,pfmoore/invoke,pyinvoke/invoke
--- +++ @@ -8,4 +8,4 @@ @ctask def run(ctx): - ctx.run('x') + ctx.run('false')
67a102e5da283e318928028e54f6a85b4d266043
nipap/nipap/nipapconfig.py
nipap/nipap/nipapconfig.py
import ConfigParser class NipapConfig(ConfigParser.SafeConfigParser): """ Makes configuration data available. Implemented as a class with a shared state; once an instance has been created, new instances with the same state can be obtained by calling the custructor again. """ __shared_state = {} _config = None _cfg_path = None def __init__(self, cfg_path=None, default={}): """ Takes config file path and command line arguments. """ self.__dict__ = self.__shared_state if len(self.__shared_state) == 0: # First time - create new instance! if cfg_path is None: raise NipapConfigError("missing configuration file") self._cfg_path = cfg_path ConfigParser.ConfigParser.__init__(self, default) self.read_file() def read_file(self): """ Read the configuration file """ try: cfg_fp = open(self._cfg_path, 'r') self.readfp(cfg_fp) except IOError, e: raise NipapConfigError(str(e)) class NipapConfigError(Exception): pass
import ConfigParser class NipapConfig(ConfigParser.SafeConfigParser): """ Makes configuration data available. Implemented as a class with a shared state; once an instance has been created, new instances with the same state can be obtained by calling the custructor again. """ __shared_state = {} _config = None _cfg_path = None def __init__(self, cfg_path=None, default={}): """ Takes config file path and command line arguments. """ self.__dict__ = self.__shared_state if len(self.__shared_state) == 0: # First time - create new instance! self._cfg_path = cfg_path ConfigParser.ConfigParser.__init__(self, default) self.read_file() def read_file(self): """ Read the configuration file """ try: cfg_fp = open(self._cfg_path, 'r') self.readfp(cfg_fp) except IOError, e: raise NipapConfigError(str(e)) class NipapConfigError(Exception): pass
Remove requirement on presence of config file
Remove requirement on presence of config file The NipapConfig object required the presence of a configuration file. As it is benficial to be able to load the NipapConfig without a configuration file (for example when building docs using Sphinx), this requirement has been removed.
Python
mit
fredsod/NIPAP,ettrig/NIPAP,SoundGoof/NIPAP,ettrig/NIPAP,fredsod/NIPAP,ettrig/NIPAP,ettrig/NIPAP,garberg/NIPAP,bbaja42/NIPAP,bbaja42/NIPAP,SoundGoof/NIPAP,SpriteLink/NIPAP,plajjan/NIPAP,fredsod/NIPAP,bbaja42/NIPAP,garberg/NIPAP,fredsod/NIPAP,SoundGoof/NIPAP,SpriteLink/NIPAP,SoundGoof/NIPAP,plajjan/NIPAP,SpriteLink/NIPAP,garberg/NIPAP,plajjan/NIPAP,SoundGoof/NIPAP,bbaja42/NIPAP,plajjan/NIPAP,ettrig/NIPAP,garberg/NIPAP,bbaja42/NIPAP,fredsod/NIPAP,SoundGoof/NIPAP,bbaja42/NIPAP,ettrig/NIPAP,garberg/NIPAP,fredsod/NIPAP,SpriteLink/NIPAP,garberg/NIPAP,plajjan/NIPAP,SpriteLink/NIPAP,plajjan/NIPAP,SpriteLink/NIPAP
--- +++ @@ -21,8 +21,6 @@ if len(self.__shared_state) == 0: # First time - create new instance! - if cfg_path is None: - raise NipapConfigError("missing configuration file") self._cfg_path = cfg_path ConfigParser.ConfigParser.__init__(self, default)
441ecd25c9fdbc3acbe0e345bbaeafd8de9e3b73
tests/test_srvy.py
tests/test_srvy.py
import unittest import context from srvy.srvy import get_current_questions class MyTest(unittest.TestCase): def setUp(self): self.questions = ["Question 1?", "Question 2?", "Question 3?", "Question 4?"] def test_get_current_questions_gets_all_questions_from_file(self): self.assertEqual(get_current_questions('questions.txt'), self.questions) if __name__ == '__main__': unittest.main()
import unittest import context from collection.srvy import get_current_questions class MyTest(unittest.TestCase): def setUp(self): self.questions = ["Question 1?", "Question 2?", "Question 3?", "Question 4?"] def test_get_current_questions_gets_all_questions_from_file(self): self.assertEqual(get_current_questions('questions.csv'), self.questions) if __name__ == '__main__': unittest.main()
Update unittest to check get_current_questions
Update unittest to check get_current_questions
Python
mit
andrewlrogers/srvy
--- +++ @@ -1,15 +1,16 @@ import unittest import context -from srvy.srvy import get_current_questions +from collection.srvy import get_current_questions class MyTest(unittest.TestCase): def setUp(self): self.questions = ["Question 1?", "Question 2?", "Question 3?", "Question 4?"] + def test_get_current_questions_gets_all_questions_from_file(self): - self.assertEqual(get_current_questions('questions.txt'), self.questions) + self.assertEqual(get_current_questions('questions.csv'), self.questions) if __name__ == '__main__':
aceee9b19920d6a78fd8edda07009480ed48f565
jsondb/__init__.py
jsondb/__init__.py
""" A flat file database for json objects. """ from .db import Database __version__ = '0.1.5' __author__ = 'Gunther Cox' __email__ = 'gunthercx@gmail.com' __url__ = 'https://github.com/gunthercox/jsondb'
""" A flat file database for json objects. """ from .db import Database __version__ = '0.1.6' __author__ = 'Gunther Cox' __email__ = 'gunthercx@gmail.com' __url__ = 'https://github.com/gunthercox/jsondb'
Update release version to 0.1.6
Update release version to 0.1.6
Python
bsd-3-clause
gunthercox/jsondb
--- +++ @@ -4,7 +4,7 @@ from .db import Database -__version__ = '0.1.5' +__version__ = '0.1.6' __author__ = 'Gunther Cox' __email__ = 'gunthercx@gmail.com' __url__ = 'https://github.com/gunthercox/jsondb'
c4741e3246ca85d621f10530e9d70a85cdff7414
learn/my_pbkdf2.py
learn/my_pbkdf2.py
import ctypes __all__ = ["pbkdf2"] libssl = ctypes.CDLL("libssl.dylib") libssl.PKCS5_PBKDF2_HMAC_SHA1.restype = ctypes.c_int def cBuf(data): return ctypes.create_string_buffer(data, len(data)) def pbkdf2(password, salt, iterations, outlen): targetbuf = cBuf("\0" * outlen) ret = libssl.PKCS5_PBKDF2_HMAC_SHA1( cBuf(password), len(password), cBuf(salt), len(salt), iterations, outlen, ctypes.byref(targetbuf)) return targetbuf.raw if ret else None
import ctypes import platform __all__ = ["pbkdf2"] name = "libssl.%s" % ("dylib" if platform.system() == "Darwin" else "so") libssl = ctypes.CDLL("libssl.dylib") libssl.PKCS5_PBKDF2_HMAC_SHA1.restype = ctypes.c_int def cBuf(data): return ctypes.create_string_buffer(data, len(data)) def pbkdf2(password, salt, iterations, outlen): targetbuf = cBuf("\0" * outlen) ret = libssl.PKCS5_PBKDF2_HMAC_SHA1( cBuf(password), len(password), cBuf(salt), len(salt), iterations, outlen, ctypes.byref(targetbuf)) return targetbuf.raw if ret else None
Load .so if not on Crap OS X
Load .so if not on Crap OS X
Python
bsd-2-clause
tzwenn/luksfs
--- +++ @@ -1,6 +1,9 @@ import ctypes +import platform __all__ = ["pbkdf2"] + +name = "libssl.%s" % ("dylib" if platform.system() == "Darwin" else "so") libssl = ctypes.CDLL("libssl.dylib") libssl.PKCS5_PBKDF2_HMAC_SHA1.restype = ctypes.c_int
4c372b62ac97bc06f18dc953fd9e0ccfe4de80fe
ibmcnx/doc/Documentation.py
ibmcnx/doc/Documentation.py
###### # Create a file (html or markdown) with the output of # - JVMHeap # - LogFiles # - Ports # - Variables # # Author: Christoph Stoettner # Mail: christoph.stoettner@stoeps.de # Documentation: http://scripting101.stoeps.de # # Version: 2.0 # Date: 2014-06-08 # # License: Apache 2.0 # # TODO: Create a menu for file selection import ibmcnx.filehandle import sys emp1 = ibmcnx.filehandle.Ibmcnxfile() sys.stdout = emp1 print '# JVM Settings of all AppServers:' execfile( 'ibmcnx/doc/JVMSettings.py' ) print '# Used Ports:' execfile( 'ibmcnx/doc/Ports.py' ) print '# LogFile Settgins:' execfile( 'ibmcnx/doc/LogFiles.py' ) print '# WebSphere Variables' execfile( 'ibmcnx/doc/Variables.py' )
###### # Create a file (html or markdown) with the output of # - JVMHeap # - LogFiles # - Ports # - Variables # # Author: Christoph Stoettner # Mail: christoph.stoettner@stoeps.de # Documentation: http://scripting101.stoeps.de # # Version: 2.0 # Date: 2014-06-08 # # License: Apache 2.0 # # TODO: Create a menu for file selection import ibmcnx.filehandle import sys emp1 = ibmcnx.filehandle.Ibmcnxfile() sys.stdout = emp1.askFileParams() print '# JVM Settings of all AppServers:' execfile( 'ibmcnx/doc/JVMSettings.py' ) print '# Used Ports:' execfile( 'ibmcnx/doc/Ports.py' ) print '# LogFile Settgins:' execfile( 'ibmcnx/doc/LogFiles.py' ) print '# WebSphere Variables' execfile( 'ibmcnx/doc/Variables.py' )
Create script to save documentation to a file
4: Create script to save documentation to a file Task-Url: http://github.com/stoeps13/ibmcnx2/issues/issue/4
Python
apache-2.0
stoeps13/ibmcnx2,stoeps13/ibmcnx2
--- +++ @@ -22,7 +22,7 @@ emp1 = ibmcnx.filehandle.Ibmcnxfile() -sys.stdout = emp1 +sys.stdout = emp1.askFileParams() print '# JVM Settings of all AppServers:' execfile( 'ibmcnx/doc/JVMSettings.py' )
058a0eb16a5a807c137553042f973c907d231cf1
ndb/operate/__init__.py
ndb/operate/__init__.py
# coding=utf-8 import node_locate import node_filter import node_select import node_update import node_delete import node_insert import node_script def select(node, path, action=None): return node_select.NodeSelect().select(node, path, action) def update(node, path, value, action=None): return node_update.NodeUpdate().update(node, path, value, action) def delete(node, path, value, action=None): return node_delete.NodeDelete().delete(node, path, value, action) def insert(node, path, value, action=None): return node_insert.NodeInsert().insert(node, path, value, action) def locate(node, query, multi, is_create=False): return node_locate.NodeLocate().locate(node, query, multi, is_create) def script(node, script_filename): return node_script.NodeScript().run(node, script_filename) def filte(table, query=None, union=False, sort_key=None): return node_filter.NodeFilter().filte(table, query, union, sort_key)
# coding=utf-8 import node_locate import node_select import node_update import node_delete import node_insert import node_script import node_clean import node_travel def select(node, path, action=None): return node_select.NodeSelect().select(node, path, action) def update(node, path, value, action=None): return node_update.NodeUpdate().update(node, path, value, action) def delete(node, path, value, action=None): return node_delete.NodeDelete().delete(node, path, value, action) def insert(node, path, value, action=None): return node_insert.NodeInsert().insert(node, path, value, action) def locate(node, query, multi, is_create=False): return node_locate.NodeLocate().locate(node, query, multi, is_create) def clean(node): return node_clean.NodeClean().clean(node) def travel(node, action): return node_travel.NodeTravel().travel(node, action) def script(node, script_filename): return node_script.NodeScript().run(node, script_filename)
Add clean and travel to operate
Add clean and travel to operate
Python
apache-2.0
PinaeOS/ndb-py,node-db/ndb-py
--- +++ @@ -1,13 +1,14 @@ # coding=utf-8 import node_locate -import node_filter import node_select import node_update import node_delete import node_insert import node_script +import node_clean +import node_travel def select(node, path, action=None): return node_select.NodeSelect().select(node, path, action) @@ -24,8 +25,12 @@ def locate(node, query, multi, is_create=False): return node_locate.NodeLocate().locate(node, query, multi, is_create) +def clean(node): + return node_clean.NodeClean().clean(node) + +def travel(node, action): + return node_travel.NodeTravel().travel(node, action) + def script(node, script_filename): return node_script.NodeScript().run(node, script_filename) -def filte(table, query=None, union=False, sort_key=None): - return node_filter.NodeFilter().filte(table, query, union, sort_key)
c9eb050771c487aae67e0a1f8c69ad011b6aaa90
repomgmt/management/commands/process-build-queue.py
repomgmt/management/commands/process-build-queue.py
# # Copyright 2012 Cisco Systems, Inc. # # Author: Soren Hansen <sorhanse@cisco.com> # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from django.core.management.base import BaseCommand from repomgmt.models import BuildNode, BuildRecord import repomgmt.utils class Command(BaseCommand): args = '' help = 'Processes the build queue' def handle(self, **options): if BuildRecord.pending_build_count() > 0: bn = BuildNode.start_new() br = BuildRecord.pick_build(bn) bn.prepare(br) bn.build(br)
# # Copyright 2012 Cisco Systems, Inc. # # Author: Soren Hansen <sorhanse@cisco.com> # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from django.core.management.base import BaseCommand from repomgmt.models import BuildNode, BuildRecord class Command(BaseCommand): args = '' help = 'Processes the build queue' def handle(self, **options): if BuildRecord.pending_build_count() > 0: bn = BuildNode.start_new() br = BuildRecord.pick_build(bn) bn.prepare(br) bn.build(br)
Add tailing / to APT_REPO_BASE_URL
Add tailing / to APT_REPO_BASE_URL
Python
apache-2.0
sorenh/python-django-repomgmt,sorenh/python-django-repomgmt
--- +++ @@ -17,7 +17,7 @@ # from django.core.management.base import BaseCommand from repomgmt.models import BuildNode, BuildRecord -import repomgmt.utils + class Command(BaseCommand): args = ''
7f611e99d36089bc6836042ba8aec2df02a56f3a
pymemcache/test/test_serde.py
pymemcache/test/test_serde.py
from unittest import TestCase from pymemcache.serde import (python_memcache_serializer, python_memcache_deserializer) import pytest import six @pytest.mark.unit() class TestSerde(TestCase): def check(self, value): serialized, flags = python_memcache_serializer(b'key', value) # pymemcache stores values as byte strings, so we immediately the value # if needed so deserialized works as it would with a real server if not isinstance(serialized, six.binary_type): serialized = six.text_type(serialized).encode('ascii') deserialized = python_memcache_deserializer(b'key', serialized, flags) assert deserialized == value def test_bytes(self): self.check(b'value') def test_unicode(self): self.check(u'value') def test_int(self): self.check(1) def test_long(self): self.check(123123123123123123123) def test_pickleable(self): self.check({'a': 'dict'})
from unittest import TestCase from pymemcache.serde import (python_memcache_serializer, python_memcache_deserializer, FLAG_PICKLE, FLAG_INTEGER, FLAG_LONG, FLAG_TEXT) import pytest import six @pytest.mark.unit() class TestSerde(TestCase): def check(self, value, expected_flags=0): serialized, flags = python_memcache_serializer(b'key', value) assert flags == expected_flags # pymemcache stores values as byte strings, so we immediately the value # if needed so deserialized works as it would with a real server if not isinstance(serialized, six.binary_type): serialized = six.text_type(serialized).encode('ascii') deserialized = python_memcache_deserializer(b'key', serialized, flags) assert deserialized == value def test_bytes(self): self.check(b'value') def test_unicode(self): self.check(u'value', FLAG_TEXT) def test_int(self): self.check(1, FLAG_INTEGER) def test_long(self): # long only exists with Python 2, so we're just testing for another # integer with Python 3 if six.PY2: expected_flags = FLAG_LONG else: expected_flags = FLAG_INTEGER self.check(123123123123123123123, expected_flags) def test_pickleable(self): self.check({'a': 'dict'}, FLAG_PICKLE)
Test for expected flags with serde tests
Test for expected flags with serde tests
Python
apache-2.0
bwalks/pymemcache,sontek/pymemcache,pinterest/pymemcache,ewdurbin/pymemcache,pinterest/pymemcache,sontek/pymemcache
--- +++ @@ -1,7 +1,8 @@ from unittest import TestCase from pymemcache.serde import (python_memcache_serializer, - python_memcache_deserializer) + python_memcache_deserializer, FLAG_PICKLE, + FLAG_INTEGER, FLAG_LONG, FLAG_TEXT) import pytest import six @@ -9,8 +10,9 @@ @pytest.mark.unit() class TestSerde(TestCase): - def check(self, value): + def check(self, value, expected_flags=0): serialized, flags = python_memcache_serializer(b'key', value) + assert flags == expected_flags # pymemcache stores values as byte strings, so we immediately the value # if needed so deserialized works as it would with a real server @@ -24,13 +26,19 @@ self.check(b'value') def test_unicode(self): - self.check(u'value') + self.check(u'value', FLAG_TEXT) def test_int(self): - self.check(1) + self.check(1, FLAG_INTEGER) def test_long(self): - self.check(123123123123123123123) + # long only exists with Python 2, so we're just testing for another + # integer with Python 3 + if six.PY2: + expected_flags = FLAG_LONG + else: + expected_flags = FLAG_INTEGER + self.check(123123123123123123123, expected_flags) def test_pickleable(self): - self.check({'a': 'dict'}) + self.check({'a': 'dict'}, FLAG_PICKLE)
f050c0429beffa13d94ad303c1730fef5b44f544
pymysql/tests/test_nextset.py
pymysql/tests/test_nextset.py
from pymysql.tests import base from pymysql import util class TestNextset(base.PyMySQLTestCase): def setUp(self): super(TestNextset, self).setUp() self.con = self.connections[0] def test_nextset(self): cur = self.con.cursor() cur.execute("SELECT 1; SELECT 2;") self.assertEqual([(1,)], list(cur)) r = cur.nextset() self.assertTrue(r) self.assertEqual([(2,)], list(cur)) self.assertIsNone(cur.nextset()) def test_skip_nextset(self): cur = self.con.cursor() cur.execute("SELECT 1; SELECT 2;") self.assertEqual([(1,)], list(cur)) cur.execute("SELECT 42") self.assertEqual([(42,)], list(cur))
from pymysql.tests import base from pymysql import util try: import unittest2 as unittest except ImportError: import unittest class TestNextset(base.PyMySQLTestCase): def setUp(self): super(TestNextset, self).setUp() self.con = self.connections[0] def test_nextset(self): cur = self.con.cursor() cur.execute("SELECT 1; SELECT 2;") self.assertEqual([(1,)], list(cur)) r = cur.nextset() self.assertTrue(r) self.assertEqual([(2,)], list(cur)) self.assertIsNone(cur.nextset()) def test_skip_nextset(self): cur = self.con.cursor() cur.execute("SELECT 1; SELECT 2;") self.assertEqual([(1,)], list(cur)) cur.execute("SELECT 42") self.assertEqual([(42,)], list(cur)) @unittest.expectedFailure def test_multi_cursor(self): cur1 = self.con.cursor() cur2 = self.con.cursor() cur1.execute("SELECT 1; SELECT 2;") cur2.execute("SELECT 42") self.assertEqual([(1,)], list(cur1)) self.assertEqual([(42,)], list(cur2)) r = cur1.nextset() self.assertTrue(r) self.assertEqual([(2,)], list(cur1)) self.assertIsNone(cur1.nextset())
Add multi cursor test currently failed.
Add multi cursor test currently failed.
Python
mit
Geoion/Tornado-MySQL,PyMySQL/PyMySQL,PyMySQL/Tornado-MySQL,boneyao/PyMySQL,aio-libs/aiomysql,jwjohns/PyMySQL,yeyinzhu3211/PyMySQL,jheld/PyMySQL,eibanez/PyMySQL,pymysql/pymysql,lzedl/PyMySQL,modulexcite/PyMySQL,xjzhou/PyMySQL,xjzhou/PyMySQL,MartinThoma/PyMySQL,wraziens/PyMySQL,mosquito/Tornado-MySQL,pulsar314/Tornado-MySQL,anson-tang/PyMySQL,yeyinzhu3211/PyMySQL,nju520/PyMySQL,Ting-y/PyMySQL,NunoEdgarGub1/PyMySQL,eibanez/PyMySQL,DashaChuk/PyMySQL,lzedl/PyMySQL,wraziens/PyMySQL,methane/PyMySQL
--- +++ @@ -1,5 +1,10 @@ from pymysql.tests import base from pymysql import util + +try: + import unittest2 as unittest +except ImportError: + import unittest class TestNextset(base.PyMySQLTestCase): @@ -26,3 +31,20 @@ cur.execute("SELECT 42") self.assertEqual([(42,)], list(cur)) + + @unittest.expectedFailure + def test_multi_cursor(self): + cur1 = self.con.cursor() + cur2 = self.con.cursor() + + cur1.execute("SELECT 1; SELECT 2;") + cur2.execute("SELECT 42") + + self.assertEqual([(1,)], list(cur1)) + self.assertEqual([(42,)], list(cur2)) + + r = cur1.nextset() + self.assertTrue(r) + + self.assertEqual([(2,)], list(cur1)) + self.assertIsNone(cur1.nextset())
21ac167e827cde53ccbb60f713c8190ec2ff6bda
api/management/commands/cron_notifications.py
api/management/commands/cron_notifications.py
# -*- coding: utf-8 -*- from django.core.management.base import BaseCommand, CommandError from api import models from web.utils import send_email class Command(BaseCommand): can_import_settings = True def handle(self, *args, **options): notifications = models.Notification.objects.filter(email_sent=False).select_related('owner', 'owner__preferences') for notification in notifications: preferences = notification.owner.preferences if preferences.is_notification_email_allowed(notification.message): send_email( subject=(u'School Idol Tomodachi' + u'✨ ' + u' Notification: ' + notification.english_message), template_name = 'notification', to=[notification.owner.email, 'contact@schoolido.lu'], context={ 'notification': notification, 'user': notification.owner, }, ) # todo ios push notifications print 'Email sent to {}: {}'.format(notification.owner.username, notification.localized_message) else: print ' No email for {}: {}'.format(notification.owner.username, notification.localized_message) notification.email_sent = True notification.save()
# -*- coding: utf-8 -*- from django.core.management.base import BaseCommand, CommandError from api import models from web.utils import send_email class Command(BaseCommand): can_import_settings = True def handle(self, *args, **options): notifications = models.Notification.objects.filter(email_sent=False).select_related('owner', 'owner__preferences') for notification in notifications: preferences = notification.owner.preferences if preferences.is_notification_email_allowed(notification.message): try: send_email( subject=(u'School Idol Tomodachi' + u'✨ ' + u' Notification: ' + notification.english_message), template_name = 'notification', to=[notification.owner.email, 'contact@schoolido.lu'], context={ 'notification': notification, 'user': notification.owner, }, ) print 'Email sent to {}: {}'.format(notification.owner.username, notification.localized_message) except Exception, e: print '!! Error when sending email to {} !!'.format(notification.owner.email) print e # todo ios push notifications else: print ' No email for {}: {}'.format(notification.owner.username, notification.localized_message) notification.email_sent = True notification.save()
Handle errors in cron notifications
Handle errors in cron notifications
Python
apache-2.0
SchoolIdolTomodachi/SchoolIdolAPI,dburr/SchoolIdolAPI,rdsathene/SchoolIdolAPI,SchoolIdolTomodachi/SchoolIdolAPI,rdsathene/SchoolIdolAPI,dburr/SchoolIdolAPI,dburr/SchoolIdolAPI,rdsathene/SchoolIdolAPI,SchoolIdolTomodachi/SchoolIdolAPI
--- +++ @@ -12,17 +12,21 @@ for notification in notifications: preferences = notification.owner.preferences if preferences.is_notification_email_allowed(notification.message): - send_email( - subject=(u'School Idol Tomodachi' + u'✨ ' + u' Notification: ' + notification.english_message), - template_name = 'notification', - to=[notification.owner.email, 'contact@schoolido.lu'], - context={ - 'notification': notification, - 'user': notification.owner, - }, - ) + try: + send_email( + subject=(u'School Idol Tomodachi' + u'✨ ' + u' Notification: ' + notification.english_message), + template_name = 'notification', + to=[notification.owner.email, 'contact@schoolido.lu'], + context={ + 'notification': notification, + 'user': notification.owner, + }, + ) + print 'Email sent to {}: {}'.format(notification.owner.username, notification.localized_message) + except Exception, e: + print '!! Error when sending email to {} !!'.format(notification.owner.email) + print e # todo ios push notifications - print 'Email sent to {}: {}'.format(notification.owner.username, notification.localized_message) else: print ' No email for {}: {}'.format(notification.owner.username, notification.localized_message) notification.email_sent = True
c955628b134586491265bc2e6b4045398072cead
allauth/socialaccount/providers/kakao/provider.py
allauth/socialaccount/providers/kakao/provider.py
from allauth.account.models import EmailAddress from allauth.socialaccount.providers.base import ProviderAccount from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider class KakaoAccount(ProviderAccount): @property def properties(self): return self.account.extra_data['properties'] def get_avatar_url(self): return self.properties['profile_image'] def to_str(self): dflt = super(KakaoAccount, self).to_str() return self.properties['nickname'] or dflt class KakaoProvider(OAuth2Provider): id = 'kakao' name = 'Kakao' account_class = KakaoAccount def extract_uid(self, data): return str(data['id']) def extract_common_fields(self, data): email = data.get("kaccount_email") return dict(email=email) def extract_email_addresses(self, data): ret = [] email = data.get("kaccount_email") verified = data.get("kaccount_email_verified") # data["kaccount_email_verified"] imply the email address is # verified ret.append(EmailAddress(email=email, verified=verified, primary=True)) return ret provider_classes = [KakaoProvider]
from allauth.account.models import EmailAddress from allauth.socialaccount.providers.base import ProviderAccount from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider class KakaoAccount(ProviderAccount): @property def properties(self): return self.account.extra_data['properties'] def get_avatar_url(self): return self.properties['profile_image'] def to_str(self): dflt = super(KakaoAccount, self).to_str() return self.properties['nickname'] or dflt class KakaoProvider(OAuth2Provider): id = 'kakao' name = 'Kakao' account_class = KakaoAccount def extract_uid(self, data): return str(data['id']) def extract_common_fields(self, data): email = data.get("kaccount_email") return dict(email=email) def extract_email_addresses(self, data): ret = [] email = data.get("kaccount_email") if email: verified = data.get("kaccount_email_verified") # data["kaccount_email_verified"] imply the email address is # verified ret.append(EmailAddress(email=email, verified=verified, primary=True)) return ret provider_classes = [KakaoProvider]
Handle case where email is not present
fix(kakao): Handle case where email is not present
Python
mit
pennersr/django-allauth,rsalmaso/django-allauth,rsalmaso/django-allauth,lukeburden/django-allauth,bittner/django-allauth,AltSchool/django-allauth,pennersr/django-allauth,AltSchool/django-allauth,rsalmaso/django-allauth,AltSchool/django-allauth,lukeburden/django-allauth,bittner/django-allauth,lukeburden/django-allauth,bittner/django-allauth,pennersr/django-allauth
--- +++ @@ -31,12 +31,13 @@ def extract_email_addresses(self, data): ret = [] email = data.get("kaccount_email") - verified = data.get("kaccount_email_verified") - # data["kaccount_email_verified"] imply the email address is - # verified - ret.append(EmailAddress(email=email, - verified=verified, - primary=True)) + if email: + verified = data.get("kaccount_email_verified") + # data["kaccount_email_verified"] imply the email address is + # verified + ret.append(EmailAddress(email=email, + verified=verified, + primary=True)) return ret
6064f95021119e781b13224febfeca2d7de4aec5
wagtailmenus/management/commands/autopopulate_main_menus.py
wagtailmenus/management/commands/autopopulate_main_menus.py
# -*- coding: utf-8 -*- import logging from django.core.management.base import BaseCommand from wagtail.wagtailcore.models import Site from wagtailmenus import app_settings logger = logging.getLogger(__name__) class Command(BaseCommand): help = ( "Create a 'main menu' for any 'Site' that doesn't already have one. " "If main menus for any site do not have menu items, identify the " "'home' and 'section root' pages for the site, and menu items linking " "to those to the menu. Assumes 'site.root_page' is the 'home page' " "and its children are the 'section root' pages") def add_arguments(self, parser): parser.add_argument( '--add-home-links', action='store_true', dest='add-home-links', default=False, help="Add menu items for 'home' pages", ) def handle(self, *args, **options): for site in Site.objects.all(): menu = app_settings.MAIN_MENU_MODEL_CLASS.get_for_site(site) if not menu.get_menu_items_manager().exists(): menu.add_menu_items_for_pages( site.root_page.get_descendants( inclusive=options['add-home-links'] ).filter(depth__lte=site.root_page.depth + 1) )
# -*- coding: utf-8 -*- import logging from django.core.management.base import BaseCommand from wagtail.wagtailcore.models import Site from wagtailmenus import app_settings logger = logging.getLogger(__name__) class Command(BaseCommand): help = ( "Create a 'main menu' for any 'Site' that doesn't already have one. " "If main menus for any site do not have menu items, identify the " "'home' and 'section root' pages for the site, and menu items linking " "to those to the menu. Assumes 'site.root_page' is the 'home page' " "and its children are the 'section root' pages") def add_arguments(self, parser): parser.add_argument( '--add-home-links', action='store_true', dest='add-home-links', default=False, help="Add menu items for 'home' pages", ) def handle(self, *args, **options): for site in Site.objects.all(): menu = app_settings.MAIN_MENU_MODEL_CLASS.get_for_site(site) if not menu.get_menu_items_manager().exists(): menu.add_menu_items_for_pages( site.root_page.get_descendants( inclusive=bool(options['add-home-links']) ).filter(depth__lte=site.root_page.depth + 1) )
Make the '--add-home-links' option work for any value that evaluates to a bool
Make the '--add-home-links' option work for any value that evaluates to a bool
Python
mit
rkhleics/wagtailmenus,ababic/wagtailmenus,ababic/wagtailmenus,rkhleics/wagtailmenus,rkhleics/wagtailmenus,ababic/wagtailmenus
--- +++ @@ -32,6 +32,6 @@ if not menu.get_menu_items_manager().exists(): menu.add_menu_items_for_pages( site.root_page.get_descendants( - inclusive=options['add-home-links'] + inclusive=bool(options['add-home-links']) ).filter(depth__lte=site.root_page.depth + 1) )
f0a1cd06f954094bc5ef3dfa337901a87d22485c
prod.py
prod.py
#! /usr/bin/env python2.7 import cherrypy import medlem wsgiapp = cherrypy.Application(medlem.Medlem(), '/', config="config/production.conf")
#! /usr/bin/env python2.7 import cherrypy import medlem app = cherrypy.Application(medlem.Medlem(), '/', config="config/production.conf")
Change name of the wsgi-object to match what uwsgi
Change name of the wsgi-object to match what uwsgi
Python
bsd-3-clause
UngaForskareStockholm/medlem2
--- +++ @@ -3,4 +3,4 @@ import cherrypy import medlem -wsgiapp = cherrypy.Application(medlem.Medlem(), '/', config="config/production.conf") +app = cherrypy.Application(medlem.Medlem(), '/', config="config/production.conf")
5aa13f1aafd2afa71d7a95f6b59ff28a1c97fbd2
compare_mt/__init__.py
compare_mt/__init__.py
import compare_mt.ngram_utils import compare_mt.stat_utils import compare_mt.corpus_utils import compare_mt.sign_utils import compare_mt.scorers import compare_mt.bucketers import compare_mt.reporters import compare_mt.arg_utils import compare_mt.print_utils __version__ = "0.2"
import compare_mt.ngram_utils import compare_mt.stat_utils import compare_mt.corpus_utils import compare_mt.sign_utils import compare_mt.scorers import compare_mt.bucketers import compare_mt.reporters import compare_mt.arg_utils import compare_mt.print_utils __version__ = "0.2.1"
Increase version number to update pipy
Increase version number to update pipy
Python
bsd-3-clause
neulab/compare-mt,neulab/compare-mt
--- +++ @@ -9,4 +9,4 @@ import compare_mt.print_utils -__version__ = "0.2" +__version__ = "0.2.1"
94edf518993860dbff8d845292bfe4ce94d9fe5e
netdumplings/console/__init__.py
netdumplings/console/__init__.py
from .info import main as info from .printer import main as printer from .shifty import main as shifty from .snifty import main as snifty from .status import main as status ( info, printer, shifty, snifty, status, )
from .printer import printer from .shifty import shifty from .shiftydetails import shiftydetails from .shiftysummary import shiftysummary from .snifty import snifty ( printer, shifty, shiftydetails, shiftysummary, snifty, )
Update console module with new cli names
Update console module with new cli names
Python
mit
mjoblin/netdumplings,mjoblin/netdumplings,mjoblin/netdumplings
--- +++ @@ -1,14 +1,14 @@ -from .info import main as info -from .printer import main as printer -from .shifty import main as shifty -from .snifty import main as snifty -from .status import main as status +from .printer import printer +from .shifty import shifty +from .shiftydetails import shiftydetails +from .shiftysummary import shiftysummary +from .snifty import snifty ( - info, printer, shifty, + shiftydetails, + shiftysummary, snifty, - status, )
68e8dfb52aea3a3f6ee99b3ce2a2b479a39c19db
doc/examples/special/plot_errorfill.py
doc/examples/special/plot_errorfill.py
""" ================ Plot `errorfill` ================ When you have continuous data measurement and errors associated with every data point, plotting error bars can get really noisy. `special.errorfill` plots a filled region to represent the error values instead of using individual bars. """ import numpy as np import matplotlib.pyplot as plt from mpltools import special x = np.linspace(0, 2 * np.pi) y_sin = np.sin(x) y_cos = np.cos(x) y_err = 0.2 special.errorfill(x, y_sin, y_err, label='blue', label_fill='blue error') special.errorfill(x, y_cos, y_err, label='red', label_fill='red error', alpha_fill=0.1) plt.legend() plt.show()
""" ================ Plot `errorfill` ================ When you have continuous data measurement and errors associated with every data point, plotting error bars can get really noisy. `special.errorfill` plots a filled region to represent the error values instead of using individual bars. """ import numpy as np import matplotlib.pyplot as plt from mpltools import special x = np.linspace(0, 2 * np.pi) y_sin = np.sin(x) y_cos = np.cos(x) y_err = 0.2 special.errorfill(x, y_sin, y_err, label='sin', label_fill='sin error') special.errorfill(x, y_cos, y_err, label='cos', label_fill='cos error', alpha_fill=0.1) plt.legend() plt.show()
Fix labeling on plots so it matches elements.
DOC: Fix labeling on plots so it matches elements.
Python
bsd-3-clause
tonysyu/mpltools,matteoicardi/mpltools
--- +++ @@ -16,8 +16,8 @@ y_cos = np.cos(x) y_err = 0.2 -special.errorfill(x, y_sin, y_err, label='blue', label_fill='blue error') -special.errorfill(x, y_cos, y_err, label='red', label_fill='red error', +special.errorfill(x, y_sin, y_err, label='sin', label_fill='sin error') +special.errorfill(x, y_cos, y_err, label='cos', label_fill='cos error', alpha_fill=0.1) plt.legend()
2a2c9e01b51b10594da97c5ce273073931e44c43
social_auth/backends/pipeline/misc.py
social_auth/backends/pipeline/misc.py
from social_auth.backends import PIPELINE from social_auth.utils import setting PIPELINE_ENTRY = 'social_auth.backends.pipeline.misc.save_status_to_session' def tuple_index(t, e): for (i, te) in enumerate(t): if te == e: return i return None def save_status_to_session(request, auth, *args, **kwargs): """Saves current social-auth status to session.""" next_entry = setting('SOCIAL_AUTH_PIPELINE_RESUME_ENTRY') if next_entry: idx = tuple_index(PIPELINE, next_entry) else: idx = tuple_index(PIPELINE, PIPELINE_ENTRY) if idx: idx += 1 data = auth.to_session_dict(idx, *args, **kwargs) name = setting('SOCIAL_AUTH_PARTIAL_PIPELINE_KEY', 'partial_pipeline') request.session[name] = data request.session.modified = True
from social_auth.backends import PIPELINE from social_auth.utils import setting PIPELINE_ENTRY = 'social_auth.backends.pipeline.misc.save_status_to_session' def save_status_to_session(request, auth, *args, **kwargs): """Saves current social-auth status to session.""" next_entry = setting('SOCIAL_AUTH_PIPELINE_RESUME_ENTRY') try: if next_entry: idx = PIPELINE.index(next_entry) else: idx = PIPELINE.index(PIPELINE_ENTRY) + 1 except ValueError: idx = None data = auth.to_session_dict(idx, *args, **kwargs) name = setting('SOCIAL_AUTH_PARTIAL_PIPELINE_KEY', 'partial_pipeline') request.session[name] = data request.session.modified = True
Revert "Add own tuple_index function to stay compatible with python 2.5"
Revert "Add own tuple_index function to stay compatible with python 2.5" This reverts commit 7e6af723e15a785b403010de4b44b49fce924e91.
Python
bsd-3-clause
michael-borisov/django-social-auth,qas612820704/django-social-auth,VishvajitP/django-social-auth,beswarm/django-social-auth,lovehhf/django-social-auth,antoviaque/django-social-auth-norel,qas612820704/django-social-auth,MjAbuz/django-social-auth,omab/django-social-auth,caktus/django-social-auth,VishvajitP/django-social-auth,limdauto/django-social-auth,1st/django-social-auth,czpython/django-social-auth,vxvinh1511/django-social-auth,dongguangming/django-social-auth,krvss/django-social-auth,MjAbuz/django-social-auth,vuchau/django-social-auth,lovehhf/django-social-auth,dongguangming/django-social-auth,duoduo369/django-social-auth,WW-Digital/django-social-auth,beswarm/django-social-auth,getsentry/django-social-auth,adw0rd/django-social-auth,sk7/django-social-auth,limdauto/django-social-auth,caktus/django-social-auth,mayankcu/Django-social,gustavoam/django-social-auth,vuchau/django-social-auth,vxvinh1511/django-social-auth,gustavoam/django-social-auth,michael-borisov/django-social-auth,omab/django-social-auth
--- +++ @@ -4,22 +4,18 @@ PIPELINE_ENTRY = 'social_auth.backends.pipeline.misc.save_status_to_session' -def tuple_index(t, e): - for (i, te) in enumerate(t): - if te == e: - return i - return None def save_status_to_session(request, auth, *args, **kwargs): """Saves current social-auth status to session.""" next_entry = setting('SOCIAL_AUTH_PIPELINE_RESUME_ENTRY') - if next_entry: - idx = tuple_index(PIPELINE, next_entry) - else: - idx = tuple_index(PIPELINE, PIPELINE_ENTRY) - if idx: - idx += 1 + try: + if next_entry: + idx = PIPELINE.index(next_entry) + else: + idx = PIPELINE.index(PIPELINE_ENTRY) + 1 + except ValueError: + idx = None data = auth.to_session_dict(idx, *args, **kwargs)
93effb501a50d8265afd37826fbcab4dd4a87611
qa_app/views.py
qa_app/views.py
# Copyright 2016 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from flask import Blueprint, render_template, request, session from flask_login import login_required from qa_app.models import Users, Attempts views = Blueprint('views', __name__) @views.before_request def redirect_setup(): if request.path.startswith("/static"): return @views.route('/') def index(): return render_template("index.html", page="Home") @views.route('/profile') @login_required def profile(): user = Users.query(email=session['email']).first() attempts = Attempts.query(user_id=user.id).all() return render_template("profile.html", page="Profile", user=user, attempts=attempts)
# Copyright 2016 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from flask import Blueprint, render_template, request, session from flask_login import login_required from qa_app.models import Users, Attempts views = Blueprint('views', __name__) @views.before_request def redirect_setup(): if request.path.startswith("/static"): return @views.route('/') def index(): return render_template("index.html", page="Home") @views.route('/profile') @login_required def profile(): user = Users.query.filter_by(email=session['email']).first() attempts = Attempts.query.filter_by(user_id=user.id).all() return render_template("profile.html", page="Profile", user=user, attempts=attempts)
Fix user and attempts sqlalchemia request.
Fix user and attempts sqlalchemia request.
Python
apache-2.0
molecul/qa_app_flask,molecul/qa_app_flask,molecul/qa_app_flask
--- +++ @@ -33,6 +33,6 @@ @views.route('/profile') @login_required def profile(): - user = Users.query(email=session['email']).first() - attempts = Attempts.query(user_id=user.id).all() + user = Users.query.filter_by(email=session['email']).first() + attempts = Attempts.query.filter_by(user_id=user.id).all() return render_template("profile.html", page="Profile", user=user, attempts=attempts)
1914bd9a9fc2f1ce7a557dd2134d98796866283d
rootpy/userdata.py
rootpy/userdata.py
""" This module handles creation of the user-data area """ import os import tempfile import atexit DATA_ROOT = None if os.getenv('ROOTPY_GRIDMODE') not in ('1', 'true'): DATA_ROOT = os.getenv('ROOTPY_DATA') if DATA_ROOT is None: DATA_ROOT = os.path.expanduser('~/.rootpy') else: DATA_ROOT = os.path.expandvars(os.path.expanduser(DATA_ROOT)) # check if expanduser failed: if DATA_ROOT.startswith('~'): DATA_ROOT = None elif not os.path.exists(DATA_ROOT): os.mkdir(DATA_ROOT) elif not os.path.isdir(DATA_ROOT): # A file at DATA_ROOT already exists DATA_ROOT = None __is_tmp = False if DATA_ROOT is None: print "Warning: placing user data in /tmp.\n" \ "Make sure ~/.rootpy or $ROOTPY_DATA\n" \ "is a writable directory so that I don't need to\n" \ "recreate all user data each time" DATA_ROOT = tempfile.mkdtemp() __is_tmp = True @atexit.register def __cleanup(): if __is_tmp: import shutil shutil.rmtree(DATA_ROOT)
""" This module handles creation of the user-data area """ import os import tempfile import atexit from os.path import expanduser, expandvars, exists, isdir if "XDG_CONFIG_HOME" not in os.environ: os.environ["XDG_CONFIG_HOME"] = expanduser('~/.config') if "XDG_CACHE_HOME" not in os.environ: os.environ["XDG_CACHE_HOME"] = expanduser('~/.cache') def ensure_directory(variable, default): path = os.getenv(variable) if path is None: path = expandvars(default) else: path = expandvars(expanduser(path)) # check if expanduser failed: if path.startswith('~'): path = None elif not exists(path): os.makedirs(path) elif not isdir(path): # A file at path already exists path = None return path DATA_ROOT = CONFIG_ROOT = None if os.getenv('ROOTPY_GRIDMODE') not in ('1', 'true'): DATA_ROOT = ensure_directory('ROOTPY_DATA', '${XDG_CACHE_HOME}/rootpy') CONFIG_ROOT = ensure_directory('ROOTPY_CONFIG', '${XDG_CONFIG_HOME}/rootpy') if DATA_ROOT is None: log.info("Placing user data in /tmp.") log.warning("Make sure '~/.cache/rootpy' or $ROOTPY_DATA is a writable " "directory so that it isn't necessary to recreate all user data" " each time") DATA_ROOT = tempfile.mkdtemp() @atexit.register def __cleanup(): import shutil shutil.rmtree(DATA_ROOT)
Use XDG base directory specificiation
Use XDG base directory specificiation
Python
bsd-3-clause
rootpy/rootpy,rootpy/rootpy,ndawe/rootpy,kreczko/rootpy,ndawe/rootpy,kreczko/rootpy,ndawe/rootpy,kreczko/rootpy,rootpy/rootpy
--- +++ @@ -5,35 +5,47 @@ import tempfile import atexit - -DATA_ROOT = None -if os.getenv('ROOTPY_GRIDMODE') not in ('1', 'true'): - DATA_ROOT = os.getenv('ROOTPY_DATA') - if DATA_ROOT is None: - DATA_ROOT = os.path.expanduser('~/.rootpy') - else: - DATA_ROOT = os.path.expandvars(os.path.expanduser(DATA_ROOT)) - # check if expanduser failed: - if DATA_ROOT.startswith('~'): - DATA_ROOT = None - elif not os.path.exists(DATA_ROOT): - os.mkdir(DATA_ROOT) - elif not os.path.isdir(DATA_ROOT): - # A file at DATA_ROOT already exists - DATA_ROOT = None - -__is_tmp = False -if DATA_ROOT is None: - print "Warning: placing user data in /tmp.\n" \ - "Make sure ~/.rootpy or $ROOTPY_DATA\n" \ - "is a writable directory so that I don't need to\n" \ - "recreate all user data each time" - DATA_ROOT = tempfile.mkdtemp() - __is_tmp = True +from os.path import expanduser, expandvars, exists, isdir -@atexit.register -def __cleanup(): - if __is_tmp: +if "XDG_CONFIG_HOME" not in os.environ: + os.environ["XDG_CONFIG_HOME"] = expanduser('~/.config') +if "XDG_CACHE_HOME" not in os.environ: + os.environ["XDG_CACHE_HOME"] = expanduser('~/.cache') + +def ensure_directory(variable, default): + path = os.getenv(variable) + if path is None: + path = expandvars(default) + else: + path = expandvars(expanduser(path)) + + # check if expanduser failed: + if path.startswith('~'): + path = None + elif not exists(path): + os.makedirs(path) + elif not isdir(path): + # A file at path already exists + path = None + return path + +DATA_ROOT = CONFIG_ROOT = None +if os.getenv('ROOTPY_GRIDMODE') not in ('1', 'true'): + DATA_ROOT = ensure_directory('ROOTPY_DATA', '${XDG_CACHE_HOME}/rootpy') + CONFIG_ROOT = ensure_directory('ROOTPY_CONFIG', '${XDG_CONFIG_HOME}/rootpy') + + +if DATA_ROOT is None: + log.info("Placing user data in /tmp.") + log.warning("Make sure '~/.cache/rootpy' or $ROOTPY_DATA is a writable " + "directory so that it isn't necessary to recreate all user data" + " each time") + + DATA_ROOT = tempfile.mkdtemp() + + @atexit.register + def __cleanup(): import shutil shutil.rmtree(DATA_ROOT) +
1ae98c0f2186dcdbd658f774a14172b4618bb0a8
logging_util.py
logging_util.py
# https://docs.python.org/3.6/howto/logging.html#logging-basic-tutorial import logging import sys def get_logger(name): """ https://stackoverflow.com/questions/28330317/print-timestamp-for-logging-in-python https://docs.python.org/3/library/logging.html#formatter-objects https://docs.python.org/3.6/howto/logging.html#logging-basic-tutorial https://docs.python.org/3.6/howto/logging.html#logging-to-a-file :param name: logger name :return: a configured logger """ formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(funcName)s line:%(lineno)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) # add one or more handlers # log to file handler = logging.FileHandler('./data/output/fib.log', mode='w') handler.setFormatter(formatter) logger.addHandler(handler) # log to terminal stdout screen_handler = logging.StreamHandler(stream=sys.stdout) screen_handler.setFormatter(formatter) logger.addHandler(screen_handler) return logger
# https://docs.python.org/3.6/howto/logging.html#logging-basic-tutorial import logging import sys def get_logger(name): """ https://stackoverflow.com/questions/28330317/print-timestamp-for-logging-in-python https://docs.python.org/3/library/logging.html#formatter-objects https://docs.python.org/3.6/howto/logging.html#logging-basic-tutorial https://docs.python.org/3.6/howto/logging.html#logging-to-a-file :param name: logger name :return: a configured logger """ formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(funcName)s line:%(lineno)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) # add one or more handlers # log to file # mode 'a' append, not 'w' write handler = logging.FileHandler('./data/output/fib.log', mode='a') handler.setFormatter(formatter) logger.addHandler(handler) # log to terminal stdout screen_handler = logging.StreamHandler(stream=sys.stdout) screen_handler.setFormatter(formatter) logger.addHandler(screen_handler) return logger
Fix bug some log output showing on screen not present in log file by changing logging file handler mode from 'w' write to 'a' append.
Fix bug some log output showing on screen not present in log file by changing logging file handler mode from 'w' write to 'a' append.
Python
mit
beepscore/fibonacci
--- +++ @@ -21,7 +21,8 @@ # add one or more handlers # log to file - handler = logging.FileHandler('./data/output/fib.log', mode='w') + # mode 'a' append, not 'w' write + handler = logging.FileHandler('./data/output/fib.log', mode='a') handler.setFormatter(formatter) logger.addHandler(handler)
98fd04596367f94b7f47056c429ea23b2dd6165b
miller-rabin.py
miller-rabin.py
import sys, math, random if len(sys.argv) > 1: candidate = eval(sys.argv[1]) else: candidate = 221 modulo = candidate - 1 s = -1 quotient = modulo remainder = 0 while remainder == 0: quotient, remainder = divmod(quotient, 2) s += 1 d = quotient * 2 + 1 for k in range(10): witness = random.randint(2, modulo - 1) x = pow(witness, d, candidate) if x == 1 or x == modulo: continue for i in range(s - 1): x = pow(x, 2, candidate) if x == 1: print('Composite.') exit() if x == modulo: break if x != modulo: print('Composite.') exit() print('Prime.')
import sys, math, random # Receive candidate number from arguments, or default to 221 for test purposes. if len(sys.argv) > 1: candidate = eval(sys.argv[1]) else: candidate = 221 modulo = candidate - 1 # Write the modulo (candidate -1) number in the form # 2^s * d. s = 0 quotient = modulo remainder = 0 while remainder == 0: quotient, remainder = divmod(quotient, 2) s += 1 # The last division failed, so we must decrement `s`. s -= 1 # quotient here contains the leftover which we could not divide by two, # and we have a 1 remaining from this last division. d = quotient * 2 + 1 # Here 10 is the precision. Every increment to this value decreases the # chance of a false positive by 3/4. for k in range(10): # Every witness may prove that the candidate is composite, or assert # nothing. witness = random.randint(2, modulo - 1) x = pow(witness, d, candidate) if x == 1 or x == modulo: continue for i in range(s - 1): x = pow(x, 2, candidate) if x == 1: print('Composite.') exit() if x == modulo: break if x != modulo: # We arrived here because the `i` loop ran its course naturally without # meeting the `x == modulo` break. print('Composite.') exit() print('Prime.')
Add comments to Python version
Add comments to Python version
Python
mit
boppreh/miller-rabin,boppreh/miller-rabin
--- +++ @@ -1,33 +1,55 @@ import sys, math, random +# Receive candidate number from arguments, or default to 221 for test purposes. if len(sys.argv) > 1: candidate = eval(sys.argv[1]) else: candidate = 221 modulo = candidate - 1 -s = -1 + +# Write the modulo (candidate -1) number in the form +# 2^s * d. + +s = 0 quotient = modulo remainder = 0 while remainder == 0: quotient, remainder = divmod(quotient, 2) s += 1 + +# The last division failed, so we must decrement `s`. +s -= 1 +# quotient here contains the leftover which we could not divide by two, +# and we have a 1 remaining from this last division. d = quotient * 2 + 1 +# Here 10 is the precision. Every increment to this value decreases the +# chance of a false positive by 3/4. for k in range(10): + + # Every witness may prove that the candidate is composite, or assert + # nothing. witness = random.randint(2, modulo - 1) + x = pow(witness, d, candidate) if x == 1 or x == modulo: continue for i in range(s - 1): x = pow(x, 2, candidate) + if x == 1: print('Composite.') exit() + if x == modulo: break + if x != modulo: + # We arrived here because the `i` loop ran its course naturally without + # meeting the `x == modulo` break. print('Composite.') exit() + print('Prime.')
0fed2ca675967f1d43d0abacb9110875b30b0d64
tests/test_input.py
tests/test_input.py
from unittest.mock import patch from rcfc import server, input_methods from test_helpers import IgnoredArgument input_value = 0 def set_input_value(val): global input_value input_value = val @patch("bottle.Bottle.route") def test_slider(mock_route): server.clear_buttons() input_methods.slider("Slider text", lambda: input_value)(set_input_value) expected = {"text": "Slider text", "type": "input.slider", "groups": [], "state": 0, "min": 0, "max": 100, "id": 0} assert server.get_buttons_registered() == {"buttons": [expected]} mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"], IgnoredArgument())
from unittest.mock import patch from rcfc import server, input_methods from test_helpers import IgnoredArgument input_value = 0 def set_input_value(val): global input_value input_value = val @patch("bottle.Bottle.route") def test_slider(mock_route): server.clear_buttons() input_methods.slider("Slider text", lambda: input_value)(set_input_value) expected = {"text": "Slider text", "type": "input.slider", "groups": [], "state": 0, "min": 0, "max": 100, "id": 0} assert server.get_buttons_registered() == {"buttons": [expected]} mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"], IgnoredArgument()) @patch("bottle.Bottle.route") def test_slider_with_range(mock_route): server.clear_buttons() input_methods.slider("Slider text", lambda: input_value, (10, 20))(set_input_value) expected = {"text": "Slider text", "type": "input.slider", "groups": [], "state": 0, "min": 10, "max": 20, "id": 0} assert server.get_buttons_registered() == {"buttons": [expected]} mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"], IgnoredArgument())
Add custom rangers to slider
Add custom rangers to slider
Python
mit
pviafore/rcfc,pviafore/rcfc,pviafore/rcfc
--- +++ @@ -27,3 +27,23 @@ mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"], IgnoredArgument()) + + +@patch("bottle.Bottle.route") +def test_slider_with_range(mock_route): + server.clear_buttons() + input_methods.slider("Slider text", + lambda: input_value, + (10, 20))(set_input_value) + expected = {"text": "Slider text", + "type": "input.slider", + "groups": [], + "state": 0, + "min": 10, + "max": 20, + "id": 0} + assert server.get_buttons_registered() == {"buttons": [expected]} + + mock_route.assert_called_once_with("/buttons/0", + ["POST", "OPTIONS"], + IgnoredArgument())
91bdd47afe409e86bceca71ebb07ae1975e9073a
tests/test_sweep.py
tests/test_sweep.py
import os import numpy as np import crepe def test_sweep(): # this data contains a sine sweep file = os.path.join(os.path.dirname(__file__), 'sweep.wav') model = crepe.build_and_load_model() crepe.process_file(model, file) f0_file = os.path.join(os.path.dirname(__file__), 'sweep.f0.csv') result = np.loadtxt(f0_file, delimiter=',') # the result should be confident enough about the presence of pitch in every # frame assert np.mean(result[:, 2] > 0.5) > 0.99 # the frequencies should be linear assert np.corrcoef(result[:, 1]) > 0.99
import os import numpy as np import crepe def test_sweep(): # this data contains a sine sweep file = os.path.join(os.path.dirname(__file__), 'sweep.wav') model = crepe.build_and_load_model() crepe.process_file(model, file) f0_file = os.path.join(os.path.dirname(__file__), 'sweep.f0.csv') result = np.loadtxt(f0_file, delimiter=',', skiprows=1) # the result should be confident enough about the presence of pitch in every # frame assert np.mean(result[:, 2] > 0.5) > 0.99 # the frequencies should be linear assert np.corrcoef(result[:, 1]) > 0.99
Fix bug in unit test (ignore header row in output csv file)
Fix bug in unit test (ignore header row in output csv file)
Python
mit
marl/crepe
--- +++ @@ -11,7 +11,7 @@ crepe.process_file(model, file) f0_file = os.path.join(os.path.dirname(__file__), 'sweep.f0.csv') - result = np.loadtxt(f0_file, delimiter=',') + result = np.loadtxt(f0_file, delimiter=',', skiprows=1) # the result should be confident enough about the presence of pitch in every # frame
fcfe2513fc8532dc2212a254da42d75048e76de7
form_designer/tests/test_cms_plugin.py
form_designer/tests/test_cms_plugin.py
from django.contrib.auth.models import AnonymousUser from django.utils.crypto import get_random_string import pytest from cms import api from cms.page_rendering import render_page from form_designer.contrib.cms_plugins.form_designer_form.cms_plugins import FormDesignerPlugin from form_designer.models import FormDefinition, FormDefinitionField @pytest.mark.django_db def test_cms_plugin_renders_in_cms_page(rf): fd = FormDefinition.objects.create( mail_to='test@example.com', mail_subject='Someone sent you a greeting: {{ test }}' ) field = FormDefinitionField.objects.create( form_definition=fd, name='test', label=get_random_string(), field_class='django.forms.CharField', ) page = api.create_page("test", "page.html", "en") ph = page.get_placeholders()[0] api.add_plugin(ph, FormDesignerPlugin, "en", form_definition=fd) request = rf.get("/") request.user = AnonymousUser() request.current_page = page response = render_page(request, page, "fi", "test") response.render() content = response.content.decode("utf8") assert field.label in content assert "<form" in content
import django from django.contrib.auth.models import AnonymousUser from django.utils.crypto import get_random_string import pytest from cms import api from cms.page_rendering import render_page from form_designer.contrib.cms_plugins.form_designer_form.cms_plugins import FormDesignerPlugin from form_designer.models import FormDefinition, FormDefinitionField @pytest.mark.django_db def test_cms_plugin_renders_in_cms_page(rf): if django.VERSION >= (1, 10): pytest.xfail('This test is broken in Django 1.10+') fd = FormDefinition.objects.create( mail_to='test@example.com', mail_subject='Someone sent you a greeting: {{ test }}' ) field = FormDefinitionField.objects.create( form_definition=fd, name='test', label=get_random_string(), field_class='django.forms.CharField', ) page = api.create_page("test", "page.html", "en") ph = page.get_placeholders()[0] api.add_plugin(ph, FormDesignerPlugin, "en", form_definition=fd) request = rf.get("/") request.user = AnonymousUser() request.current_page = page response = render_page(request, page, "fi", "test") response.render() content = response.content.decode("utf8") assert field.label in content assert "<form" in content
Disable Django-CMS test on Django 1.10+
Disable Django-CMS test on Django 1.10+ Someone with the time and inclination should set up the test to work with a Django-CMS version compatible with Django 1.10+, then try again
Python
bsd-3-clause
andersinno/django-form-designer-ai,kcsry/django-form-designer,andersinno/django-form-designer,andersinno/django-form-designer,kcsry/django-form-designer,andersinno/django-form-designer-ai
--- +++ @@ -1,3 +1,4 @@ +import django from django.contrib.auth.models import AnonymousUser from django.utils.crypto import get_random_string @@ -10,6 +11,8 @@ @pytest.mark.django_db def test_cms_plugin_renders_in_cms_page(rf): + if django.VERSION >= (1, 10): + pytest.xfail('This test is broken in Django 1.10+') fd = FormDefinition.objects.create( mail_to='test@example.com', mail_subject='Someone sent you a greeting: {{ test }}'
1d82b988fdd913e291ed73552964c8724934ad32
tools/build_interface_docs.py
tools/build_interface_docs.py
#!/usr/bin/env python """Script to auto-generate our API docs. """ # stdlib imports import os import sys # local imports from interfacedocgen import InterfaceHelpWriter #***************************************************************************** if __name__ == '__main__': nipypepath = os.path.abspath('..') sys.path.insert(1,nipypepath) package = 'nipype' outdir = os.path.join('interfaces','generated') docwriter = InterfaceHelpWriter(package) # Packages that should not be included in generated API docs. docwriter.package_skip_patterns += ['\.externals$', '\.utils$', '\.pipeline', '.\testing', '\.interfaces\.gorlin_glue', ] # Modules that should not be included in generated API docs. docwriter.module_skip_patterns += ['\.version$', '\.interfaces\.afni$', '\.interfaces\.base$', '\.interfaces\.matlab$', '\.interfaces\.rest$', '\.pipeline\.alloy$', '\.pipeline\.s3_node_wrapper$', ] docwriter.class_skip_patterns += ['FSL', 'spm.\SpecifyModel', 'SpmInfo', 'FSCommandLine', 'SpmMatlab' ] docwriter.write_api_docs(outdir) docwriter.write_index(outdir, 'gen', relative_to='interfaces') print '%d files written' % len(docwriter.written_modules)
#!/usr/bin/env python """Script to auto-generate our API docs. """ # stdlib imports import os import sys # local imports from interfacedocgen import InterfaceHelpWriter #***************************************************************************** if __name__ == '__main__': nipypepath = os.path.abspath('..') sys.path.insert(1,nipypepath) package = 'nipype' outdir = os.path.join('interfaces','generated') docwriter = InterfaceHelpWriter(package) # Packages that should not be included in generated API docs. docwriter.package_skip_patterns += ['\.externals$', '\.utils$', '\.pipeline', '.\testing', '\.interfaces\.gorlin_glue', ] # Modules that should not be included in generated API docs. docwriter.module_skip_patterns += ['\.version$', '\.interfaces\.afni$', '\.interfaces\.base$', '\.interfaces\.matlab$', '\.interfaces\.rest$', '\.interfaces\.pymvpa$', '\.pipeline\.alloy$', '\.pipeline\.s3_node_wrapper$', ] docwriter.class_skip_patterns += ['FSL', 'spm.\SpecifyModel', 'SpmInfo', 'FSCommandLine', 'SpmMatlab' ] docwriter.write_api_docs(outdir) docwriter.write_index(outdir, 'gen', relative_to='interfaces') print '%d files written' % len(docwriter.written_modules)
Remove pymvpa from documentation build.
Remove pymvpa from documentation build. git-svn-id: 24f545668198cdd163a527378499f2123e59bf9f@931 ead46cd0-7350-4e37-8683-fc4c6f79bf00
Python
bsd-3-clause
arokem/nipype,grlee77/nipype,JohnGriffiths/nipype,wanderine/nipype,fprados/nipype,fprados/nipype,christianbrodbeck/nipype,dgellis90/nipype,wanderine/nipype,sgiavasis/nipype,arokem/nipype,rameshvs/nipype,mick-d/nipype,FredLoney/nipype,mick-d/nipype_source,mick-d/nipype,blakedewey/nipype,sgiavasis/nipype,rameshvs/nipype,FCP-INDI/nipype,sgiavasis/nipype,carlohamalainen/nipype,dgellis90/nipype,JohnGriffiths/nipype,glatard/nipype,FredLoney/nipype,mick-d/nipype,gerddie/nipype,iglpdc/nipype,arokem/nipype,dmordom/nipype,carolFrohlich/nipype,pearsonlab/nipype,pearsonlab/nipype,wanderine/nipype,arokem/nipype,christianbrodbeck/nipype,glatard/nipype,blakedewey/nipype,dgellis90/nipype,mick-d/nipype,Leoniela/nipype,wanderine/nipype,gerddie/nipype,blakedewey/nipype,carolFrohlich/nipype,grlee77/nipype,iglpdc/nipype,grlee77/nipype,iglpdc/nipype,dmordom/nipype,gerddie/nipype,carlohamalainen/nipype,dgellis90/nipype,mick-d/nipype_source,Leoniela/nipype,Leoniela/nipype,grlee77/nipype,fprados/nipype,glatard/nipype,carolFrohlich/nipype,JohnGriffiths/nipype,rameshvs/nipype,rameshvs/nipype,glatard/nipype,pearsonlab/nipype,satra/NiPypeold,FCP-INDI/nipype,dmordom/nipype,carolFrohlich/nipype,FredLoney/nipype,iglpdc/nipype,pearsonlab/nipype,carlohamalainen/nipype,FCP-INDI/nipype,sgiavasis/nipype,blakedewey/nipype,mick-d/nipype_source,gerddie/nipype,JohnGriffiths/nipype,satra/NiPypeold,FCP-INDI/nipype
--- +++ @@ -28,6 +28,7 @@ '\.interfaces\.base$', '\.interfaces\.matlab$', '\.interfaces\.rest$', + '\.interfaces\.pymvpa$', '\.pipeline\.alloy$', '\.pipeline\.s3_node_wrapper$', ]
0c69c3e25f52ab126886a2a2f1c33d099d0bb5a4
annfab/distances/matrix_cosine.py
annfab/distances/matrix_cosine.py
import numpy as np import nearpy.distances class MatrixCosineDistance(nearpy.distances.CosineDistance): """ A distance measure for calculating the cosine distance between matrices. """ def distance(self, x, y): if len(x.shape) <= 1: return super(MatrixCosineDistance, self).distance(x, y) k = x.shape[1] if len(y.shape) > 1: m = y.shape[1] else: m = 1 d = np.empty((k, m), dtype=np.dtype(x[0,0])) for i in xrange(k): d[i,:] = super(MatrixCosineDistance, self).distance(x[:,i], y) return d
import numpy as np import nearpy.distances class MatrixCosineDistance(nearpy.distances.CosineDistance): """ A distance measure for calculating the cosine distance between matrices. """ def distance(self, x, y): if len(x.shape) <= 1: return super(MatrixCosineDistance, self).distance(x, y) k = x.shape[1] if len(y.shape) > 1: m = y.shape[1] else: m = 1 d = np.empty((k, m), dtype=np.dtype(x[0, 0])) for i in xrange(k): d[i, :] = super(MatrixCosineDistance, self).distance(x[:, i], y) return d
Add simple tests for matrix operands for distance measure.
Add simple tests for matrix operands for distance measure.
Python
mit
elezar/ann-fab,elezar/ann-fab,elezar/ann-fab
--- +++ @@ -9,18 +9,17 @@ """ def distance(self, x, y): - if len(x.shape) <= 1: - return super(MatrixCosineDistance, self).distance(x, y) + if len(x.shape) <= 1: + return super(MatrixCosineDistance, self).distance(x, y) - k = x.shape[1] - if len(y.shape) > 1: - m = y.shape[1] - else: - m = 1 + k = x.shape[1] + if len(y.shape) > 1: + m = y.shape[1] + else: + m = 1 - d = np.empty((k, m), dtype=np.dtype(x[0,0])) - for i in xrange(k): - d[i,:] = super(MatrixCosineDistance, self).distance(x[:,i], y) + d = np.empty((k, m), dtype=np.dtype(x[0, 0])) + for i in xrange(k): + d[i, :] = super(MatrixCosineDistance, self).distance(x[:, i], y) - return d - + return d
6723dd3e2980d040cef4f7d0f7675933666eb088
tests/benchmarks/constructs/LocalVariableAssign.py
tests/benchmarks/constructs/LocalVariableAssign.py
# Copyright 2015, Kay Hayen, mailto:kay.hayen@gmail.com # # Python test originally created or extracted from other peoples work. The # parts from me are licensed as below. It is at least Free Softwar where # it's copied from other people. In these cases, that will normally be # indicated. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module_value1 = 1000 module_value2 = 50 def calledRepeatedly(): # Force frame and eliminate forward propagation (currently). module_value1 local_value = module_value1 local_value2 = module_value2 # construct_begin local_value2 = local_value * 2 # construct_alternative local_value * 2 # construct_end for x in xrange(50000): calledRepeatedly() print("OK.")
# Copyright 2015, Kay Hayen, mailto:kay.hayen@gmail.com # # Python test originally created or extracted from other peoples work. The # parts from me are licensed as below. It is at least Free Softwar where # it's copied from other people. In these cases, that will normally be # indicated. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module_value1 = 1000 module_value2 = 50 def calledRepeatedly(): # Force frame and eliminate forward propagation (currently). module_value1 local_value = module_value1 local_value2 = module_value2 # construct_begin local_value2 = local_value * 2 # construct_alternative local_value * 2 # construct_end return local_value for x in xrange(50000): calledRepeatedly() print("OK.")
Enhance construct test to avoid local variable optimization.
Tests: Enhance construct test to avoid local variable optimization.
Python
apache-2.0
wfxiang08/Nuitka,kayhayen/Nuitka,tempbottle/Nuitka,kayhayen/Nuitka,wfxiang08/Nuitka,tempbottle/Nuitka,tempbottle/Nuitka,kayhayen/Nuitka,kayhayen/Nuitka,wfxiang08/Nuitka,tempbottle/Nuitka,wfxiang08/Nuitka
--- +++ @@ -33,6 +33,8 @@ local_value * 2 # construct_end + return local_value + for x in xrange(50000): calledRepeatedly()
6f939e9c2bd4cf42cb4ad58112375f36abf489bf
terraform/templates/sch_log_parser.py
terraform/templates/sch_log_parser.py
import time from datetime import datetime def my_log_parser(logger, line): if line.count(',') >= 6: date, report_type, group_id, job_id, event, package, rest = line.split(',',6) if report_type == 'J' and event != 'Pending': date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S") date = time.mktime(date.timetuple()) url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id) if event == 'Failed': error = rest.split(',')[-1] message = package + ' ' + error + ' ' + url elif event == 'Complete': message = package + ' ' + url else: message = package logged_event = { 'msg_title': event, 'timestamp': date, 'msg_text': message, 'priority': 'normal', 'event_type': report_type, 'aggregation_key': group_id, 'alert_type': 'info' } return logged_event return None
import time from datetime import datetime def my_log_parser(logger, line): if line.count(',') >= 6: date, report_type, group_id, job_id, event, package, rest = line.split(',',6) if report_type == 'J' and event != 'Pending': date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S") date = time.mktime(date.timetuple()) url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id) if event == 'Failed': error = rest.split(',')[-1] message = package + ' ' + error + ' ' + url elif event == 'Complete': message = package + ' ' + url else: message = package + ' grp:' + group_id + ' job:' + job_id logged_event = { 'msg_title': event, 'timestamp': date, 'msg_text': message, 'priority': 'normal', 'event_type': report_type, 'aggregation_key': group_id, 'alert_type': 'info' } return logged_event return None
Add group/job info to job dashboard
Add group/job info to job dashboard Signed-off-by: Salim Alam <18ae4dd1e3db1d49a738226169e3b099325c79a0@chef.io>
Python
apache-2.0
habitat-sh/habitat,nathenharvey/habitat,nathenharvey/habitat,georgemarshall/habitat,georgemarshall/habitat,habitat-sh/habitat,rsertelon/habitat,habitat-sh/habitat,rsertelon/habitat,habitat-sh/habitat,rsertelon/habitat,rsertelon/habitat,nathenharvey/habitat,rsertelon/habitat,nathenharvey/habitat,habitat-sh/habitat,georgemarshall/habitat,georgemarshall/habitat,habitat-sh/habitat,habitat-sh/habitat,georgemarshall/habitat,rsertelon/habitat,rsertelon/habitat,nathenharvey/habitat,georgemarshall/habitat,georgemarshall/habitat,nathenharvey/habitat,georgemarshall/habitat,habitat-sh/habitat
--- +++ @@ -16,7 +16,7 @@ elif event == 'Complete': message = package + ' ' + url else: - message = package + message = package + ' grp:' + group_id + ' job:' + job_id logged_event = { 'msg_title': event,
51dc6f26ef8c063c51e1218a0cc09105ae16022c
twext/who/test/test_aggregate.py
twext/who/test/test_aggregate.py
## # Copyright (c) 2013 Apple Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## """ Aggregate directory service tests """ from twisted.python.components import proxyForInterface from twext.who.idirectory import IDirectoryService from twext.who.aggregate import DirectoryService from twext.who.test import test_directory from twext.who.test.test_xml import xmlService class BaseTest(object): def service(self, services=None): if services is None: services = (self.xmlService(),) # # Make sure aggregate DirectoryService isn't making # implementation assumptions about the IDirectoryService # objects it gets. # # services = tuple(( # proxyForInterface(IDirectoryService)(s) # for s in services # )) return DirectoryService("xyzzy", services) def xmlService(self, xmlData=None): return xmlService(self.mktemp(), xmlData) class DirectoryServiceTest(BaseTest, test_directory.DirectoryServiceTest): pass
## # Copyright (c) 2013 Apple Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## """ Aggregate directory service tests """ from twisted.python.components import proxyForInterface from twext.who.idirectory import IDirectoryService from twext.who.aggregate import DirectoryService from twext.who.test import test_directory from twext.who.test.test_xml import xmlService class BaseTest(object): def service(self, services=None): if services is None: services = (self.xmlService(),) # # Make sure aggregate DirectoryService isn't making # implementation assumptions about the IDirectoryService # objects it gets. # services = tuple(( proxyForInterface(IDirectoryService)(s) for s in services )) return DirectoryService("xyzzy", services) def xmlService(self, xmlData=None): return xmlService(self.mktemp(), xmlData) class DirectoryServiceTest(BaseTest, test_directory.DirectoryServiceTest): pass
Make sure the aggregate service only using the IDirectoryService interface when interactive with its sub-services.
Make sure the aggregate service only using the IDirectoryService interface when interactive with its sub-services. git-svn-id: 81e381228600e5752b80483efd2b45b26c451ea2@10781 e27351fd-9f3e-4f54-a53b-843176b1656c
Python
apache-2.0
trevor/calendarserver,trevor/calendarserver,trevor/calendarserver
--- +++ @@ -38,10 +38,10 @@ # implementation assumptions about the IDirectoryService # objects it gets. # -# services = tuple(( -# proxyForInterface(IDirectoryService)(s) -# for s in services -# )) + services = tuple(( + proxyForInterface(IDirectoryService)(s) + for s in services + )) return DirectoryService("xyzzy", services)
29ecb6f6bac85aeecba6b2602744f178735c0adc
pyautoupdate/_move_glob.py
pyautoupdate/_move_glob.py
import glob import shutil import os if os.name == "nt": from .ntcommonpath import commonpath else: from .posixcommonpath import commonpath def move_glob(src,dst): """Moves files from src to dest. src may be any glob to recognize files. dst must be a folder.""" for obj in glob.iglob(src): shutil.move(obj,dst) def copy_glob(src,dst): """Copies files from src to dest. src may be any glob to recognize files. dst must be a folder.""" for obj in glob.iglob(src): if os.path.isdir(obj): start_part=commonpath([src,obj]) end_part=os.path.relpath(obj,start_part) shutil.copytree(obj,os.path.join(dst,end_part)) else: shutil.copy2(obj,dst)
import glob import shutil import os if os.name == "nt": from .ntcommonpath import commonpath else: from .posixcommonpath import commonpath def move_glob(src,dst): """Moves files from src to dest. src may be any glob to recognize files. dst must be a folder.""" for obj in glob.iglob(src): shutil.move(obj,dst) def copy_glob(src,dst): """Copies files from src to dest. src may be any glob to recognize files. dst must be a folder.""" for obj in glob.iglob(src): if os.path.isdir(obj): start_part=commonpath([src,obj]) end_part=os.path.relpath(obj,start_part) ctree_dst=os.path.join(dst,end_part) if not os.path.isdir(ctree_dst): shutil.copytree(obj,ctree_dst) else: copy_glob(os.path.join(obj,"*"),ctree_dst) else: shutil.copy2(obj,dst)
Fix bug in copy_glob when destination directory already has files
Fix bug in copy_glob when destination directory already has files
Python
lgpl-2.1
rlee287/pyautoupdate,rlee287/pyautoupdate
--- +++ @@ -22,8 +22,10 @@ if os.path.isdir(obj): start_part=commonpath([src,obj]) end_part=os.path.relpath(obj,start_part) - shutil.copytree(obj,os.path.join(dst,end_part)) + ctree_dst=os.path.join(dst,end_part) + if not os.path.isdir(ctree_dst): + shutil.copytree(obj,ctree_dst) + else: + copy_glob(os.path.join(obj,"*"),ctree_dst) else: shutil.copy2(obj,dst) - -
7698ad7a907da5e7b4ad7cfd40255bb9c44b5b87
scripts/sort-cluster-issue.py
scripts/sort-cluster-issue.py
#!/usr/bin/python from pyspark import SparkContext from pyspark.sql import SQLContext, Row from pyspark.sql.functions import asc, desc if __name__ == "__main__": sc = SparkContext(appName='resort data') sqlContext = SQLContext(sc) df = sqlContext.read.load('hdfs://discovery3:9000/tmp/dasmith/c19-20160919-a50-o08/pretty.parquet') #df = sqlContext.read.load('hdfs://discovery3:9000/tmp/dasmith/c19-20160402-a50-o08/out.parquet') df.registerTempTable("newspaper") df2 = sqlContext.sql("select series, date, count(*) as cnt from newspaper group by series, date order by cnt desc") df3 = df.join(df2, ['series', 'date']) df3.sort(desc("cnt"), asc("begin"), asc("end"))\ .write.json('/gss_gpfs_scratch/xu.shao/network/resorted-pretty.json')
#!/usr/bin/python from __future__ import print_function import sys from pyspark import SparkContext from pyspark.sql import SQLContext from pyspark.sql.functions import desc if __name__ == "__main__": if len(sys.argv) < 3: print("Usage: sort-cluster-issue.py <input> <output>", file=sys.stderr) exit(-1) sc = SparkContext(appName='resort data') sqlContext = SQLContext(sc) df = sqlContext.read.load(sys.argv[1]) df.registerTempTable("newspaper") df2 = sqlContext.sql('select series, date, count(*) as cnt from newspaper group by series, date') df3 = df.join(df2, ['series', 'date']) df3.sort(desc("cnt"), "series", "date", "id", "begin", "end")\ .write.option('compression', 'gzip').json(sys.argv[2]) sc.stop()
Use command-line arguments for paths.
Use command-line arguments for paths.
Python
apache-2.0
ViralTexts/vt-passim,ViralTexts/vt-passim,ViralTexts/vt-passim
--- +++ @@ -1,17 +1,24 @@ #!/usr/bin/python +from __future__ import print_function +import sys from pyspark import SparkContext -from pyspark.sql import SQLContext, Row -from pyspark.sql.functions import asc, desc +from pyspark.sql import SQLContext +from pyspark.sql.functions import desc if __name__ == "__main__": + if len(sys.argv) < 3: + print("Usage: sort-cluster-issue.py <input> <output>", file=sys.stderr) + exit(-1) sc = SparkContext(appName='resort data') sqlContext = SQLContext(sc) - df = sqlContext.read.load('hdfs://discovery3:9000/tmp/dasmith/c19-20160919-a50-o08/pretty.parquet') - #df = sqlContext.read.load('hdfs://discovery3:9000/tmp/dasmith/c19-20160402-a50-o08/out.parquet') + df = sqlContext.read.load(sys.argv[1]) df.registerTempTable("newspaper") - df2 = sqlContext.sql("select series, date, count(*) as cnt from newspaper group by series, date order by cnt desc") + df2 = sqlContext.sql('select series, date, count(*) as cnt from newspaper group by series, date') df3 = df.join(df2, ['series', 'date']) - df3.sort(desc("cnt"), asc("begin"), asc("end"))\ - .write.json('/gss_gpfs_scratch/xu.shao/network/resorted-pretty.json') + df3.sort(desc("cnt"), "series", "date", "id", "begin", "end")\ + .write.option('compression', 'gzip').json(sys.argv[2]) + + sc.stop() +
742e5e7a998e8e397a438d4edf9fa3d6234009fc
popit/migrations/0001_initial.py
popit/migrations/0001_initial.py
# encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): def forwards(self, orm): pass def backwards(self, orm): pass models = { } complete_apps = ['{{ app_name }}']
# encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): def forwards(self, orm): pass def backwards(self, orm): pass models = { } complete_apps = ['popit']
Replace placeholders with actual app name
Replace placeholders with actual app name
Python
agpl-3.0
ciudadanointeligente/popit-django,mysociety/popit-django,ciudadanointeligente/popit-django,mysociety/popit-django,mysociety/popit-django,ciudadanointeligente/popit-django
--- +++ @@ -18,4 +18,4 @@ } - complete_apps = ['{{ app_name }}'] + complete_apps = ['popit']
c05e1d39af6089f31e72fa8dc1c27e22795e8e2f
sites/docs/conf.py
sites/docs/conf.py
# Obtain shared config values import os, sys from os.path import abspath, join, dirname sys.path.append(abspath(join(dirname(__file__), '..'))) sys.path.append(abspath(join(dirname(__file__), '..', '..'))) from shared_conf import * # Enable autodoc, intersphinx extensions.extend(['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']) # Autodoc settings autodoc_default_flags = ['members', 'special-members'] # Default is 'local' building, but reference the public WWW site when building # under RTD. target = join(dirname(__file__), '..', 'www', '_build') if os.environ.get('READTHEDOCS') == 'True': target = 'http://www.fabfile.org/' www = (target, None) # Ditto Invoke target = join(dirname(__file__), '..', '..', '..', 'invoke', 'docs', '_build') if os.environ.get('READTHEDOCS') == 'True': target = 'http://docs.pyinvoke.org/' invoke = (target, None) # Intersphinx connection to stdlib + www site intersphinx_mapping = { 'python': ('http://docs.python.org/2.6', None), 'www': www, 'invoke': invoke, } # Sister-site links to WWW html_theme_options['extra_nav_links'] = { "Main website": 'http://www.fabfile.org', }
# Obtain shared config values import os, sys from os.path import abspath, join, dirname sys.path.append(abspath(join(dirname(__file__), '..'))) sys.path.append(abspath(join(dirname(__file__), '..', '..'))) from shared_conf import * # Enable autodoc, intersphinx extensions.extend(['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']) # Autodoc settings autodoc_default_flags = ['members', 'special-members'] # Default is 'local' building, but reference the public WWW site when building # under RTD. target = join(dirname(__file__), '..', 'www', '_build') if os.environ.get('READTHEDOCS') == 'True': target = 'http://www.fabfile.org/' www = (target, None) # Ditto Invoke target = join( dirname(__file__), '..', '..', '..', 'invoke', 'sites', 'docs', '_build' ) if os.environ.get('READTHEDOCS') == 'True': target = 'http://docs.pyinvoke.org/' invoke = (target, None) # Intersphinx connection to stdlib + www site intersphinx_mapping = { 'python': ('http://docs.python.org/2.6', None), 'www': www, 'invoke': invoke, } # Sister-site links to WWW html_theme_options['extra_nav_links'] = { "Main website": 'http://www.fabfile.org', }
Fix Invoke doc intersphinx path (and tweak formatting)
Fix Invoke doc intersphinx path (and tweak formatting)
Python
bsd-2-clause
fabric/fabric
--- +++ @@ -18,7 +18,11 @@ target = 'http://www.fabfile.org/' www = (target, None) # Ditto Invoke -target = join(dirname(__file__), '..', '..', '..', 'invoke', 'docs', '_build') +target = join( + dirname(__file__), + '..', '..', '..', + 'invoke', 'sites', 'docs', '_build' +) if os.environ.get('READTHEDOCS') == 'True': target = 'http://docs.pyinvoke.org/' invoke = (target, None)
e12138061b0babca3f14b1479cd3269fec36e9ea
remo/featuredrep/models.py
remo/featuredrep/models.py
from django.contrib.auth.models import User from django.db import models from django.dispatch import receiver from south.signals import post_migrate from remo.base.utils import add_permissions_to_groups class FeaturedRep(models.Model): """Featured Rep model. Featured Rep -or Rep of the Month- relates existing users with some text explaining why they are so cool. """ created_on = models.DateTimeField(auto_now_add=True) updated_on = models.DateTimeField(auto_now=True) created_by = models.ForeignKey(User, related_name='reps_featured') text = models.TextField(blank=False, null=False) users = models.ManyToManyField(User, related_name='featuredrep_users') class Meta: ordering = ['-updated_on'] get_latest_by = 'created_on' permissions = (('can_edit_featured', 'Can edit featured reps'), ('can_delete_featured', 'Can delete featured reps')) @receiver(post_migrate, dispatch_uid='featuredrep_set_groups_signal') def featuredrep_set_groups(app, sender, signal, **kwargs): """Set permissions to groups.""" if (isinstance(app, basestring) and app != 'featuredrep'): return True perms = {'can_edit_featured': ['Admin', 'Council'], 'can_delete_featured': ['Admin', 'Council']} add_permissions_to_groups('featuredrep', perms)
from django.contrib.auth.models import User from django.db import models from django.dispatch import receiver from south.signals import post_migrate from remo.base.utils import add_permissions_to_groups class FeaturedRep(models.Model): """Featured Rep model. Featured Rep -or Rep of the Month- relates existing users with some text explaining why they are so cool. """ created_on = models.DateTimeField(auto_now_add=True) updated_on = models.DateTimeField(auto_now=True) created_by = models.ForeignKey(User, related_name='reps_featured') text = models.TextField(blank=False, null=False) users = models.ManyToManyField(User, related_name='featuredrep_users') class Meta: ordering = ['-updated_on'] get_latest_by = 'updated_on' permissions = (('can_edit_featured', 'Can edit featured reps'), ('can_delete_featured', 'Can delete featured reps')) @receiver(post_migrate, dispatch_uid='featuredrep_set_groups_signal') def featuredrep_set_groups(app, sender, signal, **kwargs): """Set permissions to groups.""" if (isinstance(app, basestring) and app != 'featuredrep'): return True perms = {'can_edit_featured': ['Admin', 'Council'], 'can_delete_featured': ['Admin', 'Council']} add_permissions_to_groups('featuredrep', perms)
Change ordering to FeaturedRep model.
Change ordering to FeaturedRep model.
Python
bsd-3-clause
flamingspaz/remo,akatsoulas/remo,Mte90/remo,flamingspaz/remo,johngian/remo,abdullah2891/remo,flamingspaz/remo,akatsoulas/remo,chirilo/remo,abdullah2891/remo,mozilla/remo,Mte90/remo,johngian/remo,johngian/remo,tsmrachel/remo,Mte90/remo,mozilla/remo,chirilo/remo,mozilla/remo,chirilo/remo,johngian/remo,chirilo/remo,akatsoulas/remo,akatsoulas/remo,tsmrachel/remo,abdullah2891/remo,flamingspaz/remo,tsmrachel/remo,tsmrachel/remo,abdullah2891/remo,Mte90/remo,mozilla/remo
--- +++ @@ -22,7 +22,7 @@ class Meta: ordering = ['-updated_on'] - get_latest_by = 'created_on' + get_latest_by = 'updated_on' permissions = (('can_edit_featured', 'Can edit featured reps'), ('can_delete_featured', 'Can delete featured reps'))
27e86c661021b1276123b264f00536fc89d203c4
common/templatetags/lutris.py
common/templatetags/lutris.py
import copy from django import template from django.conf import settings from games import models register = template.Library() def get_links(user_agent): systems = ['ubuntu', 'fedora', 'linux'] downloads = copy.copy(settings.DOWNLOADS) main_download = None for system in systems: if system in user_agent: main_download = {system: downloads[system]} downloads.pop(system) if not main_download: main_download = {'linux': downloads.pop('linux')} return (main_download, downloads) @register.inclusion_tag('includes/download_links.html', takes_context=True) def download_links(context): request = context['request'] user_agent = request.META.get('HTTP_USER_AGENT', '').lower() context['main_download'], context['downloads'] = get_links(user_agent) return context @register.inclusion_tag('includes/featured_slider.html', takes_context=True) def featured_slider(context): context['featured_contents'] = models.Featured.objects.all() return context @register.inclusion_tag('includes/latest_games.html', takes_context=True) def latest_games(context): games = models.Game.objects.published().order_by('-created')[:5] context['latest_games'] = games return context
import copy from django import template from django.conf import settings from games import models register = template.Library() def get_links(user_agent): systems = ['ubuntu', 'fedora', 'linux'] downloads = copy.copy(settings.DOWNLOADS) main_download = None for system in systems: if system in user_agent: main_download = {system: downloads[system]} downloads.pop(system) break if main_download is None: main_download = {'linux': downloads.pop('linux')} return (main_download, downloads) @register.inclusion_tag('includes/download_links.html', takes_context=True) def download_links(context): request = context['request'] user_agent = request.META.get('HTTP_USER_AGENT', '').lower() context['main_download'], context['downloads'] = get_links(user_agent) return context @register.inclusion_tag('includes/featured_slider.html', takes_context=True) def featured_slider(context): context['featured_contents'] = models.Featured.objects.all() return context @register.inclusion_tag('includes/latest_games.html', takes_context=True) def latest_games(context): games = models.Game.objects.published().order_by('-created')[:5] context['latest_games'] = games return context
Fix download link , again
Fix download link , again
Python
agpl-3.0
Turupawn/website,Turupawn/website,lutris/website,lutris/website,lutris/website,Turupawn/website,Turupawn/website,lutris/website
--- +++ @@ -16,7 +16,8 @@ if system in user_agent: main_download = {system: downloads[system]} downloads.pop(system) - if not main_download: + break + if main_download is None: main_download = {'linux': downloads.pop('linux')} return (main_download, downloads)
a367b1d4bdbb639b4eab862c7ce691eb4a861d26
wandb/compat/windows.py
wandb/compat/windows.py
""" Windows-related compatibility helpers. """ import re _find_unsafe = re.compile(r'[\s<>|&^]').search def quote_arg(s): """Based on shlex.quote in the standard library.""" if not s: return '""' if _find_unsafe(s) is None: return s # If we found an unsafe character, escape with double quotes. return '"' + s + '"'
""" Windows-related compatibility helpers. """ import re _find_unsafe = re.compile(r'[\s<>|&^]').search def quote_arg(s): """Based on shlex.quote in the standard library.""" if not s: return '""' if _find_unsafe(s) is None: return s if s.startswith('"') and s.endswith('"'): return s # If we found an unsafe character, escape with double quotes. return '"' + s + '"'
Add check for args which are already quotes
Add check for args which are already quotes
Python
mit
wandb/client,wandb/client,wandb/client
--- +++ @@ -12,6 +12,8 @@ return '""' if _find_unsafe(s) is None: return s + if s.startswith('"') and s.endswith('"'): + return s # If we found an unsafe character, escape with double quotes. return '"' + s + '"'
508ca596d46c08fdc9295769059f5de974b2d1df
base/components/accounts/admin.py
base/components/accounts/admin.py
from django.contrib import admin from django.contrib.auth.models import Group from .models import Editor class ContributorMixin(admin.ModelAdmin): def save_model(self, request, obj, form, change): super(ContributorMixin, self).save_model(request, obj, form, change) if not change: obj.submitted_by = request.user obj.edited_by.add(request.user) obj.save() class EditorAdmin(admin.ModelAdmin): fieldsets = ( (None, {'fields': (('username', 'password'),)}), ('Personal Information', {'fields': (('name', 'email'),)}), ('Important Dates', { 'classes': ('grp-collapse grp-open',), 'fields': ('started', 'last_login', 'active_since') }), ('Permissions', { 'classes': ('grp-collapse grp-open',), 'fields': (('is_active', 'is_staff', 'is_superuser'),) }), ('OAuth', { 'classes': ('grp-collapse grp-closed',), 'fields': ('base_id', ('access_token', 'refresh_token', 'token_expiration')) }) ) list_display = ['username', 'name', 'email', 'is_active', 'is_staff', 'is_superuser', 'base_id', 'access_token'] list_filter = ['is_active', 'is_staff', 'is_superuser'] admin.site.register(Editor, EditorAdmin) admin.site.unregister(Group)
from django.contrib import admin from django.contrib.auth.models import Group from .models import Editor class ContributorMixin(admin.ModelAdmin): def save_model(self, request, obj, form, change): if not change: obj.submitted_by = request.user obj.edited_by.add(request.user) obj.save() super(ContributorMixin, self).save_model(request, obj, form, change) class EditorAdmin(admin.ModelAdmin): fieldsets = ( (None, {'fields': (('username', 'password'),)}), ('Personal Information', {'fields': (('name', 'email'),)}), ('Important Dates', { 'classes': ('grp-collapse grp-open',), 'fields': ('started', 'last_login', 'active_since') }), ('Permissions', { 'classes': ('grp-collapse grp-open',), 'fields': (('is_active', 'is_staff', 'is_superuser'),) }), ('OAuth', { 'classes': ('grp-collapse grp-closed',), 'fields': ('base_id', ('access_token', 'refresh_token', 'token_expiration')) }) ) list_display = ['username', 'name', 'email', 'is_active', 'is_staff', 'is_superuser', 'base_id', 'access_token'] list_filter = ['is_active', 'is_staff', 'is_superuser'] admin.site.register(Editor, EditorAdmin) admin.site.unregister(Group)
Move this to the bottom...
Move this to the bottom...
Python
apache-2.0
hello-base/web,hello-base/web,hello-base/web,hello-base/web
--- +++ @@ -6,11 +6,11 @@ class ContributorMixin(admin.ModelAdmin): def save_model(self, request, obj, form, change): - super(ContributorMixin, self).save_model(request, obj, form, change) if not change: obj.submitted_by = request.user obj.edited_by.add(request.user) obj.save() + super(ContributorMixin, self).save_model(request, obj, form, change) class EditorAdmin(admin.ModelAdmin):
9502755baf7efba7851c07edbf2579f7cff95e44
py/rackattack/tcp/debug.py
py/rackattack/tcp/debug.py
import contextlib import logging import time import os logger = logging.getLogger('network') @contextlib.contextmanager def logNetwork(message): transaction = Transaction(message) yield transaction.finished() class Transaction: def __init__(self, message): self._message = message self._before = time.time() unique = _generateUnique() self._uniqueStrRepr = "'%(message)s' unique '%(unique)s'" % dict(message=self._message, unique=unique) logger.debug("Starting %(transaction)s", dict(transaction=self._uniqueStrRepr)) def reportState(self, state): logger.debug("%(state)s %(transaction)s", dict(transaction=self._uniqueStrRepr, state=state)) def finished(self): took = time.time() - self._before msg = "Finished %(transaction)s took %(took)s" % dict(transaction=self._uniqueStrRepr, took=took) logger.debug(msg) if took > 0.1: logger.error(msg) logging.error(msg) def _generateUnique(): return os.urandom(10).encode('hex')
import contextlib import logging import time import os logger = logging.getLogger('network') @contextlib.contextmanager def logNetwork(message): transaction = Transaction(message) yield transaction.finished() class Transaction: TRANSACTION_PERIOD_MAX = 0.3 def __init__(self, message): self._message = message self._before = time.time() unique = _generateUnique() self._uniqueStrRepr = "'%(message)s' unique '%(unique)s'" % dict(message=self._message, unique=unique) logger.debug("Starting %(transaction)s", dict(transaction=self._uniqueStrRepr)) def reportState(self, state): logger.debug("%(state)s %(transaction)s", dict(transaction=self._uniqueStrRepr, state=state)) def finished(self): took = time.time() - self._before msg = "Finished %(transaction)s took %(took)s" % dict(transaction=self._uniqueStrRepr, took=took) logger.debug(msg) if took > self.TRANSACTION_PERIOD_MAX: logger.error(msg) logging.error(msg) def _generateUnique(): return os.urandom(10).encode('hex')
Increase max transaction period due to more networking tasks
Increase max transaction period due to more networking tasks
Python
apache-2.0
eliran-stratoscale/rackattack-api,Stratoscale/rackattack-api
--- +++ @@ -15,6 +15,7 @@ class Transaction: + TRANSACTION_PERIOD_MAX = 0.3 def __init__(self, message): self._message = message self._before = time.time() @@ -30,7 +31,7 @@ took = time.time() - self._before msg = "Finished %(transaction)s took %(took)s" % dict(transaction=self._uniqueStrRepr, took=took) logger.debug(msg) - if took > 0.1: + if took > self.TRANSACTION_PERIOD_MAX: logger.error(msg) logging.error(msg)
1a04c983eb921f47452ea6c013313f90875c400f
pkgconf/__init__.py
pkgconf/__init__.py
import sys from functools import partial, update_wrapper from django.utils import six def proxy(attr, default): def wrapper(self): # It has to be most recent, # to override settings in tests from django.conf import settings value = getattr(settings, attr, default) if callable(value): func = partial(value, self) return update_wrapper(func, value) elif isinstance(value, property): return value.__get__(self) return value return property(wrapper) class ConfMeta(type): def __new__(mcs, name, bases, attrs): prefix = attrs.get('__prefix__', name.upper()) + '_' fields = { key: proxy(prefix + key, value) for key, value in attrs.items() if not key.startswith('__') } attrs.update(fields, __all__=fields.keys()) # Ready to build cls = super(ConfMeta, mcs).__new__(mcs, name, bases, attrs) # Sets non-abstract conf as module abstract = attrs.get('__abstract__', False) if not abstract: # http://mail.python.org/pipermail/python-ideas/2012-May/ # 014969.html ins = cls() ins.__name__ = ins.__module__ sys.modules[ins.__module__] = ins return cls class Conf(six.with_metaclass(ConfMeta)): __abstract__ = True
import sys from functools import partial, update_wrapper from django.utils import six def proxy(attr, default): def wrapper(self): # It has to be most recent, # to override settings in tests from django.conf import settings value = getattr(settings, attr, default) if callable(value): func = partial(value, self) return update_wrapper(func, value) elif isinstance(value, property): return value.__get__(self) return value return property(wrapper) class ConfMeta(type): def __new__(mcs, name, bases, attrs): prefix = attrs.get('__prefix__', name.upper()) + '_' fields = { key: proxy(prefix + key, value) for key, value in attrs.items() if not key.startswith('__') } attrs.update(fields, __all__=tuple(fields)) # Ready to build cls = super(ConfMeta, mcs).__new__(mcs, name, bases, attrs) # Sets non-abstract conf as module abstract = attrs.get('__abstract__', False) if not abstract: # http://mail.python.org/pipermail/python-ideas/2012-May/ # 014969.html ins = cls() ins.__name__ = ins.__module__ sys.modules[ins.__module__] = ins return cls class Conf(six.with_metaclass(ConfMeta)): __abstract__ = True
Fix "import star" feature support
Fix "import star" feature support `dict.keys()` returns `dict_keys` object in py3, which does not support indexing.
Python
bsd-3-clause
byashimov/django-pkgconf
--- +++ @@ -26,7 +26,7 @@ for key, value in attrs.items() if not key.startswith('__') } - attrs.update(fields, __all__=fields.keys()) + attrs.update(fields, __all__=tuple(fields)) # Ready to build cls = super(ConfMeta, mcs).__new__(mcs, name, bases, attrs)
4fe1350e5bb5d093e4d41fb1deace70fd8dfec50
main.py
main.py
#!/usr/bin/python from flask import Flask from flask.ext.pymongo import PyMongo app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" @app.route("/recent") def get_recent_questions(): pass @app.route('/register', methods=["POST"]) def register(): pass def login(): pass def logout(): pass @app.route('/questions/<question_id>') def get_question(question_id): pass def add_answser(question_id): pass @app.route('/add_question', methods=['POST']) def add_question(): pass if __name__ == "__main__": app.run()
#!/usr/bin/python from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" @app.route("/recent") def get_recent_questions(): pass @app.route('/register', methods=["POST"]) def register(): pass @app.route("/login", methods=["POST"]) def login(): pass @app.route("/logout") def logout(): pass @app.route('/questions/<question_id>') def get_question(question_id): pass @app.route('/new_answer', methods=["POST"]) def add_answser(question_id): pass @app.route('/add_question', methods=['POST']) def add_question(): pass if __name__ == "__main__": app.run(debug=True)
Add missing routes to API.
Add missing routes to API.
Python
agpl-3.0
tatsuhirosatou/p2p-app-backend,tatsuhirosatou/p2p-app-backend
--- +++ @@ -1,7 +1,6 @@ #!/usr/bin/python from flask import Flask -from flask.ext.pymongo import PyMongo app = Flask(__name__) @@ -17,9 +16,11 @@ def register(): pass +@app.route("/login", methods=["POST"]) def login(): pass +@app.route("/logout") def logout(): pass @@ -27,6 +28,7 @@ def get_question(question_id): pass +@app.route('/new_answer', methods=["POST"]) def add_answser(question_id): pass @@ -35,4 +37,4 @@ pass if __name__ == "__main__": - app.run() + app.run(debug=True)
d61bc5d2d5dad607332bfe131e537d139011ab57
main.py
main.py
#!/usr/bin/env python # -*- coding: utf-8 -*- from bot import Bot if __name__ == "__main__": bot = Bot() bot.start()
#!/usr/bin/env python # -*- coding: utf-8 -*- from bot import Bot import os import signal def signal_handler(signal, frame): print "Caught SIGINT, terminating." os._exit(0) if __name__ == "__main__": bot = Bot() bot.start() signal.signal(signal.SIGINT, signal_handler) while Ture: signal.pause()
Allow program termination using SIGINT
Allow program termination using SIGINT It's a rather crude method, but it works.
Python
mit
gehaxelt/python-rss2irc
--- +++ @@ -1,7 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from bot import Bot +import os +import signal + +def signal_handler(signal, frame): + print "Caught SIGINT, terminating." + os._exit(0) if __name__ == "__main__": bot = Bot() bot.start() + signal.signal(signal.SIGINT, signal_handler) + while Ture: + signal.pause()
c49024439978fddee1cd688524741e8ee482132b
pi_gpio/sockets.py
pi_gpio/sockets.py
from flask.ext.socketio import emit from pi_gpio import socketio from config.pins import PinManager PIN_MANAGER = PinManager() @socketio.on('pin:list') def pin_list(): response = PIN_MANAGER.read_all() emit('pin:list', response) @socketio.on('pin:read') def pin_read(data): response = PIN_MANAGER.read_one(data.num) emit('pin:read', response) @socketio.on('pin:write') def pin_write(data): result = PIN_MANAGER.update_value(data.num, data.value) if not result: emit('pin:write', {'message': 'Pin not found'}) else: response = PIN_MANAGER.read_one(data.num) emit('pin:write', response)
from flask.ext.socketio import emit from pi_gpio import socketio from config.pins import PinManager PIN_MANAGER = PinManager() @socketio.on('pin:list') def pin_list(): response = PIN_MANAGER.read_all() emit('pin:list', response) @socketio.on('pin:read') def pin_read(data): response = PIN_MANAGER.read_one(data['num']) emit('pin:read', response) @socketio.on('pin:write') def pin_write(data): result = PIN_MANAGER.update_value(data['num'], data['value']) if not result: emit('pin:write', {'message': 'Pin not found'}) else: response = PIN_MANAGER.read_one(data['num']) emit('pin:write', response)
Fix the usage of dict object
Fix the usage of dict object Fix this error: ```sh pi@raspberrypi:~/Pi-GPIO-Server $ !sudo sudo python pi_gpio_server.py Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 327, in run result = self._run(*self.args, **self.kwargs) File "/usr/local/lib/python2.7/dist-packages/socketio/virtsocket.py", line 403, in _receiver_loop retval = pkt_ns.process_packet(pkt) File "/usr/local/lib/python2.7/dist-packages/socketio/namespace.py", line 155, in process_packet return self.process_event(packet) File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 58, in process_event return self.socketio._dispatch_message(app, self, message, args) File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 127, in _dispatch_message ret = self.messages[namespace.ns_name][message](*args) File "/home/pi/Pi-GPIO-Server/pi_gpio/sockets.py", line 17, in pin_read response = PIN_MANAGER.read_one(data.num) AttributeError: 'dict' object has no attribute 'num' <Greenlet at 0x76232030: <bound method Socket._receiver_loop of <socketio.virtsocket.Socket object at 0x762369d0>>> failed with AttributeError ```
Python
mit
projectweekend/Pi-GPIO-Server,projectweekend/Pi-GPIO-Server,projectweekend/Pi-GPIO-Server,projectweekend/Pi-GPIO-Server
--- +++ @@ -14,15 +14,15 @@ @socketio.on('pin:read') def pin_read(data): - response = PIN_MANAGER.read_one(data.num) + response = PIN_MANAGER.read_one(data['num']) emit('pin:read', response) @socketio.on('pin:write') def pin_write(data): - result = PIN_MANAGER.update_value(data.num, data.value) + result = PIN_MANAGER.update_value(data['num'], data['value']) if not result: emit('pin:write', {'message': 'Pin not found'}) else: - response = PIN_MANAGER.read_one(data.num) + response = PIN_MANAGER.read_one(data['num']) emit('pin:write', response)
324c61e220fcb66973007cab4b95ca249aef3274
bvggrabber/api/actualdeparture.py
bvggrabber/api/actualdeparture.py
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup from bvggrabber.api import QueryApi, Departure ACTUAL_QUERY_API_ENDPOINT = 'http://mobil.bvg.de/IstAbfahrtzeiten/index/mobil' class ActualDepartureQueryApi(QueryApi): def __init__(self, station): super(ActualDepartureQueryApi, self).__init__() if isinstance(station, str): self.station_enc = station.encode('iso-8859-1') elif isinstance(station, bytes): self.station_enc = station else: raise ValueError("Invalid type for station") self.station = station def call(self): params = {'input': self.station_enc} response = requests.get(ACTUAL_QUERY_API_ENDPOINT, params=params) if response.status_code == requests.codes.ok: soup = BeautifulSoup(response.text) if soup.find_all('form'): # The station we are looking for is ambiguous or does not exist stations = soup.find_all('option') if stations: # The station is ambiguous stationlist = [s.get('value') for s in stations] return (False, stationlist) else: # The station does not exist return (False, []) else: # The station seems to exist rows = soup.find('tbody').find_all('tr') departures = [] for row in rows: tds = row.find_all('td') dep = Departure(start=self.station, end=tds[2].text.strip(), line=tds[1].text.strip()) departures.append(dep) return (True, departures) else: response.raise_for_status()
Add first attempt of ActualDepartureQueryApi
Add first attempt of ActualDepartureQueryApi
Python
bsd-3-clause
MarkusH/bvg-grabber
--- +++ @@ -1 +1,53 @@ # -*- coding: utf-8 -*- + + +import requests + +from bs4 import BeautifulSoup + +from bvggrabber.api import QueryApi, Departure + + +ACTUAL_QUERY_API_ENDPOINT = 'http://mobil.bvg.de/IstAbfahrtzeiten/index/mobil' + + +class ActualDepartureQueryApi(QueryApi): + + def __init__(self, station): + super(ActualDepartureQueryApi, self).__init__() + if isinstance(station, str): + self.station_enc = station.encode('iso-8859-1') + elif isinstance(station, bytes): + self.station_enc = station + else: + raise ValueError("Invalid type for station") + self.station = station + + def call(self): + params = {'input': self.station_enc} + response = requests.get(ACTUAL_QUERY_API_ENDPOINT, params=params) + if response.status_code == requests.codes.ok: + soup = BeautifulSoup(response.text) + if soup.find_all('form'): + # The station we are looking for is ambiguous or does not exist + stations = soup.find_all('option') + if stations: + # The station is ambiguous + stationlist = [s.get('value') for s in stations] + return (False, stationlist) + else: + # The station does not exist + return (False, []) + else: + # The station seems to exist + rows = soup.find('tbody').find_all('tr') + departures = [] + for row in rows: + tds = row.find_all('td') + dep = Departure(start=self.station, + end=tds[2].text.strip(), + line=tds[1].text.strip()) + departures.append(dep) + return (True, departures) + else: + response.raise_for_status()
98bb4305ccdd8a83763bedb1f09c261e9904487c
cla_backend/apps/legalaid/tests/test_views.py
cla_backend/apps/legalaid/tests/test_views.py
import unittest from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test import TestCase, Client from django.contrib.auth.models import Permission from legalaid.tests.views.test_base import CLAProviderAuthBaseApiTestMixin from legalaid.views import FullCaseViewSet from cla_backend.apps.call_centre.permissions import * from cla_backend.urls import * from rest_framework import routers class FullCaseViewSetTestCase(CLAProviderAuthBaseApiTestMixin, TestCase): def setUp(self): super(FullCaseViewSetTestCase, self).setUp() def test_filter_queryset_success_200(self): response = self.client.get('/call_centre/api/v1/case/?search=Mark%20O%E2%80%99Brien', HTTP_AUTHORIZATION='Bearer %s' % 'operator_manager_token') self.assertEqual(response.status_code, 200)
from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test import TestCase, Client from django.contrib.auth.models import Permission from django.core.urlresolvers import reverse from legalaid.views import FullCaseViewSet from cla_backend.apps.call_centre.permissions import * from cla_backend.urls import * from rest_framework import routers from legalaid.tests.views.test_base import CLAOperatorAuthBaseApiTestMixin class FullCaseViewSetTestCase(CLAOperatorAuthBaseApiTestMixin,TestCase): def setUp(self): super(FullCaseViewSetTestCase, self).setUp() self.url = reverse('call_centre:case-list') def test_filter_queryset_for_unicode_characters_status_code_200(self): response = self.client.get(self.url+'?search=Mark%20O%E2%80%99Brien', HTTP_AUTHORIZATION='Bearer %s' % self.operator_manager_token) self.assertEqual(response.status_code, 200) def test_filter_queryset_for_only_ASCII_characters_status_code_200(self): response = self.client.get(self.url+'?search=John Smith', HTTP_AUTHORIZATION='Bearer %s' % self.operator_manager_token) self.assertEqual(response.status_code, 200)
Refactor the test for the method test_filter inside class FullCaseViewSet and create a new test that allows you to test for just ASCII characters
Refactor the test for the method test_filter inside class FullCaseViewSet and create a new test that allows you to test for just ASCII characters
Python
mit
ministryofjustice/cla_backend,ministryofjustice/cla_backend,ministryofjustice/cla_backend,ministryofjustice/cla_backend
--- +++ @@ -1,22 +1,26 @@ -import unittest - from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test import TestCase, Client from django.contrib.auth.models import Permission +from django.core.urlresolvers import reverse -from legalaid.tests.views.test_base import CLAProviderAuthBaseApiTestMixin from legalaid.views import FullCaseViewSet from cla_backend.apps.call_centre.permissions import * from cla_backend.urls import * - from rest_framework import routers +from legalaid.tests.views.test_base import CLAOperatorAuthBaseApiTestMixin -class FullCaseViewSetTestCase(CLAProviderAuthBaseApiTestMixin, TestCase): +class FullCaseViewSetTestCase(CLAOperatorAuthBaseApiTestMixin,TestCase): def setUp(self): super(FullCaseViewSetTestCase, self).setUp() + self.url = reverse('call_centre:case-list') - def test_filter_queryset_success_200(self): - response = self.client.get('/call_centre/api/v1/case/?search=Mark%20O%E2%80%99Brien', HTTP_AUTHORIZATION='Bearer %s' % 'operator_manager_token') + def test_filter_queryset_for_unicode_characters_status_code_200(self): + response = self.client.get(self.url+'?search=Mark%20O%E2%80%99Brien', HTTP_AUTHORIZATION='Bearer %s' % self.operator_manager_token) self.assertEqual(response.status_code, 200) + + def test_filter_queryset_for_only_ASCII_characters_status_code_200(self): + response = self.client.get(self.url+'?search=John Smith', HTTP_AUTHORIZATION='Bearer %s' % self.operator_manager_token) + self.assertEqual(response.status_code, 200) +
e9a5bbd1eba1cdad15626a712bfc7994008c7381
byceps/blueprints/snippet/init.py
byceps/blueprints/snippet/init.py
""" byceps.blueprints.snippet.init ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Copyright: 2006-2019 Jochen Kupperschmidt :License: Modified BSD, see LICENSE for details. """ from flask import current_app from ...services.snippet import mountpoint_service from .views import blueprint as snippet_blueprint, view_current_version_by_name def add_routes_for_snippets(site_id): """Register routes for snippets with the application.""" mountpoints = mountpoint_service.get_mountpoints_for_site(site_id) for mountpoint in mountpoints: add_route_for_snippet(mountpoint) def add_route_for_snippet(mountpoint): """Register a route for the snippet.""" endpoint = '{}.{}'.format(snippet_blueprint.name, mountpoint.endpoint_suffix) defaults = {'name': mountpoint.snippet.name} current_app.add_url_rule( mountpoint.url_path, endpoint, view_func=view_current_version_by_name, defaults=defaults)
""" byceps.blueprints.snippet.init ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Copyright: 2006-2019 Jochen Kupperschmidt :License: Modified BSD, see LICENSE for details. """ from flask import current_app from ...services.snippet import mountpoint_service from .views import blueprint as snippet_blueprint, view_current_version_by_name def add_routes_for_snippets(site_id): """Register routes for snippets with the application.""" mountpoints = mountpoint_service.get_mountpoints_for_site(site_id) for mountpoint in mountpoints: add_route_for_snippet(mountpoint) def add_route_for_snippet(mountpoint): """Register a route for the snippet.""" endpoint = '{}.{}'.format(snippet_blueprint.name, mountpoint.endpoint_suffix) defaults = {'name': mountpoint.endpoint_suffix} current_app.add_url_rule( mountpoint.url_path, endpoint, view_func=view_current_version_by_name, defaults=defaults)
Fix snippet URL rules to use mountpoints' endpoint suffix
Fix snippet URL rules to use mountpoints' endpoint suffix
Python
bsd-3-clause
m-ober/byceps,homeworkprod/byceps,m-ober/byceps,m-ober/byceps,homeworkprod/byceps,homeworkprod/byceps
--- +++ @@ -25,7 +25,7 @@ """Register a route for the snippet.""" endpoint = '{}.{}'.format(snippet_blueprint.name, mountpoint.endpoint_suffix) - defaults = {'name': mountpoint.snippet.name} + defaults = {'name': mountpoint.endpoint_suffix} current_app.add_url_rule( mountpoint.url_path,
5611d502c30ee0274fcd523deffcb68c77f31fd8
basic.py
basic.py
from brutal.core.plugin import BotPlugin, cmd, event, match, threaded @cmd def ping(event): """Responds 'pong' to your 'ping'.""" return 'pong' @cmd def echo(event): """Echoes back the message it recieves.""" return ' '.join(event.args) @cmd def sudo(event): return 'okay.' @cmd def make(event): return 'what? make it yourself.' welcomes = { "LordPotato_": "Everybody on your knees and let's praise the mighty Potato!", "pepol": "Nazimod sighted, take cover!", "mrshu": "Hide yo codes, hide yo wife, nazireviewer is on site!", "jn_": "Swiggidy swooty, he's comin' for dat booty!", "kalerab" : "Hide your apples, 'cause he's gonna eat 'em!" } @event def auto_welcome(event): if event.event_type == 'join': if event.meta['nick'] in welcomes: return welcomes[event.meta['nick']] else: return event.meta['nick'] + ': hi!'
from brutal.core.plugin import BotPlugin, cmd, event, match, threaded @cmd def ping(event): """Responds 'pong' to your 'ping'.""" return 'pong' @cmd def echo(event): """Echoes back the message it recieves.""" return ' '.join(event.args) @cmd def sudo(event): """Responds 'okay.' to your 'sudo ...' (http://xkcd.com/149/).""" return 'okay.' @cmd def make(event): """Tells user to go make it himself (http://xkcd.com/149/').""" return 'what? make it yourself.' welcomes = { "LordPotato_": "Everybody on your knees and let's praise the mighty Potato!", "pepol": "Nazimod sighted, take cover!", "mrshu": "Hide yo codes, hide yo wife, nazireviewer is on site!", "jn_": "Swiggidy swooty, he's comin' for dat booty!", "kalerab" : "Hide your apples, 'cause he's gonna eat 'em!" } @event def auto_welcome(event): if event.event_type == 'join': if event.meta['nick'] in welcomes: return welcomes[event.meta['nick']] else: return event.meta['nick'] + ': hi!'
Add docstrings to 'sudo' and 'make'.
Add docstrings to 'sudo' and 'make'.
Python
apache-2.0
Adman/brutal-plugins,mrshu/brutal-plugins
--- +++ @@ -16,10 +16,12 @@ @cmd def sudo(event): + """Responds 'okay.' to your 'sudo ...' (http://xkcd.com/149/).""" return 'okay.' @cmd def make(event): + """Tells user to go make it himself (http://xkcd.com/149/').""" return 'what? make it yourself.'
d37cac61f1457609806fba507cf9568188d1664d
button.py
button.py
import RPi.GPIO as GPIO import time import os #sets the Input Pin for your Button #in this case it is GPIO24 or HardwarePin 19 buttonPin = 19 #sets GPIO Mode to use Hardware Pin Layout GPIO.setmode(GPIO.BCM) #sets GPIO Pin to INPUT mode with a Pull Down Resistor GPIO.setup(buttonPin,GPIO.IN, pull_up_down=GPIO.PUD_DOWN) while True: #waits for Pin Input and then exectures the script below if (GPIO.input(buttonPin)): #the script that will be executed (as root) os.system("node /home/pi/guest-password-printer/index.js")
import RPi.GPIO as GPIO import time import os import sys from optparse import OptionParser # Parse input arguments parser = OptionParser() parser.add_option("-t", "--testGPIO", action="store_true", help="Test GPIO connection, does not call the JS script.") # The option --pin sets the Input Pin for your Button # It default to GPIO24 or HardwarePin 19 parser.add_option("-p", "--pin", dest="pin", help="GPIO pin to use. If not provided it defaults to HardwarePin 19.", default=19) (options, args) = parser.parse_args() testingGPIO = False if options.testGPIO: testingGPIO = True buttonPin = options.pin #sets GPIO Mode to use Hardware Pin Layout GPIO.setmode(GPIO.BCM) #sets GPIO Pin to INPUT mode with a Pull Down Resistor GPIO.setup(buttonPin,GPIO.IN, pull_up_down=GPIO.PUD_DOWN) if(testingGPIO): print "Press the connected button. If you are pressing but you do not see any further output then....there is something wrong with the connection." while True: #waits for Pin Input and then exectures the script below if (GPIO.input(buttonPin)): if (testingGPIO): print "PIN " + buttonPing + " works correctly." continue #the script that will be executed (as root) os.system("node /home/pi/guest-password-printer/index.js")
Allow parsing of option arguments and basic GPIO testing.
Allow parsing of option arguments and basic GPIO testing.
Python
mit
henne-/guest-password-printer,henne-/guest-password-printer
--- +++ @@ -1,17 +1,39 @@ import RPi.GPIO as GPIO import time import os +import sys -#sets the Input Pin for your Button -#in this case it is GPIO24 or HardwarePin 19 -buttonPin = 19 +from optparse import OptionParser + +# Parse input arguments +parser = OptionParser() +parser.add_option("-t", "--testGPIO", action="store_true", help="Test GPIO connection, does not call the JS script.") + +# The option --pin sets the Input Pin for your Button +# It default to GPIO24 or HardwarePin 19 +parser.add_option("-p", "--pin", dest="pin", help="GPIO pin to use. If not provided it defaults to HardwarePin 19.", default=19) + +(options, args) = parser.parse_args() + +testingGPIO = False +if options.testGPIO: + testingGPIO = True + +buttonPin = options.pin + #sets GPIO Mode to use Hardware Pin Layout GPIO.setmode(GPIO.BCM) #sets GPIO Pin to INPUT mode with a Pull Down Resistor GPIO.setup(buttonPin,GPIO.IN, pull_up_down=GPIO.PUD_DOWN) +if(testingGPIO): + print "Press the connected button. If you are pressing but you do not see any further output then....there is something wrong with the connection." + while True: #waits for Pin Input and then exectures the script below if (GPIO.input(buttonPin)): -#the script that will be executed (as root) - os.system("node /home/pi/guest-password-printer/index.js") + if (testingGPIO): + print "PIN " + buttonPing + " works correctly." + continue + #the script that will be executed (as root) + os.system("node /home/pi/guest-password-printer/index.js")
eb39ec42078994eac9a5d085f35bcb35dea77a64
salt/states/apt.py
salt/states/apt.py
# Import python libs import logging # Import salt libs import salt.utils log = logging.getLogger(__name__) def held(name): ''' Set package in 'hold' state, meaning it will not be upgraded. name The name of the package, e.g., 'tmux' ''' ret = {'name': name} state = __salt__['pkg.get_selections']( pattern=name, ) if not state: ret.update({'changes': {}, 'result': False, 'comment': 'Package {0} does not have a state'.format( name )}) return ret if not salt.utils.is_true(state.get('hold', False)): if not __opts__['test']: result = __salt__['pkg.set_selections']( selection={'hold': [name]} ) ret.update({'changes': result[name], 'result': True, 'comment': 'Package {0} is now being held'.format( name )}) else: ret.update({'changes': {}, 'result': None, 'comment': 'Package {0} is set to be held'.format( name )}) else: ret.update({'changes': {}, 'result': True, 'comment': 'Package {0} is already held'.format(name)}) return ret
# Import python libs import logging # Import salt libs import salt.utils log = logging.getLogger(__name__) def held(name): ''' Set package in 'hold' state, meaning it will not be upgraded. name The name of the package, e.g., 'tmux' ''' ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} state = __salt__['pkg.get_selections']( pattern=name, ) if not state: ret.update(comment='Package {0} does not have a state'.format(name)) return ret if not salt.utils.is_true(state.get('hold', False)): if not __opts__['test']: result = __salt__['pkg.set_selections']( selection={'hold': [name]} ) ret.update(changes=result[name], result=True, comment='Package {0} is now being held'.format(name)) else: ret.update(result=None, comment='Package {0} is set to be held'.format(name)) else: ret.update(result= True, comment='Package {0} is already held'.format(name)) return ret
Make dict updates more dense
Make dict updates more dense
Python
apache-2.0
saltstack/salt,saltstack/salt,saltstack/salt,saltstack/salt,saltstack/salt
--- +++ @@ -14,36 +14,26 @@ name The name of the package, e.g., 'tmux' ''' - ret = {'name': name} + ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} state = __salt__['pkg.get_selections']( pattern=name, ) if not state: - ret.update({'changes': {}, - 'result': False, - 'comment': 'Package {0} does not have a state'.format( - name - )}) + ret.update(comment='Package {0} does not have a state'.format(name)) return ret if not salt.utils.is_true(state.get('hold', False)): if not __opts__['test']: result = __salt__['pkg.set_selections']( selection={'hold': [name]} ) - ret.update({'changes': result[name], - 'result': True, - 'comment': 'Package {0} is now being held'.format( - name - )}) + ret.update(changes=result[name], + result=True, + comment='Package {0} is now being held'.format(name)) else: - ret.update({'changes': {}, - 'result': None, - 'comment': 'Package {0} is set to be held'.format( - name - )}) + ret.update(result=None, + comment='Package {0} is set to be held'.format(name)) else: - ret.update({'changes': {}, - 'result': True, - 'comment': 'Package {0} is already held'.format(name)}) + ret.update(result= True, + comment='Package {0} is already held'.format(name)) return ret
d0818c7dcabebe7697444b73b6b8f30ade73958d
openedx/core/djangoapps/appsembler/eventtracking/utils.py
openedx/core/djangoapps/appsembler/eventtracking/utils.py
""" Utility functions for event tracking processing. """ from django.core.exceptions import MultipleObjectsReturned from . import exceptions def get_site_config_for_event(event_props): """ Try multiple strategies to find a SiteConfiguration object to use for evaluating and processing an event. Return a SiteConfiguration object if found; otherwise, None. """ from openedx.core.djangoapps.appsembler.sites import utils from openedx.core.djangoapps.site_configuration import helpers from organizations import models # try first via request obj in thread site_configuration = helpers.get_current_site_configuration() if not site_configuration: try: if 'org' in event_props: org_name = event_props['org'] org = models.Organization.objects.get(short_name=org_name) # try by OrganizationCourse relationship if event has a course_id property elif 'course_id' in event_props: course_id = event_props['course_id'] # allow to fail if more than one Organization to avoid sharing data orgcourse = models.OrganizationCourse.objects.get(course_id=args) org = orgcourse.organization site = utils.get_site_by_organization(org) site_configuration = site.configuration except ( AttributeError, TypeError, MultipleObjectsReturned, models.Organization.DoesNotExist, models.OrganizationCourse.DoesNotExist ) as e: raise exceptions.EventProcessingError(e) return site_configuration
""" Utility functions for event tracking processing. """ from django.core.exceptions import MultipleObjectsReturned from . import exceptions def get_site_config_for_event(event_props): """ Try multiple strategies to find a SiteConfiguration object to use for evaluating and processing an event. Return a SiteConfiguration object if found; otherwise, None. """ from openedx.core.djangoapps.appsembler.sites import utils from openedx.core.djangoapps.site_configuration import helpers from organizations import models # try first via request obj in thread site_configuration = helpers.get_current_site_configuration() if not site_configuration: try: if 'org' in event_props: org_name = event_props['org'] org = models.Organization.objects.get(short_name=org_name) # try by OrganizationCourse relationship if event has a course_id property elif 'course_id' in event_props: course_id = event_props['course_id'] # allow to fail if more than one Organization to avoid sharing data orgcourse = models.OrganizationCourse.objects.get(course_id=args) org = orgcourse.organization else: raise exceptions.EventProcessingError( "There isn't and org or course_id attribute set in the " "segment event, so we couldn't determine the site." ) site = utils.get_site_by_organization(org) site_configuration = site.configuration except ( AttributeError, TypeError, MultipleObjectsReturned, models.Organization.DoesNotExist, models.OrganizationCourse.DoesNotExist ) as e: raise exceptions.EventProcessingError(e) return site_configuration
Return exeption if cannot get the site config in event
Return exeption if cannot get the site config in event
Python
agpl-3.0
appsembler/edx-platform,appsembler/edx-platform,appsembler/edx-platform,appsembler/edx-platform
--- +++ @@ -31,6 +31,11 @@ # allow to fail if more than one Organization to avoid sharing data orgcourse = models.OrganizationCourse.objects.get(course_id=args) org = orgcourse.organization + else: + raise exceptions.EventProcessingError( + "There isn't and org or course_id attribute set in the " + "segment event, so we couldn't determine the site." + ) site = utils.get_site_by_organization(org) site_configuration = site.configuration except (
872875ecb3b5a09c14da8836cdd4b7a6f6610675
vumi/transports/mxit/responses.py
vumi/transports/mxit/responses.py
import re from twisted.web.template import Element, renderer, XMLFile from twisted.python.filepath import FilePath class ResponseParser(object): HEADER_PATTERN = r'^(.*)[\r\n]{1,2}\d?' ITEM_PATTERN = r'^(\d+)\. (.+)$' def __init__(self, content): header_match = re.match(self.HEADER_PATTERN, content) if header_match: [self.header] = header_match.groups() self.items = re.findall(self.ITEM_PATTERN, content, re.MULTILINE) else: self.header = content self.items = [] @classmethod def parse(cls, content): p = cls(content) return p.header, p.items class MxitResponse(Element): loader = XMLFile( FilePath('vumi/transports/mxit/templates/response.xml')) def __init__(self, message, loader=None): self.header, self.items = ResponseParser.parse(message['content']) super(MxitResponse, self).__init__(loader or self.loader) @renderer def render_header(self, request, tag): return tag(self.header) @renderer def render_body(self, request, tag): if not self.items: return '' return tag @renderer def render_item(self, request, tag): for index, text in self.items: yield tag.clone().fillSlots(index=str(index), text=text)
import re from twisted.web.template import Element, renderer, XMLFile from twisted.python.filepath import FilePath from vumi.utils import PkgResources MXIT_RESOURCES = PkgResources(__name__) class ResponseParser(object): HEADER_PATTERN = r'^(.*)[\r\n]{1,2}\d?' ITEM_PATTERN = r'^(\d+)\. (.+)$' def __init__(self, content): header_match = re.match(self.HEADER_PATTERN, content) if header_match: [self.header] = header_match.groups() self.items = re.findall(self.ITEM_PATTERN, content, re.MULTILINE) else: self.header = content self.items = [] @classmethod def parse(cls, content): p = cls(content) return p.header, p.items class MxitResponse(Element): loader = XMLFile(FilePath(MXIT_RESOURCES.path('templates/response.xml'))) def __init__(self, message, loader=None): self.header, self.items = ResponseParser.parse(message['content']) super(MxitResponse, self).__init__(loader or self.loader) @renderer def render_header(self, request, tag): return tag(self.header) @renderer def render_body(self, request, tag): if not self.items: return '' return tag @renderer def render_item(self, request, tag): for index, text in self.items: yield tag.clone().fillSlots(index=str(index), text=text)
Use PkgResources helper to load response templates.
Use PkgResources helper to load response templates.
Python
bsd-3-clause
TouK/vumi,TouK/vumi,TouK/vumi,harrissoerja/vumi,harrissoerja/vumi,vishwaprakashmishra/xmatrix,vishwaprakashmishra/xmatrix,harrissoerja/vumi,vishwaprakashmishra/xmatrix
--- +++ @@ -2,6 +2,11 @@ from twisted.web.template import Element, renderer, XMLFile from twisted.python.filepath import FilePath + +from vumi.utils import PkgResources + + +MXIT_RESOURCES = PkgResources(__name__) class ResponseParser(object): @@ -25,8 +30,7 @@ class MxitResponse(Element): - loader = XMLFile( - FilePath('vumi/transports/mxit/templates/response.xml')) + loader = XMLFile(FilePath(MXIT_RESOURCES.path('templates/response.xml'))) def __init__(self, message, loader=None): self.header, self.items = ResponseParser.parse(message['content'])
4719401819a877ceebfcc49f1084fb01395a3f4d
nyuki/bus/persistence/mongo_backend.py
nyuki/bus/persistence/mongo_backend.py
from datetime import datetime import logging from motor.motor_asyncio import AsyncIOMotorClient from pymongo.errors import AutoReconnect log = logging.getLogger(__name__) class MongoBackend(object): def __init__(self, name): self.name = name self.host = None self._collection = None async def init(self, host, ttl=60): self.host = host # Get collection for this nyuki client = AsyncIOMotorClient(host) db = client['bus_persistence'] self._collection = db[self.name] # Set a TTL to the documents in this collection try: await self._collection.create_index( 'created_at', expireAfterSeconds=ttl*60 ) except AutoReconnect: log.error("Could not reach mongo at address '%s'", self.host) async def store(self, topic, message): await self._collection.insert({ 'created_at': datetime.utcnow(), 'topic': str(topic), 'message': message }) async def retrieve(self, since=None): if since: cursor = self._collection.find({'created_at': {'$gte': since}}) else: cursor = self._collection.find() cursor.sort('created_at') return await cursor.to_list(None)
from datetime import datetime import logging from motor.motor_asyncio import AsyncIOMotorClient from pymongo.errors import AutoReconnect log = logging.getLogger(__name__) class MongoBackend(object): def __init__(self, name): self.name = name self.host = None self._collection = None async def init(self, host, ttl=60): self.host = host # Get collection for this nyuki client = AsyncIOMotorClient(host) db = client['bus_persistence'] self._collection = db[self.name] # Set a TTL to the documents in this collection try: await self._collection.create_index( 'created_at', expireAfterSeconds=ttl*60 ) except AutoReconnect: log.error("Could not reach mongo at address '%s'", self.host) async def store(self, topic, message): try: await self._collection.insert({ 'created_at': datetime.utcnow(), 'topic': str(topic), 'message': message }) except AutoReconnect: log.error("Could not reach mongo at address '%s'", self.host) async def retrieve(self, since=None): if since: cursor = self._collection.find({'created_at': {'$gte': since}}) else: cursor = self._collection.find() cursor.sort('created_at') try: return await cursor.to_list(None) except AutoReconnect: log.error("Could not reach mongo at address '%s'", self.host)
Add failsafe mongo calls
Add failsafe mongo calls [ci skip]
Python
apache-2.0
optiflows/nyuki,gdraynz/nyuki,gdraynz/nyuki,optiflows/nyuki
--- +++ @@ -30,11 +30,14 @@ log.error("Could not reach mongo at address '%s'", self.host) async def store(self, topic, message): - await self._collection.insert({ - 'created_at': datetime.utcnow(), - 'topic': str(topic), - 'message': message - }) + try: + await self._collection.insert({ + 'created_at': datetime.utcnow(), + 'topic': str(topic), + 'message': message + }) + except AutoReconnect: + log.error("Could not reach mongo at address '%s'", self.host) async def retrieve(self, since=None): if since: @@ -43,4 +46,8 @@ cursor = self._collection.find() cursor.sort('created_at') - return await cursor.to_list(None) + + try: + return await cursor.to_list(None) + except AutoReconnect: + log.error("Could not reach mongo at address '%s'", self.host)
eb7201789bc5ce03ca415fc4c208ce5a41bfc249
sha1.py
sha1.py
#!/usr/bin/env python """ usage: python -m sha1 <filename> """ import sys import hashlib # --- these fields are required for packaging __version__ = '1.0' __author__ = 'anatoly techtonik <techtonik@gmail.com>' __license__ = 'Public Domain' __url__ = 'https://gist.github.com/techtonik/df09baeacbebc52d234b' # /-- these fields are required for packaging if not sys.argv[1:]: sys.exit(__doc__.strip()) sha1sum = hashlib.sha1() with open(sys.argv[1], 'rb') as source: block = source.read(2**16) while len(block) != 0: sha1sum.update(block) block = source.read(2**16) print(sha1sum.hexdigest())
#!/usr/bin/env python """ usage: python -m sha1 <filename> """ import sys import hashlib # --- these fields are required for packaging __version__ = '1.0' __author__ = 'anatoly techtonik <techtonik@gmail.com>' __license__ = 'Public Domain' __url__ = 'https://github.com/techtonik/sha1' # /-- these fields are required for packaging if not sys.argv[1:]: sys.exit(__doc__.strip()) sha1sum = hashlib.sha1() with open(sys.argv[1], 'rb') as source: block = source.read(2**16) while len(block) != 0: sha1sum.update(block) block = source.read(2**16) print(sha1sum.hexdigest())
Move from Gist to GitHub
Move from Gist to GitHub
Python
unlicense
techtonik/sha1
--- +++ @@ -9,7 +9,7 @@ __version__ = '1.0' __author__ = 'anatoly techtonik <techtonik@gmail.com>' __license__ = 'Public Domain' -__url__ = 'https://gist.github.com/techtonik/df09baeacbebc52d234b' +__url__ = 'https://github.com/techtonik/sha1' # /-- these fields are required for packaging if not sys.argv[1:]:
fbbb01a3ef5811c102be6822a16a881212e421a9
typo.py
typo.py
from __future__ import absolute_import __all__ = ['app'] from ConfigParser import SafeConfigParser as ConfigParser from urlparse import urlparse, urlunparse from flask import Flask, request, redirect from fuzzywuzzy import process from tldextract import extract config = ConfigParser() config.read(['config.ini', 'config.ini.tpl']) BASE = config.get('typo', 'base') CUTOFF = config.getint('typo', 'cutoff') DEFAULT_SITE = config.get('typo', 'default_site') MATCH_SITES = dict(config.items('match_sites')) app = Flask(__name__) @app.route('/', defaults={'path': ''}) @app.route(r'/<path:path>') def catch_all(path): redirect_to = get_best_match(request.url) new_url = replace_host(request.url, redirect_to) return redirect(new_url) def replace_host(url, host): parsed = urlparse(url) netloc = u'%s.%s' % (host, BASE) return urlunparse(parsed[:1] + (netloc,) + parsed[2:]) def get_best_match(url): original_url = extract(request.url) sub = original_url.subdomain closest, score = process.extractOne(sub, MATCH_SITES.keys(), score_cutoff=CUTOFF) or (None, 0) return MATCH_SITES.get(closest, DEFAULT_SITE)
from __future__ import absolute_import __all__ = ['app'] from ConfigParser import SafeConfigParser as ConfigParser from urlparse import urlparse, urlunparse from flask import Flask, request, redirect from fuzzywuzzy import process from tldextract import extract config = ConfigParser() config.read(['config.ini', 'config.ini.tpl']) BASE = config.get('typo', 'base') CUTOFF = config.getint('typo', 'cutoff') DEFAULT_SITE = config.get('typo', 'default_site') MATCH_SITES = dict(config.items('match_sites')) app = Flask(__name__) @app.route('/', defaults={'path': ''}) @app.route(r'/<path:path>') def catch_all(path): redirect_to = get_best_match(request.url) new_url = replace_host(request.url, redirect_to) return redirect(new_url) def replace_host(url, host): parsed = urlparse(url) netloc = u'%s.%s' % (host, BASE) return urlunparse(parsed[:1] + (netloc,) + parsed[2:]) def get_best_match(url): original_url = extract(url) sub = original_url.subdomain closest, score = process.extractOne(sub, MATCH_SITES.keys(), score_cutoff=CUTOFF) or (None, 0) return MATCH_SITES.get(closest, DEFAULT_SITE)
Use passed url argument in get_best_match
Use passed url argument in get_best_match
Python
mit
sabf/typo
--- +++ @@ -35,7 +35,7 @@ def get_best_match(url): - original_url = extract(request.url) + original_url = extract(url) sub = original_url.subdomain closest, score = process.extractOne(sub, MATCH_SITES.keys(), score_cutoff=CUTOFF) or (None, 0)
75e0c323871d6eae6959523b105a06cfe8460a28
etk2/etk.py
etk2/etk.py
import json class ETK(object): def __init__(self): pass def get_glossary(self, file_path): res = dict() with open(file_path) as fp: line = fp.readline().rstrip('\n') while line: res[line] = line line = fp.readline().rstrip('\n') return res def invoke_extractor(self, extractor=None, doc=None, json_path=None, input_key=None, output_key=None): # cache parsed json_path, not a string, globally containers = doc.cdr_document['__content_strict'] # containers = doc.select_containers(json_path) if isinstance(containers, list): for c in containers: segment = c.get(input_key) tokens = doc.get_tokens(segment) else: segment = containers.get(input_key) tokens = doc.get_tokens(segment) fake_extraction = [i.text for i in tokens] doc.store_extraction(extractor, fake_extraction, containers, output_key) print(json.dumps(doc.cdr_document, indent=2)) # if extractor.requires_tokens(): # tokens = doc.get_tokens(segment, tokenizer=extractor.preferred_tokenizer()) # if tokens: # extraction = extractor.extract(tokens, doc) # doc.store_extraction(extractor, extraction, c, output_key)
from typing import List import json class ETK(object): def __init__(self): pass def get_glossary(self, file_path) -> List[str]: """ A glossary is a text file, one entry per line. Args: file_path (str): path to a text file containing a glossary. Returns: List of the strings in the glossary. """ #to-do: this should be a list, not a dict res = dict() with open(file_path) as fp: line = fp.readline().rstrip('\n') while line: res[line] = line line = fp.readline().rstrip('\n') return res def invoke_extractor(self, extractor=None, doc=None, json_path=None, input_key=None, output_key=None): # cache parsed json_path, not a string, globally containers = doc.cdr_document['__content_strict'] # containers = doc.select_containers(json_path) if isinstance(containers, list): for c in containers: segment = c.get(input_key) tokens = doc.get_tokens(segment) else: segment = containers.get(input_key) tokens = doc.get_tokens(segment) fake_extraction = [i.text for i in tokens] doc.store_extraction(extractor, fake_extraction, containers, output_key) print(json.dumps(doc.cdr_document, indent=2)) # if extractor.requires_tokens(): # tokens = doc.get_tokens(segment, tokenizer=extractor.preferred_tokenizer()) # if tokens: # extraction = extractor.extract(tokens, doc) # doc.store_extraction(extractor, extraction, c, output_key)
Add comments and typing annotations
Add comments and typing annotations
Python
mit
usc-isi-i2/etk,usc-isi-i2/etk,usc-isi-i2/etk
--- +++ @@ -1,3 +1,4 @@ +from typing import List import json class ETK(object): @@ -5,7 +6,16 @@ def __init__(self): pass - def get_glossary(self, file_path): + def get_glossary(self, file_path) -> List[str]: + """ + A glossary is a text file, one entry per line. + + Args: + file_path (str): path to a text file containing a glossary. + + Returns: List of the strings in the glossary. + """ + #to-do: this should be a list, not a dict res = dict() with open(file_path) as fp: line = fp.readline().rstrip('\n') @@ -13,7 +23,6 @@ res[line] = line line = fp.readline().rstrip('\n') return res - def invoke_extractor(self, extractor=None, doc=None, json_path=None, input_key=None, output_key=None): # cache parsed json_path, not a string, globally
3f1c988830b7b5128c8da141326ecbf7234a791a
kolibri/core/content/utils/content_types_tools.py
kolibri/core/content/utils/content_types_tools.py
from django.db.models import Q from le_utils.constants import content_kinds from kolibri.core.content.hooks import ContentRendererHook from kolibri.core.content.models import ContentNode # Start with an empty queryset, as we'll be using OR to add conditions renderable_contentnodes_without_topics_q_filter = ContentNode.objects.none() # loop through all the registered content renderer hooks for hook in ContentRendererHook().registered_hooks: for obj in hook.content_types['kinds']: # iterate through each of the content types that each hook can handle for extension in obj['extensions']: # Extend the q filter by ORing with a q filter for this content kind, and this file extension renderable_contentnodes_without_topics_q_filter |= Q(kind=obj['name'], files__local_file__extension=extension) # Regardless of which renderers are installed, we can render topics! renderable_contentnodes_q_filter = Q(kind=content_kinds.TOPIC) | renderable_contentnodes_without_topics_q_filter
from django.db.models import Q from le_utils.constants import content_kinds from kolibri.core.content.hooks import ContentRendererHook # Start with an empty Q object, as we'll be using OR to add conditions renderable_contentnodes_without_topics_q_filter = Q() # loop through all the registered content renderer hooks for hook in ContentRendererHook().registered_hooks: for obj in hook.content_types['kinds']: # iterate through each of the content types that each hook can handle for extension in obj['extensions']: # Extend the q filter by ORing with a q filter for this content kind, and this file extension renderable_contentnodes_without_topics_q_filter |= Q(kind=obj['name'], files__local_file__extension=extension) # Regardless of which renderers are installed, we can render topics! renderable_contentnodes_q_filter = Q(kind=content_kinds.TOPIC) | renderable_contentnodes_without_topics_q_filter
Use Q object instead of empty queryset
Use Q object instead of empty queryset
Python
mit
mrpau/kolibri,lyw07/kolibri,lyw07/kolibri,learningequality/kolibri,mrpau/kolibri,learningequality/kolibri,indirectlylit/kolibri,learningequality/kolibri,indirectlylit/kolibri,mrpau/kolibri,lyw07/kolibri,indirectlylit/kolibri,lyw07/kolibri,learningequality/kolibri,indirectlylit/kolibri,mrpau/kolibri
--- +++ @@ -2,10 +2,10 @@ from le_utils.constants import content_kinds from kolibri.core.content.hooks import ContentRendererHook -from kolibri.core.content.models import ContentNode -# Start with an empty queryset, as we'll be using OR to add conditions -renderable_contentnodes_without_topics_q_filter = ContentNode.objects.none() +# Start with an empty Q object, as we'll be using OR to add conditions +renderable_contentnodes_without_topics_q_filter = Q() + # loop through all the registered content renderer hooks for hook in ContentRendererHook().registered_hooks:
756456992247bf8dbb0731556e37ecd0cf32e3ab
scripts/splitfa.py
scripts/splitfa.py
#!/usr/bin/env python from __future__ import print_function, absolute_import, division import screed import docopt CLI = """ USAGE: fasplit <fasta> <prefix> """ opts = docopt.docopt(CLI) prefix = opts['<prefix>'] with screed.open(opts['<fasta>']) as fh: for record in fh: fname = "{}{}.fasta".format(prefix, record.name) with open(fname, 'w') as ofh: print(">", record.name, sep='', file=ofh) print(record.sequence, file=ofh)
#!/usr/bin/env python from __future__ import print_function, absolute_import, division import screed import docopt CLI = """ USAGE: fasplit <fasta> <prefix> """ opts = docopt.docopt(CLI) prefix = opts['<prefix>'] with screed.open(opts['<fasta>']) as fh: for record in fh: fname = "{}{}.fasta".format(prefix, record.name) with open(fname, 'w') as ofh: print(">", record.name, sep='', file=ofh) print(str(record.sequence).translate(None, '-'), file=ofh)
Remove gaps from individual genomes
Remove gaps from individual genomes
Python
mit
kdmurray91/kwip-experiments,kdmurray91/kwip-experiments,kdmurray91/kwip-experiments
--- +++ @@ -16,5 +16,5 @@ fname = "{}{}.fasta".format(prefix, record.name) with open(fname, 'w') as ofh: print(">", record.name, sep='', file=ofh) - print(record.sequence, file=ofh) + print(str(record.sequence).translate(None, '-'), file=ofh)
e8880d6a4fb96722551bdc50274cdfddc2bd41d2
corehq/ex-submodules/casexml/apps/case/tests/test_signals.py
corehq/ex-submodules/casexml/apps/case/tests/test_signals.py
from django.test import TestCase from casexml.apps.case.mock import CaseFactory from casexml.apps.case.signals import cases_received from casexml.apps.case.xform import process_cases_with_casedb from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL from corehq.form_processor.interfaces.processor import FormProcessorInterface from corehq.form_processor.models import CommCareCaseSQL class TestCasesReceivedSignal(TestCase): def test_casedb_already_has_cases(self): casedb_cache = FormProcessorInterface().casedb_cache case = CaseFactory().create_case() case_db = casedb_cache(initial=[ CommCareCaseSQL(case_id='fake1'), CommCareCaseSQL(case_id='fake2'), ]) form = FormAccessorSQL.get_form(case.xform_ids[0]) def assert_exactly_one_case(sender, xform, cases, **kwargs): global case_count case_count = len(cases) cases_received.connect(assert_exactly_one_case) try: process_cases_with_casedb([form], case_db) self.assertEqual(1, case_count) finally: cases_received.disconnect(assert_exactly_one_case)
from django.test import TestCase from casexml.apps.case.mock import CaseFactory from casexml.apps.case.signals import cases_received from casexml.apps.case.xform import process_cases_with_casedb from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL from corehq.form_processor.interfaces.processor import FormProcessorInterface from corehq.form_processor.models import CommCareCaseSQL class TestCasesReceivedSignal(TestCase): def test_casedb_already_has_cases(self): casedb_cache = FormProcessorInterface().casedb_cache case = CaseFactory().create_case() case_db = casedb_cache(initial=[ CommCareCaseSQL(case_id='fake1'), CommCareCaseSQL(case_id='fake2'), ]) form = FormAccessorSQL.get_form(case.xform_ids[0]) received = [] def receive_cases(sender, xform, cases, **kwargs): received.extend(cases) cases_received.connect(receive_cases) try: process_cases_with_casedb([form], case_db) self.assertEqual(len(received), 1) finally: cases_received.disconnect(receive_cases)
Refactor test to not use global variable
Refactor test to not use global variable
Python
bsd-3-clause
dimagi/commcare-hq,dimagi/commcare-hq,dimagi/commcare-hq,dimagi/commcare-hq,dimagi/commcare-hq
--- +++ @@ -17,14 +17,14 @@ CommCareCaseSQL(case_id='fake2'), ]) form = FormAccessorSQL.get_form(case.xform_ids[0]) + received = [] - def assert_exactly_one_case(sender, xform, cases, **kwargs): - global case_count - case_count = len(cases) + def receive_cases(sender, xform, cases, **kwargs): + received.extend(cases) - cases_received.connect(assert_exactly_one_case) + cases_received.connect(receive_cases) try: process_cases_with_casedb([form], case_db) - self.assertEqual(1, case_count) + self.assertEqual(len(received), 1) finally: - cases_received.disconnect(assert_exactly_one_case) + cases_received.disconnect(receive_cases)
081b1cd60e363adf941ba511c7683c0ed2843a97
gubernator/appengine_config.py
gubernator/appengine_config.py
# Copyright 2016 The Kubernetes Authors All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os from google.appengine.ext import vendor # Add any libraries installed in the "third_party" folder. vendor.add('third_party') # Use remote GCS calls for local development. if os.environ.get('SERVER_SOFTWARE','').startswith('Development'): os.environ['SERVER_SOFTWARE'] += ' remote_api'
# Copyright 2016 The Kubernetes Authors All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os from google.appengine.ext import vendor from google.appengine.api import urlfetch # Add any libraries installed in the "third_party" folder. vendor.add('third_party') # Use remote GCS calls for local development. if os.environ.get('SERVER_SOFTWARE','').startswith('Development'): os.environ['SERVER_SOFTWARE'] += ' remote_api' # The default deadline of 5 seconds is too aggressive of a target for GCS # directory listing operations. urlfetch.set_default_fetch_deadline(60)
Increase Gubernator's url fetch deadline -- 5 seconds is too fast!
Increase Gubernator's url fetch deadline -- 5 seconds is too fast! This should avoid a lot of refreshes because some directory listing or download takes slightly too long.
Python
apache-2.0
mikedanese/test-infra,gmarek/test-infra,mindprince/test-infra,shashidharatd/test-infra,cblecker/test-infra,rmmh/kubernetes-test-infra,mikedanese/test-infra,jlowdermilk/test-infra,shyamjvs/test-infra,mikedanese/test-infra,girishkalele/test-infra,grodrigues3/test-infra,monopole/test-infra,foxish/test-infra,mikedanese/test-infra,shyamjvs/test-infra,spxtr/test-infra,jlowdermilk/test-infra,mtaufen/test-infra,shyamjvs/test-infra,madhusudancs/test-infra,kargakis/test-infra,mtaufen/test-infra,shashidharatd/test-infra,madhusudancs/test-infra,girishkalele/test-infra,nlandolfi/test-infra-1,kewu1992/test-infra,madhusudancs/test-infra,dims/test-infra,kubernetes/test-infra,ixdy/kubernetes-test-infra,brahmaroutu/test-infra,kewu1992/test-infra,dims/test-infra,krousey/test-infra,BenTheElder/test-infra,brahmaroutu/test-infra,maisem/test-infra,kubernetes/test-infra,jessfraz/test-infra,krzyzacy/test-infra,cjwagner/test-infra,dchen1107/test-infra,piosz/test-infra,piosz/test-infra,abgworrall/test-infra,BenTheElder/test-infra,michelle192837/test-infra,pwittrock/test-infra,mtaufen/test-infra,mindprince/test-infra,shashidharatd/test-infra,dchen1107/test-infra,dchen1107/test-infra,kubernetes/test-infra,cblecker/test-infra,dchen1107/test-infra,shyamjvs/test-infra,brahmaroutu/test-infra,cblecker/test-infra,jessfraz/test-infra,grodrigues3/test-infra,shyamjvs/test-infra,fejta/test-infra,abgworrall/test-infra,monopole/test-infra,piosz/test-infra,kewu1992/test-infra,girishkalele/test-infra,dims/test-infra,gmarek/test-infra,michelle192837/test-infra,shyamjvs/test-infra,gmarek/test-infra,nlandolfi/test-infra-1,grodrigues3/test-infra,BenTheElder/test-infra,lavalamp/test-infra,piosz/test-infra,lavalamp/test-infra,abgworrall/test-infra,nlandolfi/test-infra-1,brahmaroutu/test-infra,kargakis/test-infra,jessfraz/test-infra,rmmh/kubernetes-test-infra,abgworrall/test-infra,shashidharatd/test-infra,brahmaroutu/test-infra,cblecker/test-infra,dims/test-infra,cjwagner/test-infra,krzyzacy/test-infra,kewu1992/test-infra,kargakis/test-infra,pwittrock/test-infra,fejta/test-infra,cjwagner/test-infra,gmarek/test-infra,pwittrock/test-infra,girishkalele/test-infra,fejta/test-infra,spxtr/test-infra,piosz/test-infra,lavalamp/test-infra,pwittrock/test-infra,brahmaroutu/test-infra,nlandolfi/test-infra-1,BenTheElder/test-infra,jessfraz/test-infra,pwittrock/test-infra,krousey/test-infra,gmarek/test-infra,krzyzacy/test-infra,jlowdermilk/test-infra,kubernetes/test-infra,ixdy/kubernetes-test-infra,monopole/test-infra,foxish/test-infra,monopole/test-infra,michelle192837/test-infra,mindprince/test-infra,kewu1992/test-infra,krousey/test-infra,krzyzacy/test-infra,cblecker/test-infra,rmmh/kubernetes-test-infra,mindprince/test-infra,monopole/test-infra,kargakis/test-infra,michelle192837/test-infra,spxtr/test-infra,dims/test-infra,monopole/test-infra,spxtr/test-infra,jlowdermilk/test-infra,michelle192837/test-infra,maisem/test-infra,jessfraz/test-infra,dims/test-infra,grodrigues3/test-infra,rmmh/kubernetes-test-infra,fejta/test-infra,ixdy/kubernetes-test-infra,cjwagner/test-infra,girishkalele/test-infra,abgworrall/test-infra,maisem/test-infra,maisem/test-infra,lavalamp/test-infra,grodrigues3/test-infra,shashidharatd/test-infra,maisem/test-infra,mindprince/test-infra,jessfraz/test-infra,mikedanese/test-infra,BenTheElder/test-infra,krousey/test-infra,cjwagner/test-infra,madhusudancs/test-infra,foxish/test-infra,kubernetes/test-infra,kubernetes/test-infra,rmmh/kubernetes-test-infra,cblecker/test-infra,kargakis/test-infra,jlowdermilk/test-infra,lavalamp/test-infra,krzyzacy/test-infra,lavalamp/test-infra,foxish/test-infra,ixdy/kubernetes-test-infra,nlandolfi/test-infra-1,BenTheElder/test-infra,madhusudancs/test-infra,foxish/test-infra,mtaufen/test-infra,spxtr/test-infra,michelle192837/test-infra,fejta/test-infra,fejta/test-infra,mtaufen/test-infra,krzyzacy/test-infra,krousey/test-infra,kargakis/test-infra,dchen1107/test-infra,cjwagner/test-infra,jlowdermilk/test-infra,ixdy/kubernetes-test-infra
--- +++ @@ -15,6 +15,7 @@ import os from google.appengine.ext import vendor +from google.appengine.api import urlfetch # Add any libraries installed in the "third_party" folder. vendor.add('third_party') @@ -22,3 +23,7 @@ # Use remote GCS calls for local development. if os.environ.get('SERVER_SOFTWARE','').startswith('Development'): os.environ['SERVER_SOFTWARE'] += ' remote_api' + +# The default deadline of 5 seconds is too aggressive of a target for GCS +# directory listing operations. +urlfetch.set_default_fetch_deadline(60)
e8e326fe39623ea04082553d1293b1e79c3611f6
proto/ho.py
proto/ho.py
#!/usr/bin/env python import sys from board import Board, BoardView from utils import clear, getch def main(): board = Board(19, 19) view = BoardView(board) def move(): board.move(*view.cursor) view.redraw() def exit(): sys.exit(0) KEYS = { 'w': view.cursor_up, 'r': view.cursor_down, 'a': view.cursor_left, 's': view.cursor_right, 'x': move, '\x1b': exit, } while True: # Print board clear() sys.stdout.write('{0}\n'.format(view)) sys.stdout.write('Black: {black} -- White: {white}\n'.format(**board.score)) sys.stdout.write('{0}\'s move... '.format(board.turn)) # Get action c = getch() try: # Execute selected action KEYS[c]() except KeyError: # Action not found, do nothing pass if __name__ == '__main__': main()
#!/usr/bin/env python import sys from board import Board, BoardView from utils import clear, getch def main(): board = Board(19, 19) view = BoardView(board) err = None def move(): board.move(*view.cursor) view.redraw() def exit(): sys.exit(0) KEYS = { 'w': view.cursor_up, 'r': view.cursor_down, 'a': view.cursor_left, 's': view.cursor_right, 'x': move, '\x1b': exit, } while True: # Print board clear() sys.stdout.write('{0}\n'.format(view)) sys.stdout.write('Black: {black} <===> White: {white}\n'.format(**board.score)) sys.stdout.write('{0}\'s move... '.format(board.turn)) if err: sys.stdout.write(err + '\n') err = None # Get action c = getch() try: # Execute selected action KEYS[c]() except Board.BoardError as be: # Board error (move on top of other piece, suicidal move, etc.) err = be.message except KeyError: # Action not found, do nothing pass if __name__ == '__main__': main()
Add error handling to main game loop
Add error handling to main game loop
Python
mit
davesque/go.py
--- +++ @@ -9,6 +9,7 @@ def main(): board = Board(19, 19) view = BoardView(board) + err = None def move(): board.move(*view.cursor) @@ -30,8 +31,12 @@ # Print board clear() sys.stdout.write('{0}\n'.format(view)) - sys.stdout.write('Black: {black} -- White: {white}\n'.format(**board.score)) + sys.stdout.write('Black: {black} <===> White: {white}\n'.format(**board.score)) sys.stdout.write('{0}\'s move... '.format(board.turn)) + + if err: + sys.stdout.write(err + '\n') + err = None # Get action c = getch() @@ -39,6 +44,9 @@ try: # Execute selected action KEYS[c]() + except Board.BoardError as be: + # Board error (move on top of other piece, suicidal move, etc.) + err = be.message except KeyError: # Action not found, do nothing pass
bc399ed6902f6ba3d24e1ce1a8ff88a259793c3a
Artifactorial/urls.py
Artifactorial/urls.py
# -*- coding: utf-8 -*- # vim: set ts=4 # Copyright 2014 Rémi Duraffort # This file is part of Artifactorial. # # Artifactorial is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Artifactorial is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Artifactorial. If not, see <http://www.gnu.org/licenses/> from __future__ import unicode_literals from django.conf.urls import patterns, url urlpatterns = patterns('Artifactorial.views', url(r'^artifacts/(?P<filename>.*)$', 'artifacts', name='artifacts'), url(r'^shared/(?P<token>.*)$', 'shared', name='shared'))
# -*- coding: utf-8 -*- # vim: set ts=4 # Copyright 2014 Rémi Duraffort # This file is part of Artifactorial. # # Artifactorial is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Artifactorial is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Artifactorial. If not, see <http://www.gnu.org/licenses/> from __future__ import unicode_literals from django.conf.urls import patterns, url import Artifactorial.views as a_views urlpatterns = [ url(r'^artifacts/(?P<filename>.*)$', a_views.artifacts, name='artifacts'), url(r'^shared/(?P<token>.*)$', a_views.shared, name='shared') ]
Use the new url pattern
Use the new url pattern
Python
mit
ivoire/Artifactorial,ivoire/Artifactorial,ivoire/Artifactorial
--- +++ @@ -21,7 +21,10 @@ from django.conf.urls import patterns, url +import Artifactorial.views as a_views -urlpatterns = patterns('Artifactorial.views', - url(r'^artifacts/(?P<filename>.*)$', 'artifacts', name='artifacts'), - url(r'^shared/(?P<token>.*)$', 'shared', name='shared')) + +urlpatterns = [ + url(r'^artifacts/(?P<filename>.*)$', a_views.artifacts, name='artifacts'), + url(r'^shared/(?P<token>.*)$', a_views.shared, name='shared') +]
ff2d9b276928d2bf06ae81b1fa243ee2816cd694
seawater/__init__.py
seawater/__init__.py
# -*- coding: utf-8 -*- __all__ = ["csiro", "extras"] __authors__ = 'Filipe Fernandes' __created_ = "14-Jan-2010" __email__ = "ocefpaf@gmail.com" __license__ = "MIT" __maintainer__ = "Filipe Fernandes" __modified__ = "16-Mar-2013" __status__ = "Production" __version__ = "2.0.0" import csiro import extras
# -*- coding: utf-8 -*- from csiro import *
Update to reflect some small re-factoring.
Update to reflect some small re-factoring.
Python
mit
ocefpaf/python-seawater,pyoceans/python-seawater,pyoceans/python-seawater,ocefpaf/python-seawater
--- +++ @@ -1,14 +1,3 @@ # -*- coding: utf-8 -*- -__all__ = ["csiro", "extras"] -__authors__ = 'Filipe Fernandes' -__created_ = "14-Jan-2010" -__email__ = "ocefpaf@gmail.com" -__license__ = "MIT" -__maintainer__ = "Filipe Fernandes" -__modified__ = "16-Mar-2013" -__status__ = "Production" -__version__ = "2.0.0" - -import csiro -import extras +from csiro import *
9e8093fe66da557ca9e976e600b8977c002f5241
blog/testsettings.py
blog/testsettings.py
DEBUG = True DEBUG_TEMPLATE = True SITE_ID = 1 DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = '/tmp/asgard-blog-devel.db' INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.comments', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.sites', 'django.contrib.sitemaps', 'django_markup', 'taggit', 'blog', ] ROOT_URLCONF = 'blog.testurls' BLOG_MUTIPLE_SITE = True
DEBUG = True DEBUG_TEMPLATE = True SITE_ID = 1 DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = '/tmp/asgard-blog-devel.db' INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.comments', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.sites', 'django.contrib.sitemaps', 'django_markup', 'taggit', 'django_graffle', 'blog', ] ROOT_URLCONF = 'blog.testurls' BLOG_MUTIPLE_SITE = True
Revert "Fixed up some things."
Revert "Fixed up some things." This reverts commit 2d3d6c1b569e1f35faf9cd79a369862651c008ff.
Python
bsd-3-clause
myles-archive/asgard-blog,asgardproject/asgard-blog,asgardproject/asgard-blog,asgardproject/asgard-blog,myles-archive/asgard-blog,myles-archive/asgard-blog
--- +++ @@ -14,6 +14,7 @@ 'django_markup', 'taggit', + 'django_graffle', 'blog', ]
0d135a746dd79ad1b703570e2bb3b27a694c67b0
simuvex/procedures/stubs/NoReturnUnconstrained.py
simuvex/procedures/stubs/NoReturnUnconstrained.py
import simuvex ###################################### # NoReturnUnconstrained # Use in places you would put ReturnUnconstrained as a default action # But the function shouldn't actually return ###################################### use_cases = {'exit_group', 'exit', 'abort', 'longjmp', 'pthread_exit', 'siglongjmp'} class NoReturnUnconstrained(simuvex.SimProcedure): #pylint:disable=redefined-builtin NO_RET = True def run(self): #pylint:disable=unused-argument return
import simuvex ###################################### # NoReturnUnconstrained # Use in places you would put ReturnUnconstrained as a default action # But the function shouldn't actually return ###################################### class NoReturnUnconstrained(simuvex.SimProcedure): #pylint:disable=redefined-builtin use_cases = {'exit_group', 'exit', 'abort', 'longjmp', 'pthread_exit', 'siglongjmp', '__longjmp_chk', '__siglongjmp_chk'} NO_RET = True def run(self, **kwargs): #pylint:disable=unused-argument return
Move use_cases into the class
Move use_cases into the class
Python
bsd-2-clause
iamahuman/angr,iamahuman/angr,f-prettyland/angr,chubbymaggie/simuvex,chubbymaggie/angr,schieb/angr,angr/angr,tyb0807/angr,f-prettyland/angr,tyb0807/angr,axt/angr,tyb0807/angr,chubbymaggie/angr,angr/angr,angr/angr,iamahuman/angr,axt/angr,f-prettyland/angr,chubbymaggie/angr,angr/simuvex,chubbymaggie/simuvex,zhuyue1314/simuvex,axt/angr,schieb/angr,chubbymaggie/simuvex,schieb/angr
--- +++ @@ -6,9 +6,9 @@ # But the function shouldn't actually return ###################################### -use_cases = {'exit_group', 'exit', 'abort', 'longjmp', 'pthread_exit', 'siglongjmp'} - class NoReturnUnconstrained(simuvex.SimProcedure): #pylint:disable=redefined-builtin + use_cases = {'exit_group', 'exit', 'abort', 'longjmp', 'pthread_exit', 'siglongjmp', + '__longjmp_chk', '__siglongjmp_chk'} NO_RET = True - def run(self): #pylint:disable=unused-argument + def run(self, **kwargs): #pylint:disable=unused-argument return
4e5825b732597d7adcfcf8eaea3468c893b86347
src/akllt/tests.py
src/akllt/tests.py
# coding: utf-8 import pkg_resources from django.test.testcases import TransactionTestCase from homophony import BrowserTestCase, Browser def import_pages(directory): pass class SmokeTest(TransactionTestCase): def test_nothing(self): self.client.get('/') class FoobarTestCase(BrowserTestCase): def test_home(self): browser = Browser() browser.open('http://testserver') browser.getLink('Naujienos').click() self.assertEquals(browser.title, 'Atviras Kodas Lietuvai') class ImportTestCase(BrowserTestCase): def test_import(self): import_pages(pkg_resources .resource_filename('akllt', 'test_data/pages')) browser = Browser() browser.open('http://testserver') browser.getLink('Apie').click() # expected_content = pkg_resources.resource_string( # 'akllt', 'test_data/pages/apie.html') # self.assertTrue(expected_content in browser.contents)
# coding: utf-8 import pkg_resources from django.test.testcases import TransactionTestCase from homophony import BrowserTestCase, Browser from akllt.models import StandardPage def import_pages(directory): pass def import_pages(directory): pass class SmokeTest(TransactionTestCase): def test_nothing(self): self.client.get('/') class FoobarTestCase(BrowserTestCase): def test_home(self): browser = Browser() browser.open('http://testserver') browser.getLink('Naujienos').click() self.assertEquals(browser.title, 'Atviras Kodas Lietuvai') class ImportTestCase(BrowserTestCase): def test_import(self): import_pages(pkg_resources .resource_filename('akllt', 'test_data/pages')) browser = Browser() browser.open('http://testserver') browser.getLink('Apie').click() # expected_content = pkg_resources.resource_string( # 'akllt', 'test_data/pages/apie.html') # self.assertTrue(expected_content in browser.contents) def test_create_page(self): StandardPage.objects.create( intro='Atviras kodas Lietuvai', body='Turinys', depth=0, slug='atviras-kodas-lietuvai') # Browser('http://testserver/atviras-kodas-lietuvai')
Create functional test for data import
Create functional test for data import
Python
agpl-3.0
python-dirbtuves/akl.lt,python-dirbtuves/akl.lt,python-dirbtuves/akl.lt,python-dirbtuves/akl.lt,python-dirbtuves/akl.lt
--- +++ @@ -3,6 +3,11 @@ from django.test.testcases import TransactionTestCase from homophony import BrowserTestCase, Browser +from akllt.models import StandardPage + + +def import_pages(directory): + pass def import_pages(directory): @@ -35,3 +40,11 @@ # expected_content = pkg_resources.resource_string( # 'akllt', 'test_data/pages/apie.html') # self.assertTrue(expected_content in browser.contents) + + def test_create_page(self): + StandardPage.objects.create( + intro='Atviras kodas Lietuvai', + body='Turinys', + depth=0, + slug='atviras-kodas-lietuvai') + # Browser('http://testserver/atviras-kodas-lietuvai')
983e4fc9c5fafcfb60996c73571fc9ae9dd6b307
app/__init__.py
app/__init__.py
from flask import Flask from flask_login import LoginManager from flask_bcrypt import Bcrypt from flask_admin import Admin from flask_admin.contrib.peewee import ModelView from playhouse.flask_utils import FlaskDB app = Flask(__name__) app.config.from_object('config') @app.before_request def _db_connect(): db.connect() @app.teardown_request def _db_close(exc): if not db.is_closed(): db.close() login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'users.login' flask_db = FlaskDB(app) db = flask_db.database bcrypt = Bcrypt(app) from app.models import User, Page, Post, Event admin = Admin(app, name='teknologkoren.se') admin.add_view(ModelView(User, db)) admin.add_view(ModelView(Page, db)) admin.add_view(ModelView(Post, db)) admin.add_view(ModelView(Event, db)) from app.views import (general, users, index, about, intranet) app.register_blueprint(general.mod) app.register_blueprint(users.mod) app.register_blueprint(index.mod) app.register_blueprint(about.mod) app.register_blueprint(intranet.mod)
from flask import Flask from flask_login import LoginManager from flask_bcrypt import Bcrypt from flask_admin import Admin from flask_admin.contrib.peewee import ModelView from playhouse.flask_utils import FlaskDB app = Flask(__name__) app.config.from_object('config') @app.before_request def _db_connect(): db.connect() @app.teardown_request def _db_close(exc): if not db.is_closed(): db.close() login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'users.login' flask_db = FlaskDB(app) db = flask_db.database bcrypt = Bcrypt(app) from app.models import User, Page, Post, Event admin = Admin(app, name='teknologkoren.se') admin.add_view(ModelView(User, name='User')) admin.add_view(ModelView(Page, name='Page')) admin.add_view(ModelView(Post, name='Post')) admin.add_view(ModelView(Event, name='Event')) from app.views import (general, users, index, about, intranet) app.register_blueprint(general.mod) app.register_blueprint(users.mod) app.register_blueprint(index.mod) app.register_blueprint(about.mod) app.register_blueprint(intranet.mod)
Fix table names in flask-admin
Fix table names in flask-admin
Python
mpl-2.0
teknologkoren/teknologkoren-se,teknologkoren/teknologkoren-se,teknologkoren/teknologkoren-se,teknologkoren/teknologkoren-se
--- +++ @@ -31,10 +31,10 @@ from app.models import User, Page, Post, Event admin = Admin(app, name='teknologkoren.se') -admin.add_view(ModelView(User, db)) -admin.add_view(ModelView(Page, db)) -admin.add_view(ModelView(Post, db)) -admin.add_view(ModelView(Event, db)) +admin.add_view(ModelView(User, name='User')) +admin.add_view(ModelView(Page, name='Page')) +admin.add_view(ModelView(Post, name='Post')) +admin.add_view(ModelView(Event, name='Event')) from app.views import (general, users,
d617ce484c1c85032f6c792b7f03d7710df97acf
GoldenDictMedia/2.1/golden_dict_media/__init__.py
GoldenDictMedia/2.1/golden_dict_media/__init__.py
import aqt from golden_dict_media.AddonInitializer import init_addon if aqt.mw is not None: init_addon()
import aqt from .AddonInitializer import init_addon if aqt.mw is not None: init_addon()
Use relative paths in golden_dict_media
Use relative paths in golden_dict_media
Python
mit
searene/Anki-Addons,searene/Anki-Addons
--- +++ @@ -1,6 +1,6 @@ import aqt -from golden_dict_media.AddonInitializer import init_addon +from .AddonInitializer import init_addon if aqt.mw is not None: init_addon()
130dbb5003273e0681b35aa171c8c7e235fbbe59
src/bibim/lexer.py
src/bibim/lexer.py
# -*- coding: utf-8 -*- from __future__ import absolute_import from rply import LexerGenerator op_map = { 'NUMBER': r'\d[\d\s]*', 'PLUS': r'\+', 'MINUS': r'-', 'MUL': r'\*', 'NUMBER_SEP': r'/', 'EXPR_OPEN': r'\(', 'EXPR_CLOSE': r'\)', 'AND': r'&', 'OR': r'\|', 'NOT': r'!', 'EQ': r'\?\s*=', 'GT': r'>', 'LT': r'<', 'BOWL': r':', 'BOWL_OPEN': r'{', 'BOWL_CLOSE': r'}', 'NOODLE_OPEN': r'\[', 'NOODLE_SEP': r';', 'NOODLE_CLOSE': r'\]', 'ASSIGN': r'=', 'DENO': r'\^', 'MEM': r'@', } lg = LexerGenerator() for name, regex in op_map.items(): lg.add(name, regex) lg.ignore('\s+') lg.ignore('~\s*#((?!#~).)*#\s*~') lexer = lg.build()
# -*- coding: utf-8 -*- from __future__ import absolute_import from rply import LexerGenerator op_map = { 'NUMBER': r'\d[\d\s]*', 'PLUS': r'\+', 'MINUS': r'-', 'MUL': r'\*', 'NUMBER_SEP': r'/', 'EXPR_OPEN': r'\(', 'EXPR_CLOSE': r'\)', 'AND': r'&', 'OR': r'\|', 'NOT': r'!', 'EQ': r'\?\s*=', 'GT': r'>', 'LT': r'<', 'BOWL': r':', 'BOWL_OPEN': r'{', 'BOWL_CLOSE': r'}', 'NOODLE_OPEN': r'\[', 'NOODLE_SEP': r';', 'NOODLE_CLOSE': r'\]', 'ASSIGN': r'=', 'DENO': r'\^', 'MEM': r'@', } lg = LexerGenerator() for name, regex in op_map.items(): lg.add(name, regex) lg.ignore('\s+') lg.ignore('~\s*#((?!#~)[\s|\S])*#\s*~') lexer = lg.build()
Fix issue on multi-line comment
Fix issue on multi-line comment
Python
mit
bibim-lang/pybibim,rishubil/pybibim,bibim-lang/pybibim
--- +++ @@ -33,6 +33,6 @@ lg.add(name, regex) lg.ignore('\s+') -lg.ignore('~\s*#((?!#~).)*#\s*~') +lg.ignore('~\s*#((?!#~)[\s|\S])*#\s*~') lexer = lg.build()
5e736819e35efaad8568bb0782af3d256d55963d
game/quests/__init__.py
game/quests/__init__.py
# -*- coding: utf-8 -*- """ Quests - questcache.wdb """ from .. import * class Quest(Model): def getTooltip(self): return QuestTooltip(self) class QuestTooltip(Tooltip): def tooltip(self): self.append("name", self.obj.getName(), color=YELLOW) ret = self.values self.values = [] return ret class QuestProxy(object): """ WDBC proxy for quests """ def __init__(self, cls): from pywow import wdbc self.__file = wdbc.get("questcache.wdb", build=-1) def get(self, id): return self.__file[id] def getCompleteSummary(self, row): return row.complete_summary def getDescription(self, row): return row.description.replace("$B", "\n") def getName(self, row): return row.name def getSummary(self, row): return row.summary Quest.initProxy(QuestProxy)
# -*- coding: utf-8 -*- """ Quests - questcache.wdb """ from .. import * class Quest(Model): def getTooltip(self): return QuestTooltip(self) class QuestTooltip(Tooltip): def tooltip(self): self.append("name", self.obj.getName(), color=YELLOW) self.appendEmptyLine() self.append("objective", self.obj.getObjective()) self.appendEmptyLine() ret = self.values self.values = [] return ret class QuestProxy(object): """ WDBC proxy for quests """ def __init__(self, cls): from pywow import wdbc self.__file = wdbc.get("questcache.wdb", build=-1) def get(self, id): return self.__file[id] def getCompleteSummary(self, row): return row.complete_summary def getDescription(self, row): return row.description.replace("$B", "\n") def getName(self, row): return row.name def getObjective(self, row): return row.objective def getSummary(self, row): return row.summary Quest.initProxy(QuestProxy)
Implement getObjective and tooltip objective
game/quests: Implement getObjective and tooltip objective
Python
cc0-1.0
jleclanche/pywow,jleclanche/pywow,jleclanche/pywow,jleclanche/pywow,jleclanche/pywow,jleclanche/pywow
--- +++ @@ -15,6 +15,10 @@ def tooltip(self): self.append("name", self.obj.getName(), color=YELLOW) + self.appendEmptyLine() + + self.append("objective", self.obj.getObjective()) + self.appendEmptyLine() ret = self.values self.values = [] @@ -40,6 +44,9 @@ def getName(self, row): return row.name + def getObjective(self, row): + return row.objective + def getSummary(self, row): return row.summary