commit
stringlengths 40
40
| subject
stringlengths 4
1.73k
| repos
stringlengths 5
127k
| old_file
stringlengths 2
751
| new_file
stringlengths 2
751
| new_contents
stringlengths 1
8.98k
| old_contents
stringlengths 0
6.59k
| license
stringclasses 13
values | lang
stringclasses 23
values |
---|---|---|---|---|---|---|---|---|
f682300d4a8ab7e13ad0e26d2b37fdf24cdbdce9
|
Bump development version
|
stefanfoulis/django-filer,divio/django-filer,skirsdeda/django-filer,webu/django-filer,webu/django-filer,stefanfoulis/django-filer,webu/django-filer,divio/django-filer,stefanfoulis/django-filer,skirsdeda/django-filer,skirsdeda/django-filer,stefanfoulis/django-filer,webu/django-filer,skirsdeda/django-filer,divio/django-filer,skirsdeda/django-filer,divio/django-filer,stefanfoulis/django-filer
|
filer/__init__.py
|
filer/__init__.py
|
# -*- coding: utf-8 -*-
# version string following pep-0396 and pep-0386
__version__ = '1.2.6.rc2' # pragma: nocover
default_app_config = 'filer.apps.FilerConfig'
|
# -*- coding: utf-8 -*-
# version string following pep-0396 and pep-0386
__version__ = '1.2.6.rc1' # pragma: nocover
default_app_config = 'filer.apps.FilerConfig'
|
bsd-3-clause
|
Python
|
05c8dffcbfc08bbfd98d0f6a506af245719b3ac8
|
FIX dependency
|
ingadhoc/account-payment,ClearCorp/account-financial-tools,maljac/odoo-addons,ingadhoc/sale,dvitme/odoo-addons,adhoc-dev/odoo-addons,HBEE/odoo-addons,ingadhoc/partner,dvitme/odoo-addons,bmya/odoo-addons,sysadminmatmoz/ingadhoc,jorsea/odoo-addons,adhoc-dev/account-financial-tools,adhoc-dev/odoo-addons,bmya/odoo-addons,ingadhoc/odoo-addons,ingadhoc/sale,ingadhoc/product,ingadhoc/account-invoicing,bmya/odoo-addons,ingadhoc/odoo-addons,ingadhoc/sale,sysadminmatmoz/ingadhoc,adhoc-dev/account-financial-tools,ingadhoc/odoo-addons,HBEE/odoo-addons,ingadhoc/sale,HBEE/odoo-addons,jorsea/odoo-addons,dvitme/odoo-addons,ingadhoc/account-financial-tools,ingadhoc/product,sysadminmatmoz/ingadhoc,ingadhoc/account-analytic,maljac/odoo-addons,ClearCorp/account-financial-tools,maljac/odoo-addons,adhoc-dev/odoo-addons,jorsea/odoo-addons,ingadhoc/stock
|
stock_picking_ean128_report/__openerp__.py
|
stock_picking_ean128_report/__openerp__.py
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Stock Picking EAN128 Report',
'version': '1.0',
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
'description': """
Stock Picking EAN128 Report
===========================
""",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'images': [
],
'depends': [
'stock_ean128',
'report_aeroo',
],
'data': [
'wizard/stock_print_remit_view.xml',
'report/stock_report.xml'
],
'demo': [
],
'test': [
],
'installable': True,
'auto_install': False,
'application': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Stock Picking EAN128 Report',
'version': '1.0',
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
'description': """
Stock Picking EAN128 Report
===========================
""",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'images': [
],
'depends': [
'stock_ean128',
],
'data': [
'wizard/stock_print_remit_view.xml',
'report/stock_report.xml'
],
'demo': [
],
'test': [
],
'installable': True,
'auto_install': False,
'application': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
Python
|
9608fff230665f5120e6ea98d4ae0efc91a345ef
|
Revert "Add teuthology git version query/logging"
|
ceph/teuthology,dmick/teuthology,SUSE/teuthology,ktdreyer/teuthology,SUSE/teuthology,SUSE/teuthology,dmick/teuthology,ktdreyer/teuthology,ceph/teuthology,dmick/teuthology
|
teuthology/__init__.py
|
teuthology/__init__.py
|
from gevent import monkey
monkey.patch_all(
dns=False,
# Don't patch subprocess to avoid http://tracker.ceph.com/issues/14990
subprocess=False,
)
import sys
# Don't write pyc files
sys.dont_write_bytecode = True
from .orchestra import monkey
monkey.patch_all()
import logging
import os
__version__ = '0.1.0'
# If we are running inside a virtualenv, ensure we have its 'bin' directory in
# our PATH. This doesn't happen automatically if scripts are called without
# first activating the virtualenv.
exec_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
if os.path.split(exec_dir)[-1] == 'bin' and exec_dir not in os.environ['PATH']:
os.environ['PATH'] = ':'.join((exec_dir, os.environ['PATH']))
# We don't need to see log entries for each connection opened
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(
logging.WARN)
# if requests doesn't bundle it, shut it up anyway
logging.getLogger('urllib3.connectionpool').setLevel(
logging.WARN)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s')
log = logging.getLogger(__name__)
def setup_log_file(log_path):
root_logger = logging.getLogger()
handlers = root_logger.handlers
for handler in handlers:
if isinstance(handler, logging.FileHandler) and \
handler.stream.name == log_path:
log.debug("Already logging to %s; not adding new handler",
log_path)
return
formatter = logging.Formatter(
fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s',
datefmt='%Y-%m-%dT%H:%M:%S')
handler = logging.FileHandler(filename=log_path)
handler.setFormatter(formatter)
root_logger.addHandler(handler)
|
from gevent import monkey
monkey.patch_all(
dns=False,
# Don't patch subprocess to avoid http://tracker.ceph.com/issues/14990
subprocess=False,
)
import sys
# Don't write pyc files
sys.dont_write_bytecode = True
from .orchestra import monkey
monkey.patch_all()
import logging
import os
import subprocess
__version__ = '1.0.0'
# do our best, but if it fails, continue with above
try:
__version__ += '-' + subprocess.check_output(
'git rev-parse --short HEAD'.split(),
cwd=os.path.dirname(os.path.realpath(__file__))
).strip()
except Exception as e:
# before logging; should be unusual
print >>sys.stderr, 'Can\'t get version from git rev-parse', e
# If we are running inside a virtualenv, ensure we have its 'bin' directory in
# our PATH. This doesn't happen automatically if scripts are called without
# first activating the virtualenv.
exec_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
if os.path.split(exec_dir)[-1] == 'bin' and exec_dir not in os.environ['PATH']:
os.environ['PATH'] = ':'.join((exec_dir, os.environ['PATH']))
# We don't need to see log entries for each connection opened
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(
logging.WARN)
# if requests doesn't bundle it, shut it up anyway
logging.getLogger('urllib3.connectionpool').setLevel(
logging.WARN)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s')
log = logging.getLogger(__name__)
log.info('teuthology version: %s', __version__)
def setup_log_file(log_path):
root_logger = logging.getLogger()
handlers = root_logger.handlers
for handler in handlers:
if isinstance(handler, logging.FileHandler) and \
handler.stream.name == log_path:
log.debug("Already logging to %s; not adding new handler",
log_path)
return
formatter = logging.Formatter(
fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s',
datefmt='%Y-%m-%dT%H:%M:%S')
handler = logging.FileHandler(filename=log_path)
handler.setFormatter(formatter)
root_logger.addHandler(handler)
root_logger.log.info('teuthology version: %s', __version__)
|
mit
|
Python
|
0e4c8fb4965eadf8cf45ff0f6d3406df17015f46
|
remove print
|
Parisson/TimeSide,Parisson/TimeSide,Parisson/TimeSide,Parisson/TimeSide,Parisson/TimeSide
|
timeside/server/tasks.py
|
timeside/server/tasks.py
|
from __future__ import absolute_import
import time
import gc
from celery import shared_task
from celery.result import AsyncResult
from celery.result import GroupResult
from .models import Item, Selection, Preset, Experience, Task
from .models import _DONE
from celery.task import chord
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
@shared_task
def task_run(task_id):
task = Task.objects.get(uuid=task_id)
results = []
if task.selection:
for item in task.selection.get_all_items():
results.append(experience_run.delay(str(task.experience.uuid), str(item.uuid)))
results_id = [res.id for res in results]
elif task.item:
results.append(experience_run.delay(str(task.experience.uuid), str(task.item.uuid)))
results_id = [res.id for res in results]
task_monitor.delay(task_id, results_id)
@shared_task
def experience_run(exp_id, item_id):
item = Item.objects.get(uuid=item_id)
experience = Experience.objects.get(uuid=exp_id)
item.run(experience)
gc.collect()
@shared_task
def task_monitor(task_id, results_id):
results = [AsyncResult(id) for id in results_id]
while not all([res.ready() for res in results]):
time.sleep(1)
task = Task.objects.get(uuid=task_id)
task.status_setter(_DONE)
|
from __future__ import absolute_import
import time
import gc
from celery import shared_task
from celery.result import AsyncResult
from celery.result import GroupResult
from .models import Item, Selection, Preset, Experience, Task
from .models import _DONE
from celery.task import chord
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
@shared_task
def task_run(task_id):
print(task_id)
task = Task.objects.get(uuid=task_id)
results = []
if task.selection:
for item in task.selection.get_all_items():
results.append(experience_run.delay(str(task.experience.uuid), str(item.uuid)))
results_id = [res.id for res in results]
elif task.item:
results.append(experience_run.delay(str(task.experience.uuid), str(task.item.uuid)))
results_id = [res.id for res in results]
task_monitor.delay(task_id, results_id)
@shared_task
def experience_run(exp_id, item_id):
item = Item.objects.get(uuid=item_id)
experience = Experience.objects.get(uuid=exp_id)
item.run(experience)
gc.collect()
@shared_task
def task_monitor(task_id, results_id):
results = [AsyncResult(id) for id in results_id]
while not all([res.ready() for res in results]):
time.sleep(1)
task = Task.objects.get(uuid=task_id)
task.status_setter(_DONE)
|
agpl-3.0
|
Python
|
0138eacf0d518b86e819a70000b7b527434a6b35
|
Change les arguments passés à celery pour gérer la sérialisation JSON.
|
dezede/dezede,dezede/dezede,dezede/dezede,dezede/dezede
|
libretto/signals.py
|
libretto/signals.py
|
# coding: utf-8
from __future__ import unicode_literals
from celery_haystack.signals import CelerySignalProcessor
from django.contrib.admin.models import LogEntry
from django.contrib.sessions.models import Session
from reversion.models import Version, Revision
from .tasks import auto_invalidate
class CeleryAutoInvalidator(CelerySignalProcessor):
def enqueue(self, action, instance, sender, **kwargs):
if sender in (LogEntry, Session, Revision, Version):
return
auto_invalidate.delay(action, instance.__class__, instance.pk)
|
# coding: utf-8
from __future__ import unicode_literals
from celery_haystack.signals import CelerySignalProcessor
from django.contrib.admin.models import LogEntry
from reversion.models import Version, Revision
from .tasks import auto_invalidate
class CeleryAutoInvalidator(CelerySignalProcessor):
def enqueue(self, action, instance, sender, **kwargs):
if sender in (LogEntry, Revision, Version):
return
auto_invalidate.delay(action, instance)
|
bsd-3-clause
|
Python
|
eb102bb8550d59b34373f1806633a6079f7064a8
|
Make sure that all requests for static files are correctly hidden from output
|
caffodian/django-devserver,madgeekfiend/django-devserver,jimmyye/django-devserver,takeshineshiro/django-devserver,pjdelport/django-devserver,bastianh/django-devserver,Stackdriver/django-devserver,dcramer/django-devserver,chriscauley/django-devserver,coagulant/django-devserver,mathspace/django-devserver
|
devserver/utils/http.py
|
devserver/utils/http.py
|
from django.conf import settings
from django.core.servers.basehttp import WSGIRequestHandler
from django.db import connection
from devserver.utils.time import ms_from_timedelta
from datetime import datetime
class SlimWSGIRequestHandler(WSGIRequestHandler):
"""
Hides all requests that originate from either ``STATIC_URL`` or ``MEDIA_URL``
as well as any request originating with a prefix included in
``DEVSERVER_IGNORED_PREFIXES``.
"""
def handle(self, *args, **kwargs):
self._start_request = datetime.now()
return WSGIRequestHandler.handle(self, *args, **kwargs)
def log_message(self, format, *args):
duration = datetime.now() - self._start_request
env = self.get_environ()
for url in (settings.STATIC_URL, settings.MEDIA_URL):
if self.path.startswith(url):
return
elif url.startswith('http:'):
if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(url):
return
for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
if self.path.startswith(path):
return
format += " (time: %.2fs; sql: %dms (%dq))"
args = list(args) + [
ms_from_timedelta(duration) / 1000,
sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
len(connection.queries),
]
return WSGIRequestHandler.log_message(self, format, *args)
|
from django.conf import settings
from django.core.servers.basehttp import WSGIRequestHandler
from django.db import connection
from devserver.utils.time import ms_from_timedelta
from datetime import datetime
class SlimWSGIRequestHandler(WSGIRequestHandler):
"""
Hides all requests that originate from ```MEDIA_URL`` as well as any
request originating with a prefix included in ``DEVSERVER_IGNORED_PREFIXES``.
"""
def handle(self, *args, **kwargs):
self._start_request = datetime.now()
return WSGIRequestHandler.handle(self, *args, **kwargs)
def log_message(self, format, *args):
duration = datetime.now() - self._start_request
env = self.get_environ()
if settings.MEDIA_URL.startswith('http:'):
if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(settings.MEDIA_URL):
return
# if self.path.startswith(settings.MEDIA_URL):
# return
for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
if self.path.startswith(path):
return
format += " (time: %.2fs; sql: %dms (%dq))"
args = list(args) + [
ms_from_timedelta(duration) / 1000,
sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
len(connection.queries),
]
return WSGIRequestHandler.log_message(self, format, *args)
|
bsd-3-clause
|
Python
|
649d4b7fb22c92fa116fb574c1e4a07578ca6faa
|
Create methods for getting revisions.
|
xfix/NextBoard
|
forum/models.py
|
forum/models.py
|
from django.db import models
import django.contrib.auth.models as auth
class User(auth.User):
"""Model for representing users.
It has few fields that aren't in the standard authentication user
table, and are needed for the forum to work, like footers.
"""
display_name = models.CharField(max_length=30, null=True)
footer = models.TextField(null=True)
def __str__(self):
"""Show display name or user name."""
return self.display_name or self.username
class Thread(models.Model):
"""Model for representing threads."""
title = models.CharField(max_length=100)
views = models.PositiveIntegerField(default=0)
sticky = models.BooleanField(default=False)
closed = models.BooleanField(default=False)
def __str__(self):
"""Show thread title."""
return self.title
class Post(models.Model):
"""Model for representing posts.
Actual posts are stored in PostRevision, this only stores the
thread number. The first created revision contains the author
of post and date of its creation. The last revision contains actual
text post.
"""
thread = models.ForeignKey(Thread)
def first_revision(self):
return self.postrevision_set.first()
def last_revision(self):
return self.postrevision_set.last()
class PostRevision(models.Model):
"""Model for representing post revisions.
The first revision for given post contains its author and date to
show to the user. The last revision shows the date it was created
on.
"""
post = models.ForeignKey(Post)
author = models.ForeignKey(User)
date_created = models.DateTimeField(auto_now=True)
text = models.TextField()
class Meta:
ordering = ['date_created']
|
from django.db import models
import django.contrib.auth.models as auth
class User(auth.User):
"""Model for representing users.
It has few fields that aren't in the standard authentication user
table, and are needed for the forum to work, like footers.
"""
display_name = models.CharField(max_length=30, null=True)
footer = models.TextField(null=True)
def __str__(self):
"""Show display name or user name."""
return self.display_name or self.username
class Thread(models.Model):
"""Model for representing threads."""
title = models.CharField(max_length=100)
views = models.PositiveIntegerField(default=0)
sticky = models.BooleanField(default=False)
closed = models.BooleanField(default=False)
def __str__(self):
"""Show thread title."""
return self.title
class Post(models.Model):
"""Model for representing posts.
Actual posts are stored in PostRevision, this only stores the
thread number. The first created revision contains the author
of post and date of its creation. The last revision contains actual
text post.
"""
thread = models.ForeignKey(Thread)
class PostRevision(models.Model):
"""Model for representing post revisions.
The first revision for given post contains its author and date to
show to the user. The last revision shows the date it was created
on.
"""
post = models.ForeignKey(Post)
author = models.ForeignKey(User)
date_created = models.DateTimeField(auto_now=True)
text = models.TextField()
class Meta:
ordering = ['date_created']
|
mit
|
Python
|
65eb9bcd58d78fd80fabd03a26be73335f1a1122
|
Update ci nose config to run with four processes
|
slashk/goldstone-server,Solinea/goldstone-server,slashk/goldstone-server,Solinea/goldstone-server,slashk/goldstone-server,Solinea/goldstone-server,slashk/goldstone-server,Solinea/goldstone-server,slashk/goldstone-server,Solinea/goldstone-server
|
goldstone/settings/ci.py
|
goldstone/settings/ci.py
|
"""Settings for accessing a distributed docker instance."""
# Copyright 2015 Solinea, 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 .docker import * # pylint: disable=W0614,W0401
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get('GS_DEBUG', True))
TEMPLATE_DEBUG = bool(os.environ.get('GS_TEMPLATE_DEBUG', True))
STATIC_ROOT = os.path.join(os.getcwd(), 'static')
INSTALLED_APPS += (
'django_nose',
)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = (
'--verbosity=2',
'--detailed-errors',
'--with-xunit',
'--xunit-file=/reports/nosetests.xml',
'--with-coverage',
'--cover-package=goldstone',
'--processes=4',
)
|
"""Settings for accessing a distributed docker instance."""
# Copyright 2015 Solinea, 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 .docker import * # pylint: disable=W0614,W0401
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get('GS_DEBUG', True))
TEMPLATE_DEBUG = bool(os.environ.get('GS_TEMPLATE_DEBUG', True))
STATIC_ROOT = os.path.join(os.getcwd(), 'static')
INSTALLED_APPS += (
'django_nose',
)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = (
'--verbosity=2',
'--detailed-errors',
'--with-xunit',
'--xunit-file=/reports/nosetests.xml',
'--with-coverage',
'--cover-package=goldstone',
)
|
apache-2.0
|
Python
|
0fe56f804a7ed4958f33a534e30e3b6c79526ea6
|
Update SimplyPremiumCom.py
|
vuolter/pyload,vuolter/pyload,vuolter/pyload
|
module/plugins/accounts/SimplyPremiumCom.py
|
module/plugins/accounts/SimplyPremiumCom.py
|
# -*- coding: utf-8 -*-
from module.common.json_layer import json_loads
from module.plugins.Account import Account
class SimplyPremiumCom(Account):
__name__ = "SimplyPremiumCom"
__type__ = "account"
__version__ = "0.04"
__description__ = """Simply-Premium.com account plugin"""
__license__ = "GPLv3"
__authors__ = [("EvolutionClip", "[email protected]")]
def loadAccountInfo(self, user, req):
validuntil = -1
trafficleft = None
json_data = req.load('http://www.simply-premium.com/api/user.php?format=json')
self.logDebug("JSON data: " + json_data)
json_data = json_loads(json_data)
if 'vip' in json_data['result'] and json_data['result']['vip'] == 0:
return {"premium": False}
if 'timeend' in json_data['result'] and json_data['result']['timeend']:
validuntil = float(json_data['result']['timeend'])
if 'traffic' in json_data['result'] and json_data['result']['remain_traffic']:
trafficleft = float(json_data['result']['remain_traffic']) / 1024 #@TODO: Remove `/ 1024` in 0.4.10
return {"premium": True, "validuntil": validuntil, "trafficleft": trafficleft}
def login(self, user, data, req):
req.cj.setCookie("simply-premium.com", "lang", "EN")
if data['password'] == '' or data['password'] == '0':
post_data = {"key": user}
else:
post_data = {"login_name": user, "login_pass": data['password']}
html = req.load("http://www.simply-premium.com/login.php", post=post_data, decode=True)
if 'logout' not in html:
self.wrongPassword()
|
# -*- coding: utf-8 -*-
from module.common.json_layer import json_loads
from module.plugins.Account import Account
class SimplyPremiumCom(Account):
__name__ = "SimplyPremiumCom"
__type__ = "account"
__version__ = "0.03"
__description__ = """Simply-Premium.com account plugin"""
__license__ = "GPLv3"
__authors__ = [("EvolutionClip", "[email protected]")]
def loadAccountInfo(self, user, req):
validuntil = -1
trafficleft = None
json_data = req.load('http://www.simply-premium.com/api/user.php?format=json')
self.logDebug("JSON data: " + json_data)
json_data = json_loads(json_data)
if 'vip' in json_data['result'] and json_data['result']['vip'] == 0:
return {"premium": False}
if 'timeend' in json_data['result'] and json_data['result']['timeend']:
validuntil = float(json_data['result']['timeend'])
if 'traffic' in json_data['result'] and json_data['result']['traffic']:
trafficleft = float(json_data['result']['traffic']) / 1024 #@TODO: Remove `/ 1024` in 0.4.10
return {"premium": True, "validuntil": validuntil, "trafficleft": trafficleft}
def login(self, user, data, req):
req.cj.setCookie("simply-premium.com", "lang", "EN")
if data['password'] == '' or data['password'] == '0':
post_data = {"key": user}
else:
post_data = {"login_name": user, "login_pass": data['password']}
html = req.load("http://www.simply-premium.com/login.php", post=post_data, decode=True)
if 'logout' not in html:
self.wrongPassword()
|
agpl-3.0
|
Python
|
187e8237f9ba56dc517b2ad6e58be3e8031fa9df
|
Update __init__.py
|
rushter/MLAlgorithms
|
examples/__init__.py
|
examples/__init__.py
|
# coding: utf-8
import sys
sys.path.append("./examples")
|
# coding: utf-8
# In[1]:
import sys
sys.path.append("./examples")#add the examples as a module
|
mit
|
Python
|
9ee0ad7dfad15e3d933b4d1c3fab508d99480748
|
Fix example.
|
kubkon/gmm
|
examples/faithful.py
|
examples/faithful.py
|
import numpy as np
import matplotlib.pyplot as plt
from gmm.algorithm import GMM
# Read in dataset from file
with open('faithful.txt', 'rt') as f:
data = []
for row in f:
cols = row.strip('\r\n').split(' ')
data.append(np.fromiter(map(lambda x: float(x), cols), np.float))
data = np.array(data)
# Initialize GMM algorithm
means = np.array([np.array([4.0, 80], np.float), np.array([2.0, 55], np.float)])
covariances = np.array([np.identity(2), np.identity(2)])
mixing_probs = np.array([1/2, 1/2], np.float)
gmm_model = GMM(means, covariances, mixing_probs)
# Fit GMM to the data
gmm_model.fit(data)
# Cluster data
labelled = gmm_model.cluster(data)
# Plot clustered data with the location of Gaussian mixtures
plt.figure()
# Plot contours of Gaussian mixtures
for mean, cov in zip(gmm_model.means, gmm_model.covariances):
# Create grid
mean_x = mean[0]
std_x = np.sqrt(cov[0][0])
mean_y = mean[1]
std_y = np.sqrt(cov[1][1])
x = np.linspace(mean_x - 3*std_x, mean_x + 3*std_x, 100)
y = np.linspace(mean_y - 3*std_y, mean_y + 3*std_y, 100)
X, Y = np.meshgrid(x, y)
# Tabulate pdf values
Z = np.empty(X.shape, np.float)
for i in np.arange(X.shape[0]):
for j in np.arange(X.shape[1]):
v = np.array([X[i][j], Y[i][j]])
Z[i][j] = gmm_model.multivariate_normal_pdf(v, mean, cov)
# Plot contours
plt.contour(X, Y, Z)
# Plot features assigned to each Gaussian mixture
markers = ['o', '+']
colors = ['r', 'b']
for d, l in zip(data, labelled):
plt.scatter(d[0], d[1], color=colors[l], marker=markers[l])
plt.savefig('scatter_plot.pdf')
|
import numpy as np
import matplotlib.pyplot as plt
from gmm.algorithm import GMM
# Read in dataset from file
with open('faithful.txt', 'rt') as f:
data = []
for row in f:
cols = row.strip('\r\n').split(' ')
data.append(np.fromiter(map(lambda x: float(x), cols), np.float))
data = np.array(data)
# Initialize GMM algorithm
means = np.array([np.array([4.0, 80], np.float), np.array([2.0, 55], np.float)])
covariances = np.array([np.identity(3), np.identity(2)])
mixing_probs = np.array([1/2, 1/2], np.float)
gmm_model = GMM(means, covariances, mixing_probs)
# Fit GMM to the data
gmm_model.fit(data)
# Cluster data
labelled = gmm_model.cluster(data)
# Plot clustered data with the location of Gaussian mixtures
plt.figure()
# Plot contours of Gaussian mixtures
for mean, cov in zip(gmm_model.means, gmm_model.covariances):
# Create grid
mean_x = mean[0]
std_x = np.sqrt(cov[0][0])
mean_y = mean[1]
std_y = np.sqrt(cov[1][1])
x = np.linspace(mean_x - 3*std_x, mean_x + 3*std_x, 100)
y = np.linspace(mean_y - 3*std_y, mean_y + 3*std_y, 100)
X, Y = np.meshgrid(x, y)
# Tabulate pdf values
Z = np.empty(X.shape, np.float)
for i in np.arange(X.shape[0]):
for j in np.arange(X.shape[1]):
v = np.array([X[i][j], Y[i][j]])
Z[i][j] = gmm_model.multivariate_normal_pdf(v, mean, cov)
# Plot contours
plt.contour(X, Y, Z)
# Plot features assigned to each Gaussian mixture
markers = ['o', '+']
colors = ['r', 'b']
for d, l in zip(data, labelled):
plt.scatter(d[0], d[1], color=colors[l], marker=markers[l])
plt.savefig('scatter_plot.pdf')
|
mit
|
Python
|
2c09c700b524a7272436feff19c4128ca3211725
|
Update word2vec.py
|
cvangysel/pyndri,cvangysel/pyndri
|
examples/word2vec.py
|
examples/word2vec.py
|
import copy
import gensim
import logging
import pyndri
import sys
logging.basicConfig(level=logging.INFO)
if len(sys.argv) <= 1:
logging.error('Usage: python %s <path-to-indri-index>'.format(sys.argv[0]))
sys.exit(0)
logging.info('Initializing word2vec.')
word2vec_init = gensim.models.Word2Vec(
size=300, # Embedding size
window=5, # One-sided window size
sg=True, # Skip-gram.
min_count=5, # Minimum word frequency.
sample=1e-3, # Sub-sample threshold.
hs=False, # Hierarchical softmax.
negative=10, # Number of negative examples.
iter=1, # Number of iterations.
workers=8, # Number of workers.
)
with pyndri.open(sys.argv[1]) as index:
logging.info('Loading vocabulary.')
dictionary = pyndri.extract_dictionary(index)
sentences = pyndri.compat.IndriSentences(index, dictionary)
logging.info('Constructing word2vec vocabulary.')
# Build vocab.
word2vec_init.build_vocab(sentences, trim_rule=None)
models = [word2vec_init]
for epoch in range(1, 5 + 1):
logging.info('Epoch %d', epoch)
model = copy.deepcopy(models[-1])
model.train(sentences)
models.append(model)
logging.info('Trained models: %s', models)
|
import copy
import gensim
import logging
import pyndri
import sys
logging.basicConfig(level=logging.INFO)
if len(sys.argv) <= 1:
logging.error('Usage: python %s <path-to-indri-index>'.format(sys.argv[0]))
sys.exit(0)
logging.info('Initializing word2vec.')
word2vec_init = gensim.models.Word2Vec(
size=300, # Embedding size
window=5, # One-sided window size
sg=True, # Skip-gram.
min_count=5, # Minimum word frequency.
sample=1e-3, # Sub-sample treshold.
hs=False, # Hierarchical softmax.
negative=10, # Number of negative examples.
iter=1, # Number of iterations.
workers=8, # Number of workers.
)
with pyndri.open(sys.argv[1]) as index:
logging.info('Loading vocabulary.')
dictionary = pyndri.extract_dictionary(index)
sentences = pyndri.compat.IndriSentences(index, dictionary)
logging.info('Constructing word2vec vocabulary.')
# Build vocab.
word2vec_init.build_vocab(sentences, trim_rule=None)
models = [word2vec_init]
for epoch in range(1, 5 + 1):
logging.info('Epoch %d', epoch)
model = copy.deepcopy(models[-1])
model.train(sentences)
models.append(model)
logging.info('Trained models: %s', models)
|
mit
|
Python
|
2ece6032b2344e3cf6304a757714d0ecf5015324
|
split drive controller to allow other pwm interface eg raspy juice
|
FishPi/FishPi-POCV---Command---Control,FishPi/FishPi-POCV---Command---Control
|
fishpi/vehicle/test_drive.py
|
fishpi/vehicle/test_drive.py
|
#!/usr/bin/python
#
# FishPi - An autonomous drop in the ocean
#
# Simple test of PWM motor and servo drive
#
import raspberrypi
from time import sleep
from drive_controller import AdafruitDriveController
if __name__ == "__main__":
print "testing drive controller..."
drive = AdafruitDriveController(debug=True, i2c_bus=raspberrypi.i2c_bus())
print "run full ahead for 5 sec..."
drive.set_throttle(1.0)
sleep(5)
print "run 50% ahead for 5 sec..."
drive.set_throttle(0.5)
sleep(5)
print "run 0% for 5 sec..."
drive.set_throttle(0.0)
sleep(5)
print "run 50% reverse for 5 sec"
drive.set_throttle(-0.5)
sleep(5)
print "run full reverse for 5 sec"
drive.set_throttle(-1.0)
sleep(5)
print "and back to neutral..."
drive.set_throttle(0.0)
sleep(5)
print "check out of bounds errors"
try:
drive.set_throttle(15.0)
except ValueError:
print "caught 15"
try:
drive.set_throttle(-10.0)
except ValueError:
print "caught -10"
# test steering
print "steer hard to port for 5 sec"
drive.set_heading(-0.785398)
sleep(5)
print "steer to port for 5 sec"
drive.set_heading(-0.3927)
sleep(5)
print "and back to neutral..."
drive.set_heading(0.0)
sleep(5)
print "steer to starboard for 5 sec"
drive.set_heading(0.3927)
sleep(5)
print "steer hard to starboard for 5 sec"
drive.set_heading(0.785398)
sleep(5)
print "and back to neutral..."
drive.set_heading(0.0)
sleep(5)
|
#!/usr/bin/python
#
# FishPi - An autonomous drop in the ocean
#
# Simple test of PWM motor and servo drive
#
import raspberrypi
from time import sleep
from drive_controller import DriveController
if __name__ == "__main__":
print "testing drive controller..."
drive = DriveController(debug=True, i2c_bus=raspberrypi.i2c_bus())
print "run full ahead for 5 sec..."
drive.set_throttle(1.0)
sleep(5)
print "run 50% ahead for 5 sec..."
drive.set_throttle(0.5)
sleep(5)
print "run 0% for 5 sec..."
drive.set_throttle(0.0)
sleep(5)
print "run 50% reverse for 5 sec"
drive.set_throttle(-0.5)
sleep(5)
print "run full reverse for 5 sec"
drive.set_throttle(-1.0)
sleep(5)
print "and back to neutral..."
drive.set_throttle(0.0)
sleep(5)
print "check out of bounds errors"
try:
drive.set_throttle(15.0)
except ValueError:
print "caught 15"
try:
drive.set_throttle(-10.0)
except ValueError:
print "caught -10"
# test steering
print "steer hard to port for 5 sec"
drive.set_heading(-0.785398)
sleep(5)
print "steer to port for 5 sec"
drive.set_heading(-0.3927)
sleep(5)
print "and back to neutral..."
drive.set_heading(0.0)
sleep(5)
print "steer to starboard for 5 sec"
drive.set_heading(0.3927)
sleep(5)
print "steer hard to starboard for 5 sec"
drive.set_heading(0.785398)
sleep(5)
print "and back to neutral..."
drive.set_heading(0.0)
sleep(5)
|
bsd-2-clause
|
Python
|
3566c7689f59715f2d58886f52d3dd0c00a0ce4e
|
change manage.py
|
fortyMiles/my-family,fortyMiles/my-family,fortyMiles/my-family
|
maili-develop/manage.py
|
maili-develop/manage.py
|
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
if 'test' in sys.argv:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.settings")
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "maili.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
|
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "maili.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
|
bsd-3-clause
|
Python
|
ed267933edf8b6e2e2b63d11ece7457943fe9646
|
Add documentation for powerline.lib.shell.run_cmd
|
bartvm/powerline,lukw00/powerline,Luffin/powerline,cyrixhero/powerline,xxxhycl2010/powerline,EricSB/powerline,prvnkumar/powerline,wfscheper/powerline,blindFS/powerline,QuLogic/powerline,seanfisk/powerline,Liangjianghao/powerline,S0lll0s/powerline,bezhermoso/powerline,kenrachynski/powerline,russellb/powerline,russellb/powerline,xfumihiro/powerline,bezhermoso/powerline,bartvm/powerline,lukw00/powerline,firebitsbr/powerline,IvanAli/powerline,prvnkumar/powerline,blindFS/powerline,kenrachynski/powerline,dragon788/powerline,junix/powerline,darac/powerline,s0undt3ch/powerline,Liangjianghao/powerline,junix/powerline,QuLogic/powerline,EricSB/powerline,kenrachynski/powerline,wfscheper/powerline,DoctorJellyface/powerline,DoctorJellyface/powerline,Luffin/powerline,firebitsbr/powerline,darac/powerline,magus424/powerline,S0lll0s/powerline,junix/powerline,firebitsbr/powerline,EricSB/powerline,Liangjianghao/powerline,s0undt3ch/powerline,Luffin/powerline,xfumihiro/powerline,S0lll0s/powerline,QuLogic/powerline,bezhermoso/powerline,areteix/powerline,xfumihiro/powerline,xxxhycl2010/powerline,prvnkumar/powerline,wfscheper/powerline,dragon788/powerline,seanfisk/powerline,darac/powerline,blindFS/powerline,areteix/powerline,magus424/powerline,s0undt3ch/powerline,russellb/powerline,bartvm/powerline,areteix/powerline,IvanAli/powerline,dragon788/powerline,xxxhycl2010/powerline,lukw00/powerline,cyrixhero/powerline,seanfisk/powerline,IvanAli/powerline,magus424/powerline,cyrixhero/powerline,DoctorJellyface/powerline
|
powerline/lib/shell.py
|
powerline/lib/shell.py
|
# vim:fileencoding=utf-8:noet
from __future__ import absolute_import, unicode_literals, division, print_function
from subprocess import Popen, PIPE
from locale import getlocale, getdefaultlocale, LC_MESSAGES
def _get_shell_encoding():
return getlocale(LC_MESSAGES)[1] or getdefaultlocale()[1] or 'utf-8'
def run_cmd(pl, cmd, stdin=None):
'''Run command and return its stdout, stripped
If running command fails returns None and logs failure to ``pl`` argument.
:param PowerlineLogger pl:
Logger used to log failures.
:param list cmd:
Command which will be run.
:param str stdin:
String passed to command. May be None.
'''
try:
p = Popen(cmd, stdout=PIPE, stdin=PIPE)
except OSError as e:
pl.exception('Could not execute command ({0}): {1}', e, cmd)
return None
else:
stdout, err = p.communicate(stdin)
stdout = stdout.decode(_get_shell_encoding())
return stdout.strip()
def asrun(pl, ascript):
'''Run the given AppleScript and return the standard output and error.'''
return run_cmd(pl, ['osascript', '-'], ascript)
def readlines(cmd, cwd):
'''Run command and read its output, line by line
:param list cmd:
Command which will be run.
:param str cwd:
Working directory of the command which will be run.
'''
p = Popen(cmd, shell=False, stdout=PIPE, stderr=PIPE, cwd=cwd)
encoding = _get_shell_encoding()
p.stderr.close()
with p.stdout:
for line in p.stdout:
yield line[:-1].decode(encoding)
|
# vim:fileencoding=utf-8:noet
from __future__ import absolute_import, unicode_literals, division, print_function
from subprocess import Popen, PIPE
from locale import getlocale, getdefaultlocale, LC_MESSAGES
def _get_shell_encoding():
return getlocale(LC_MESSAGES)[1] or getdefaultlocale()[1] or 'utf-8'
def run_cmd(pl, cmd, stdin=None):
try:
p = Popen(cmd, stdout=PIPE, stdin=PIPE)
except OSError as e:
pl.exception('Could not execute command ({0}): {1}', e, cmd)
return None
else:
stdout, err = p.communicate(stdin)
stdout = stdout.decode(_get_shell_encoding())
return stdout.strip()
def asrun(pl, ascript):
'''Run the given AppleScript and return the standard output and error.'''
return run_cmd(pl, ['osascript', '-'], ascript)
def readlines(cmd, cwd):
'''Run command and read its output, line by line
:param list cmd:
Command which will be run.
:param str cwd:
Working directory of the command which will be run.
'''
p = Popen(cmd, shell=False, stdout=PIPE, stderr=PIPE, cwd=cwd)
encoding = _get_shell_encoding()
p.stderr.close()
with p.stdout:
for line in p.stdout:
yield line[:-1].decode(encoding)
|
mit
|
Python
|
be8fd3f10dbfd8e2099a046340a8e51758e60bd5
|
Add signout view so we can signout (by entering url manually)
|
markpasc/makerbase,markpasc/makerbase
|
makerbase/views/auth.py
|
makerbase/views/auth.py
|
import json
from urllib import urlencode
from urlparse import parse_qs, urlsplit, urlunsplit
from flask import redirect, request, url_for
from flaskext.login import LoginManager, login_user, logout_user
import requests
from makerbase import app
from makerbase.models import User
login_manager = LoginManager()
login_manager.setup_app(app, add_context_processor=True)
login_manager.user_loader(User.get)
@app.route('/signin/github')
def signin_github():
urlparts = urlsplit(request.base_url)
params = {
'client_id': app.config['GITHUB_CLIENT_ID'],
'redirect_url': urlunsplit((urlparts.scheme, urlparts.netloc, url_for('complete_github'), None, None)),
'scope': '',
}
redirect_url = 'https://github.com/login/oauth/authorize?%s' % urlencode(params)
return redirect(redirect_url)
@app.route('/signout')
def signout():
logout_user()
return redirect(url_for('home'))
@app.route('/complete/github')
def complete_github():
try:
code = request.args.get('code')
except KeyError:
raise # TODO
params = {
'client_id': app.config['GITHUB_CLIENT_ID'],
'client_secret': app.config['GITHUB_SECRET'],
'code': code,
}
token_resp = requests.post('https://github.com/login/oauth/access_token', data=params)
token_params = parse_qs(token_resp.content)
access_token = token_params['access_token']
user_resp = requests.get('https://api.github.com/user', data={'access_token': access_token})
github_user = json.loads(user_resp.content)
userid = u"github:%s" % github_user['login']
user = User.get(userid)
if user is None:
user = User(userid)
user.name = github_user['name']
user.avatar_url = github_user['avatar_url']
user.profile_url = github_user['html_url']
user.save()
login_user(user)
return redirect(url_for('home'))
|
import json
from urllib import urlencode
from urlparse import parse_qs, urlsplit, urlunsplit
from flask import redirect, request, url_for
from flaskext.login import LoginManager, login_user
import requests
from makerbase import app
from makerbase.models import User
login_manager = LoginManager()
login_manager.setup_app(app, add_context_processor=True)
login_manager.user_loader(User.get)
@app.route('/signin/github')
def signin_github():
urlparts = urlsplit(request.base_url)
params = {
'client_id': app.config['GITHUB_CLIENT_ID'],
'redirect_url': urlunsplit((urlparts.scheme, urlparts.netloc, url_for('complete_github'), None, None)),
'scope': '',
}
redirect_url = 'https://github.com/login/oauth/authorize?%s' % urlencode(params)
return redirect(redirect_url)
@app.route('/complete/github')
def complete_github():
try:
code = request.args.get('code')
except KeyError:
raise # TODO
params = {
'client_id': app.config['GITHUB_CLIENT_ID'],
'client_secret': app.config['GITHUB_SECRET'],
'code': code,
}
token_resp = requests.post('https://github.com/login/oauth/access_token', data=params)
token_params = parse_qs(token_resp.content)
access_token = token_params['access_token']
user_resp = requests.get('https://api.github.com/user', data={'access_token': access_token})
github_user = json.loads(user_resp.content)
userid = u"github:%s" % github_user['login']
user = User.get(userid)
if user is None:
user = User(userid)
user.name = github_user['name']
user.avatar_url = github_user['avatar_url']
user.profile_url = github_user['html_url']
user.save()
login_user(user)
return redirect(url_for('home'))
|
mit
|
Python
|
df27f7ad62eebf29b42bfa9b2bce7d73739c4a8e
|
Fix minor template modernization bug
|
aptiko/enhydris,ellak-monades-aristeias/enhydris,openmeteo/enhydris,ellak-monades-aristeias/enhydris,kickapoo/enhydris,aptiko/enhydris,openmeteo/enhydris,kickapoo/enhydris,ellak-monades-aristeias/enhydris,kickapoo/enhydris,aptiko/enhydris,openmeteo/enhydris
|
enhydris/conf/settings.py
|
enhydris/conf/settings.py
|
# Enhydris settings for {{ project_name }} project.
#
# Generated by 'enhydris-admin newinstance' using Enhydris {{ enhydris_version }}
# and Django {{ django_version }}.
#
# For more information on this file, see
# http://enhydris.readthedocs.org/en/{{ enhydris_docs_version }}/general/install.html#settings-reference
from enhydris.settings.base import *
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# SECURITY_WARNING: Keep the secret key used in production secret!
SECRET_KEY = '{{ secret_key }}'
# List the domains through which this instance will be accessible. Enhydris
# will refuse to serve other domains.
ALLOWED_HOSTS = ['example.com']
# Administrators who will be notified whenever attention is needed.
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
# Whenever the system emails users, this is the address from which the emails
# will appear to have been sent.
DEFAULT_FROM_EMAIL = '[email protected]'
# Whenever the system emails administrators, this is the address from which the
# emails will appear to have been sent.
SERVER_EMAIL = DEFAULT_FROM_EMAIL
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'enhydris_db',
'USER': 'enhydris_user',
'PASSWORD': 'topsecret',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Default system timezone, such as 'Europe/Athens'.
TIME_ZONE = 'UTC'
# You should probably leave this as it is. See the installation instructions if
# in doubt.
SITE_ID = 1
# Where static files will be stored. By "static" files we mean css, javascript,
# and images of the skin. These files will be copied there at installation
# time when executing "python manage.py collectstatic".
STATIC_ROOT = '/var/cache/enhydris/static/'
# Where media files will be stored. "media" files are static files uploaded
# by users, e.g. images and videos of stations. The web server must be
# configured to map the URL /enhydris-media/ to that directory. See the
# installation instructions for more information.
MEDIA_ROOT = '/var/lib/enhydris/media/'
# The web server must be configured to map the URLs below to the directories
# specified by STATIC_ROOT and MEDIA_ROOT above. Enhydris will use the settings
# below to create appropriate links.
STATIC_URL = '/enhydris-static/'
MEDIA_URL = '/enhydris-media/'
# Mail server settings; used whenever the system needs to email users or
# admins.
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.example.com'
EMAIL_HOST_USER = 'emailuser'
EMAIL_HOST_PASSWORD = 'topsecret'
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# The above are only the settings that are absolutely essential. Check the
# installation instructions for more settings that you can set.
|
# Enhydris settings for {{ project_name }} project.
#
# Generated by 'enhydris-admin newinstance' using Enhydris {{ enhydris_version }}
# and Django {{ django_version }}.
#
# For more information on this file, see
# http://enhydris.readthedocs.org/en/{{ enhydris_docs_version }}/general/install.html#settings-reference
from enhydris.settings.base import *
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = DEBUG
# SECURITY_WARNING: Keep the secret key used in production secret!
SECRET_KEY = '{{ secret_key }}'
# List the domains through which this instance will be accessible. Enhydris
# will refuse to serve other domains.
ALLOWED_HOSTS = ['example.com']
# Administrators who will be notified whenever attention is needed.
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
# Whenever the system emails users, this is the address from which the emails
# will appear to have been sent.
DEFAULT_FROM_EMAIL = '[email protected]'
# Whenever the system emails administrators, this is the address from which the
# emails will appear to have been sent.
SERVER_EMAIL = DEFAULT_FROM_EMAIL
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'enhydris_db',
'USER': 'enhydris_user',
'PASSWORD': 'topsecret',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Default system timezone, such as 'Europe/Athens'.
TIME_ZONE = 'UTC'
# You should probably leave this as it is. See the installation instructions if
# in doubt.
SITE_ID = 1
# Where static files will be stored. By "static" files we mean css, javascript,
# and images of the skin. These files will be copied there at installation
# time when executing "python manage.py collectstatic".
STATIC_ROOT = '/var/cache/enhydris/static/'
# Where media files will be stored. "media" files are static files uploaded
# by users, e.g. images and videos of stations. The web server must be
# configured to map the URL /enhydris-media/ to that directory. See the
# installation instructions for more information.
MEDIA_ROOT = '/var/lib/enhydris/media/'
# The web server must be configured to map the URLs below to the directories
# specified by STATIC_ROOT and MEDIA_ROOT above. Enhydris will use the settings
# below to create appropriate links.
STATIC_URL = '/enhydris-static/'
MEDIA_URL = '/enhydris-media/'
# Mail server settings; used whenever the system needs to email users or
# admins.
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.example.com'
EMAIL_HOST_USER = 'emailuser'
EMAIL_HOST_PASSWORD = 'topsecret'
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# The above are only the settings that are absolutely essential. Check the
# installation instructions for more settings that you can set.
|
agpl-3.0
|
Python
|
4464919c5114193179490c151844fd771bfd880b
|
fix setup without flask installed
|
salsita/flask-ecstatic
|
flask_ecstatic.py
|
flask_ecstatic.py
|
"""Serves static files with optional directory index.
Files in static folder are automatically served on static URL by Flask.
See http://flask.pocoo.org/docs/0.10/api/#application-object.
It's recommended to specify static folder and URL path directly on Flask application object,
unless you need additional static folders, or have multiple route handlers for the URL path,
e.g. when serving static files on root URL ('') for any path unmatched with previous routes.
"""
__all__ = 'add'.split()
__version__ = '0.1.1'
import os
def add(app, url = None, path = None, endpoint=None, index='index.html', send_from_directory=None):
"""Adds static files endpoint with optional directory index."""
if not send_from_directory:
from flask import send_from_directory
url = url or app.static_url_path or ''
path = os.path.abspath(path or app.static_folder or '.')
endpoint = endpoint or 'static_' + os.path.basename(path)
if path == app.static_folder:
if url != app.static_url_path:
raise ValueError('Files in `{}` path are automatically served on `{}` URL by Flask.'
' Use different path for serving them at `{}` URL'.format(path, app.static_url_path, url))
else:
@app.route(url + '/<path:filename>', endpoint = endpoint)
def static_files(filename):
return send_from_directory(path, filename)
if index:
@app.route(url + '/', endpoint = endpoint + '_index')
def static_index():
return send_from_directory(path, index)
if url:
@app.route(url, endpoint = endpoint + '_index_bare')
def static_index_bare():
return send_from_directory(path, index)
|
"""Serves static files with optional directory index.
Files in static folder are automatically served on static URL by Flask.
See http://flask.pocoo.org/docs/0.10/api/#application-object.
It's recommended to specify static folder and URL path directly on Flask application object,
unless you need additional static folders, or have multiple route handlers for the URL path,
e.g. when serving static files on root URL ('') for any path unmatched with previous routes.
"""
__all__ = 'add'.split()
__version__ = '0.1.1'
import os
from flask import send_from_directory
def add(app, url = None, path = None, endpoint=None, index='index.html'):
"""Adds static files endpoint with optional directory index."""
url = url or app.static_url_path or ''
path = os.path.abspath(path or app.static_folder or '.')
endpoint = endpoint or 'static_' + os.path.basename(path)
if path == app.static_folder:
if url != app.static_url_path:
raise ValueError('Files in `{}` path are automatically served on `{}` URL by Flask.'
' Use different path for serving them at `{}` URL'.format(path, app.static_url_path, url))
else:
@app.route(url + '/<path:filename>', endpoint = endpoint)
def static_files(filename):
return send_from_directory(path, filename)
if index:
@app.route(url + '/', endpoint = endpoint + '_index')
def static_index():
return send_from_directory(path, index)
if url:
@app.route(url, endpoint = endpoint + '_index_bare')
def static_index_bare():
return send_from_directory(path, index)
|
mit
|
Python
|
b83e371f37477b5eaf552ac78383e3f0ac94bc21
|
Change in presseurop RSS feed
|
Konubinix/weboob,willprice/weboob,sputnick-dev/weboob,laurent-george/weboob,sputnick-dev/weboob,nojhan/weboob-devel,RouxRC/weboob,eirmag/weboob,Boussadia/weboob,yannrouillard/weboob,RouxRC/weboob,frankrousseau/weboob,Boussadia/weboob,Boussadia/weboob,laurent-george/weboob,RouxRC/weboob,yannrouillard/weboob,franek/weboob,eirmag/weboob,Boussadia/weboob,willprice/weboob,eirmag/weboob,frankrousseau/weboob,Konubinix/weboob,franek/weboob,frankrousseau/weboob,sputnick-dev/weboob,franek/weboob,willprice/weboob,yannrouillard/weboob,Konubinix/weboob,nojhan/weboob-devel,nojhan/weboob-devel,laurent-george/weboob
|
modules/presseurop/backend.py
|
modules/presseurop/backend.py
|
# -*- coding: utf-8 -*-
# Copyright(C) 2012 Florent Fourcot
#
# This file is part of weboob.
#
# weboob 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.
#
# weboob 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 weboob. If not, see <http://www.gnu.org/licenses/>.
"backend for http://www.presseurop.eu"
from weboob.capabilities.messages import ICapMessages, Thread
from weboob.tools.capabilities.messages.GenericBackend import GenericNewspaperBackend
from weboob.tools.backend import BackendConfig
from weboob.tools.value import Value
from .browser import NewspaperPresseuropBrowser
from .tools import rssid, url2id
from weboob.tools.newsfeed import Newsfeed
class NewspaperPresseuropBackend(GenericNewspaperBackend, ICapMessages):
MAINTAINER = 'Florent Fourcot'
EMAIL = '[email protected]'
VERSION = '0.d'
LICENSE = 'AGPLv3+'
STORAGE = {'seen': {}}
NAME = 'presseurop'
DESCRIPTION = u'Presseurop website'
BROWSER = NewspaperPresseuropBrowser
RSSID = staticmethod(rssid)
URL2ID = staticmethod(url2id)
RSSSIZE = 140
CONFIG = BackendConfig(Value('lang', label='Lang of articles',
choices={'fr': 'fr', 'de': 'de', 'en': 'en', 'cs': 'cs', 'es': 'es', 'it': 'it', 'nl': 'nl', 'pl': 'pl', 'pt': 'pt', 'ro': 'ro'}, default='fr'))
def __init__(self, *args, **kwargs):
GenericNewspaperBackend.__init__(self, *args, **kwargs)
self.RSS_FEED = 'http://www.presseurop.eu/%s/rss.xml' % (self.config['lang'].get())
def iter_threads(self):
for article in Newsfeed(self.RSS_FEED, self.RSSID).iter_entries():
thread = Thread(article.link)
thread.title = article.title
thread.date = article.datetime
yield(thread)
|
# -*- coding: utf-8 -*-
# Copyright(C) 2012 Florent Fourcot
#
# This file is part of weboob.
#
# weboob 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.
#
# weboob 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 weboob. If not, see <http://www.gnu.org/licenses/>.
"backend for http://www.presseurop.eu"
from weboob.capabilities.messages import ICapMessages, Thread
from weboob.tools.capabilities.messages.GenericBackend import GenericNewspaperBackend
from weboob.tools.backend import BackendConfig
from weboob.tools.value import Value
from .browser import NewspaperPresseuropBrowser
from .tools import rssid, url2id
from weboob.tools.newsfeed import Newsfeed
class NewspaperPresseuropBackend(GenericNewspaperBackend, ICapMessages):
MAINTAINER = 'Florent Fourcot'
EMAIL = '[email protected]'
VERSION = '0.d'
LICENSE = 'AGPLv3+'
STORAGE = {'seen': {}}
NAME = 'presseurop'
DESCRIPTION = u'Presseurop website'
BROWSER = NewspaperPresseuropBrowser
RSSID = staticmethod(rssid)
URL2ID = staticmethod(url2id)
RSSSIZE = 50
CONFIG = BackendConfig(Value('lang', label='Lang of articles',
choices={'fr': 'fr', 'de': 'de', 'en': 'en', 'cs': 'cs', 'es': 'es', 'it': 'it', 'nl': 'nl', 'pl': 'pl', 'pt': 'pt', 'ro': 'ro'}, default='fr'))
def __init__(self, *args, **kwargs):
GenericNewspaperBackend.__init__(self, *args, **kwargs)
self.RSS_FEED = 'http://www.presseurop.eu/%s/rss.xml' % (self.config['lang'].get())
def iter_threads(self):
for article in Newsfeed(self.RSS_FEED, self.RSSID).iter_entries():
thread = Thread(article.link)
thread.title = article.title
thread.date = article.datetime
yield(thread)
|
agpl-3.0
|
Python
|
a3ae8a7ece6bc75437b9848cf43335690250c128
|
exit http server gracefully
|
regadas/presstatic
|
presstatic/__main__.py
|
presstatic/__main__.py
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import argparse
import SimpleHTTPServer
import SocketServer
from clint.textui import colored, puts, indent
from presstatic import help
from presstatic.builders import SiteBuilder
from presstatic.storage import s3
def http_server(host, port, dir):
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
os.chdir(dir)
httpd = SocketServer.TCPServer((host, int(port)), Handler)
with indent(4, quote='>>'):
puts(colored.green("Serving {path}".format(path=dir)))
puts(colored.yellow("@ {host}:{port} ".format(host=host, port=port)))
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
def main():
cli_parser = argparse.ArgumentParser(prog='presstatic')
cli_parser.add_argument('-output',
help="relative directory for the generated files.",
default='public')
cli_parser.add_argument('-http',
metavar='HOST:PORT',
help="creates an HTTP Server with <directory> as root dir.")
cli_parser.add_argument('-s3',
help="deploy on the specified S3 bucket.",
metavar='bucket')
cli_parser.add_argument('directory',
help='directory containing the static website.')
cli_args = cli_parser.parse_args()
site_builder = SiteBuilder(cli_args.directory, output=cli_args.output)
site_builder.build()
if cli_args.http:
host, port = cli_args.http.split(':')
root_dir = os.path.join(cli_args.directory, cli_args.output)
http_server(host, port, root_dir)
elif cli_args.s3:
s3.S3Storage(cli_args.s3).store(site_builder.output_path)
puts(help.s3_setup(bucket=cli_args.s3))
if __name__ == '__main__':
main()
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import argparse
import SimpleHTTPServer
import SocketServer
from clint.textui import colored, puts, indent
from presstatic import help
from presstatic.builders import SiteBuilder
from presstatic.storage import s3
def http_server_on_dir(host, port, dir):
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
os.chdir(dir)
httpd = SocketServer.TCPServer((host, int(port)), Handler)
with indent(4, quote='>>'):
puts(colored.green("Serving {path}".format(path=dir)))
puts(colored.yellow("@ {host}:{port} ".format(host=host, port=port)))
httpd.serve_forever()
def main():
cli_parser = argparse.ArgumentParser(prog='presstatic')
cli_parser.add_argument('-output',
help="relative directory for the generated files.",
default='public')
cli_parser.add_argument('-http',
metavar='HOST:PORT',
help="creates an HTTP Server with <directory> as root dir.")
cli_parser.add_argument('-s3',
help="deploy on the specified S3 bucket.",
metavar='bucket')
cli_parser.add_argument('directory',
help='directory containing the static website.')
cli_args = cli_parser.parse_args()
site_builder = SiteBuilder(cli_args.directory, output=cli_args.output)
site_builder.build()
if cli_args.http:
host, port = cli_args.http.split(':')
root_dir = os.path.join(cli_args.directory, cli_args.output)
http_server_on_dir(host, port, root_dir)
elif cli_args.s3:
s3.S3Storage(cli_args.s3).store(site_builder.output_path)
puts(help.s3_setup(bucket=cli_args.s3))
if __name__ == '__main__':
main()
|
mit
|
Python
|
9381657d8ad2e96c2537c89fad7a4b3d8d8ddff5
|
Add gpu parameter to htcondor_at_vispa example.
|
riga/law,riga/law
|
examples/htcondor_at_vispa/analysis/framework.py
|
examples/htcondor_at_vispa/analysis/framework.py
|
# -*- coding: utf-8 -*-
"""
Law example tasks to demonstrate HTCondor workflows at VISPA.
In this file, some really basic tasks are defined that can be inherited by
other tasks to receive the same features. This is usually called "framework"
and only needs to be defined once per user / group / etc.
"""
import os
import luigi
import law
import law.contrib.htcondor
class Task(law.Task):
"""
Base task that we use to force a version parameter on all inheriting tasks, and that provides
some convenience methods to create local file and directory targets at the default data path.
"""
version = luigi.Parameter()
def store_parts(self):
return (self.__class__.__name__, self.version)
def local_path(self, *path):
# ANALYSIS_DATA_PATH is defined in setup.sh
parts = (os.getenv("ANALYSIS_DATA_PATH"),) + self.store_parts() + path
return os.path.join(*parts)
def local_target(self, *path):
return law.LocalFileTarget(self.local_path(*path))
class HTCondorWorkflow(law.contrib.htcondor.HTCondorWorkflow):
"""
Batch systems are typically very heterogeneous by design, and so is HTCondor. Law does not aim
to "magically" adapt to all possible HTCondor setups which would certainly end in a mess.
Therefore we have to configure the base HTCondor workflow in law.contrib.htcondor to work with
the VISPA environment. In most cases, like in this example, only a minimal amount of
configuration is required.
"""
htcondor_gpus = luigi.IntParameter(default=law.NO_INT, significant=False, desription="number "
"of GPUs to request on the VISPA cluster, leave empty to use only CPUs")
def htcondor_output_directory(self):
# the directory where submission meta data should be stored
return law.LocalDirectoryTarget(self.local_path())
def htcondor_create_job_file_factory(self):
# tell the factory, which is responsible for creating our job files,
# that the files are not temporary, i.e., it should not delete them after submission
factory = super(HTCondorWorkflow, self).htcondor_create_job_file_factory()
factory.is_tmp = False
return factory
def htcondor_bootstrap_file(self):
# each job can define a bootstrap file that is executed prior to the actual job
# in order to setup software and environment variables
return law.util.rel_path(__file__, "bootstrap.sh")
def htcondor_job_config(self, config, job_num, branches):
# render_data is rendered into all files sent with a job
config.render_variables["analysis_path"] = os.getenv("ANALYSIS_PATH")
# tell the job config if GPUs are requested
if not law.is_no_param(self.htcondor_gpus):
config.custom_config = [("request_gpus", self.htcondor_gpus)]
return config
|
# -*- coding: utf-8 -*-
"""
Law example tasks to demonstrate HTCondor workflows at VISPA.
In this file, some really basic tasks are defined that can be inherited by
other tasks to receive the same features. This is usually called "framework"
and only needs to be defined once per user / group / etc.
"""
import os
import luigi
import law
import law.contrib.htcondor
class Task(law.Task):
"""
Base task that we use to force a version parameter on all inheriting tasks, and that provides
some convenience methods to create local file and directory targets at the default data path.
"""
version = luigi.Parameter()
def store_parts(self):
return (self.__class__.__name__, self.version)
def local_path(self, *path):
# ANALYSIS_DATA_PATH is defined in setup.sh
parts = (os.getenv("ANALYSIS_DATA_PATH"),) + self.store_parts() + path
return os.path.join(*parts)
def local_target(self, *path):
return law.LocalFileTarget(self.local_path(*path))
class HTCondorWorkflow(law.contrib.htcondor.HTCondorWorkflow):
"""
Batch systems are typically very heterogeneous by design, and so is HTCondor. Law does not aim
to "magically" adapt to all possible HTCondor setups which would certainly end in a mess.
Therefore we have to configure the base HTCondor workflow in law.contrib.htcondor to work with
the VISPA environment. In most cases, like in this example, only a minimal amount of
configuration is required.
"""
def htcondor_output_directory(self):
# the directory where submission meta data should be stored
return law.LocalDirectoryTarget(self.local_path())
def htcondor_create_job_file_factory(self):
# tell the factory, which is responsible for creating our job files,
# that the files are not temporary, i.e., it should not delete them after submission
factory = super(HTCondorWorkflow, self).htcondor_create_job_file_factory()
factory.is_tmp = False
return factory
def htcondor_bootstrap_file(self):
# each job can define a bootstrap file that is executed prior to the actual job
# in order to setup software and environment variables
return law.util.rel_path(__file__, "bootstrap.sh")
def htcondor_job_config(self, config, job_num, branches):
# render_data is rendered into all files sent with a job
config.render_variables["analysis_path"] = os.getenv("ANALYSIS_PATH")
return config
|
bsd-3-clause
|
Python
|
a5de78328cc2e63c901c409fb6c7b376abf921e2
|
reorganize code the object oriented way
|
enricobacis/cineca-scopus
|
src/scopus.py
|
src/scopus.py
|
from itertools import chain
import requests
_HEADERS = {'Accept': 'application/json'}
class ScopusResponse(object):
def __init__(self, data):
self._data = data
def __getitem__(self, key):
return self._data['search-results'][key]
def __iter__(self):
resp = self
while resp:
yield resp
resp = resp.next()
def entries(self):
return [] if self.is_empty() else self['entry']
def is_empty(self):
return int(self['opensearch:totalResults']) == 0
def next_page_url(self):
try: return next(l['@href'] for l in self['link'] if l['@ref']=='next')
except: return None
def next(self):
url = self.next_page_url()
if not url: return None
return ScopusResponse(requests.get(url, headers=_HEADERS).json())
def all_entries(self):
return list(chain.from_iterable(page.entries() for page in self))
class ScopusClient(object):
_AUTHOR_API = 'http://api.elsevier.com/content/search/author'
_SCOPUS_API = 'http://api.elsevier.com/content/search/scopus'
def __init__(self, apiKey):
self.apiKey = apiKey
def _api(self, endpoint, query):
resp = requests.get(endpoint, headers=_HEADERS,
params={'apiKey': self.apiKey, 'query': query})
return ScopusResponse(resp.json())
def authorSearch(self, query):
return self._api(self._AUTHOR_API, query)
def scopusSearch(self, query):
return self._api(self._SCOPUS_API, query)
def get_scopus_entries(self, same_author_ids):
query = ' OR '.join('AU-ID(%s)' % ID for ID in same_author_ids)
return self.scopusSearch(query).all_entries()
def get_authors(self, first, last, affil, subjabbr):
query = ('authlast(%s) AND authfirst(%s) AND affil(%s) AND subjabbr(%s)'
% (last, first, affil, subjabbr))
return self.authorSearch(query).all_entries()
|
import requests
class ScopusClient(object):
_AUTHOR_API = 'http://api.elsevier.com/content/search/author'
_SCOPUS_API = 'http://api.elsevier.com/content/search/scopus'
_HEADERS = {'Accept': 'application/json'}
def __init__(self, apiKey):
self.apiKey = apiKey
def _api(self, endpoint, query, parse=False):
resp = requests.get(endpoint, headers=self._HEADERS,
params={'apiKey': self.apiKey, 'query': query})
return resp.json() if parse else resp
def _is_empty(self, resp):
return int(resp['search-results']['opensearch:totalResults']) == 0
def _all_pages(self, resp):
if not self._is_empty(resp):
while True:
yield resp
try:
url = next(li['@href']
for li in resp['search-results']['link']
if li['@ref'] == 'next')
resp = requests.get(url, headers=self._HEADERS).json()
except: break
def authorSearch(self, query, parse=False):
return self._api(self._AUTHOR_API, query, parse)
def scopusSearch(self, query, parse=False):
return self._api(self._SCOPUS_API, query, parse)
def get_scopus_entries(self, same_author_ids):
query = ' OR '.join('AU-ID(%s)' % ID for ID in same_author_ids)
resp = self.scopusSearch(query, parse=True)
return [entry for page in self._all_pages(resp)
for entry in page['search-results']['entry']]
def get_authors(self, first, last, affil, subjabbr):
query = ('authlast(%s) AND authfirst(%s) AND affil(%s) AND subjabbr(%s)'
% (last, first, affil, subjabbr))
resp = self.authorSearch(query, parse=True)
return [] if self._is_empty(resp) else resp['search-results']['entry']
|
mit
|
Python
|
0bf9c011ca36df2d72dfd3b8fc59f6320e837e43
|
Update __init__.py
|
DMOJ/judge,DMOJ/judge,DMOJ/judge
|
dmoj/cptbox/__init__.py
|
dmoj/cptbox/__init__.py
|
from collections import defaultdict
from dmoj.cptbox.sandbox import SecurePopen, PIPE
from dmoj.cptbox.handlers import DISALLOW, ALLOW
from dmoj.cptbox.chroot import CHROOTSecurity
from dmoj.cptbox.syscalls import SYSCALL_COUNT
if sys.version_info.major == 2:
range = xrange
class NullSecurity(defaultdict):
def __init__(self):
for i in range(SYSCALL_COUNT):
self[i] = ALLOW
|
from collections import defaultdict
from dmoj.cptbox.sandbox import SecurePopen, PIPE
from dmoj.cptbox.handlers import DISALLOW, ALLOW
from dmoj.cptbox.chroot import CHROOTSecurity
from dmoj.cptbox.syscalls import SYSCALL_COUNT
class NullSecurity(defaultdict):
def __init__(self):
for i in xrange(SYSCALL_COUNT):
self[i] = ALLOW
|
agpl-3.0
|
Python
|
ca050969d1267d13986a0494a86f7fd50616937e
|
Remove old code.
|
HackatONG-ProgramAR/resoluciones-unc,HackatONG-ProgramAR/resoluciones-unc
|
process/scripts/run.py
|
process/scripts/run.py
|
"""
Document processing script. Does NER for persons, dates, etc.
Usage:
process.py <dbname>
process.py -h | --help | --version
Options:
-h --help Show this screen
--version Version number
"""
import logging
from docopt import docopt
from iepy.db import connect, DocumentManager
from iepy.preprocess import PreProcessPipeline
from process.settings import pipeline_steps
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('process')
opts = docopt(__doc__, version=0.1)
connect(opts['<dbname>'])
docs = DocumentManager()
pipeline = PreProcessPipeline(pipeline_steps, docs)
pipeline.process_everything()
|
"""
Document processing script. Does NER for persons, dates, etc.
Usage:
process.py <dbname>
process.py -h | --help | --version
Options:
-h --help Show this screen
--version Version number
"""
import logging
from docopt import docopt
from iepy.db import connect, DocumentManager
from iepy.preprocess import PreProcessPipeline
from process.settings import pipeline_steps
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('process')
opts = docopt(__doc__, version=0.1)
connect(opts['<dbname>'])
docs = DocumentManager()
"""set_custom_entity_kinds(zip(map(lambda x: x.lower(), CUSTOM_ENTITIES),
CUSTOM_ENTITIES))"""
pipeline = PreProcessPipeline(pipeline_steps, docs)
pipeline.process_everything()
|
bsd-3-clause
|
Python
|
9bc1c77250d338ca93ff33d2832c2b3117b3550e
|
Use the raw domain for Netflix, because there's only one now
|
foauth/foauth.org,foauth/foauth.org,foauth/foauth.org
|
services/netflix.py
|
services/netflix.py
|
import urlparse
import foauth.providers
from oauthlib.oauth1.rfc5849 import SIGNATURE_TYPE_QUERY
class Netflix(foauth.providers.OAuth1):
# General info about the provider
provider_url = 'https://www.netflix.com/'
favicon_url = 'https://netflix.hs.llnwd.net/e1/en_US/icons/nficon.ico'
docs_url = 'http://developer.netflix.com/docs'
category = 'Movies/TV'
# URLs to interact with the API
request_token_url = 'http://api-public.netflix.com/oauth/request_token'
authorize_url = 'https://api-user.netflix.com/oauth/login'
access_token_url = 'http://api-public.netflix.com/oauth/access_token'
api_domain = 'api-public.netflix.com'
available_permissions = [
(None, 'read and manage your queue'),
]
https = False
signature_type = SIGNATURE_TYPE_QUERY
def get_authorize_params(self, *args, **kwargs):
params = super(Netflix, self).get_authorize_params(*args, **kwargs)
params['oauth_consumer_key'] = self.client_id
return params
def get_user_id(self, key):
r = self.api(key, self.api_domain, u'/users/current',
params={'output': 'json'})
redirect = r.json[u'resource'][u'link'][u'href']
parts = urlparse.urlparse(redirect)
r = self.api(key, parts.netloc, parts.path,
params={'output': 'json'})
return r.json[u'user'][u'user_id']
|
import urlparse
import foauth.providers
from oauthlib.oauth1.rfc5849 import SIGNATURE_TYPE_QUERY
class Netflix(foauth.providers.OAuth1):
# General info about the provider
provider_url = 'https://www.netflix.com/'
favicon_url = 'https://netflix.hs.llnwd.net/e1/en_US/icons/nficon.ico'
docs_url = 'http://developer.netflix.com/docs'
category = 'Movies/TV'
# URLs to interact with the API
request_token_url = 'http://api-public.netflix.com/oauth/request_token'
authorize_url = 'https://api-user.netflix.com/oauth/login'
access_token_url = 'http://api-public.netflix.com/oauth/access_token'
api_domain = 'api-public.netflix.com'
available_permissions = [
(None, 'read and manage your queue'),
]
https = False
signature_type = SIGNATURE_TYPE_QUERY
def get_authorize_params(self, *args, **kwargs):
params = super(Netflix, self).get_authorize_params(*args, **kwargs)
params['oauth_consumer_key'] = self.client_id
return params
def get_user_id(self, key):
r = self.api(key, self.api_domains[0], u'/users/current',
params={'output': 'json'})
redirect = r.json[u'resource'][u'link'][u'href']
parts = urlparse.urlparse(redirect)
r = self.api(key, parts.netloc, parts.path,
params={'output': 'json'})
return r.json[u'user'][u'user_id']
|
bsd-3-clause
|
Python
|
87cc7ccb8626d9e236954cce0667167f5f9742be
|
fix prometheus test
|
uw-it-aca/uw-restclients-core,uw-it-aca/uw-restclients-core
|
restclients_core/tests/test_prometheus.py
|
restclients_core/tests/test_prometheus.py
|
from restclients_core.tests.dao_implementation.test_live import TDAO
from unittest import TestCase, skipUnless
from prometheus_client import generate_latest, REGISTRY
import os
@skipUnless("RUN_LIVE_TESTS" in os.environ, "RUN_LIVE_TESTS=1 to run tests")
class TestPrometheusObservations(TestCase):
def test_prometheus_observation(self):
response = TDAO().getURL('/ok', {})
metrics = generate_latest(REGISTRY).decode('utf-8')
self.assertRegexpMatches(
metrics,
r'.*\nrestclient_request_duration_seconds_bucket{le="0.005",'
r'service="backend_test"} [1-9].*', metrics)
self.assertRegexpMatches(
metrics,
r'.*\nrestclient_response_status_code_bucket{le="200.0",'
r'service="backend_test"} [1-9].*', metrics)
self.assertIn('restclient_request_timeout_total counter', metrics)
self.assertIn('restclient_request_ssl_error_total counter', metrics)
|
from restclients_core.tests.dao_implementation.test_backend import TDAO
from unittest import TestCase
from prometheus_client import generate_latest, REGISTRY
class TestPrometheusObservations(TestCase):
def test_prometheus_observation(self):
metrics = generate_latest(REGISTRY).decode('utf-8')
self.assertRegexpMatches(
metrics,
r'.*\nrestclient_request_duration_seconds_bucket{le="0.005",'
r'service="backend_test"} [1-9].*', metrics)
self.assertRegexpMatches(
metrics,
r'.*\nrestclient_response_status_code_bucket{le="200.0",'
r'service="backend_test"} [1-9].*', metrics)
self.assertIn('restclient_request_timeout_total counter', metrics)
self.assertIn('restclient_request_ssl_error_total counter', metrics)
|
apache-2.0
|
Python
|
fa78baf7eb05e465ac265fad02de763e0ab56403
|
Speed up cache keys generation
|
MahjongRepository/tenhou-python-bot,MahjongRepository/tenhou-python-bot
|
project/utils/cache.py
|
project/utils/cache.py
|
import hashlib
import marshal
from typing import List, Optional
from utils.decisions_logger import MeldPrint
def build_shanten_cache_key(tiles_34: List[int], open_sets_34: Optional[List[List[int]]], use_chiitoitsu: bool):
prepared_array = tiles_34 + [200] + (open_sets_34 and [x for x in open_sets_34] or []) + [use_chiitoitsu and 1 or 0]
return hashlib.md5(marshal.dumps(prepared_array)).hexdigest()
def build_estimate_hand_value_cache_key(
tiles_136: List[int], is_riichi: bool, is_tsumo: bool, melds: List[MeldPrint], dora_indicators: List[int]
):
prepared_array = (
tiles_136
+ [is_tsumo and 1 or 0]
+ [is_riichi and 1 or 0]
+ [200] # to be sure that hand and meld tiles will not be mixed together
+ (melds and [x.tiles for x in melds] or [])
+ [200]
+ dora_indicators
)
return hashlib.md5(marshal.dumps(prepared_array)).hexdigest()
|
from typing import List, Optional
from mahjong.tile import TilesConverter
from utils.decisions_logger import MeldPrint
def build_shanten_cache_key(tiles_34: List[int], open_sets_34: Optional[List[List[int]]], use_chiitoitsu: bool):
cache_key = "{},{},{}".format(
"".join([str(x) for x in tiles_34]),
open_sets_34 and ";".join([str(x) for x in open_sets_34]) or "",
use_chiitoitsu and 1 or 0,
)
return cache_key
def build_estimate_hand_value_cache_key(
tiles_136: List[int], is_riichi: bool, is_tsumo: bool, melds: List[MeldPrint], dora_indicators: List[int]
):
cache_key = "{}.{}.{}.{}.{}".format(
TilesConverter.to_one_line_string(tiles_136),
is_tsumo and 1 or 0,
is_riichi and 1 or 0,
",".join([";".join([str(x) for x in x.tiles]) for x in melds]),
",".join([str(x) for x in dora_indicators]),
)
return cache_key
|
mit
|
Python
|
62404979e69ccd129f8382e8a2fce5329c577a78
|
fix version
|
hsharrison/experimentator
|
experimentator/__version__.py
|
experimentator/__version__.py
|
__version__ = '0.2.0dev5'
|
__version__ = '0.2.0.dev5'
|
mit
|
Python
|
3471381b5894536142a9460410e0efe5e8b1b294
|
make doc regex more lenient
|
mitsuhiko/flask-website,mitsuhiko/flask-website,mitsuhiko/flask-website
|
flask_website/docs.py
|
flask_website/docs.py
|
# -*- coding: utf-8 -*-
import os
import re
from flask import url_for, Markup
from flask_website import app
from flask_website.search import Indexable
_doc_body_re = re.compile(r'''(?smx)
<title>(.*?)</title>.*?
<div.*?class=".*?body.*?>(.*)
<div.*?class=".*?sphinxsidebar
''')
class DocumentationPage(Indexable):
search_document_kind = 'documentation'
def __init__(self, slug):
self.slug = slug
fn = os.path.join(app.config['DOCUMENTATION_PATH'],
slug, 'index.html')
with open(fn) as f:
contents = f.read().decode('utf-8')
title, text = _doc_body_re.search(contents).groups()
self.title = Markup(title).striptags().split(u'—')[0].strip()
self.text = Markup(text).striptags().strip().replace(u'¶', u'')
def get_search_document(self):
return dict(
id=unicode(self.slug),
title=self.title,
keywords=[],
content=self.text
)
@property
def url(self):
return url_for('docs.show', page=self.slug)
@classmethod
def describe_search_result(cls, result):
rv = cls(result['id'])
return Markup(result.highlights('content', text=rv.text)) or None
@classmethod
def iter_pages(cls):
base_folder = os.path.abspath(app.config['DOCUMENTATION_PATH'])
for dirpath, dirnames, filenames in os.walk(base_folder):
if 'index.html' in filenames:
slug = dirpath[len(base_folder) + 1:]
# skip the index page. useless
if slug:
yield DocumentationPage(slug)
|
# -*- coding: utf-8 -*-
import os
import re
from flask import url_for, Markup
from flask_website import app
from flask_website.search import Indexable
_doc_body_re = re.compile(r'''(?smx)
<title>(.*?)</title>.*?
<div\s+class="body">(.*?)<div\s+class="sphinxsidebar">
''')
class DocumentationPage(Indexable):
search_document_kind = 'documentation'
def __init__(self, slug):
self.slug = slug
fn = os.path.join(app.config['DOCUMENTATION_PATH'],
slug, 'index.html')
with open(fn) as f:
contents = f.read().decode('utf-8')
title, text = _doc_body_re.search(contents).groups()
self.title = Markup(title).striptags().split(u'—')[0].strip()
self.text = Markup(text).striptags().strip().replace(u'¶', u'')
def get_search_document(self):
return dict(
id=unicode(self.slug),
title=self.title,
keywords=[],
content=self.text
)
@property
def url(self):
return url_for('docs.show', page=self.slug)
@classmethod
def describe_search_result(cls, result):
rv = cls(result['id'])
return Markup(result.highlights('content', text=rv.text)) or None
@classmethod
def iter_pages(cls):
base_folder = os.path.abspath(app.config['DOCUMENTATION_PATH'])
for dirpath, dirnames, filenames in os.walk(base_folder):
if 'index.html' in filenames:
slug = dirpath[len(base_folder) + 1:]
# skip the index page. useless
if slug:
yield DocumentationPage(slug)
|
bsd-3-clause
|
Python
|
98e899d5e76f8bee5c288bffe78ccf943665693c
|
Fix white space to be 4 spaces
|
adadlani/hello-world,adadlani/hello-world
|
get_cve_data.py
|
get_cve_data.py
|
# Script to import CVE data from NIST https://nvd.nist.gov/vuln/data-feeds#JSON_FEED
# https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-modified.json.gz
import gzip
import json
import pycurl
from io import BytesIO
NVD_CVE_ENDPOINT = 'https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-modified.json.gz'
DATA_FILE = './data.json.gz'
with open(DATA_FILE, 'wb') as fd:
c = pycurl.Curl()
c.setopt(c.URL, NVD_CVE_ENDPOINT)
c.setopt(c.WRITEDATA, fd)
c.perform()
if c.getinfo(c.RESPONSE_CODE) != 200:
print('data request failed')
exit(1)
# Close Curl
c.close()
# Test: Ensure we received a valid gzip file
# Extract gzip and load JSON to in-memory
with gzip.open(DATA_FILE, 'rt') as fd:
data = json.load(fd)
# Read in-memory JSON structure keys
# CVE_data_version
# CVE_data_format
# CVE_Items
# CVE_data_timestamp
# CVE_data_numberOfCVEs
# CVE_data_type
print('CVE_data_version:', data['CVE_data_version'])
print('CVE_data_format:', data['CVE_data_format'])
print('CVE_data_timestamp:', data['CVE_data_timestamp'])
print('CVE_data_numberOfCVEs:', data['CVE_data_numberOfCVEs'])
print('CVE_data_type:', data['CVE_data_type'])
count = 0
for item in data['CVE_Items']:
if 'cve' in item:
if 'CVE_data_meta' in item['cve']:
if 'ID' in item['cve']['CVE_data_meta']:
#print(item['cve']['CVE_data_meta']['ID'])
count = count + 1
|
# Script to import CVE data from NIST https://nvd.nist.gov/vuln/data-feeds#JSON_FEED
# https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-modified.json.gz
import gzip
import json
import pycurl
from io import BytesIO
NVD_CVE_ENDPOINT = 'https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-modified.json.gz'
DATA_FILE = './data.json.gz'
with open(DATA_FILE, 'wb') as fd:
c = pycurl.Curl()
c.setopt(c.URL, NVD_CVE_ENDPOINT)
c.setopt(c.WRITEDATA, fd)
c.perform()
if c.getinfo(c.RESPONSE_CODE) != 200:
print('data request failed')
exit(1)
# Close Curl
c.close()
# Test: Ensure we received a valid gzip file
# Extract gzip and load JSON to in-memory
with gzip.open(DATA_FILE, 'rt') as fd:
data = json.load(fd)
# Read in-memory JSON structure keys
# CVE_data_version
# CVE_data_format
# CVE_Items
# CVE_data_timestamp
# CVE_data_numberOfCVEs
# CVE_data_type
print('CVE_data_version:', data['CVE_data_version'])
print('CVE_data_format:', data['CVE_data_format'])
print('CVE_data_timestamp:', data['CVE_data_timestamp'])
print('CVE_data_numberOfCVEs:', data['CVE_data_numberOfCVEs'])
print('CVE_data_type:', data['CVE_data_type'])
count = 0
for item in data['CVE_Items']:
if 'cve' in item:
if 'CVE_data_meta' in item['cve']:
if 'ID' in item['cve']['CVE_data_meta']:
#print(item['cve']['CVE_data_meta']['ID'])
count = count + 1
|
apache-2.0
|
Python
|
5e3a4c84d31fe63a67fdb2e64c5edc1ffe8d24ab
|
Tweak return message
|
gazpachoking/Flexget,Flexget/Flexget,LynxyssCZ/Flexget,Danfocus/Flexget,gazpachoking/Flexget,Danfocus/Flexget,qk4l/Flexget,JorisDeRieck/Flexget,crawln45/Flexget,jawilson/Flexget,qk4l/Flexget,malkavi/Flexget,jacobmetrick/Flexget,malkavi/Flexget,Danfocus/Flexget,drwyrm/Flexget,ianstalk/Flexget,jacobmetrick/Flexget,malkavi/Flexget,poulpito/Flexget,jawilson/Flexget,OmgOhnoes/Flexget,OmgOhnoes/Flexget,qk4l/Flexget,Flexget/Flexget,malkavi/Flexget,crawln45/Flexget,tobinjt/Flexget,ianstalk/Flexget,JorisDeRieck/Flexget,LynxyssCZ/Flexget,jacobmetrick/Flexget,jawilson/Flexget,sean797/Flexget,LynxyssCZ/Flexget,crawln45/Flexget,sean797/Flexget,poulpito/Flexget,Danfocus/Flexget,JorisDeRieck/Flexget,tobinjt/Flexget,JorisDeRieck/Flexget,poulpito/Flexget,OmgOhnoes/Flexget,ianstalk/Flexget,jawilson/Flexget,LynxyssCZ/Flexget,tobinjt/Flexget,tobinjt/Flexget,drwyrm/Flexget,drwyrm/Flexget,sean797/Flexget,Flexget/Flexget,Flexget/Flexget,crawln45/Flexget
|
flexget/api/cached.py
|
flexget/api/cached.py
|
from __future__ import unicode_literals, division, absolute_import
from builtins import * # pylint: disable=unused-import, redefined-builtin
from flask.helpers import send_file
from flask_restplus import inputs
from flexget.api import api, APIResource, APIError, BadRequest
from flexget.utils.tools import cached_resource
from requests import RequestException
cached_api = api.namespace('cached', description='Cache remote resources')
cached_parser = api.parser()
cached_parser.add_argument('url', required=True, help='URL to cache')
cached_parser.add_argument('force', type=inputs.boolean, default=False, help='Force fetching remote resource')
@cached_api.route('/')
@api.doc(description='Returns a cached copy of the requested resource, matching its mime type')
class CachedResource(APIResource):
@api.response(200, description='Cached resource')
@api.response(BadRequest)
@api.response(APIError)
@api.doc(parser=cached_parser)
def get(self, session=None):
""" Cache remote resources """
args = cached_parser.parse_args()
url = args.get('url')
force = args.get('force')
try:
file_path, mime_type = cached_resource(url, force)
except RequestException as e:
raise BadRequest('Request Error: {}'.format(e.args[0]))
except OSError as e:
raise APIError('Error: {}'.format(e.args[0]))
return send_file(file_path, mimetype=mime_type)
|
from __future__ import unicode_literals, division, absolute_import
from builtins import * # pylint: disable=unused-import, redefined-builtin
from flask.helpers import send_file
from flask_restplus import inputs
from flexget.api import api, APIResource, APIError, BadRequest
from flexget.utils.tools import cached_resource
from requests import RequestException
cached_api = api.namespace('cached', description='Cache remote resources')
cached_parser = api.parser()
cached_parser.add_argument('url', required=True, help='URL to cache')
cached_parser.add_argument('force', type=inputs.boolean, default=False, help='Force fetching remote resource')
@cached_api.route('/')
@api.doc(description='Returns a cached copy of the requested resource, matching its mime type')
class CachedResource(APIResource):
@api.response(200, description='Return file')
@api.response(BadRequest)
@api.response(APIError)
@api.doc(parser=cached_parser)
def get(self, session=None):
""" Cache remote resources """
args = cached_parser.parse_args()
url = args.get('url')
force = args.get('force')
try:
file_path, mime_type = cached_resource(url, force)
except RequestException as e:
raise BadRequest('Request Error: {}'.format(e.args[0]))
except OSError as e:
raise APIError('Error: {}'.format(e.args[0]))
return send_file(file_path, mimetype=mime_type)
|
mit
|
Python
|
9df0c21bcefdeda4ca65ee4126ed965a6d099416
|
Fix line length on import statement
|
Dekker1/moore,UTNkar/moore,UTNkar/moore,UTNkar/moore,Dekker1/moore,UTNkar/moore,Dekker1/moore,Dekker1/moore
|
website/website/wagtail_hooks.py
|
website/website/wagtail_hooks.py
|
from wagtail.contrib.modeladmin.options import ModelAdmin,\
modeladmin_register, ThumbnailMixin
from website.models import Logo
class LogoAdmin(ThumbnailMixin, ModelAdmin):
model = Logo
menu_icon = 'picture'
menu_order = 1000
list_display = ('admin_thumb', 'category', 'link')
add_to_settings_menu = True
thumb_image_field_name = 'logo'
thumb_image_filter_spec = 'fill-128x128'
modeladmin_register(LogoAdmin)
|
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register, \
ThumbnailMixin
from website.models import Logo
class LogoAdmin(ThumbnailMixin, ModelAdmin):
model = Logo
menu_icon = 'picture'
menu_order = 1000
list_display = ('admin_thumb', 'category', 'link')
add_to_settings_menu = True
thumb_image_field_name = 'logo'
thumb_image_filter_spec = 'fill-128x128'
modeladmin_register(LogoAdmin)
|
agpl-3.0
|
Python
|
d4d69ed62cbd726c92de9382136175e0fbdbb8af
|
Remove super-stale file paths
|
andre-senna/opencog,andre-senna/opencog,andre-senna/opencog,AmeBel/opencog,AmeBel/opencog,andre-senna/opencog,AmeBel/opencog,AmeBel/opencog,AmeBel/opencog,andre-senna/opencog,AmeBel/opencog,andre-senna/opencog,andre-senna/opencog,AmeBel/opencog
|
opencog/nlp/anaphora/agents/testingAgent.py
|
opencog/nlp/anaphora/agents/testingAgent.py
|
from __future__ import print_function
from pprint import pprint
# from pln.examples.deduction import deduction_agent
from opencog.atomspace import types, AtomSpace, TruthValue
from agents.hobbs import HobbsAgent
from agents.dumpAgent import dumpAgent
from opencog.scheme_wrapper import load_scm,scheme_eval_h, scheme_eval, __init__
__author__ = 'Hujie Wang'
'''
This agent is purely for testing purposes, which can be used to test hobbsAgent in a standalone atomspace environment.
'''
atomspace = AtomSpace()
# __init__(atomspace)
scheme_eval(atomspace, "(use-modules (opencog) (opencog exec))")
scheme_eval(atomspace, "(use-modules (opencog nlp))")
#status2 = load_scm(atomspace, "opencog/nlp/anaphora/tests/atomspace.scm")
#init=initAgent()
#init.run(atomspace)
dump=dumpAgent()
dump.run(atomspace)
hobbsAgent = HobbsAgent()
hobbsAgent.run(atomspace)
|
from __future__ import print_function
from pprint import pprint
# from pln.examples.deduction import deduction_agent
from opencog.atomspace import types, AtomSpace, TruthValue
from agents.hobbs import HobbsAgent
from agents.dumpAgent import dumpAgent
from opencog.scheme_wrapper import load_scm,scheme_eval_h, scheme_eval, __init__
__author__ = 'Hujie Wang'
'''
This agent is purely for testing purposes, which can be used to test hobbsAgent in a standalone atomspace environment.
'''
atomspace = AtomSpace()
# __init__(atomspace)
scheme_eval(atomspace, "(use-modules (opencog) (opencog exec))")
scheme_eval(atomspace, "(use-modules (opencog nlp))")
data=["opencog/scm/config.scm",
"opencog/scm/core_types.scm",
"spacetime/spacetime_types.scm",
"opencog/nlp/types/nlp_types.scm",
"opencog/attention/attention_types.scm",
"opencog/embodiment/embodiment_types.scm",
"opencog/scm/apply.scm",
"opencog/scm/file-utils.scm",
"opencog/scm/persistence.scm",
#"opencog/scm/repl-shell.scm",
"opencog/scm/utilities.scm",
"opencog/scm/av-tv.scm",
"opencog/nlp/scm/type-definitions.scm",
"opencog/nlp/scm/config.scm",
"opencog/nlp/scm/file-utils.scm",
"opencog/nlp/scm/nlp-utils.scm",
"opencog/nlp/scm/disjunct-list.scm",
"opencog/nlp/scm/processing-utils.scm",
"opencog/nlp/anaphora/tests/atomspace.log"
]
#status2 = load_scm(atomspace, "opencog/nlp/anaphora/tests/atomspace.scm")
# for item in data:
# load_scm(atomspace, item)
#init=initAgent()
#init.run(atomspace)
dump=dumpAgent()
dump.run(atomspace)
hobbsAgent = HobbsAgent()
hobbsAgent.run(atomspace)
|
agpl-3.0
|
Python
|
f585a7cdf4ecbecfe240873a3b4b8e7d4376e69c
|
Move fallback URL pattern to the end of the list so it gets matched last.
|
fladi/django-campus02,fladi/django-campus02
|
campus02/urls.py
|
campus02/urls.py
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.views.static import serve
urlpatterns = [
url(r'^', include('django.contrib.auth.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^web/', include('campus02.web.urls', namespace='web')),
]
if settings.DEBUG:
import debug_toolbar
urlpatterns.append(
url(
r'^__debug__/',
include(debug_toolbar.urls)
)
)
urlpatterns.append(
url(
r'^media/(?P<path>.*)$',
serve,
{
'document_root': settings.MEDIA_ROOT,
}
)
)
urlpatterns.append(
url(
r'^static/(?P<path>.*)$',
serve,
{
'document_root': settings.STATIC_ROOT,
}
),
)
urlpatterns.append(
url(r'^', include('campus02.base.urls', namespace='base'))
)
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.views.static import serve
urlpatterns = [
url(r'^', include('django.contrib.auth.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^web/', include('campus02.web.urls', namespace='web')),
url(r'^', include('campus02.base.urls', namespace='base')),
]
if settings.DEBUG:
import debug_toolbar
urlpatterns.append(
url(
r'^__debug__/',
include(debug_toolbar.urls)
)
)
urlpatterns.append(
url(
r'^media/(?P<path>.*)$',
serve,
{
'document_root': settings.MEDIA_ROOT,
}
)
)
urlpatterns.append(
url(
r'^static/(?P<path>.*)$',
serve,
{
'document_root': settings.STATIC_ROOT,
}
),
)
|
mit
|
Python
|
c05a93d8993e14fc8521dd01a13a930e85fcb882
|
fix code style in `test_db_util` (#9594)
|
DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core,DataDog/integrations-core
|
datadog_checks_base/tests/test_db_util.py
|
datadog_checks_base/tests/test_db_util.py
|
# -*- coding: utf-8 -*-
# (C) Datadog, Inc. 2020-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import time
from datadog_checks.base.utils.db.utils import ConstantRateLimiter, RateLimitingTTLCache
def test_constant_rate_limiter():
rate_limit = 8
test_duration_s = 0.5
ratelimiter = ConstantRateLimiter(rate_limit)
start = time.time()
sleep_count = 0
while time.time() - start < test_duration_s:
ratelimiter.sleep()
sleep_count += 1
max_expected_count = rate_limit * test_duration_s
assert max_expected_count - 1 <= sleep_count <= max_expected_count + 1
def test_ratelimiting_ttl_cache():
ttl = 0.1
cache = RateLimitingTTLCache(maxsize=5, ttl=ttl)
for i in range(5):
assert cache.acquire(i), "cache is empty so the first set of keys should pass"
for i in range(5, 10):
assert not cache.acquire(i), "cache is full so we do not expect any more new keys to pass"
for i in range(5):
assert not cache.acquire(i), "none of the first set of keys should pass because they're still under TTL"
assert len(cache) == 5, "cache should be at the max size"
time.sleep(ttl * 2)
assert len(cache) == 0, "cache should be empty after the TTL has kicked in"
for i in range(5, 10):
assert cache.acquire(i), "cache should be empty again so these keys should go in OK"
|
# -*- coding: utf-8 -*-
# (C) Datadog, Inc. 2020-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import math
import time
from datadog_checks.base.utils.db.utils import RateLimitingTTLCache, ConstantRateLimiter
def test_constant_rate_limiter():
rate_limit = 8
test_duration_s = 0.5
ratelimiter = ConstantRateLimiter(rate_limit)
start = time.time()
sleep_count = 0
while time.time() - start < test_duration_s:
ratelimiter.sleep()
sleep_count += 1
max_expected_count = rate_limit * test_duration_s
assert max_expected_count - 1 <= sleep_count <= max_expected_count + 1
def test_ratelimiting_ttl_cache():
ttl = 0.1
cache = RateLimitingTTLCache(maxsize=5, ttl=ttl)
for i in range(5):
assert cache.acquire(i), "cache is empty so the first set of keys should pass"
for i in range(5, 10):
assert not cache.acquire(i), "cache is full so we do not expect any more new keys to pass"
for i in range(5):
assert not cache.acquire(i), "none of the first set of keys should pass because they're still under TTL"
assert len(cache) == 5, "cache should be at the max size"
time.sleep(ttl * 2)
assert len(cache) == 0, "cache should be empty after the TTL has kicked in"
for i in range(5, 10):
assert cache.acquire(i), "cache should be empty again so these keys should go in OK"
|
bsd-3-clause
|
Python
|
a9a9b60d9994bc4780e74ddd01df833a85247b95
|
Change state serialiser to pass hex color values.
|
SuddenDevs/SuddenDev,SuddenDevs/SuddenDev,SuddenDevs/SuddenDev,SuddenDevs/SuddenDev
|
suddendev/game/state_encoder.py
|
suddendev/game/state_encoder.py
|
#!/usr/bin/python3
import json
def encodeState(game):
return json.dumps(game, cls=StateEncoder)
def clamp(x):
return max(0, min(x, 255))
class StateEncoder(json.JSONEncoder):
def default(self, o):
return self.serializeState(o)
def serializeState(self, state):
return {
'players': self.serializePlayers(state.players),
'enemies': self.serializeEnemies(state.enemies),
'powerups': self.serializePowerups(state.powerups),
'core': self.serializeCore(state.core)
}
def serializeEntity(self, entity):
return {
'tag': entity.tag,
'pos': self.serializeVector(entity.pos),
'vel': self.serializeVector(entity.vel),
'size': entity.size,
'healthMax': entity.healthMax,
'health': entity.health
}
def serializePlayers(self, players):
result = []
for p in players:
json = self.serializeEntity(p)
json['name'] = p.name;
#json['ammo'] = p.ammo;
json['color'] = self.serializeColor(p.color);
result.append(json)
return result
def serializeVector(self, pos):
return {'x' : pos.x, 'y': pos.y}
def serializeColor(self, color):
return "#{0:02x}{1:02x}{2:02x}".format(clamp(color.r), clamp(color.g), clamp(color.b))
#TODO
#Duplication, will extend if enemies or powerups start to differ
def serializeEnemies(self, enemies):
result = []
for e in enemies:
json = self.serializeEntity(e)
result.append(json)
return result
def serializePowerups(self, powerups):
result = []
for p in powerups:
json = self.serializeEntity(p)
result.append(json)
return result
def serializeCore(self, core):
return self.serializeEntity(core)
|
#!/usr/bin/python3
import json
def encodeState(game):
return json.dumps(game, cls=StateEncoder)
class StateEncoder(json.JSONEncoder):
def default(self, o):
return self.serializeState(o)
def serializeState(self, state):
return {
'players': self.serializePlayers(state.players),
'enemies': self.serializeEnemies(state.enemies),
'powerups': self.serializePowerups(state.powerups),
'core': self.serializeCore(state.core)
}
def serializeEntity(self, entity):
return {
'tag': entity.tag,
'pos': self.serializeVector(entity.pos),
'vel': self.serializeVector(entity.vel),
'size': entity.size,
'healthMax': entity.healthMax,
'health': entity.health
}
def serializePlayers(self, players):
result = []
for p in players:
json = self.serializeEntity(p)
json['name'] = p.name;
#json['ammo'] = p.ammo;
json['color'] = self.serializeColor(p.color);
result.append(json)
return result
def serializeVector(self, pos):
return {'x' : pos.x, 'y': pos.y}
def serializeColor(self, color):
return {
'r': color.r,
'g': color.g,
'b': color.b
}
#TODO
#Duplication, will extend if enemies or powerups start to differ
def serializeEnemies(self, enemies):
result = []
for e in enemies:
json = self.serializeEntity(e)
result.append(json)
return result
def serializePowerups(self, powerups):
result = []
for p in powerups:
json = self.serializeEntity(p)
result.append(json)
return result
def serializeCore(self, core):
return self.serializeEntity(core)
|
mit
|
Python
|
3e5c500eed84ca24ffc31e802e061833a5a43225
|
use unicode names in test
|
suvitorg/suvit-odoo,suvitorg/suvit-odoo
|
suvit_system/tests/test_node.py
|
suvit_system/tests/test_node.py
|
# -*- coding: utf-8 -*-
from openerp.tests.common import TransactionCase
class TestNode(TransactionCase):
def test_node_crud(self):
Node = self.env['suvit.system.node']
root = Node.create({'name': u'Root1'})
ch1 = Node.create({'name': u'Ch1', 'parent_id': root.id})
ch2 = Node.create({'name': u'Ch3', 'parent_id': root.id})
ch3 = Node.create({'name': u'Ch2', 'parent_id': root.id})
ch2.write({'name': u'Ch3-last', 'sequence': 1000})
self.assertEqual(len(root.child_ids), 3)
self.assertEqual(root.child_ids.mapped('name'), [u'Ch1', u'Ch2', u'Ch3-last'])
ch3.unlink()
# create duplicate to ch2
ch2.action_duplicate()
# add children for ch2
ch2_1 = Node.create({'name': u'Ch2-1', 'parent_id': ch2.id})
ch2_2 = Node.create({'name': u'Ch2-2', 'parent_id': ch2.id})
|
# -*- coding: utf-8 -*-
from openerp.tests.common import TransactionCase
class TestNode(TransactionCase):
def test_node_crud(self):
Node = self.env['suvit.system.node']
root = Node.create({'name': 'Root1'})
ch1 = Node.create({'name': 'Ch1', 'parent_id': root.id})
ch2 = Node.create({'name': 'Ch3', 'parent_id': root.id})
ch3 = Node.create({'name': 'Ch2', 'parent_id': root.id})
ch2.write({'name': 'Ch3-last', 'sequence': 1000})
self.assertEqual(len(root.child_ids), 3)
self.assertEqual(root.child_ids.mapped('name'), ['Ch1', 'Ch2', 'Ch3-last'])
ch3.unlink()
# create duplicate to ch2
ch2.action_duplicate()
# add children for ch2
ch2_1 = Node.create({'name': 'Ch2-1', 'parent_id': ch2.id})
ch2_2 = Node.create({'name': 'Ch2-2', 'parent_id': ch2.id})
|
agpl-3.0
|
Python
|
c300e70bb65da3678f27c4ba01b22f9a3d4fc717
|
Use spi_serial for tools
|
ps2/subg_rfspy,ps2/subg_rfspy,ps2/subg_rfspy
|
tools/serial_rf_spy.py
|
tools/serial_rf_spy.py
|
#!/usr/bin/env python
import os
import serial
import time
class SerialRfSpy:
CMD_GET_STATE = 1
CMD_GET_VERSION = 2
CMD_GET_PACKET = 3
CMD_SEND_PACKET = 4
CMD_SEND_AND_LISTEN = 5
CMD_UPDATE_REGISTER = 6
CMD_RESET = 7
def __init__(self, serial_port, rtscts=None):
if not rtscts:
rtscts = int(os.getenv('RFSPY_RTSCTS', 1))
if serial_port.find('spi') >= 0:
import spi_serial
self.ser = spi_serial.SpiSerial()
else:
self.ser = serial.Serial(serial_port, 19200, rtscts=rtscts, timeout=1)
self.buf = bytearray()
def do_command(self, command, param=""):
self.send_command(command, param)
return self.get_response()
def send_command(self, command, param=""):
self.ser.write(chr(command))
if len(param) > 0:
self.ser.write(param)
def get_response(self, timeout=0):
start = time.time()
while 1:
bytesToRead = self.ser.inWaiting()
if bytesToRead > 0:
self.buf.extend(self.ser.read(bytesToRead))
eop = self.buf.find(b'\x00',0)
if eop >= 0:
r = self.buf[:eop]
del self.buf[:(eop+1)]
return r
if (timeout > 0) and (start + timeout < time.time()):
return bytearray()
time.sleep(0.005)
def sync(self):
while 1:
self.send_command(self.CMD_GET_STATE)
data = self.get_response(1)
if data == "OK":
print "RileyLink " + data
break
print "retry", len(data), str(data).encode('hex')
while 1:
self.send_command(self.CMD_GET_VERSION)
data = self.get_response(1)
if len(data) >= 3:
print "Version: " + data
break
print "retry", len(data), str(data).encode('hex')
|
#!/usr/bin/env python
import os
import serial
import time
class SerialRfSpy:
CMD_GET_STATE = 1
CMD_GET_VERSION = 2
CMD_GET_PACKET = 3
CMD_SEND_PACKET = 4
CMD_SEND_AND_LISTEN = 5
CMD_UPDATE_REGISTER = 6
CMD_RESET = 7
def __init__(self, serial_port, rtscts=None):
if not rtscts:
rtscts = int(os.getenv('RFSPY_RTSCTS', 1))
self.ser = serial.Serial(serial_port, 19200, rtscts=rtscts, timeout=1)
self.buf = bytearray()
def do_command(self, command, param=""):
self.send_command(command, param)
return self.get_response()
def send_command(self, command, param=""):
self.ser.write(chr(command))
if len(param) > 0:
self.ser.write(param)
def get_response(self, timeout=0):
start = time.time()
while 1:
bytesToRead = self.ser.inWaiting()
if bytesToRead > 0:
self.buf.extend(self.ser.read(bytesToRead))
eop = self.buf.find(b'\x00',0)
if eop >= 0:
r = self.buf[:eop]
del self.buf[:(eop+1)]
return r
if (timeout > 0) and (start + timeout < time.time()):
return bytearray()
time.sleep(0.005)
def sync(self):
while 1:
self.send_command(self.CMD_GET_STATE)
data = self.get_response(1)
if data == "OK":
print "RileyLink " + data
break
print "retry", len(data), str(data).encode('hex')
while 1:
self.send_command(self.CMD_GET_VERSION)
data = self.get_response(1)
if len(data) >= 3:
print "Version: " + data
break
print "retry", len(data), str(data).encode('hex')
|
mit
|
Python
|
73029223f54dc6c793c190e70a135d0bd3faa50b
|
Update download script
|
syllog1sm/TextBlob,syllog1sm/TextBlob,adelq/TextBlob,Windy-Ground/TextBlob,IrisSteenhout/TextBlob,freakynit/TextBlob,laugustyniak/TextBlob,sargam111/python,nvoron23/TextBlob,jonmcoe/TextBlob,beni55/TextBlob,jcalbert/TextBlob,syllog1sm/TextBlob,sloria/TextBlob,dipeshtech/TextBlob
|
download_corpora.py
|
download_corpora.py
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Downloads the necessary NLTK models and corpora.'''
from text.packages import nltk
REQUIRED_CORPORA = [
'brown',
'punkt',
'conll2000',
'maxent_treebank_pos_tagger',
]
def main():
for each in REQUIRED_CORPORA:
print(('Downloading "{0}"'.format(each)))
nltk.download(each)
print("Finished.")
if __name__ == '__main__':
main()
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Downloads the necessary NLTK models and corpora.'''
from nltk import download
REQUIRED_CORPORA = [
'brown',
'punkt',
'conll2000',
'maxent_treebank_pos_tagger',
]
def main():
for each in REQUIRED_CORPORA:
print(('Downloading "{0}"'.format(each)))
download(each)
print("Finished.")
if __name__ == '__main__':
main()
|
mit
|
Python
|
02490615e82be65520a8d608cff467dcf1bd7b96
|
add picture commands help messages
|
MagiChau/ZonBot
|
extensions/picture/picture.py
|
extensions/picture/picture.py
|
from discord.ext import commands
import discord
import os
class Picture():
def __init__(self, bot):
self.bot = bot
@commands.command(help="Awoo!")
async def awoo(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/awoo.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
@commands.command(help="Shows a baka.")
async def baka(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/baka.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
@commands.command(help="Summons the anti-bully ranger.")
async def nobully(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/nobully.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
@commands.command(help="Sad things are sad.")
async def sad(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/sad.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
def setup(bot):
bot.add_cog(Picture(bot))
|
from discord.ext import commands
import discord
import os
class Picture():
def __init__(self, bot):
self.bot = bot
@commands.command()
async def awoo(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/awoo.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
@commands.command()
async def baka(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/baka.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
@commands.command()
async def nobully(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/nobully.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
@commands.command()
async def sad(self):
fp = os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/sad.jpg')
with open(fp, 'rb') as f:
try:
await self.bot.upload(f)
except discord.Forbidden:
await self.bot.say("Error: bot does not have permission to upload pictures.")
def setup(bot):
bot.add_cog(Picture(bot))
|
mit
|
Python
|
6148e7cccc50023955ef7c3d86709c5197ae78e7
|
Make output more understandable
|
Rohde-Schwarz-Cybersecurity/botan,webmaster128/botan,webmaster128/botan,randombit/botan,webmaster128/botan,Rohde-Schwarz-Cybersecurity/botan,Rohde-Schwarz-Cybersecurity/botan,randombit/botan,randombit/botan,Rohde-Schwarz-Cybersecurity/botan,Rohde-Schwarz-Cybersecurity/botan,randombit/botan,webmaster128/botan,Rohde-Schwarz-Cybersecurity/botan,webmaster128/botan,randombit/botan
|
doc/python/cryptobox.py
|
doc/python/cryptobox.py
|
#!/usr/bin/python
import sys
import botan
def main(args = None):
if args is None:
args = sys.argv
if len(args) != 3:
raise Exception("Usage: <password> <input>");
password = args[1]
input = ''.join(open(args[2]).readlines())
rng = botan.RandomNumberGenerator()
ciphertext = botan.cryptobox_encrypt(input, password, rng)
print ciphertext
plaintext = ''
try:
plaintext = botan.cryptobox_decrypt(ciphertext, password + 'FAIL')
except Exception, e:
print "Good news: bad password caused exception: "
print e
plaintext = botan.cryptobox_decrypt(ciphertext, password)
print "Original input was: "
print plaintext
if __name__ == '__main__':
sys.exit(main())
|
#!/usr/bin/python
import sys
import botan
def main(args = None):
if args is None:
args = sys.argv
if len(args) != 3:
raise Exception("Bad usage")
password = args[1]
input = ''.join(open(args[2]).readlines())
rng = botan.RandomNumberGenerator()
ciphertext = botan.cryptobox_encrypt(input, password, rng)
print ciphertext
plaintext = ''
try:
plaintext = botan.cryptobox_decrypt(ciphertext, password + 'FAIL')
except Exception, e:
print "Oops -- ", e
plaintext = botan.cryptobox_decrypt(ciphertext, password)
print plaintext
if __name__ == '__main__':
sys.exit(main())
|
bsd-2-clause
|
Python
|
a2a26ed8b216c4a40db7a384571d05c690e25cef
|
Update test expectation
|
JasonGross/coq-tools,JasonGross/coq-tools
|
examples/run-example-8.py
|
examples/run-example-8.py
|
#!/usr/bin/python
import os, sys, inspect
DIR = os.path.dirname(os.path.realpath(__file__))
NORM_EXPECT='Require Coq.omega.Omega.\nRequire Top.A.\nRequire Top.B.\nRequire Top.C.\nRequire Top.D.\n\nImport Top.D.\n\nFail Check A.mA.axA.\n'
GET_EXPECT = {
'Coq.omega.Omega': None,
'Top.A': 'Module Export Top_DOT_A.\nModule Export Top.\nModule A.\nImport Coq.omega.Omega.\nModule mA.\n Section secA.\n Axiom axA : Set.\n End secA.\nEnd mA.\n\nModule mA2.\nEnd mA2.\n\nEnd A.\n\nEnd Top.\n\nEnd Top_DOT_A.\n',
'Top.B': 'Module Export Top_DOT_B.\nModule Export Top.\nModule B.\nImport Top.A.\n\nEnd B.\n\nEnd Top.\n\nEnd Top_DOT_B.\n',
'Top.C': 'Module Export Top_DOT_C.\nModule Export Top.\nModule C.\nImport Top.A.\n\nEnd C.\n\nEnd Top.\n\nEnd Top_DOT_C.\n',
'Top.D': 'Module Export Top_DOT_D.\nModule Export Top.\nModule D.\nImport Top.C Top.B.\nImport Top.A.\n\nEnd D.\n\nEnd Top.\n\nEnd Top_DOT_D.\n'
}
def trace(frame, event, arg):
print((frame, event, arg))
if __name__ == '__main__':
# from http://stackoverflow.com/a/6098238/377022
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0], "..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
from replace_imports import normalize_requires, get_required_contents
os.chdir(DIR)
os.chdir('example_8')
NORM_FOUND = normalize_requires("example_8.v")
print('if %s != %s:' % (repr(NORM_FOUND), repr(NORM_EXPECT)))
if NORM_FOUND != NORM_EXPECT:
print('sys.exit(1)')
sys.exit(1)
for libname, expect in GET_EXPECT.items():
print('libname: ' + libname)
try:
got = get_required_contents(libname)
except IOError:
got = None
print('if %s != %s:' % (repr(got), repr(expect)))
if got != expect:
print('sys.exit(1)')
sys.exit(1)
print('sys.exit(0)')
sys.exit(0)
|
#!/usr/bin/python
import os, sys, inspect
DIR = os.path.dirname(os.path.realpath(__file__))
NORM_EXPECT='Require Coq.omega.Omega.\nRequire Top.A.\nRequire Top.B.\nRequire Top.C.\nRequire Top.D.\n\nImport Top.D.\n'
GET_EXPECT = {
'Coq.omega.Omega': None,
'Top.A': 'Module Export Top_DOT_A.\nModule Export Top.\nModule A.\nImport Coq.omega.Omega.\nModule mA.\n Section secA.\n Axiom axA : Set.\n End secA.\nEnd mA.\n\nModule mA2.\nEnd mA2.\n\nEnd A.\n\nEnd Top.\n\nEnd Top_DOT_A.\n',
'Top.B': 'Module Export Top_DOT_B.\nModule Export Top.\nModule B.\nImport Top.A.\n\nEnd B.\n\nEnd Top.\n\nEnd Top_DOT_B.\n',
'Top.C': 'Module Export Top_DOT_C.\nModule Export Top.\nModule C.\nImport Top.A.\n\nEnd C.\n\nEnd Top.\n\nEnd Top_DOT_C.\n',
'Top.D': 'Module Export Top_DOT_D.\nModule Export Top.\nModule D.\nImport Top.C Top.B.\nImport Top.A.\n\nEnd D.\n\nEnd Top.\n\nEnd Top_DOT_D.\n'
}
def trace(frame, event, arg):
print((frame, event, arg))
if __name__ == '__main__':
# from http://stackoverflow.com/a/6098238/377022
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0], "..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
from replace_imports import normalize_requires, get_required_contents
os.chdir(DIR)
os.chdir('example_8')
NORM_FOUND = normalize_requires("example_8.v")
print('if %s != %s:' % (repr(NORM_FOUND), repr(NORM_EXPECT)))
if NORM_FOUND != NORM_EXPECT:
print('sys.exit(1)')
sys.exit(1)
for libname, expect in GET_EXPECT.items():
print('libname: ' + libname)
try:
got = get_required_contents(libname)
except IOError:
got = None
print('if %s != %s:' % (repr(got), repr(expect)))
if got != expect:
print('sys.exit(1)')
sys.exit(1)
print('sys.exit(0)')
sys.exit(0)
|
mit
|
Python
|
0dcad3ac5f3754fedf12c7aca7050ec6ab85840d
|
fix merge cleaning
|
texttochange/vusion-backend,texttochange/vusion-backend,texttochange/vusion-backend
|
transports/__init__.py
|
transports/__init__.py
|
from yo_ug_http import YoUgHttpTransport
from cm_nl_yo_ug_http import CmYoTransport
from cm_nl_http import CmTransport
from push_tz_yo_ug_http import PushYoTransport
from push_tz_http import PushTransport
from push_tz_smpp import PushTzSmppTransport
from mobivate_http import MobivateHttpTransport
from movilgate_http import MovilgateHttpTransport
from mobtech_ml_http import MobtechMlHttpTransport
from smsgh_smpp import SmsghSmppTransport
from forward_http import ForwardHttp
from ttc_bf_http import TtcBfHttpTransport
__all__ = ["YoUgHttpTransport",
"CmYoTransport",
"CmTransport",
"PushYoTransport",
"PushTransport",
"PushTzSmppTransport",
"MobivateHttpTransport",
"MovilgateHttpTransport",
"MobtechMlHttpTransport",
"SmsghSmppTransport",
"TtcBfHttpTransport",
"ForwardHttp"]
|
from yo_ug_http import YoUgHttpTransport
from cm_nl_yo_ug_http import CmYoTransport
from cm_nl_http import CmTransport
from push_tz_yo_ug_http import PushYoTransport
from push_tz_http import PushTransport
from push_tz_smpp import PushTzSmppTransport
from mobivate_http import MobivateHttpTransport
from movilgate_http import MovilgateHttpTransport
from mobtech_ml_http import MobtechMlHttpTransport
from smsgh_smpp import SmsghSmppTransport
from forward_http import ForwardHttp
from ttc_bf_http import TtcBfHttpTransport
__all__ = ["YoUgHttpTransport",
"CmYoTransport",
"CmTransport",
"PushYoTransport",
"PushTransport",
"PushTzSmppTransport",
"MobivateHttpTransport",
"MovilgateHttpTransport",
<<<<<<< HEAD
"MobtechMlHttpTransport",
"SmsghSmppTransport",
=======
"TtcBfHttpTransport",
>>>>>>> feature/burkina
"ForwardHttp"]
|
bsd-3-clause
|
Python
|
f66cee94d2ae4ba12cc8d56c40be0d2e07f69a5a
|
Tag 0.0.2
|
SwingTix/bookkeeper,g--/bookkeeper-dev,omarkhan/bookkeeper
|
swingtix/bookkeeper/__init__.py
|
swingtix/bookkeeper/__init__.py
|
__VERSION__='0.0.1.1-29-gdc751f0M'
|
__VERSION__='0.0.1.1'
|
agpl-3.0
|
Python
|
101dae4f5a12605a791b0f81fb2ff599cbf2facb
|
Return early
|
darkfeline/mir.dlsite,darkfeline/mir.dlsite
|
mir/dlsite/cmd/dlorg.py
|
mir/dlsite/cmd/dlorg.py
|
# Copyright (C) 2016, 2017 Allen Li
#
# 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.
"""Organize DLsite works."""
import argparse
import logging
from pathlib import Path
import sys
from mir.dlsite import api
from mir.dlsite import org
logger = logging.getLogger(__name__)
def main(argv):
logging.basicConfig(level='DEBUG')
parser = argparse.ArgumentParser(prog=argv[0],
description=__doc__)
parser.add_argument('top_dir', nargs='?', default=Path.cwd(),
type=Path)
parser.add_argument('-n', '--dry-run', action='store_true')
parser.add_argument('-a', '--all', action='store_true')
args = parser.parse_args(argv[1:])
paths = list(org.find_works(args.top_dir))
if not args.all:
paths = [p for p in paths if len(p.parts) == 1]
with api.get_fetcher() as fetcher:
renames = list(org.calculate_path_renames(fetcher, paths))
if args.dry_run:
for r in renames:
logger.info('Would rename %s to %s', r.old, r.new)
return 0
for r in renames:
r.execute(args.top_dir)
org.remove_empty_dirs(args.top_dir)
paths = org.apply_renames(paths, renames)
with api.get_fetcher() as fetcher:
for p in paths:
org.add_dlsite_files(fetcher, p)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
|
# Copyright (C) 2016, 2017 Allen Li
#
# 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.
"""Organize DLsite works."""
import argparse
import logging
from pathlib import Path
import sys
from mir.dlsite import api
from mir.dlsite import org
logger = logging.getLogger(__name__)
def main(argv):
logging.basicConfig(level='DEBUG')
parser = argparse.ArgumentParser(prog=argv[0],
description=__doc__)
parser.add_argument('top_dir', nargs='?', default=Path.cwd(),
type=Path)
parser.add_argument('-n', '--dry-run', action='store_true')
parser.add_argument('-a', '--all', action='store_true')
args = parser.parse_args(argv[1:])
paths = list(org.find_works(args.top_dir))
if not args.all:
paths = [p for p in paths if len(p.parts) == 1]
with api.get_fetcher() as fetcher:
renames = list(org.calculate_path_renames(fetcher, paths))
if args.dry_run:
for r in renames:
logger.info('Would rename %s to %s', r.old, r.new)
else:
for r in renames:
r.execute(args.top_dir)
org.remove_empty_dirs(args.top_dir)
paths = org.apply_renames(paths, renames)
with api.get_fetcher() as fetcher:
for p in paths:
org.add_dlsite_files(fetcher, p)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
|
apache-2.0
|
Python
|
6035ef056f6ca028828faad68a0a0954e581300e
|
Set L=4 to try other topology
|
jacobq/csci5221-viro-project,jacobq/csci5221-viro-project,jacobq/csci5221-viro-project,jacobq/csci5221-viro-project,jacobq/csci5221-viro-project
|
ext/viro_constant.py
|
ext/viro_constant.py
|
# Manually set L
L = 4
# OPERATIONS
VIRO_DATA_OP = 0x0000
VIRO_DATA = 0x0802
VIRO_CONTROL = 0x0803
RDV_PUBLISH = 0x1000
RDV_QUERY = 0x2000
RDV_REPLY = 0x3000
DISCOVERY_ECHO_REQUEST = 0x4000
DISCOVERY_ECHO_REPLY = 0x5000
GW_WITHDRAW = 0x6000
RDV_WITHDRAW = 0x7000
# OTHER PARTS OF THE HEADER
HTYPE = 0x1
PTYPE = 0x0800
HLEN = 0x06
PLEN = 0x04
# Per the CSCI 5221 Project 2 assignment document:
# "We limit the maximal number of < Gateway; Nexthop > pairs in each level to 3."
MAX_GW_PER_LEVEL = 3
MAX_GW_PER_RDV_REPLY = MAX_GW_PER_LEVEL
# HARDWARE ADDRESS FOR THE VEIL MASTER
VEIL_MASTER_MAC = "00:00:00:00:00:00"
# An arbitrary/fake MAC address that seems to be used in various places
FAKE_MAC = '00:14:4f:e2:b3:70'
# OFFSET FOR THE OPER
OPER_OFFSET = 6
OPER_LEN = 2
# OFFSET FOR THE ECHO_SRC_VID
ECHO_SRC_OFFSET = 8
# The following _TIME parameter are all measured in seconds
ROUND_TIME = 10 # Time between "bottom up" rounds for routing table construction (RDV_PUBLISH / RDV_QUERY)
DISCOVER_TIME = 5 # Time between checking neighbor status
FAILURE_TIME = 7 # Time between checks for failures
# OPERATION NUMBER TO STRING MAPPING
OPERATION_NAMES = {
0x1000: 'RDV_PUBLISH',
0x2000: 'RDV_QUERY',
0x3000: 'RDV_REPLY',
0x4000: 'DISCOVERY_ECHO_REQUEST',
0x5000: 'DISCOVERY_ECHO_REPLY',
0x6000: 'GW_WITHDRAW',
0x7000: 'RDV_WITHDRAW'
}
|
# Manually set L
L = 3
# OPERATIONS
VIRO_DATA_OP = 0x0000
VIRO_DATA = 0x0802
VIRO_CONTROL = 0x0803
RDV_PUBLISH = 0x1000
RDV_QUERY = 0x2000
RDV_REPLY = 0x3000
DISCOVERY_ECHO_REQUEST = 0x4000
DISCOVERY_ECHO_REPLY = 0x5000
GW_WITHDRAW = 0x6000
RDV_WITHDRAW = 0x7000
# OTHER PARTS OF THE HEADER
HTYPE = 0x1
PTYPE = 0x0800
HLEN = 0x06
PLEN = 0x04
# Per the CSCI 5221 Project 2 assignment document:
# "We limit the maximal number of < Gateway; Nexthop > pairs in each level to 3."
MAX_GW_PER_LEVEL = 3
MAX_GW_PER_RDV_REPLY = MAX_GW_PER_LEVEL
# HARDWARE ADDRESS FOR THE VEIL MASTER
VEIL_MASTER_MAC = "00:00:00:00:00:00"
# An arbitrary/fake MAC address that seems to be used in various places
FAKE_MAC = '00:14:4f:e2:b3:70'
# OFFSET FOR THE OPER
OPER_OFFSET = 6
OPER_LEN = 2
# OFFSET FOR THE ECHO_SRC_VID
ECHO_SRC_OFFSET = 8
# The following _TIME parameter are all measured in seconds
ROUND_TIME = 10 # Time between "bottom up" rounds for routing table construction (RDV_PUBLISH / RDV_QUERY)
DISCOVER_TIME = 5 # Time between checking neighbor status
FAILURE_TIME = 7 # Time between checks for failures
# OPERATION NUMBER TO STRING MAPPING
OPERATION_NAMES = {
0x1000: 'RDV_PUBLISH',
0x2000: 'RDV_QUERY',
0x3000: 'RDV_REPLY',
0x4000: 'DISCOVERY_ECHO_REQUEST',
0x5000: 'DISCOVERY_ECHO_REPLY',
0x6000: 'GW_WITHDRAW',
0x7000: 'RDV_WITHDRAW'
}
|
apache-2.0
|
Python
|
fd1a6abb003832919eea99fce05e06188889527c
|
Change the urls import line. Fix #6
|
AdrianRibao/cerberos,AdrianRibao/cerberos
|
cerberos/urls.py
|
cerberos/urls.py
|
# -*- coding: utf-8 -*-
from django.conf.urls import *
from cerberos.views import *
urlpatterns = patterns('',
)
|
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from cerberos.views import *
urlpatterns = patterns('',
)
|
bsd-3-clause
|
Python
|
bdcdeaea6eb760d91690439da43d72ef0673df48
|
change replace statement
|
nprapps/elections14,nprapps/elections14,nprapps/elections14,nprapps/elections14
|
fabfile/instagram.py
|
fabfile/instagram.py
|
#!/usr/bin/env python
import csv
import json
from fabric.api import task
import requests
FIELDNAMES = ['date', 'username', 'caption', 'instagram_url', 'image', 'image_url', 'embed_code', 'approved']
class Photo(object):
def __init__(self, **kwargs):
for field in FIELDNAMES:
if kwargs[field]:
setattr(self, field, kwargs[field])
setattr(
self,
'local_img_id',
self.image_url\
.split(u'/')[-1]\
.replace('_n.jpg', '.jpg'))
setattr(
self,
'local_img_url',
'assets/instagram/nprparty-instagram-%s' % self.image_url\
.split(u'/')[-1]\
.replace('_n.jpg', '.jpg'))
def get_photo_csv():
r = requests.get('https://docs.google.com/spreadsheets/d/1DAirjcVoeeLtfpurOzJIqqgLqOWClxCOCD_wIkMUscI/export?format=csv')
with open('data/photos.csv', 'wb') as writefile:
writefile.write(r.content)
def parse_photo_csv():
with open('data/photos.csv', 'rb') as readfile:
photos = list(csv.DictReader(readfile, fieldnames=FIELDNAMES))
print "Processing %s entries from Google Docs." % len(photos)
payload = []
for photo in photos:
if photo['approved'] != '':
r = requests.get(photo['image_url'])
if r.status_code == 200:
p = Photo(**photo)
payload.append(p.__dict__)
with open('www/assets/instagram/nprparty-instagram-%s' % p.local_img_id, 'wb') as writefile:
writefile.write(r.content)
print "Writing %s photos to JSON." % len(payload)
with open('www/live-data/photos.json', 'wb') as writefile:
writefile.write(json.dumps(payload))
@task
def get_photos():
get_photo_csv()
parse_photo_csv()
|
#!/usr/bin/env python
import csv
import json
from fabric.api import task
import requests
FIELDNAMES = ['date', 'username', 'caption', 'instagram_url', 'image', 'image_url', 'embed_code', 'approved']
class Photo(object):
def __init__(self, **kwargs):
for field in FIELDNAMES:
if kwargs[field]:
setattr(self, field, kwargs[field])
setattr(
self,
'local_img_id',
self.image_url\
.split(u'/')[-1]\
.replace('_8.jpg', '.jpg'))
setattr(
self,
'local_img_url',
'assets/instagram/nprparty-instagram-%s' % self.image_url\
.split(u'/')[-1]\
.replace('_n.jpg', '.jpg'))
def get_photo_csv():
r = requests.get('https://docs.google.com/spreadsheets/d/1DAirjcVoeeLtfpurOzJIqqgLqOWClxCOCD_wIkMUscI/export?format=csv')
with open('data/photos.csv', 'wb') as writefile:
writefile.write(r.content)
def parse_photo_csv():
with open('data/photos.csv', 'rb') as readfile:
photos = list(csv.DictReader(readfile, fieldnames=FIELDNAMES))
print "Processing %s entries from Google Docs." % len(photos)
payload = []
for photo in photos:
if photo['approved'] != '':
r = requests.get(photo['image_url'])
if r.status_code == 200:
p = Photo(**photo)
payload.append(p.__dict__)
with open('www/assets/instagram/nprparty-instagram-%s' % p.local_img_id, 'wb') as writefile:
writefile.write(r.content)
print "Writing %s photos to JSON." % len(payload)
with open('www/live-data/photos.json', 'wb') as writefile:
writefile.write(json.dumps(payload))
@task
def get_photos():
get_photo_csv()
parse_photo_csv()
|
mit
|
Python
|
54282a1b7c2ea707506078483cf806e9521f264c
|
update version number
|
theno/fabsetup,theno/fabsetup
|
fabsetup/_version.py
|
fabsetup/_version.py
|
__version__ = "0.7.7"
|
__version__ = "0.7.6"
|
mit
|
Python
|
a0ac28b8d55654e6da02b96cb7c85270a3267f3d
|
Add links for development_status and maintainers keys
|
OCA/maintainer-tools,Yajo/maintainer-tools,acsone/maintainers-tools,Yajo/maintainer-tools,acsone/maintainer-tools,acsone/maintainers-tools,acsone/maintainer-tools,OCA/maintainer-tools,OCA/maintainer-tools,acsone/maintainers-tools,Yajo/maintainer-tools,OCA/maintainer-tools,Yajo/maintainer-tools,acsone/maintainer-tools,acsone/maintainer-tools
|
template/module/__manifest__.py
|
template/module/__manifest__.py
|
# -*- coding: utf-8 -*-
# Copyright <YEAR(S)> <AUTHOR(S)>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Module name",
"summary": "Module summary",
"version": "11.0.1.0.0",
# see https://odoo-community.org/page/development-status
"development_status": "Alpha|Beta|Production/Stable|Mature",
"category": "Uncategorized",
"website": "https://github.com/OCA/<repo>" or "https://github.com/OCA/<repo>/tree/<branch>/<addon>",
"author": "<AUTHOR(S)>, Odoo Community Association (OCA)",
# see https://odoo-community.org/page/maintainer-role for a description of the maintainer role and responsibilities
"maintainers": ["your-github-login"],
"license": "AGPL-3",
"application": False,
"installable": True,
"pre_init_hook": "pre_init_hook",
"post_init_hook": "post_init_hook",
"post_load": "post_load",
"uninstall_hook": "uninstall_hook",
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"base",
],
"data": [
"security/some_model_security.xml",
"security/ir.model.access.csv",
"templates/assets.xml",
"views/report_name.xml",
"views/res_partner_view.xml",
"wizards/wizard_model_view.xml",
],
"demo": [
"demo/assets.xml",
"demo/res_partner_demo.xml",
],
"qweb": [
"static/src/xml/module_name.xml",
]
}
|
# -*- coding: utf-8 -*-
# Copyright <YEAR(S)> <AUTHOR(S)>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Module name",
"summary": "Module summary",
"version": "11.0.1.0.0",
"development_status": "Alpha|Beta|Production/Stable|Mature",
"category": "Uncategorized",
"website": "https://github.com/OCA/<repo>" or "https://github.com/OCA/<repo>/tree/<branch>/<addon>",
"author": "<AUTHOR(S)>, Odoo Community Association (OCA)",
"maintainers": [],
"license": "AGPL-3",
"application": False,
"installable": True,
"pre_init_hook": "pre_init_hook",
"post_init_hook": "post_init_hook",
"post_load": "post_load",
"uninstall_hook": "uninstall_hook",
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"base",
],
"data": [
"security/some_model_security.xml",
"security/ir.model.access.csv",
"templates/assets.xml",
"views/report_name.xml",
"views/res_partner_view.xml",
"wizards/wizard_model_view.xml",
],
"demo": [
"demo/assets.xml",
"demo/res_partner_demo.xml",
],
"qweb": [
"static/src/xml/module_name.xml",
]
}
|
agpl-3.0
|
Python
|
d45a0d97b978c18bb0a40e4cec6d3dab6ec2d566
|
fix loading crystal.json
|
dials/dials,dials/dials,dials/dials,dials/dials,dials/dials
|
test/command_line/tst_refine.py
|
test/command_line/tst_refine.py
|
#!/usr/bin/env cctbx.python
#
# Copyright (C) (2013) STFC Rutherford Appleton Laboratory, UK.
#
# Author: David Waterman.
#
# This code is distributed under the BSD license, a copy of which is
# included in the root directory of this package.
#
"""
Test command line program dials.refine by running a job with saved data and
comparing with expected output.
This serves as a high level test that not only checks whether refinement works,
but also that the command line program is functioning and that the output models
have not changed format and so on.
"""
# python imports
from __future__ import division
import os
import libtbx.load_env # required for libtbx.env.find_in_repositories
from libtbx import easy_run
from libtbx.test_utils import approx_equal
from libtbx.test_utils import open_tmp_directory
def test1():
dials_regression = libtbx.env.find_in_repositories(
relative_path="dials_regression",
test=os.path.isdir)
# use the i04_weak_data for this test
data_dir = os.path.join(dials_regression, "refinement_test_data", "i04_weak_data")
sweep_path = os.path.join(data_dir, "sweep.json")
crystal_path = os.path.join(data_dir, "crystal.json")
pickle_path = os.path.join(data_dir, "indexed_strong.pickle")
for pth in ():
assert os.path.exists(pth)
cmd = "dials.refine " + sweep_path + " " + crystal_path + " " + pickle_path
# work in a temporary directory
cwd = os.path.abspath(os.curdir)
tmp_dir = open_tmp_directory(suffix="test_dials_refine")
os.chdir(tmp_dir)
result = easy_run.fully_buffered(command=cmd).raise_if_errors()
os.chdir(cwd)
# load results
from dials.model.serialize import load
from cctbx.crystal.crystal_model.serialize import load_crystal
reg_sweep = load.sweep(os.path.join(data_dir, "regression_sweep.json"))
reg_crystal = load_crystal(os.path.join(data_dir, "regression_crystal.json"))
sweep = load.sweep(os.path.join(tmp_dir, "refined_sweep.json"))
crystal = load_crystal(os.path.join(tmp_dir, "refined_crystal.json"))
# test refined models against expected
assert crystal == reg_crystal
assert sweep.get_detector() == reg_sweep.get_detector()
assert sweep.get_beam() == reg_sweep.get_beam()
print "OK"
return
def run():
if not libtbx.env.has_module("dials_regression"):
print "Skipping tests in " + __file__ + " as dials_regression not present"
return
test1()
if __name__ == '__main__':
import sys
from libtbx.utils import show_times_at_exit
show_times_at_exit()
run()
|
#!/usr/bin/env cctbx.python
#
# Copyright (C) (2013) STFC Rutherford Appleton Laboratory, UK.
#
# Author: David Waterman.
#
# This code is distributed under the BSD license, a copy of which is
# included in the root directory of this package.
#
"""
Test command line program dials.refine by running a job with saved data and
comparing with expected output.
This serves as a high level test that not only checks whether refinement works,
but also that the command line program is functioning and that the output models
have not changed format and so on.
"""
# python imports
from __future__ import division
import os
import libtbx.load_env # required for libtbx.env.find_in_repositories
from libtbx import easy_run
from libtbx.test_utils import approx_equal
from libtbx.test_utils import open_tmp_directory
def test1():
dials_regression = libtbx.env.find_in_repositories(
relative_path="dials_regression",
test=os.path.isdir)
# use the i04_weak_data for this test
data_dir = os.path.join(dials_regression, "refinement_test_data", "i04_weak_data")
sweep_path = os.path.join(data_dir, "sweep.json")
crystal_path = os.path.join(data_dir, "crystal.json")
pickle_path = os.path.join(data_dir, "indexed_strong.pickle")
for pth in ():
assert os.path.exists(pth)
cmd = "dials.refine " + sweep_path + " " + crystal_path + " " + pickle_path
# work in a temporary directory
cwd = os.path.abspath(os.curdir)
tmp_dir = open_tmp_directory(suffix="test_dials_refine")
os.chdir(tmp_dir)
result = easy_run.fully_buffered(command=cmd).raise_if_errors()
os.chdir(cwd)
# load results
from dials.model.serialize import load
reg_sweep = load.sweep(os.path.join(data_dir, "regression_sweep.json"))
reg_crystal = load.crystal(os.path.join(data_dir, "regression_crystal.json"))
sweep = load.sweep(os.path.join(tmp_dir, "refined_sweep.json"))
crystal = load.crystal(os.path.join(tmp_dir, "refined_crystal.json"))
# test refined models against expected
assert crystal == reg_crystal
assert sweep.get_detector() == reg_sweep.get_detector()
assert sweep.get_beam() == reg_sweep.get_beam()
print "OK"
return
def run():
if not libtbx.env.has_module("dials_regression"):
print "Skipping tests in " + __file__ + " as dials_regression not present"
return
test1()
if __name__ == '__main__':
import sys
from libtbx.utils import show_times_at_exit
show_times_at_exit()
run()
|
bsd-3-clause
|
Python
|
e318497949a340b3b821efbc4492c8605441fa47
|
reformat code
|
dusktreader/flask-praetorian,dusktreader/flask-praetorian
|
flask_praetorian/constants.py
|
flask_praetorian/constants.py
|
import pendulum
import enum
from os.path import dirname, abspath
DEFAULT_JWT_PLACES = ['header', 'cookie']
DEFAULT_JWT_COOKIE_NAME = 'access_token'
DEFAULT_JWT_HEADER_NAME = 'Authorization'
DEFAULT_JWT_HEADER_TYPE = 'Bearer'
DEFAULT_JWT_ACCESS_LIFESPAN = pendulum.duration(minutes=15)
DEFAULT_JWT_REFRESH_LIFESPAN = pendulum.duration(days=30)
DEFAULT_JWT_RESET_LIFESPAN = pendulum.duration(minutes=10)
DEFAULT_JWT_ALGORITHM = 'HS256'
DEFAULT_JWT_ALLOWED_ALGORITHMS = ['HS256']
DEFAULT_USER_CLASS_VALIDATION_METHOD = 'is_valid'
DEFAULT_CONFIRMATION_TEMPLATE = (
"{}/flask_praetorian/templates/registration_email.html".format(
dirname(dirname(abspath(__file__))),
)
)
DEFAULT_CONFIRMATION_SENDER = '[email protected]'
DEFAULT_CONFIRMATION_SUBJECT = 'Please confirm your registration'
DEFAULT_RESET_TEMPLATE = (
"{}/flask_praetorian/templates/reset_email.html".format(
dirname(dirname(abspath(__file__))),
)
)
DEFAULT_RESET_SENDER = '[email protected]'
DEFAULT_RESET_SUBJECT = 'Password Reset Requested'
DEFAULT_HASH_AUTOUPDATE = False
DEFAULT_HASH_AUTOTEST = False
DEFAULT_HASH_SCHEME = 'pbkdf2_sha512'
DEFAULT_HASH_ALLOWED_SCHEMES = [
'pbkdf2_sha512', 'sha256_crypt', 'sha512_crypt', 'bcrypt', 'argon2',
'bcrypt_sha256',
]
DEFAULT_HASH_DEPRECATED_SCHEMES = []
REFRESH_EXPIRATION_CLAIM = 'rf_exp'
IS_REGISTRATION_TOKEN_CLAIM = 'is_ert'
IS_RESET_TOKEN_CLAIM = 'is_prt'
RESERVED_CLAIMS = {
'iat', 'exp', 'jti', 'id', 'rls',
REFRESH_EXPIRATION_CLAIM,
IS_REGISTRATION_TOKEN_CLAIM,
IS_RESET_TOKEN_CLAIM,
}
# 1M days seems reasonable. If this code is being used in 3000 years...welp
VITAM_AETERNUM = pendulum.Duration(days=1000000)
class AccessType(enum.Enum):
access = 'ACCESS'
refresh = 'REFRESH'
register = 'REGISTER'
reset = 'RESET'
|
import pendulum
import enum
from os.path import dirname, abspath
DEFAULT_JWT_PLACES = [
'header', 'cookie'
]
DEFAULT_JWT_COOKIE_NAME = 'access_token'
DEFAULT_JWT_HEADER_NAME = 'Authorization'
DEFAULT_JWT_HEADER_TYPE = 'Bearer'
DEFAULT_JWT_ACCESS_LIFESPAN = pendulum.duration(minutes=15)
DEFAULT_JWT_REFRESH_LIFESPAN = pendulum.duration(days=30)
DEFAULT_JWT_RESET_LIFESPAN = pendulum.duration(minutes=10)
DEFAULT_JWT_ALGORITHM = 'HS256'
DEFAULT_JWT_ALLOWED_ALGORITHMS = ['HS256']
DEFAULT_USER_CLASS_VALIDATION_METHOD = 'is_valid'
DEFAULT_CONFIRMATION_TEMPLATE = (
"{}/flask_praetorian/templates/registration_email.html".format(
dirname(dirname(abspath(__file__))),
)
)
DEFAULT_CONFIRMATION_SENDER = '[email protected]'
DEFAULT_CONFIRMATION_SUBJECT = 'Please confirm your registration'
DEFAULT_RESET_TEMPLATE = (
"{}/flask_praetorian/templates/reset_email.html".format(
dirname(dirname(abspath(__file__))),
)
)
DEFAULT_RESET_SENDER = '[email protected]'
DEFAULT_RESET_SUBJECT = 'Password Reset Requested'
DEFAULT_HASH_AUTOUPDATE = False
DEFAULT_HASH_AUTOTEST = False
DEFAULT_HASH_SCHEME = 'pbkdf2_sha512'
DEFAULT_HASH_ALLOWED_SCHEMES = [
'pbkdf2_sha512', 'sha256_crypt', 'sha512_crypt', 'bcrypt', 'argon2',
'bcrypt_sha256',
]
DEFAULT_HASH_DEPRECATED_SCHEMES = []
REFRESH_EXPIRATION_CLAIM = 'rf_exp'
IS_REGISTRATION_TOKEN_CLAIM = 'is_ert'
IS_RESET_TOKEN_CLAIM = 'is_prt'
RESERVED_CLAIMS = {
'iat', 'exp', 'jti', 'id', 'rls',
REFRESH_EXPIRATION_CLAIM,
IS_REGISTRATION_TOKEN_CLAIM,
IS_RESET_TOKEN_CLAIM,
}
# 1M days seems reasonable. If this code is being used in 3000 years...welp
VITAM_AETERNUM = pendulum.Duration(days=1000000)
class AccessType(enum.Enum):
access = 'ACCESS'
refresh = 'REFRESH'
register = 'REGISTER'
reset = 'RESET'
|
mit
|
Python
|
3109bd9a1d01e926e4fce3373db93db8a2d091e0
|
Update 4.8_subtree.py
|
HeyIamJames/CodingInterviewPractice,HeyIamJames/CodingInterviewPractice
|
CrackingCodingInterview/4.8_subtree.py
|
CrackingCodingInterview/4.8_subtree.py
|
"""
is a a subtree of b
both are bst
"""
class Node:
02
...
03
def compare_trees(self, node):
04
"""
05
Compare 2 trees
06
07
@param node tree's root node to compare to
08
@returns True if the tree passed is identical to this tree
09
"""
def compare_trees(self, node):
if node is None:
return False
if self.data != node.data:
return False
res = True
if self.left is None:
if node.left:
return False
else:
res = self.left.compare_trees(node.left)
if res is False:
return False
if self.right is None:
if node.right:
return False
else:
res = self.right.compare_trees(node.right)
return res
|
"""
is a a subtree of b
both are bst
"""
|
mit
|
Python
|
42cefe67849fd97c52210ba750077238d938fe6a
|
Fix TZ issue in order_by_score
|
skybluejamie/wikipeace,skybluejamie/wikipeace,stephenmcd/drum,stephenmcd/drum
|
drum/links/utils.py
|
drum/links/utils.py
|
from __future__ import division, unicode_literals
from re import sub, split
from django.conf import settings
from django.utils.timezone import now
def order_by_score(queryset, score_fields, date_field, reverse=True):
"""
Take some queryset (links or comments) and order them by score,
which is basically "rating_sum / age_in_seconds ^ scale", where
scale is a constant that can be used to control how quickly scores
reduce over time. To perform this in the database, it needs to
support a POW function, which Postgres and MySQL do. For databases
that don't such as SQLite, we perform the scoring/sorting in
memory, which will suffice for development.
"""
scale = getattr(settings, "SCORE_SCALE_FACTOR", 2)
# Timestamp SQL function snippets mapped to DB backends.
# Defining these assumes the SQL functions POW() and NOW()
# are available for the DB backend.
timestamp_sqls = {
"mysql": "UNIX_TIMESTAMP(%s)",
"postgresql_psycopg2": "EXTRACT(EPOCH FROM %s)" ,
}
now_tz_sqls = {
"mysql": "UTC_TIMESTAMP()",
"postgresql_psycopg2": "NOW() AT TIME ZONE 'utc'",
}
db_engine = settings.DATABASES[queryset.db]["ENGINE"].rsplit(".", 1)[1]
timestamp_sql = timestamp_sqls.get(db_engine)
now_sql = now_tz_sqls.get(db_engine) if settings.USE_TZ else "NOW()",
if timestamp_sql and now_sql:
score_sql = "(%s) / POW(%s - %s, %s)" % (
" + ".join(score_fields),
timestamp_sql % now_sql,
timestamp_sql % date_field,
scale,
)
order_by = "-score" if reverse else "score"
return queryset.extra(select={"score": score_sql}).order_by(order_by)
else:
for obj in queryset:
age = (now() - getattr(obj, date_field)).total_seconds()
score_fields_sum = sum([getattr(obj, f) for f in score_fields])
score = score_fields_sum / pow(age, scale)
setattr(obj, "score", score)
return sorted(queryset, key=lambda obj: obj.score, reverse=reverse)
def auto_tag(link_obj):
"""
Split's the link object's title into words. Default function for the
``AUTO_TAG_FUNCTION`` setting.
"""
variations = lambda word: [word,
sub("^([^A-Za-z0-9])*|([^A-Za-z0-9]|s)*$", "", word),
sub("^([^A-Za-z0-9])*|([^A-Za-z0-9])*$", "", word)]
return sum(map(variations, split("\s|/", link_obj.title)), [])
|
from __future__ import division, unicode_literals
from re import sub, split
from django.conf import settings
from django.utils.timezone import now
def order_by_score(queryset, score_fields, date_field, reverse=True):
"""
Take some queryset (links or comments) and order them by score,
which is basically "rating_sum / age_in_seconds ^ scale", where
scale is a constant that can be used to control how quickly scores
reduce over time. To perform this in the database, it needs to
support a POW function, which Postgres and MySQL do. For databases
that don't such as SQLite, we perform the scoring/sorting in
memory, which will suffice for development.
"""
scale = getattr(settings, "SCORE_SCALE_FACTOR", 2)
# Timestamp SQL function snippets mapped to DB backends.
# Defining these assumes the SQL functions POW() and NOW()
# are available for the DB backend.
timestamp_sqls = {
"mysql": "UNIX_TIMESTAMP(%s)",
"postgresql_psycopg2": "EXTRACT(EPOCH FROM %s)" ,
}
db_engine = settings.DATABASES[queryset.db]["ENGINE"].rsplit(".", 1)[1]
timestamp_sql = timestamp_sqls.get(db_engine)
if timestamp_sql:
score_sql = "(%s) / POW(%s - %s, %s)" % (
" + ".join(score_fields),
timestamp_sql % "NOW()",
timestamp_sql % date_field,
scale,
)
order_by = "-score" if reverse else "score"
return queryset.extra(select={"score": score_sql}).order_by(order_by)
else:
for obj in queryset:
age = (now() - getattr(obj, date_field)).total_seconds()
score_fields_sum = sum([getattr(obj, f) for f in score_fields])
score = score_fields_sum / pow(age, scale)
setattr(obj, "score", score)
return sorted(queryset, key=lambda obj: obj.score, reverse=reverse)
def auto_tag(link_obj):
"""
Split's the link object's title into words. Default function for the
``AUTO_TAG_FUNCTION`` setting.
"""
variations = lambda word: [word,
sub("^([^A-Za-z0-9])*|([^A-Za-z0-9]|s)*$", "", word),
sub("^([^A-Za-z0-9])*|([^A-Za-z0-9])*$", "", word)]
return sum(map(variations, split("\s|/", link_obj.title)), [])
|
bsd-2-clause
|
Python
|
a38f2690ddcc72d24ab152b0c4c21ae51db7afa0
|
Update evaluate_task.py
|
google/BIG-bench,google/BIG-bench
|
docker/evaluate_task.py
|
docker/evaluate_task.py
|
# Copyright 2021 Google LLC
#
# 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
#
# https://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.
'''Evaluates a BIG-bench task in a docker container.
'''
import absl.flags
import absl.app
import os
import subprocess
MOUNT_PATH = '/bigbench'
RESULTS_DIR = 'eval_results'
# ----------------------------------------------------------------------------
FLAGS = absl.flags.FLAGS
absl.flags.DEFINE_string(
'task', None,
'Name of task to test. This should be the name of the task directory '
'under bigbench/benchmark_tasks.')
absl.flags.DEFINE_list('models', ['openai-gpt', 'gpt2'],
f'comma-separated list of models to evaluate')
absl.flags.DEFINE_string(
'output_path', None,
f'Path to output results. This path will be placed under your top-level '
f'BIG-bench repository directory under the directory "{RESULTS_DIR}". '
f'Thus if you specify --output_path=results.json, then the output file '
f'will be created at <top-level-dir>/eval_results/results.json. If not '
f'specified, this defaults to <task name>.json')
# ----------------------------------------------------------------------------
def main(_):
assert FLAGS.task is not None, 'task must be specified'
if FLAGS.output_path is None:
output_file = f'{FLAGS.task}.json'
else:
output_file = FLAGS.output_path.strip('/')
output_path = os.path.join(MOUNT_PATH, RESULTS_DIR, output_file)
host_path = os.path.abspath(os.path.split(os.path.split(__file__)[0])[0])
container_cmd = ' '.join([
f'cd {MOUNT_PATH} &&',
f'pip install . &&',
f'python /bigbench/bigbench/evaluate_task.py ',
f'--task',
FLAGS.task,
'--models',
','.join(FLAGS.models),
'--output_path',
output_path,
])
docker_cmd = [
'docker',
'run',
'-t',
'-v',
f'{host_path}:{MOUNT_PATH}',
'bigbench:latest',
'/usr/bin/bash',
'-c',
container_cmd,
]
subprocess.check_call(docker_cmd)
# ----------------------------------------------------------------------------
if __name__ == '__main__':
absl.app.run(main)
|
# Copyright 2021 Google LLC
#
# 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
#
# https://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.
'''Evaluates a task in BIG-bench docker container.
'''
import absl.flags
import absl.app
import os
import subprocess
MOUNT_PATH = '/bigbench'
RESULTS_DIR = 'eval_results'
# ----------------------------------------------------------------------------
FLAGS = absl.flags.FLAGS
absl.flags.DEFINE_string(
'task', None,
'Name of task to test. This should be the name of the task directory '
'under bigbench/benchmark_tasks.')
absl.flags.DEFINE_list('models', ['openai-gpt', 'gpt2'],
f'comma-separated list of models to evaluate')
absl.flags.DEFINE_string(
'output_path', None,
f'Path to output results. This path will be placed under your top-level '
f'BIG-bench repository directory under the directory "{RESULTS_DIR}". '
f'Thus if you specify --output_path=results.json, then the output file '
f'will be created at <top-level-dir>/eval_results/results.json. If not '
f'specified, this defaults to <task name>.json')
# ----------------------------------------------------------------------------
def main(_):
assert FLAGS.task is not None, 'task must be specified'
if FLAGS.output_path is None:
output_file = f'{FLAGS.task}.json'
else:
output_file = FLAGS.output_path.strip('/')
output_path = os.path.join(MOUNT_PATH, RESULTS_DIR, output_file)
host_path = os.path.abspath(os.path.split(os.path.split(__file__)[0])[0])
container_cmd = ' '.join([
f'cd {MOUNT_PATH} &&',
f'pip install . &&',
f'python /bigbench/bigbench/evaluate_task.py ',
f'--task',
FLAGS.task,
'--models',
','.join(FLAGS.models),
'--output_path',
output_path,
])
docker_cmd = [
'docker',
'run',
'-t',
'-v',
f'{host_path}:{MOUNT_PATH}',
'bigbench:latest',
'/usr/bin/bash',
'-c',
container_cmd,
]
subprocess.check_call(docker_cmd)
# ----------------------------------------------------------------------------
if __name__ == '__main__':
absl.app.run(main)
|
apache-2.0
|
Python
|
10a510dc3234860c697945c8c37393a9b5790b6c
|
Update lims.py
|
Clinical-Genomics/access
|
access/lims.py
|
access/lims.py
|
#!/usr/bin/python
#Script that connects to the MySQL database and parses data from an html table
#Import the mysql.connector library/module
import sys
import time
import glob
import re
import os
import requests
from xml.etree import ElementTree
def readconfig():
configfile = os.getenv('HOME') + '/.scilifelabrc'
params = {}
with open(configfile, "r") as confs:
for line in confs:
if len(line) > 3 and not line[0] == "#":
pv = line.rstrip().split(" ")
arg = pv[0]
pv.pop(0)
params[arg] = ' '.join(pv)
return params
class limsconnect(object):
def __init__(self, User, Passwd, baseuri):
self.user = User
self.pwd = Passwd
self.uri = baseuri
self.entrypoints = { 'samples': 'limsid', 'artifacts': 'limsid' }
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
print '__exit__(%s, %s, %s)' % (exc_type, exc_val, exc_tb)
def getroot(self):
r = requests.get(self.uri, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def getentry(self, searchattribute, searchvalue):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def gettag(self, searchattribute, searchvalue, tag):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
if node.tag == tag:
hit = node.text
return hit
def getattribute(self, searchattribute, searchvalue, attribute):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
for key in node.attrib:
if (key == attribute)
hit = node.text
# hit = node.attrib[attribute]
return hit
# def getlist(self, term):
# r = requests.get(self.uri + , auth=(self.user, self.pwd))
# uri = node.attrib.get('uri')
|
#!/usr/bin/python
#Script that connects to the MySQL database and parses data from an html table
#Import the mysql.connector library/module
import sys
import time
import glob
import re
import os
import requests
from xml.etree import ElementTree
def readconfig():
configfile = os.getenv('HOME') + '/.scilifelabrc'
params = {}
with open(configfile, "r") as confs:
for line in confs:
if len(line) > 3 and not line[0] == "#":
pv = line.rstrip().split(" ")
arg = pv[0]
pv.pop(0)
params[arg] = ' '.join(pv)
return params
class limsconnect(object):
def __init__(self, User, Passwd, baseuri):
self.user = User
self.pwd = Passwd
self.uri = baseuri
self.entrypoints = { 'samples': 'limsid', 'artifacts': 'limsid' }
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
print '__exit__(%s, %s, %s)' % (exc_type, exc_val, exc_tb)
def getroot(self):
r = requests.get(self.uri, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def getentry(self, searchattribute, searchvalue):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def gettag(self, searchattribute, searchvalue, tag):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
if node.tag == tag:
hit = node.text
return hit
# def getlist(self, term):
# r = requests.get(self.uri + , auth=(self.user, self.pwd))
# uri = node.attrib.get('uri')
|
mit
|
Python
|
c2c21fabd144ec25fa46fefdfe7c460a39aa2454
|
Update lims.py
|
Clinical-Genomics/access
|
access/lims.py
|
access/lims.py
|
#!/usr/bin/python
#Script that connects to the MySQL database and parses data from an html table
#Import the mysql.connector library/module
import sys
import time
import glob
import re
import os
import requests
from xml.etree import ElementTree
def readconfig():
configfile = os.getenv('HOME') + '/.scilifelabrc'
params = {}
with open(configfile, "r") as confs:
for line in confs:
if len(line) > 3 and not line[0] == "#":
pv = line.rstrip().split(" ")
arg = pv[0]
pv.pop(0)
params[arg] = ' '.join(pv)
return params
class limsconnect(object):
def __init__(self, User, Passwd, baseuri):
self.user = User
self.pwd = Passwd
self.uri = baseuri
self.entrypoints = { 'samples': 'limsid', 'artifacts': 'limsid' }
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
print '__exit__(%s, %s, %s)' % (exc_type, exc_val, exc_tb)
def getroot(self):
r = requests.get(self.uri, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def getentry(self, searchattribute, searchvalue):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def gettag(self, searchattribute, searchvalue, tag):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
if node.tag == tag:
hit = node.text
return hit
def getattribute(self, searchattribute, searchvalue, attribute):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
print node
for key in node.attrib:
print key
if (key == attribute):
hit = node.text
# hit = node.attrib[attribute]
return hit
# def getlist(self, term):
# r = requests.get(self.uri + , auth=(self.user, self.pwd))
# uri = node.attrib.get('uri')
|
#!/usr/bin/python
#Script that connects to the MySQL database and parses data from an html table
#Import the mysql.connector library/module
import sys
import time
import glob
import re
import os
import requests
from xml.etree import ElementTree
def readconfig():
configfile = os.getenv('HOME') + '/.scilifelabrc'
params = {}
with open(configfile, "r") as confs:
for line in confs:
if len(line) > 3 and not line[0] == "#":
pv = line.rstrip().split(" ")
arg = pv[0]
pv.pop(0)
params[arg] = ' '.join(pv)
return params
class limsconnect(object):
def __init__(self, User, Passwd, baseuri):
self.user = User
self.pwd = Passwd
self.uri = baseuri
self.entrypoints = { 'samples': 'limsid', 'artifacts': 'limsid' }
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
print '__exit__(%s, %s, %s)' % (exc_type, exc_val, exc_tb)
def getroot(self):
r = requests.get(self.uri, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def getentry(self, searchattribute, searchvalue):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
return tree.iter()
def gettag(self, searchattribute, searchvalue, tag):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
if node.tag == tag:
hit = node.text
return hit
def getattribute(self, searchattribute, searchvalue, attribute):
r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))
tree = ElementTree.fromstring(r.text)
hit = "No hit"
for node in tree:
for key in node.attrib:
if (key == attribute):
hit = node.text
# hit = node.attrib[attribute]
return hit
# def getlist(self, term):
# r = requests.get(self.uri + , auth=(self.user, self.pwd))
# uri = node.attrib.get('uri')
|
mit
|
Python
|
17157a4eb9d4aa934da89892f4f42f851902b44c
|
fix missing return in celery SiteRouter :rage1:
|
mbauskar/tele-frappe,mbauskar/Das_frappe,reachalpineswift/frappe-bench,gangadharkadam/letzfrappe,MaxMorais/frappe,saurabh6790/test-frappe,manassolanki/frappe,ESS-LLP/frappe,rohitwaghchaure/vestasi-frappe,nerevu/frappe,vCentre/vFRP-6233,rohitwaghchaure/New_Theme_frappe,gangadharkadam/vervefrappe,gangadharkadam/office_frappe,hatwar/buyback-frappe,geo-poland/frappe,erpletzerp/letzerpcore,indictranstech/frappe-digitales,indictranstech/tele-frappe,sbktechnology/trufil-frappe,mbauskar/phr-frappe,indictranstech/trufil-frappe,pawaranand/phr_frappe,mbauskar/frappe,ashokrajbathu/secondrep,indautgrp/frappe,elba7r/frameworking,vCentre/vFRP-6233,indictranstech/frappe,gangadhar-kadam/verve_test_frappe,rohitwaghchaure/frappe-digitales,vCentre/vFRP-6233,rkawale/Internalhr-frappe,gangadharkadam/frappecontribution,erpletzerp/letzerpcore,Tejal011089/digitales_frappe,yashodhank/frappe,sbktechnology/sap_frappe,tmimori/frappe,mbauskar/helpdesk-frappe,indictranstech/fbd_frappe,manassolanki/frappe,suyashphadtare/propshikhari-frappe,gangadhar-kadam/verve_test_frappe,gangadharkadam/shfr,gangadhar-kadam/verve_test_frappe,praba230890/frappe,letzerp/framework,suyashphadtare/sajil-final-frappe,gangadharkadam/v6_frappe,bcornwellmott/frappe,vjFaLk/frappe,erpletzerp/letzerpcore,suyashphadtare/sajil-frappe,pombredanne/frappe,indictranstech/internal-frappe,gangadharkadam/saloon_frappe_install,elba7r/frameworking,bohlian/frappe,praba230890/frappe,indictranstech/osmosis-frappe,letzerp/framework,indautgrp/frappe,reachalpineswift/frappe-bench,indictranstech/ebuy-now-frappe,paurosello/frappe,tundebabzy/frappe,rohitwaghchaure/frappe-alec,elba7r/builder,mhbu50/frappe,BhupeshGupta/frappe,drukhil/frappe,gangadharkadam/tailorfrappe,mhbu50/frappe,indictranstech/Das_frappe,rmehta/frappe,pombredanne/frappe,indictranstech/omnitech-frappe,nerevu/frappe,saurabh6790/frappe,gangadhar-kadam/verve_frappe,saurabh6790/phr-frappe,ShashaQin/frappe,ShashaQin/frappe,StrellaGroup/frappe,mbauskar/helpdesk-frappe,gangadhar-kadam/verve_live_frappe,rohitwaghchaure/vestasi-frappe,gangadharkadam/letzfrappe,elba7r/builder,nerevu/frappe,indautgrp/frappe,gangadharkadam/frappecontribution,aboganas/frappe,paurosello/frappe,BhupeshGupta/frappe,pawaranand/phr_frappe,reachalpineswift/frappe-bench,deveninfotech/deven-frappe,gangadharkadam/v4_frappe,BhupeshGupta/frappe,indictranstech/frappe-digitales,sbktechnology/sap_frappe,gangadharkadam/saloon_frappe,tmimori/frappe,hernad/frappe,rohitwaghchaure/frappe,indautgrp/frappe,adityahase/frappe,gangadhar-kadam/smrterpfrappe,saurabh6790/frappe,elba7r/builder,gangadharkadam/v5_frappe,pawaranand/phr-frappe,ashokrajbathu/secondrep,mbauskar/helpdesk-frappe,praba230890/frappe,rohitw1991/frappe,rohitwaghchaure/vestasi-frappe,indictranstech/internal-frappe,rkawale/Internalhr-frappe,Tejal011089/digitales_frappe,rohitwaghchaure/frappe,sbktechnology/trufil-frappe,gangadharkadam/letzfrappe,mbauskar/phr-frappe,mbauskar/tele-frappe,RicardoJohann/frappe,shitolepriya/test-frappe,rohitwaghchaure/frappe-alec,vqw/frappe,pawaranand/phr-frappe,rohitwaghchaure/New_Theme_frappe,StrellaGroup/frappe,pranalik/frappe-bb,gangadharkadam/smrtfrappe,tundebabzy/frappe,indictranstech/Das_frappe,rohitw1991/smarttailorfrappe,maxtorete/frappe,gangadharkadam/tailorfrappe,hatwar/buyback-frappe,saguas/frappe,neilLasrado/frappe,gangadharkadam/v6_frappe,indictranstech/tele-frappe,rmehta/frappe,sbkolate/sap_frappe_v6,rmehta/frappe,gangadharkadam/office_frappe,anandpdoshi/frappe,indictranstech/trufil-frappe,pranalik/frappe-bb,mbauskar/helpdesk-frappe,mbauskar/Das_frappe,gangadharkadam/v5_frappe,praba230890/frappe,MaxMorais/frappe,pombredanne/frappe,saurabh6790/frappe,indictranstech/tele-frappe,mbauskar/omnitech-frappe,vqw/frappe,gangadharkadam/office_frappe,RicardoJohann/frappe,vjFaLk/frappe,gangadharkadam/stfrappe,MaxMorais/frappe,gangadharkadam/letzfrappe,sbktechnology/sap_frappe,geo-poland/frappe,saguas/frappe,indictranstech/reciphergroup-frappe,neilLasrado/frappe,mbauskar/Das_frappe,indictranstech/osmosis-frappe,sbkolate/sap_frappe_v6,pranalik/frappe-bb,gangadhar-kadam/smrterpfrappe,sbktechnology/sap_frappe,sbkolate/sap_frappe_v6,indictranstech/phr-frappe,indictranstech/frappe,mbauskar/omnitech-demo-frappe,drukhil/frappe,RicardoJohann/frappe,indictranstech/trufil-frappe,indictranstech/reciphergroup-frappe,Tejal011089/digitales_frappe,indictranstech/phr-frappe,hernad/frappe,indictranstech/reciphergroup-frappe,rohitwaghchaure/frappe-digitales,mbauskar/frappe,indictranstech/osmosis-frappe,almeidapaulopt/frappe,indictranstech/frappe-digitales,rohitwaghchaure/frappe_smart,gangadharkadam/v4_frappe,deveninfotech/deven-frappe,suyashphadtare/propshikhari-frappe,almeidapaulopt/frappe,gangadhar-kadam/laganfrappe,bohlian/frappe,sbkolate/sap_frappe_v6,indictranstech/ebuy-now-frappe,almeidapaulopt/frappe,jevonearth/frappe,neilLasrado/frappe,gangadharkadam/v6_frappe,mbauskar/tele-frappe,ShashaQin/frappe,aboganas/frappe,reachalpineswift/frappe-bench,saguas/frappe,saurabh6790/phr-frappe,paurosello/frappe,paurosello/frappe,indictranstech/reciphergroup-frappe,hatwar/buyback-frappe,gangadhar-kadam/verve_live_frappe,ashokrajbathu/secondrep,Amber-Creative/amber-frappe,yashodhank/frappe,tmimori/frappe,mhbu50/frappe,indictranstech/trufil-frappe,gangadhar-kadam/helpdesk-frappe,bcornwellmott/frappe,elba7r/frameworking,adityahase/frappe,gangadharkadam/saloon_frappe,indictranstech/fbd_frappe,aboganas/frappe,sbktechnology/trufil-frappe,saurabh6790/frappe,saurabh6790/test-frappe,manassolanki/frappe,ESS-LLP/frappe,indictranstech/omnitech-frappe,mbauskar/omnitech-frappe,sbktechnology/trufil-frappe,gangadhar-kadam/verve_frappe,indictranstech/tele-frappe,gangadharkadam/v4_frappe,suyashphadtare/propshikhari-frappe,indictranstech/phr-frappe,indictranstech/ebuy-now-frappe,anandpdoshi/frappe,adityahase/frappe,gangadharkadam/saloon_frappe_install,anandpdoshi/frappe,hernad/frappe,adityahase/frappe,tmimori/frappe,gangadhar-kadam/helpdesk-frappe,gangadhar-kadam/verve_frappe,ashokrajbathu/secondrep,saurabh6790/phr-frappe,gangadharkadam/johnfrappe,vqw/frappe,bcornwellmott/frappe,almeidapaulopt/frappe,shitolepriya/test-frappe,mbauskar/omnitech-demo-frappe,indictranstech/omnitech-frappe,gangadharkadam/frappecontribution,drukhil/frappe,indictranstech/frappe-digitales,Amber-Creative/amber-frappe,hatwar/buyback-frappe,gangadharkadam/vlinkfrappe,gangadharkadam/v4_frappe,indictranstech/frappe,gangadhar-kadam/hrfrappe,gangadharkadam/smrtfrappe,BhupeshGupta/frappe,tundebabzy/frappe,suyashphadtare/sajil-frappe,gangadharkadam/vervefrappe,gangadhar-kadam/lgnlvefrape,Amber-Creative/amber-frappe,manassolanki/frappe,mbauskar/tele-frappe,gangadharkadam/vlinkfrappe,elba7r/builder,gangadharkadam/stfrappe,indictranstech/Das_frappe,bohlian/frappe,suyashphadtare/sajil-frappe,mbauskar/phr-frappe,MaxMorais/frappe,rohitwaghchaure/frappe_smart,gangadharkadam/saloon_frappe_install,chdecultot/frappe,suyashphadtare/sajil-final-frappe,mbauskar/omnitech-frappe,mhbu50/frappe,pawaranand/phr_frappe,indictranstech/phr-frappe,elba7r/frameworking,jevonearth/frappe,indictranstech/ebuy-now-frappe,frappe/frappe,vCentre/vFRP-6233,mbauskar/omnitech-demo-frappe,gangadhar-kadam/helpdesk-frappe,RicardoJohann/frappe,pawaranand/phr_frappe,chdecultot/frappe,StrellaGroup/frappe,Tejal011089/digitales_frappe,indictranstech/Das_frappe,indictranstech/frappe,maxtorete/frappe,ESS-LLP/frappe,gangadharkadam/vlinkfrappe,erpletzerp/letzerpcore,rohitwaghchaure/frappe,tundebabzy/frappe,rohitwaghchaure/frappe-alec,jevonearth/frappe,mbauskar/frappe,indictranstech/fbd_frappe,indictranstech/internal-frappe,cadencewatches/frappe,mbauskar/phr-frappe,indictranstech/omnitech-frappe,gangadharkadam/v5_frappe,gangadhar-kadam/helpdesk-frappe,gangadhar-kadam/verve_test_frappe,gangadhar-kadam/hrfrappe,gangadhar-kadam/lgnlvefrape,ShashaQin/frappe,rohitwaghchaure/frappe,chdecultot/frappe,gangadharkadam/saloon_frappe,mbauskar/omnitech-frappe,rohitw1991/frappe,pawaranand/phr-frappe,Amber-Creative/amber-frappe,ESS-LLP/frappe,rohitw1991/smarttailorfrappe,gangadhar-kadam/laganfrappe,gangadharkadam/vlinkfrappe,letzerp/framework,vjFaLk/frappe,saguas/frappe,rohitwaghchaure/New_Theme_frappe,yashodhank/frappe,gangadharkadam/vervefrappe,yashodhank/frappe,gangadharkadam/saloon_frappe_install,aboganas/frappe,saurabh6790/test-frappe,gangadharkadam/vervefrappe,cadencewatches/frappe,chdecultot/frappe,gangadhar-kadam/verve_frappe,rohitw1991/smartfrappe,gangadharkadam/saloon_frappe,gangadhar-kadam/verve_live_frappe,rohitwaghchaure/vestasi-frappe,deveninfotech/deven-frappe,gangadhar-kadam/verve_live_frappe,hernad/frappe,gangadhar-kadam/lgnlvefrape,gangadharkadam/shfr,neilLasrado/frappe,mbauskar/frappe,gangadhar-kadam/laganfrappe,suyashphadtare/sajil-final-frappe,jevonearth/frappe,suyashphadtare/propshikhari-frappe,rmehta/frappe,shitolepriya/test-frappe,frappe/frappe,drukhil/frappe,frappe/frappe,mbauskar/Das_frappe,gangadharkadam/v6_frappe,indictranstech/internal-frappe,rohitwaghchaure/frappe-digitales,bohlian/frappe,bcornwellmott/frappe,pranalik/frappe-bb,rohitw1991/smartfrappe,anandpdoshi/frappe,nerevu/frappe,indictranstech/osmosis-frappe,pombredanne/frappe,deveninfotech/deven-frappe,vjFaLk/frappe,rohitwaghchaure/frappe-digitales,indictranstech/fbd_frappe,vqw/frappe,maxtorete/frappe,gangadharkadam/johnfrappe,mbauskar/omnitech-demo-frappe,geo-poland/frappe,saurabh6790/phr-frappe,shitolepriya/test-frappe,letzerp/framework,gangadharkadam/frappecontribution,gangadharkadam/v5_frappe,maxtorete/frappe,saurabh6790/test-frappe
|
frappe/celery_app.py
|
frappe/celery_app.py
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals, absolute_import
from celery import Celery
# initiate logger
from celery.utils.log import get_task_logger
task_logger = get_task_logger(__name__)
from datetime import timedelta
import frappe
import json
import os
SITES_PATH = os.environ.get('SITES_PATH', '.')
# defaults
DEFAULT_CELERY_BROKER = "redis://localhost"
DEFAULT_CELERY_BACKEND = None
DEFAULT_SCHEDULER_INTERVAL = 300
LONGJOBS_PREFIX = "longjobs@"
_app = None
def get_celery():
global _app
if not _app:
conf = frappe.get_site_config(sites_path=SITES_PATH)
_app = Celery('frappe',
broker=conf.celery_broker or DEFAULT_CELERY_BROKER,
backend=conf.celery_result_backend or DEFAULT_CELERY_BACKEND)
setup_celery(_app, conf)
return _app
def setup_celery(app, conf):
app.autodiscover_tasks(frappe.get_all_apps(with_frappe=True, with_internal_apps=False,
sites_path=SITES_PATH))
app.conf.CELERY_TASK_SERIALIZER = 'json'
app.conf.CELERY_ACCEPT_CONTENT = ['json']
app.conf.CELERY_TIMEZONE = 'UTC'
if conf.celery_queue_per_site:
app.conf.CELERY_ROUTES = (SiteRouter(),)
app.conf.CELERYBEAT_SCHEDULE = get_beat_schedule(conf)
class SiteRouter(object):
def route_for_task(self, task, args=None, kwargs=None):
if hasattr(frappe.local, 'site'):
if kwargs and kwargs.get("event", "").endswith("_long"):
return get_queue(frappe.local.site, LONGJOBS_PREFIX)
else:
return get_queue(frappe.local.site)
return None
def get_queue(site, prefix=None):
return {'queue': "{}{}".format(prefix or "", site)}
def get_beat_schedule(conf):
schedule = {
'scheduler': {
'task': 'frappe.tasks.enqueue_scheduler_events',
'schedule': timedelta(seconds=conf.scheduler_interval or DEFAULT_SCHEDULER_INTERVAL)
},
}
if conf.celery_queue_per_site:
schedule['sync_queues'] = {
'task': 'frappe.tasks.sync_queues',
'schedule': timedelta(seconds=conf.scheduler_interval or DEFAULT_SCHEDULER_INTERVAL)
}
return schedule
def celery_task(*args, **kwargs):
return get_celery().task(*args, **kwargs)
if __name__ == '__main__':
get_celery().start()
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals, absolute_import
from celery import Celery
# initiate logger
from celery.utils.log import get_task_logger
task_logger = get_task_logger(__name__)
from datetime import timedelta
import frappe
import json
import os
SITES_PATH = os.environ.get('SITES_PATH', '.')
# defaults
DEFAULT_CELERY_BROKER = "redis://localhost"
DEFAULT_CELERY_BACKEND = None
DEFAULT_SCHEDULER_INTERVAL = 300
LONGJOBS_PREFIX = "longjobs@"
_app = None
def get_celery():
global _app
if not _app:
conf = frappe.get_site_config(sites_path=SITES_PATH)
_app = Celery('frappe',
broker=conf.celery_broker or DEFAULT_CELERY_BROKER,
backend=conf.celery_result_backend or DEFAULT_CELERY_BACKEND)
setup_celery(_app, conf)
return _app
def setup_celery(app, conf):
app.autodiscover_tasks(frappe.get_all_apps(with_frappe=True, with_internal_apps=False,
sites_path=SITES_PATH))
app.conf.CELERY_TASK_SERIALIZER = 'json'
app.conf.CELERY_ACCEPT_CONTENT = ['json']
app.conf.CELERY_TIMEZONE = 'UTC'
if conf.celery_queue_per_site:
app.conf.CELERY_ROUTES = (SiteRouter(),)
app.conf.CELERYBEAT_SCHEDULE = get_beat_schedule(conf)
class SiteRouter(object):
def route_for_task(self, task, args=None, kwargs=None):
if hasattr(frappe.local, 'site'):
if kwargs and kwargs.get("event", "").endswith("_long"):
get_queue(frappe.local.site, LONGJOBS_PREFIX)
else:
get_queue(frappe.local.site)
return None
def get_queue(site, prefix=None):
return {'queue': "{}{}".format(prefix or "", site)}
def get_beat_schedule(conf):
schedule = {
'scheduler': {
'task': 'frappe.tasks.enqueue_scheduler_events',
'schedule': timedelta(seconds=conf.scheduler_interval or DEFAULT_SCHEDULER_INTERVAL)
},
}
if conf.celery_queue_per_site:
schedule['sync_queues'] = {
'task': 'frappe.tasks.sync_queues',
'schedule': timedelta(seconds=conf.scheduler_interval or DEFAULT_SCHEDULER_INTERVAL)
}
return schedule
def celery_task(*args, **kwargs):
return get_celery().task(*args, **kwargs)
if __name__ == '__main__':
get_celery().start()
|
mit
|
Python
|
619b51a579801b8ae211cb062b00149c19af11a7
|
Make manage task more general
|
amyshi188/osf.io,RomanZWang/osf.io,acshi/osf.io,alexschiller/osf.io,hmoco/osf.io,TomHeatwole/osf.io,mluo613/osf.io,felliott/osf.io,chrisseto/osf.io,kwierman/osf.io,aaxelb/osf.io,Johnetordoff/osf.io,chrisseto/osf.io,KAsante95/osf.io,abought/osf.io,mattclark/osf.io,emetsger/osf.io,CenterForOpenScience/osf.io,TomHeatwole/osf.io,doublebits/osf.io,GageGaskins/osf.io,mluo613/osf.io,zachjanicki/osf.io,icereval/osf.io,TomBaxter/osf.io,Johnetordoff/osf.io,zamattiac/osf.io,monikagrabowska/osf.io,mluke93/osf.io,RomanZWang/osf.io,wearpants/osf.io,kwierman/osf.io,mluo613/osf.io,zamattiac/osf.io,CenterForOpenScience/osf.io,kch8qx/osf.io,jnayak1/osf.io,caneruguz/osf.io,RomanZWang/osf.io,crcresearch/osf.io,samchrisinger/osf.io,binoculars/osf.io,SSJohns/osf.io,baylee-d/osf.io,felliott/osf.io,HalcyonChimera/osf.io,RomanZWang/osf.io,wearpants/osf.io,monikagrabowska/osf.io,DanielSBrown/osf.io,caseyrollins/osf.io,zachjanicki/osf.io,rdhyee/osf.io,laurenrevere/osf.io,emetsger/osf.io,HalcyonChimera/osf.io,zachjanicki/osf.io,acshi/osf.io,brianjgeiger/osf.io,Nesiehr/osf.io,TomBaxter/osf.io,billyhunt/osf.io,Johnetordoff/osf.io,leb2dg/osf.io,mfraezz/osf.io,monikagrabowska/osf.io,RomanZWang/osf.io,leb2dg/osf.io,Nesiehr/osf.io,kch8qx/osf.io,abought/osf.io,mattclark/osf.io,billyhunt/osf.io,abought/osf.io,jnayak1/osf.io,alexschiller/osf.io,emetsger/osf.io,erinspace/osf.io,adlius/osf.io,caseyrollins/osf.io,aaxelb/osf.io,cwisecarver/osf.io,mluke93/osf.io,saradbowman/osf.io,CenterForOpenScience/osf.io,caneruguz/osf.io,TomHeatwole/osf.io,chennan47/osf.io,leb2dg/osf.io,icereval/osf.io,SSJohns/osf.io,GageGaskins/osf.io,GageGaskins/osf.io,SSJohns/osf.io,cslzchen/osf.io,rdhyee/osf.io,zamattiac/osf.io,HalcyonChimera/osf.io,HalcyonChimera/osf.io,zamattiac/osf.io,pattisdr/osf.io,hmoco/osf.io,cwisecarver/osf.io,adlius/osf.io,sloria/osf.io,rdhyee/osf.io,wearpants/osf.io,brandonPurvis/osf.io,jnayak1/osf.io,zachjanicki/osf.io,pattisdr/osf.io,DanielSBrown/osf.io,crcresearch/osf.io,asanfilippo7/osf.io,erinspace/osf.io,aaxelb/osf.io,TomHeatwole/osf.io,KAsante95/osf.io,crcresearch/osf.io,Ghalko/osf.io,sloria/osf.io,chrisseto/osf.io,caneruguz/osf.io,acshi/osf.io,cslzchen/osf.io,Nesiehr/osf.io,KAsante95/osf.io,cslzchen/osf.io,felliott/osf.io,asanfilippo7/osf.io,kch8qx/osf.io,CenterForOpenScience/osf.io,laurenrevere/osf.io,kch8qx/osf.io,hmoco/osf.io,hmoco/osf.io,cwisecarver/osf.io,mfraezz/osf.io,alexschiller/osf.io,cwisecarver/osf.io,billyhunt/osf.io,mluke93/osf.io,Ghalko/osf.io,monikagrabowska/osf.io,amyshi188/osf.io,amyshi188/osf.io,doublebits/osf.io,KAsante95/osf.io,Ghalko/osf.io,rdhyee/osf.io,SSJohns/osf.io,felliott/osf.io,adlius/osf.io,chrisseto/osf.io,doublebits/osf.io,cslzchen/osf.io,alexschiller/osf.io,binoculars/osf.io,saradbowman/osf.io,mluo613/osf.io,acshi/osf.io,caneruguz/osf.io,jnayak1/osf.io,brandonPurvis/osf.io,DanielSBrown/osf.io,GageGaskins/osf.io,DanielSBrown/osf.io,mattclark/osf.io,brianjgeiger/osf.io,binoculars/osf.io,caseyrollins/osf.io,asanfilippo7/osf.io,mfraezz/osf.io,alexschiller/osf.io,pattisdr/osf.io,KAsante95/osf.io,mfraezz/osf.io,doublebits/osf.io,GageGaskins/osf.io,emetsger/osf.io,brandonPurvis/osf.io,brianjgeiger/osf.io,Ghalko/osf.io,brianjgeiger/osf.io,doublebits/osf.io,icereval/osf.io,kwierman/osf.io,wearpants/osf.io,kch8qx/osf.io,asanfilippo7/osf.io,acshi/osf.io,billyhunt/osf.io,baylee-d/osf.io,abought/osf.io,samchrisinger/osf.io,mluo613/osf.io,kwierman/osf.io,baylee-d/osf.io,leb2dg/osf.io,Johnetordoff/osf.io,aaxelb/osf.io,chennan47/osf.io,adlius/osf.io,samchrisinger/osf.io,amyshi188/osf.io,mluke93/osf.io,Nesiehr/osf.io,billyhunt/osf.io,sloria/osf.io,TomBaxter/osf.io,chennan47/osf.io,erinspace/osf.io,brandonPurvis/osf.io,laurenrevere/osf.io,monikagrabowska/osf.io,brandonPurvis/osf.io,samchrisinger/osf.io
|
admin/tasks.py
|
admin/tasks.py
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
from invoke import task, run
from tasks.utils import pip_install
from website import settings
HERE = os.path.dirname(os.path.abspath(__file__))
WHEELHOUSE_PATH = os.environ.get('WHEELHOUSE')
@task()
def manage(cmd_str):
"""Take command string and target (-t) for manage commands
:param args: ex. runserver, migrate
"""
manage_cmd = os.path.join(HERE, '..', 'manage.py')
env = 'DJANGO_SETTINGS_MODULE="admin.base.settings"'
cmd = '{} python {} {}'.format(env, manage_cmd, cmd_str)
run(cmd, echo=True, pty=True)
@task()
def assets(dev=False, watch=False):
"""Install and build static assets for admin."""
if os.getcwd() != HERE:
os.chdir(HERE)
npm = 'npm install'
if not dev:
npm += ' --production'
run(npm, echo=True)
bower_install()
# Always set clean=False to prevent possible mistakes
# on prod
webpack(clean=False, watch=watch, dev=dev)
@task(aliases=['pack'])
def webpack(clean=False, watch=False, dev=False):
"""Build static assets with webpack."""
if clean:
clean_assets()
if os.getcwd() != HERE:
os.chdir(HERE)
webpack_bin = os.path.join(HERE, 'node_modules', 'webpack', 'bin',
'webpack.js')
args = [webpack_bin]
if settings.DEBUG_MODE and dev:
args += ['--colors']
else:
args += ['--progress']
if watch:
args += ['--watch']
config_file = 'webpack.admin.config.js' if dev else 'webpack.prod.config.js'
args += ['--config {0}'.format(config_file)]
command = ' '.join(args)
run(command, echo=True)
@task
def clean_assets():
"""Remove built JS files."""
public_path = os.path.join(HERE, 'static', 'public')
js_path = os.path.join(public_path, 'js')
run('rm -rf {0}'.format(js_path), echo=True)
@task(aliases=['bower'])
def bower_install():
if os.getcwd() != HERE:
os.chdir(HERE)
bower_bin = os.path.join(HERE, 'node_modules', 'bower', 'bin', 'bower')
run('{} prune'.format(bower_bin), echo=True)
run('{} install'.format(bower_bin), echo=True)
@task(aliases=['req'])
def requirements():
req_file = os.path.join(HERE, '..', 'requirements', 'admin.txt')
run(pip_install(req_file), echo=True)
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
from invoke import task, run
from tasks.utils import pip_install
from website import settings
HERE = os.path.dirname(os.path.abspath(__file__))
WHEELHOUSE_PATH = os.environ.get('WHEELHOUSE')
@task()
def manage(cmd_str, target=''):
"""Take command string and target (-t) for manage commands
:param args: ex. runserver, migrate
"""
manage_cmd = os.path.join(HERE, '..', 'manage.py')
env = 'DJANGO_SETTINGS_MODULE="admin.base.settings"'
cmd = '{} python {} {} {}'.format(env, manage_cmd, cmd_str, target)
run(cmd, echo=True, pty=True)
@task()
def assets(dev=False, watch=False):
"""Install and build static assets for admin."""
if os.getcwd() != HERE:
os.chdir(HERE)
npm = 'npm install'
if not dev:
npm += ' --production'
run(npm, echo=True)
bower_install()
# Always set clean=False to prevent possible mistakes
# on prod
webpack(clean=False, watch=watch, dev=dev)
@task(aliases=['pack'])
def webpack(clean=False, watch=False, dev=False):
"""Build static assets with webpack."""
if clean:
clean_assets()
if os.getcwd() != HERE:
os.chdir(HERE)
webpack_bin = os.path.join(HERE, 'node_modules', 'webpack', 'bin',
'webpack.js')
args = [webpack_bin]
if settings.DEBUG_MODE and dev:
args += ['--colors']
else:
args += ['--progress']
if watch:
args += ['--watch']
config_file = 'webpack.admin.config.js' if dev else 'webpack.prod.config.js'
args += ['--config {0}'.format(config_file)]
command = ' '.join(args)
run(command, echo=True)
@task
def clean_assets():
"""Remove built JS files."""
public_path = os.path.join(HERE, 'static', 'public')
js_path = os.path.join(public_path, 'js')
run('rm -rf {0}'.format(js_path), echo=True)
@task(aliases=['bower'])
def bower_install():
if os.getcwd() != HERE:
os.chdir(HERE)
bower_bin = os.path.join(HERE, 'node_modules', 'bower', 'bin', 'bower')
run('{} prune'.format(bower_bin), echo=True)
run('{} install'.format(bower_bin), echo=True)
@task(aliases=['req'])
def requirements():
req_file = os.path.join(HERE, '..', 'requirements', 'admin.txt')
run(pip_install(req_file), echo=True)
|
apache-2.0
|
Python
|
50a2ac8e5aeee2c4435707a72c22092e28ecf5ba
|
Update zeromq_server.py
|
bcb/jsonrpcserver
|
examples/zeromq_server.py
|
examples/zeromq_server.py
|
from jsonrpcserver import Success, method, dispatch
import zmq
socket = zmq.Context().socket(zmq.REP)
@method
def ping():
return Success("pong")
if __name__ == "__main__":
socket.bind("tcp://*:5000")
while True:
request = socket.recv().decode()
socket.send_string(dispatch(request))
|
import zmq
from jsonrpcserver import Success, method, dispatch
socket = zmq.Context().socket(zmq.REP)
@method
def ping():
return Success("pong")
if __name__ == "__main__":
socket.bind("tcp://*:5000")
while True:
request = socket.recv().decode()
socket.send_string(dispatch(request))
|
mit
|
Python
|
709e9dddf94e8afa43d908e92f7c7d6bc0817e46
|
remove commented line
|
bappelt/WeatherPi
|
humid_temp.py
|
humid_temp.py
|
import weather_utils
import Adafruit_DHT
def get_data():
humidity, temp_c = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4)
temp_f = weather_utils.c_to_f(temp_c)
return { 'temp_f': temp_f,
'temp_c': temp_c,
'humidity': humidity,
'dewptf': weather_utils.dewpoint_f(temp_f, humidity) }
|
# import Adafruit_Python_DHT
import weather_utils
import Adafruit_DHT
def get_data():
humidity, temp_c = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4)
temp_f = weather_utils.c_to_f(temp_c)
return { 'temp_f': temp_f,
'temp_c': temp_c,
'humidity': humidity,
'dewptf': weather_utils.dewpoint_f(temp_f, humidity) }
|
mit
|
Python
|
6a415f0c0be752bd1a7677fd45d5738a1caf2ece
|
Sort accounts by name
|
mikeboers/Spoon,mikeboers/Spoon,mikeboers/Spoon,mikeboers/Spoon
|
gitbase/controllers/index.py
|
gitbase/controllers/index.py
|
from . import *
@app.route('/')
def index():
groups = Account.query.options(sa.orm.joinedload('repos')).all()
groups = [g for g in groups if auth.can('account.read', g)]
groups.sort(key=lambda g: g.name)
return render_template('index.haml', groups=groups)
|
from . import *
@app.route('/')
def index():
groups = Account.query.options(sa.orm.joinedload('repos')).all()
groups = [g for g in groups if auth.can('account.read', g)]
return render_template('index.haml', groups=groups)
|
bsd-3-clause
|
Python
|
5a0c6904c23a84d1ee931e3ef82f297197141222
|
add twitter and flags
|
davidbradway/beaglebone-python
|
light.py
|
light.py
|
#!/usr/bin/python
"""
light.py
Read analog values from the photoresistor
=======
run with:
sudo ./light.py
Copyright 2014 David P. Bradway ([email protected])
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.
"""
__author__ = "David Bradway"
__email__ = "[email protected]"
__license__ = "Apache v2.0"
def main():
import Adafruit_BBIO.ADC as ADC
import time
import datetime
import numpy as np
import matplotlib.pyplot as plt
import collections
import twitter
# Set Flags
plotit = 0
debug = 0
printit = 1
tweetit = 1
# Set ADC
sensor_pin = 'P9_40'
ADC.setup()
# Set data collection buffer
buflength = 15
circbuf=collections.deque(maxlen=buflength)
# Plot the raw data
if plotit:
#plt.axis([0, 1000, -.1, 1.7])
plt.ion()
plt.show()
# Print table of data
if debug:
print('Time\tVolts\t\tMedian\t\tVariance\t\tStable\t\t\tnewstateflag')
if tweetit:
api = twitter.Api(consumer_key='',
consumer_secret='',
access_token_key='',
access_token_secret='')
if debug:
print api.VerifyCredentials()
i = 0
med = 0
stable = 0
variance = 0
newstateflag = False
while True:
now = datetime.datetime.now()
reading = ADC.read(sensor_pin)
volts = reading * 1.800
circbuf.append(volts)
med = np.median(circbuf)
variance = np.var(circbuf)
if variance < 0.001:
stable = med
newstateflag = False
if variance > 0.01 and newstateflag == False:
if med > stable:
update = 'Lights on %s' % (str(now))
if printit:
print(update)
if tweetit:
status = api.PostUpdate(update)
newstateflag = True
elif med < stable:
update = 'Lights off %s' % (str(now))
if printit:
print(update)
if tweetit:
status = api.PostUpdate(update)
newstateflag = True
if debug:
print('%s\t%f\t%f\t%f\t%f\t%f' % (now.second, volts, med, variance, stable, newstateflag))
if plotit:
plt.scatter(i, med)
plt.draw()
time.sleep(.25)
i=i+1
if __name__ == "__main__":
main()
|
#!/usr/bin/python
"""
light.py
Read analog values from the photoresistor
=======
run with:
sudo ./light.py
Copyright 2014 David P. Bradway ([email protected])
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.
"""
__author__ = "David Bradway"
__email__ = "[email protected]"
__license__ = "Apache v2.0"
def main():
import Adafruit_BBIO.ADC as ADC
import time
import datetime
import numpy as np
import matplotlib.pyplot as plt
sensor_pin = 'P9_40'
ADC.setup()
#plt.axis([0, 1000, 0, 1])
plt.ion()
plt.show()
print('Time\tReading\t\tVolts')
i=0
while True:
now = datetime.datetime.now()
reading = ADC.read(sensor_pin)
volts = reading * 1.800
print('%s\t%f\t%f' % (now.second, reading, volts))
plt.scatter(i, volts)
plt.draw()
time.sleep(0.1)
i=i+1
if __name__ == "__main__":
main()
|
apache-2.0
|
Python
|
e6b3a02376f832ee1bf79905ececfc76933197fc
|
Fix client
|
jvictor0/TiaraBoom,jvictor0/TiaraBoom,jvictor0/TiaraBoom
|
client/client.py
|
client/client.py
|
import socket
import os
import json
import time
class Client():
def __init__(self):
abs_prefix = os.path.join(os.path.dirname(__file__), "../client")
with open(abs_prefix + '/config.json','r') as f:
conf = json.load(f)
self.port = conf["port"]
self.host = conf["host"]
print (self.host,self.port)
self.password = conf["password"]
self.sock = socket.socket()
self.sock.connect((self.host, self.port))
self.sock.send(self.password)
assert self.sock.recv(1024) == "welcome"
def Send(self, msg):
self.sock.send(msg)
if msg == "quit":
self.Close()
return False
data = self.sock.recv(1024)
print data
return True
def Prompt(self):
return self.Send(raw_input("boom> "))
def Close(self):
self.sock.close()
if __name__ == "__main__":
c = Client()
print "You are now connected to a TiaraBoom server."
print "This server enforces NO RATE LIMITS!!!"
print "Please respect that Tiara does not wish to respond to more than a few requests per hour!"
print "If you receive an error other than a syntax error, or the server does not respond, please DO NOT TRY AGAIN"
print "Instead, contact support at 513-284-5321"
print "Enter a command, or try \"help\""
print "to exit, type quit"
while True:
if not c.Prompt():
break
print "good bye"
|
import socket
import os
import json
import time
class Client():
def __init__(self):
abs_prefix = os.path.join(os.path.dirname(__file__), "../data")
with open(abs_prefix + '/config.json','r') as f:
conf = json.load(f)
self.port = conf["port"]
self.host = conf["host"]
self.password = conf["password"]
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock = socket.socket()
self.sock.connect((self.host, self.port))
self.sock.send(self.password)
assert self.sock.recv(1024) == "welcome"
def Send(self, msg):
self.sock.send(msg)
if msg == "quit":
self.sock.Close()
return False
data = self.sock.recv(1024)
print data
return True
def Prompt(self):
return self.Send(raw_input("boom> "))
def Close(self):
self.sock.close()
if __name__ == "__main__":
c = Client()
print "You are now connected to a TiaraBoom server."
print "This server enforces NO RATE LIMITS!!!"
print "Please respect that Tiara does not wish to respond to more than a few requests per hour!"
print "If you receive an error other than a syntax error, or the server does not respond, please DO NOT TRY AGAIN"
print "Instead, contact support at 513-284-5321"
print "Enter a command, or try \"help\""
print "to exit, type quit"
while True:
if not c.Prompt():
break
print "good bye"
|
mit
|
Python
|
d4d4a065323d61073eb80a4f7f04d2902a33e4fe
|
fix ntb publish service get_filename for events
|
petrjasek/superdesk-ntb,ioanpocol/superdesk-ntb,petrjasek/superdesk-ntb,superdesk/superdesk-ntb,ioanpocol/superdesk-ntb,superdesk/superdesk-ntb,superdesk/superdesk-ntb,petrjasek/superdesk-ntb,ioanpocol/superdesk-ntb,petrjasek/superdesk-ntb,superdesk/superdesk-ntb
|
server/ntb/publish/ntb_publish_service.py
|
server/ntb/publish/ntb_publish_service.py
|
# -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2016 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
from superdesk.publish.publish_service import PublishService, set_publish_service
from xml.etree import ElementTree as ET
import logging
logger = logging.getLogger(__name__)
class NTBPublishService(PublishService):
DEFAULT_EXT = "xml"
@classmethod
def get_filename(cls, item):
# we reparse formatted item to get filename from <meta name="filename"> element
# this way we are sure that we have the exact same filename
try:
xml = ET.fromstring(item['formatted_item'])
except (KeyError, ET.ParseError) as e:
filename = None
logger.error("Error on parsing, can't get filename: {}".format(e))
else:
try:
filename = xml.find('head/meta[@name="filename"]').attrib['content']
except AttributeError:
filename = None
if not filename:
return super(NTBPublishService, cls).get_filename(item)
return filename
set_publish_service(NTBPublishService)
|
# -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2016 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
from superdesk.publish.publish_service import PublishService, set_publish_service
from xml.etree import ElementTree as ET
import logging
logger = logging.getLogger(__name__)
class NTBPublishService(PublishService):
DEFAULT_EXT = "xml"
@classmethod
def get_filename(cls, item):
# we reparse formatted item to get filename from <meta name="filename"> element
# this way we are sure that we have the exact same filename
try:
xml = ET.fromstring(item['formatted_item'])
except (KeyError, ET.ParseError) as e:
filename = None
logger.error("Error on parsing, can't get filename: {}".format(e))
else:
filename = xml.find('head/meta[@name="filename"]').attrib['content']
if not filename:
return super(NTBPublishService, cls).get_filename(item)
return filename
set_publish_service(NTBPublishService)
|
agpl-3.0
|
Python
|
936e6427c48ebbf16a12fb3afa0f48ad6c397046
|
fix feature input to hb-view
|
googlefonts/fontdiffenator,googlefonts/fontdiffenator
|
Lib/diffenator/utils.py
|
Lib/diffenator/utils.py
|
import subprocess
from PIL import Image
from fontTools.varLib.mutator import instantiateVariableFont
try:
from StringIO import StringIO
except ImportError: # py3 workaround
from io import BytesIO as StringIO
def render_string(font, string, features=None, pt_size=128):
"""Use Harfbuzz to render a string"""
cmd = ['hb-view', '--font-size=%d' % pt_size]
if font.instance_coordinates:
location = ''
for axis, val in font.instance_coordinates.items():
location += '{}={}, '.format(axis, val)
cmd += ['--variations=%s' % location]
if features:
# ignore aalt tag. This feat is used so users can access glyphs
# via a glyph pallette.
# https://typedrawers.com/discussion/1319/opentype-aalt-feature
# glyphsapp will autogen this feature
cmd += ['--features=%s' % ','.join(features).replace("aalt,", "")]
cmd += [font.path, u'{}'.format(string)]
try:
img = StringIO(subprocess.check_output(cmd))
return Image.open(img)
except FileNotFoundError:
raise OSError(
"hb-view was not found. Check if Harbuzz is installed."
)
|
import subprocess
from PIL import Image
from fontTools.varLib.mutator import instantiateVariableFont
try:
from StringIO import StringIO
except ImportError: # py3 workaround
from io import BytesIO as StringIO
def render_string(font, string, features=None, pt_size=128):
"""Use Harfbuzz to render a string"""
cmd = ['hb-view', '--font-size=%d' % pt_size]
if font.instance_coordinates:
location = ''
for axis, val in font.instance_coordinates.items():
location += '{}={}, '.format(axis, val)
cmd += ['--variations=%s' % location]
if features:
cmd += ['--features=%s' % features]
cmd += [font.path, u'{}'.format(string)]
try:
img = StringIO(subprocess.check_output(cmd))
return Image.open(img)
except FileNotFoundError:
raise OSError(
"hb-view was not found. Check if Harbuzz is installed."
)
|
apache-2.0
|
Python
|
7bce0c3e1c2cc0ca8f37916ad88abd0f91ba2c38
|
Update Keras.py
|
paperrune/Neural-Networks,paperrune/Neural-Networks
|
tanh/Keras.py
|
tanh/Keras.py
|
from keras.datasets import mnist
from keras.initializers import RandomUniform
from keras.layers import Dense
from keras.models import Sequential
from keras.optimizers import SGD
from keras.utils import to_categorical
batch_size = 128
epochs = 30
learning_rate = 0.5
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape([x_train.shape[0], -1]).astype('float32') / 255
y_train = to_categorical(y_train, num_classes=10)
x_test = x_test.reshape([x_test.shape[0], -1]).astype('float32') / 255
y_test = to_categorical(y_test, num_classes=10)
model = Sequential()
model.add(Dense(512,
activation='tanh',
input_shape=(784,),
kernel_initializer=RandomUniform(minval=-0.01, maxval=0.01)))
model.add(Dense(512,
activation='tanh',
kernel_initializer=RandomUniform(minval=-0.01, maxval=0.01)))
model.add(Dense(10,
activation='softmax',
kernel_initializer=RandomUniform(minval=-0.01, maxval=0.01)))
model.summary()
model.compile(loss='categorical_crossentropy',
optimizer=SGD(lr=learning_rate),
metrics=['accuracy'])
model.fit(x_train,
y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(x_test, y_test))
|
from keras.datasets import mnist
from keras.initializers import RandomUniform
from keras.layers import Dense
from keras.models import Sequential
from keras.optimizers import SGD
from keras.utils import to_categorical
batch_size = 128
epochs = 30
learning_rate = 0.5
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape([x_train.shape[0], -1]).astype('float32') / 255
y_train = to_categorical(y_train, num_classes=10)
x_test = x_test.reshape([x_test.shape[0], -1]).astype('float32') / 255
y_test = to_categorical(y_test, num_classes=10)
model = Sequential()
model.add(Dense(512,
activation='tanh',
input_shape=(784,),
kernel_initializer=RandomUniform(minval=-0.01, maxval=0.01)))
model.add(Dense(512,
activation='tanh',
kernel_initializer=RandomUniform(minval=-0.01, maxval=0.01)))
model.add(Dense(10,
activation='softmax',
kernel_initializer=RandomUniform(minval=-0.01, maxval=0.01)))
model.summary()
model.compile(loss='categorical_crossentropy',
optimizer=SGD(lr=learning_rate),
metrics=['accuracy'])
history = model.fit(x_train,
y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(x_test, y_test))
|
mit
|
Python
|
4063d94b405a41ead8d5c3df5a1d27dd1dba140f
|
remove config for warmup
|
MiCHiLU/gae-tap,MiCHiLU/gae-tap,MiCHiLU/gae-tap,MiCHiLU/gae-tap
|
gae/tap/warmup.py
|
gae/tap/warmup.py
|
# -*- coding: utf-8 -*-
from functools import wraps
import os
import sys
import webapp2
# Search Path
def execute_once(func):
@wraps(func)
def inner(_result=[None], *argv, **kwargv):
if _result[0] is None:
_result[0] = func(*argv, **kwargv)
if _result[0] is None:
raise ValueError("The return value must be not `None`.")
return _result[0]
return inner
@execute_once
def sys_path_append():
try:
import __main__ as main
except ImportError:
is_shell = False
else:
is_shell = not hasattr(main, "__file__")
base_path = os.environ.get("SITE_PACKAGES", "site-packages")
path = base_path
if path not in sys.path and os.path.exists(path):
sys.path.append(path)
if os.path.exists(base_path):
path = os.path.join(base_path, "packages")
if path not in sys.path:
sys.path.append(path)
if os.path.exists(path):
for zipfile in os.listdir(path):
if zipfile.endswith(".zip"):
zipfile_path = os.path.join(path, zipfile)
if zipfile_path not in sys.path:
sys.path.append(zipfile_path)
if is_shell or sys.argv[0].endswith("/sphinx-build"):
import google
base = os.path.join(os.path.dirname(google.__file__), "../lib/")
for webapp2 in ["webapp2-2.5.2", "webapp2"]:
path = os.path.join(base, webapp2)
if os.path.exists(path):
sys.path.append(path)
break
for path in ["endpoints-1.0", "protorpc-1.0", "jinja2"]:
sys.path.append(os.path.join(base, path))
return True
sys_path_append()
from js.angular import angular_cookies, angular_resource
from js.bootstrap import bootstrap
import tap
class WarmUp(tap.RequestHandler):
@tap.head(angular_cookies, angular_resource, bootstrap)
def get(self):
pass
app = webapp2.WSGIApplication([
("/_ah/warmup", WarmUp),
])
|
# -*- coding: utf-8 -*-
from functools import wraps
import os
import sys
from google.appengine.api import lib_config
import webapp2
# Config
class ConfigDefaults(object):
IS_TEST = "unittest" in sys.modules.keys()
SITE_PACKAGES = "site-packages"
config = lib_config.register("warmup", ConfigDefaults.__dict__)
# Search Path
def execute_once(func):
@wraps(func)
def inner(_result=[None], *argv, **kwargv):
if _result[0] is None:
_result[0] = func(*argv, **kwargv)
if _result[0] is None:
raise ValueError("The return value must be not `None`.")
return _result[0]
return inner
@execute_once
def sys_path_append():
try:
import __main__ as main
except ImportError:
is_shell = False
else:
is_shell = not hasattr(main, "__file__")
base_path = config.SITE_PACKAGES
if config.IS_TEST or is_shell:
base_path = os.path.abspath(base_path)
path = base_path
if path not in sys.path and os.path.exists(path):
sys.path.append(path)
if os.path.exists(base_path):
path = os.path.join(base_path, "packages")
if path not in sys.path:
sys.path.append(path)
if os.path.exists(path):
for zipfile in os.listdir(path):
if zipfile.endswith(".zip"):
zipfile_path = os.path.join(path, zipfile)
if zipfile_path not in sys.path:
sys.path.append(zipfile_path)
if is_shell or sys.argv[0].endswith("/sphinx-build"):
import google
base = os.path.join(os.path.dirname(google.__file__), "../lib/")
for webapp2 in ["webapp2-2.5.2", "webapp2"]:
path = os.path.join(base, webapp2)
if os.path.exists(path):
sys.path.append(path)
break
for path in ["endpoints-1.0", "protorpc-1.0", "jinja2"]:
sys.path.append(os.path.join(base, path))
elif config.IS_TEST:
import google
base = os.path.join(os.path.dirname(google.__file__), "../lib/")
for path in ["endpoints-1.0"]:
sys.path.append(os.path.join(base, path))
return True
sys_path_append()
from js.angular import angular_cookies, angular_resource
from js.bootstrap import bootstrap
import tap
class WarmUp(tap.RequestHandler):
@tap.head(angular_cookies, angular_resource, bootstrap)
def get(self):
pass
app = webapp2.WSGIApplication([
("/_ah/warmup", WarmUp),
])
|
mit
|
Python
|
5f663eb971542d252186dbf9345ca458dca93c16
|
fix file not exist during render file
|
faycheng/tpl,faycheng/tpl
|
tpl/tpl.py
|
tpl/tpl.py
|
# -*- coding:utf-8 -*-
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import jinja2
from tpl import path
from tpl import errors
class Template(object):
IGNORE_FILES = [
'construct.sh',
'construct.py'
]
def __init__(self, tpl_dir):
self.tpl_dir = tpl_dir
def is_ignored_file(self, file):
file_name = file.split('/')[-1]
if file_name in self.IGNORE_FILES:
return True
return False
def render_file(self, file, context):
env = jinja2.Environment(undefined=jinja2.StrictUndefined)
render_file = file
if '{{' in file and '}}' in file:
render_file = env.from_string(file).render(context)
with open(file, 'r') as fd:
file_content = fd.read()
render_file_content = env.from_string(file_content).render(context)
return render_file, render_file_content
def render_dir(self, dir, context):
if not ('{{' in dir and '}}' in dir):
return dir
env = jinja2.Environment(undefined=jinja2.StrictUndefined)
dir = env.from_string(dir).render(context)
return dir
def render(self, context):
assert isinstance(context)
render_dirs = []
render_files = []
for dir in path.list_dirs(self.tpl_dir):
render_dirs.append(self.render_dir(dir, context))
for file in path.list_files(self.tpl_dir):
if self.is_ignored_file(file):
continue
render_files.append(self.render_file(file, context))
return render_dirs, render_files
|
# -*- coding:utf-8 -*-
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import jinja2
from tpl import path
from tpl import errors
class Template(object):
IGNORE_FILES = [
'construct.sh',
'construct.py'
]
def __init__(self, tpl_dir):
self.tpl_dir = tpl_dir
def is_ignored_file(self, file):
file_name = file.split('/')[-1]
if file_name in self.IGNORE_FILES:
return True
return False
def render_file(self, file, context):
env = jinja2.Environment(undefined=jinja2.StrictUndefined)
if '{{' in file and '}}' in file:
file = env.from_string(file).render(context)
with open(file, 'r') as fd:
file_content = fd.read()
file_content = env.from_string(file_content).render(context)
return file, file_content
def render_dir(self, dir, context):
if not ('{{' in dir and '}}' in dir):
return dir
env = jinja2.Environment(undefined=jinja2.StrictUndefined)
dir = env.from_string(dir).render(context)
return dir
def render(self, context):
assert isinstance(context)
render_dirs = []
render_files = []
for dir in path.list_dirs(self.tpl_dir):
render_dirs.append(self.render_dir(dir, context))
for file in path.list_files(self.tpl_dir):
if self.is_ignored_file(file):
continue
render_files.append(self.render_file(file, context))
return render_dirs, render_files
|
mit
|
Python
|
7b385ca9897ab8a7b25966cc54324a4b42596f7d
|
fix case of no saved lists or items
|
jschriesheim/manage-lists
|
lists.py
|
lists.py
|
# manage list functions
import os
import redis
import json
r = redis.from_url(os.environ.get("REDIS_URL"))
def getLists():
savedLists = r.get('lists')
if savedLists == None:
lists = []
else:
lists = json.loads(savedLists)
savedItems = r.get('items')
if savedItems == None:
items = []
else:
items = json.loads(savedItems)
return True
def putLists()
r.put('lists', json.dumps(lists))
r.pub('items', json.dumps(items))
return True
def createList(list):
getLists()
if (lists.count(list) == 0):
lists.append(list)
items.append([])
putLists()
return True
else:
print('List ' + list + ' already exists')
return False
def deleteList(list)
getLists()
if (lists.count(list) != 0):
items.pop(lists.index(list))
lists.remove(list)
putLists()
return True
else:
print('List ' + list + ' not found')
return False
def addItem(item, list):
getLists()
if (lists.count(list) == 0):
print('List ' + list + ' not found')
return False
else:
items[lists.index(list)].append(item)
putLists()
return True
def removeItem(item, list):
getLists()
if (lists.count(list) == 0):
print('List ' + list + ' not found')
return False
elif (items[lists.index(list)].count(item) == 0):
print('Item ' + item + ' not found on ' + list + ' list')
return False
else:
items[lists.index(list)].remove(item)
putLists()
return True
def readList(list):
getLists()
if (lists.count(list) == 0):
print('List ' + list + ' not found')
return []
else:
return items[lists.index(list)]
|
# manage list functions
import os
import redis
import json
r = redis.from_url(os.environ.get("REDIS_URL"))
def getLists():
lists = []
items = []
lists = json.loads(r.get('lists'))
items = json.loads(r.get('items'))
return True
def putLists()
r.put('lists', json.dumps(lists))
r.pub('items', json.dumps(items))
return True
def createList(list):
getLists()
if (lists.count(list) == 0):
lists.append(list)
items.append([])
putLists()
return True
else:
print('List ' + list + ' already exists')
return False
def deleteList(list)
getLists()
if (lists.count(list) != 0):
items.pop(lists.index(list))
lists.remove(list)
putLists()
return True
else:
print('List ' + list + ' not found')
return False
def addItem(item, list):
getLists()
if (lists.count(list) == 0):
print('List ' + list + ' not found')
return False
else:
items[lists.index(list)].append(item)
putLists()
return True
def removeItem(item, list):
getLists()
if (lists.count(list) == 0):
print('List ' + list + ' not found')
return False
elif (items[lists.index(list)].count(item) == 0):
print('Item ' + item + ' not found on ' + list + ' list')
return False
else:
items[lists.index(list)].remove(item)
putLists()
return True
def readList(list):
getLists()
if (lists.count(list) == 0):
print('List ' + list + ' not found')
return []
else:
return items[lists.index(list)]
|
apache-2.0
|
Python
|
2a08d3154992b5f0633d7cd2ca1bbfc7ecd63f69
|
Fix to allow version number to be imported without dependencies being installed.
|
dreipol/django-email-extras,blag/django-email-extras,stephenmcd/django-email-extras,blag/django-email-extras,dreipol/django-email-extras,stephenmcd/django-email-extras
|
email_extras/__init__.py
|
email_extras/__init__.py
|
from email_extras.settings import USE_GNUPG
__version__ = "0.1.0"
if USE_GNUPG:
try:
import gnupg
except ImportError:
try:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured, "Could not import gnupg"
except ImportError:
pass
|
from django.core.exceptions import ImproperlyConfigured
from email_extras.settings import USE_GNUPG
__version__ = "0.1.0"
if USE_GNUPG:
try:
import gnupg
except ImportError:
raise ImproperlyConfigured, "Could not import gnupg"
|
bsd-2-clause
|
Python
|
b39518482da1d3e064cdbc34490e4a9924f6d5f1
|
Add a test for vectorized call
|
oyamad/QuantEcon.py,QuantEcon/QuantEcon.py,oyamad/QuantEcon.py,QuantEcon/QuantEcon.py
|
quantecon/tests/test_ecdf.py
|
quantecon/tests/test_ecdf.py
|
"""
Tests for ecdf.py
"""
import unittest
import numpy as np
from quantecon import ECDF
class TestECDF(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.obs = np.random.rand(40) # observations defining dist
cls.ecdf = ECDF(cls.obs)
def test_call_high(self):
"ecdf: x above all obs give 1.0"
# all of self.obs <= 1 so ecdf(1.1) should be 1
self.assertAlmostEqual(self.ecdf(1.1), 1.0)
def test_call_low(self):
"ecdf: x below all obs give 0.0"
# all of self.obs <= 1 so ecdf(1.1) should be 1
self.assertAlmostEqual(self.ecdf(-0.1), 0.0)
def test_ascending(self):
"ecdf: larger values should return F(x) at least as big"
x = np.random.rand()
F_1 = self.ecdf(x)
F_2 = self.ecdf(1.1 * x)
self.assertGreaterEqual(F_2, F_1)
def test_vectorized(self):
"ecdf: testing vectorized __call__ method"
t = np.linspace(-1, 1, 100)
self.assertEqual(t.shape, self.ecdf(t).shape)
t = np.linspace(-1, 1, 100).reshape(2, 2, 25)
self.assertEqual(t.shape, self.ecdf(t).shape)
|
"""
Tests for ecdf.py
"""
import unittest
import numpy as np
from quantecon import ECDF
class TestECDF(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.obs = np.random.rand(40) # observations defining dist
cls.ecdf = ECDF(cls.obs)
def test_call_high(self):
"ecdf: x above all obs give 1.0"
# all of self.obs <= 1 so ecdf(1.1) should be 1
self.assertAlmostEqual(self.ecdf(1.1), 1.0)
def test_call_low(self):
"ecdf: x below all obs give 0.0"
# all of self.obs <= 1 so ecdf(1.1) should be 1
self.assertAlmostEqual(self.ecdf(-0.1), 0.0)
def test_ascending(self):
"ecdf: larger values should return F(x) at least as big"
x = np.random.rand()
F_1 = self.ecdf(x)
F_2 = self.ecdf(1.1 * x)
self.assertGreaterEqual(F_2, F_1)
|
bsd-3-clause
|
Python
|
e36192babd239366d51d1ea7cdfab94c06791fe7
|
Test assertElementPresents return function
|
XeryusTC/projman,XeryusTC/projman,XeryusTC/projman
|
functional_tests/test_base.py
|
functional_tests/test_base.py
|
# -*- coding: utf-8 -*-
from .base import FunctionalTestCase
import unittest
from unittest import mock
class TestBaseFuctionalTest(unittest.TestCase):
def test_assertelementpresent_can_find_string(self):
e = [mock.Mock(text='test')]
ft = FunctionalTestCase()
ft.assertElementPresent(e, 'test')
def test_assertelementpresent_raises_when_string_not_found(self):
e = [mock.Mock(text='some string')]
ft = FunctionalTestCase()
with self.assertRaises(AssertionError):
ft.assertElementPresent(e, 'test')
def test_assertelementpresent_returns_element_found(self):
e = [mock.Mock(text='test'), mock.Mock(text='some string')]
ft = FunctionalTestCase()
ret = ft.assertElementPresent(e, 'test')
self.assertEquals(e[0], ret)
|
# -*- coding: utf-8 -*-
from .base import FunctionalTestCase
import unittest
from unittest import mock
class TestBaseFuctionalTest(unittest.TestCase):
def test_assertelementpresent_can_find_string(self):
e = [mock.Mock(text='test')]
ft = FunctionalTestCase()
ft.assertElementPresent(e, 'test')
def test_assertelementpresent_raises_when_string_not_found(self):
e = [mock.Mock(text='some string')]
ft = FunctionalTestCase()
with self.assertRaises(AssertionError):
ft.assertElementPresent(e, 'test')
|
mit
|
Python
|
472c22a83e9e3982e5b6705757f79fba3b32f3e6
|
Set path dependency with context to development and deployment
|
chuckbutler/DNS-Charm,thomnico/DNS-Charm,chuckbutler/DNS-Charm,thomnico/DNS-Charm
|
hooks/common.py
|
hooks/common.py
|
import os
import sys
import urllib2
# Add charmhelpers to the system path.
try:
sys.path.insert(0, os.path.abspath(os.path.join(os.environ['CHARM_DIR'],
'lib')))
except:
sys.path.insert(0, os.path.abspath(os.path.join('..', 'lib')))
from charmhelpers.core.hookenv import (
log,
config,
)
from charmhelpers.core.host import (
mkdir,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
)
def sanity_check():
if not config()['canonical_domain']:
log("No Canonical Domain specified - Aborting until configured")
# It's reasonable to assume we're not doing anything useful at this
# point, as we are unconfigured. Abort doing *anything*
return False
return True
# ###########
# Environment Probe / Modifications
# ###########
# Create Configuration Directories for local Bind9 Server
def make_bind_store():
mkdir('/etc/bind')
mkdir('/etc/bind/zones')
# Parse existing nameservers from resolv.conf
def existing_nameservers():
dns_servers = []
with open('/etc/resolv.conf') as f:
contents = f.readlines()
print contents
for line in contents:
if line.find('nameserver') != -1:
dns_servers.append(line.replace('nameserver ', '').rstrip())
return dns_servers
# this is kind of arbitrary, attempt to connect to a google ip address.
# This won't be the best solution, but i'm open to ideas on how to improve
# 'onlineability' checking.
def am_i_online():
try:
urllib2.urlopen('http://74.125.228.100', timeout=1)
return True
except urllib2.URLError:
pass
return False
# ###########
# BIND tasks
# ###########
def install():
sanity_check()
log("Preparing for BIND installation")
apt_update(fatal=True)
apt_install(packages=[
'bind9',
'dnsutils',
'python-dnspython'
], fatal=True)
def install_bind():
sanity_check()
log("Preparing for BIND installation")
apt_update(fatal=True)
apt_install(packages=[
'bind9',
'dnsutils',
'python-dnspython'
], fatal=True)
|
import os
import sys
import urllib2
# Add charmhelpers to the system path.
sys.path.insert(0, os.path.abspath(os.path.join('..', 'lib')))
from charmhelpers.core.hookenv import (
log,
config,
)
from charmhelpers.core.host import (
mkdir,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
)
def sanity_check():
if not config()['canonical_domain']:
log("No Canonical Domain specified - Aborting until configured")
# It's reasonable to assume we're not doing anything useful at this
# point, as we are unconfigured. Abort doing *anything*
return False
return True
# ###########
# Environment Probe / Modifications
# ###########
# Create Configuration Directories for local Bind9 Server
def make_bind_store():
mkdir('/etc/bind')
mkdir('/etc/bind/zones')
# Parse existing nameservers from resolv.conf
def existing_nameservers():
dns_servers = []
with open('/etc/resolv.conf') as f:
contents = f.readlines()
print contents
for line in contents:
if line.find('nameserver') != -1:
dns_servers.append(line.replace('nameserver ', '').rstrip())
return dns_servers
# this is kind of arbitrary, attempt to connect to a google ip address.
# This won't be the best solution, but i'm open to ideas on how to improve
# 'onlineability' checking.
def am_i_online():
try:
urllib2.urlopen('http://74.125.228.100', timeout=1)
return True
except urllib2.URLError:
pass
return False
# ###########
# BIND tasks
# ###########
def install():
sanity_check()
log("Preparing for BIND installation")
apt_update(fatal=True)
apt_install(packages=[
'bind9',
'dnsutils',
'python-dnspython'
], fatal=True)
def install_bind():
sanity_check()
log("Preparing for BIND installation")
apt_update(fatal=True)
apt_install(packages=[
'bind9',
'dnsutils',
'python-dnspython'
], fatal=True)
|
mit
|
Python
|
a2b6cef1fc6dee679407d61312a23f96c3e99cda
|
Use a plain list of url instances for the tests urls too
|
JensTimmerman/django-oauth-toolkit,StepicOrg/django-oauth-toolkit,bleib1dj/django-oauth-toolkit,bleib1dj/django-oauth-toolkit,DeskConnect/django-oauth-toolkit,DeskConnect/django-oauth-toolkit,StepicOrg/django-oauth-toolkit,JensTimmerman/django-oauth-toolkit
|
oauth2_provider/tests/urls.py
|
oauth2_provider/tests/urls.py
|
from django.conf.urls import include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = (
url(r'^admin/', include(admin.site.urls)),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
)
|
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
)
|
bsd-2-clause
|
Python
|
aaf243646eccebea2e1d764d7de58c40c279830c
|
test info
|
onlysheep5200/NetnsEx,onlysheep5200/NetnsEx
|
hostend/main.py
|
hostend/main.py
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
sys.path.append('..')
from tornado.web import Application
import tornado.ioloop
import tornado.options
import tornado.httpserver
import tornado.autoreload
from tornado.options import define, options
from hostend.controller import *
from lib.utils import Host
from proxy import *
import docker
import json
from handlers import *
config = json.load(open('config.json','r'))
controller = Controller()
controller.reportUrl = config.get('reportUrl')
controller.requestUrl = config.get('requestUrl')
host = Host.currentHost('',switchInterface=config['switchName'],transportInterface=config['transportInterface'])
data = controller.request('getHostId',[host.mac,host.transportIP])
if 'uuid' in data :
host.uuid = data['uuid']
print 'my host id is : %s'%host.uuid
define("port", default=8000, help="run on the given port", type=int)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/createContainer',CreateContainerHandler)
]
settings = {
'template_path': 'templates',
'debug': True,
'cookie_secret' : "dfaew989q2kejczo8u8923e400ialsjdf",
'static_path': 'static'
}
self.host = host
self.controller = controller
self.containerProxy = DockerProxy(docker.Client('unix://var/run/docker.sock'),self.host,self.controller)
tornado.web.Application.__init__(self, handlers, **settings)
if __name__ == "__main__":
tornado.options.parse_command_line()
app = Application()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
sys.path.append('..')
from tornado.web import Application
import tornado.ioloop
import tornado.options
import tornado.httpserver
import tornado.autoreload
from tornado.options import define, options
from hostend.controller import *
from lib.utils import Host
from proxy import *
import docker
import json
from handlers import *
config = json.load(open('config.json','r'))
controller = Controller()
controller.reportUrl = config.get('reportUrl')
controller.requestUrl = config.get('requestUrl')
host = Host.currentHost('',switchInterface=config['switchName'],transportInterface=config['transportInterface'])
data = controller.request('getHostId',[host.mac,host.transportIP])
if 'uuid' in data :
host.uuid = data['uuid']
define("port", default=8000, help="run on the given port", type=int)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/createContainer',CreateContainerHandler)
]
settings = {
'template_path': 'templates',
'debug': True,
'cookie_secret' : "dfaew989q2kejczo8u8923e400ialsjdf",
'static_path': 'static'
}
self.host = host
self.controller = controller
self.containerProxy = DockerProxy(docker.Client('unix://var/run/docker.sock'),self.host,self.controller)
tornado.web.Application.__init__(self, handlers, **settings)
if __name__ == "__main__":
tornado.options.parse_command_line()
app = Application()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
|
apache-2.0
|
Python
|
0fbfef27d35cea23ad0e20fd2c9df3e8a4a046cb
|
Fix GCF region tags (#1827)
|
GoogleCloudPlatform/python-docs-samples,GoogleCloudPlatform/python-docs-samples,GoogleCloudPlatform/python-docs-samples,GoogleCloudPlatform/python-docs-samples
|
functions/log/main.py
|
functions/log/main.py
|
# Copyright 2018 Google LLC
#
# 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.
# [START functions_log_stackdriver]
import base64
import json
# [END functions_log_stackdriver]
# [START functions_log_helloworld]
import logging
# [END functions_log_helloworld]
# [START functions_log_retrieve]
import os
# [END functions_log_retrieve]
# [START functions_log_retrieve]
import google.cloud.logging as cloud_logging
# [END functions_log_retrieve]
# [START functions_log_helloworld]
def hello_world(data, context):
"""Background Cloud Function.
Args:
data (dict): The dictionary with data specific to the given event.
context (google.cloud.functions.Context): The event metadata.
"""
print('Hello, stdout!')
logging.warn('Hello, logging handler!')
# [END functions_log_helloworld]
# [START functions_log_retrieve]
cloud_client = cloud_logging.Client()
log_name = 'cloudfunctions.googleapis.com%2Fcloud-functions'
cloud_logger = cloud_client.logger(log_name.format(os.getenv('GCP_PROJECT')))
def get_log_entries(request):
"""
HTTP Cloud Function that displays log entries from Cloud Functions.
Args:
request (flask.Request): The request object.
Returns:
The response text, or any set of values that can be turned into a
Response object using `make_response`
<http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>.
"""
""""""
all_entries = cloud_logger.list_entries(page_size=10)
entries = next(all_entries.pages)
for entry in entries:
timestamp = entry.timestamp.isoformat()
print('* {}: {}'.format
(timestamp, entry.payload))
return 'Done!'
# [END functions_log_retrieve]
# [START functions_log_stackdriver]
def process_log_entry(data, context):
data_buffer = base64.b64decode(data['data'])
log_entry = json.loads(data_buffer)['protoPayload']
print(f"Method: {log_entry['methodName']}")
print(f"Resource: {log_entry['resourceName']}")
print(f"Initiator: {log_entry['authenticationInfo']['principalEmail']}")
# [END functions_log_stackdriver]
|
# Copyright 2018 Google LLC
#
# 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.
# [START functions_log_bigquery_stackdriver]
import base64
import json
# [END functions_log_bigquery_stackdriver]
# [START functions_log_helloworld]
import logging
# [END functions_log_helloworld]
# [START functions_log_retrieve]
import os
# [END functions_log_retrieve]
# [START functions_logs_retrieve]
import google.cloud.logging as cloud_logging
# [END functions_logs_retrieve]
# [START functions_log_helloworld]
def hello_world(data, context):
"""Background Cloud Function.
Args:
data (dict): The dictionary with data specific to the given event.
context (google.cloud.functions.Context): The event metadata.
"""
print('Hello, stdout!')
logging.warn('Hello, logging handler!')
# [END functions_log_helloworld]
# [START functions_log_retrieve]
cloud_client = cloud_logging.Client()
log_name = 'cloudfunctions.googleapis.com%2Fcloud-functions'
cloud_logger = cloud_client.logger(log_name.format(os.getenv('GCP_PROJECT')))
def get_log_entries(request):
"""
HTTP Cloud Function that displays log entries from Cloud Functions.
Args:
request (flask.Request): The request object.
Returns:
The response text, or any set of values that can be turned into a
Response object using `make_response`
<http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>.
"""
""""""
all_entries = cloud_logger.list_entries(page_size=10)
entries = next(all_entries.pages)
for entry in entries:
timestamp = entry.timestamp.isoformat()
print('* {}: {}'.format
(timestamp, entry.payload))
return 'Done!'
# [END functions_log_retrieve]
# [START functions_log_stackdriver]
def process_log_entry(data, context):
data_buffer = base64.b64decode(data['data'])
log_entry = json.loads(data_buffer)['protoPayload']
print(f"Method: {log_entry['methodName']}")
print(f"Resource: {log_entry['resourceName']}")
print(f"Initiator: {log_entry['authenticationInfo']['principalEmail']}")
# [END functions_log_stackdriver]
|
apache-2.0
|
Python
|
8d56c42dd3a721a477fa1333c1d979f4002e7cc1
|
Simplify importer paths after dockerization
|
StartupsPoleEmploi/labonneboite,StartupsPoleEmploi/labonneboite,StartupsPoleEmploi/labonneboite,StartupsPoleEmploi/labonneboite
|
labonneboite/importer/conf/lbbdev.py
|
labonneboite/importer/conf/lbbdev.py
|
import os
# --- importer input directory of DPAE and ETABLISSEMENT exports
INPUT_SOURCE_FOLDER = '/srv/lbb/data'
# --- job 1/8 & 2/8 : check_etablissements & extract_etablissements
JENKINS_ETAB_PROPERTIES_FILENAME = os.path.join(os.environ["WORKSPACE"], "properties.jenkins")
MINIMUM_OFFICES_TO_BE_EXTRACTED_PER_DEPARTEMENT = 10000
# --- job 3/8 & 4/8 : check_dpae & extract_dpae
JENKINS_DPAE_PROPERTIES_FILENAME = os.path.join(os.environ["WORKSPACE"], "properties_dpae.jenkins")
MAXIMUM_ZIPCODE_ERRORS = 100
MAXIMUM_INVALID_ROWS = 100
# --- job 5/8 : compute_scores
SCORE_COEFFICIENT_OF_VARIATION_MAX = 2.0
RMSE_MAX = 1500 # On 2017.03.15 departement 52 reached RMSE=1141
HIGH_SCORE_COMPANIES_DIFF_MAX = 70
# --- job 6/8 : validate_scores
MINIMUM_OFFICES_PER_DEPARTEMENT_FOR_DPAE = 500
MINIMUM_OFFICES_PER_DEPARTEMENT_FOR_ALTERNANCE = 0
# --- job 8/8 : populate_flags
|
import os
# --- importer input directory of DPAE and ETABLISSEMENT exports
INPUT_SOURCE_FOLDER = '/srv/lbb/data'
# --- job 1/8 & 2/8 : check_etablissements & extract_etablissements
JENKINS_ETAB_PROPERTIES_FILENAME = os.path.join(os.environ["WORKSPACE"], "properties.jenkins")
MINIMUM_OFFICES_TO_BE_EXTRACTED_PER_DEPARTEMENT = 10000
# --- job 3/8 & 4/8 : check_dpae & extract_dpae
JENKINS_DPAE_PROPERTIES_FILENAME = os.path.join(os.environ["WORKSPACE"], "properties_dpae.jenkins")
MAXIMUM_ZIPCODE_ERRORS = 100
MAXIMUM_INVALID_ROWS = 100
# --- job 5/8 : compute_scores
SCORE_COEFFICIENT_OF_VARIATION_MAX = 2.0
RMSE_MAX = 1500 # On 2017.03.15 departement 52 reached RMSE=1141
HIGH_SCORE_COMPANIES_DIFF_MAX = 70
# --- job 6/8 : validate_scores
MINIMUM_OFFICES_PER_DEPARTEMENT_FOR_DPAE = 500
MINIMUM_OFFICES_PER_DEPARTEMENT_FOR_ALTERNANCE = 0
# --- job 8/8 : populate_flags
BACKUP_OUTPUT_FOLDER = '/srv/lbb/backups/outputs'
BACKUP_FOLDER = '/srv/lbb/backups'
|
agpl-3.0
|
Python
|
f1c270f2145cf1f48a0207696cb4f6e9592af357
|
Correct db `NAME`, use in-memory database for testing
|
henryyang42/NTHU_Course,henryyang42/NTHU_Course,henryyang42/NTHU_Course,henryyang42/NTHU_Course
|
NTHU_Course/settings/testing_sqlite.py
|
NTHU_Course/settings/testing_sqlite.py
|
'''
A configuration for testing in travis CI with sqlite3
'''
from .default import * # noqa
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
# https://docs.djangoproject.com/en/1.10/topics/testing/overview/#the-test-database
# django uses in memory database for testing
'NAME': ':memory:'
}
}
|
'''
A configuration for testing in travis CI with sqlite3
'''
from .default import * # noqa
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
# https://docs.djangoproject.com/en/1.10/topics/testing/overview/#the-test-database
# django uses in memory database for testing
'NAME': 'test_sqlite'
}
}
|
mit
|
Python
|
34f3d762f608c3ea3fd12cded38dc3853d36545f
|
Update vouchers.py
|
fabianm/olympiad,fabianm/olympiad,fabianm/olympiad
|
2014-2015/B4-vouchers/vouchers.py
|
2014-2015/B4-vouchers/vouchers.py
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2014 Fabian M.
#
# 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.
vouchers = [1, 2, 3, 5, 8, 9, 18, 19, 46, 154, 313]
def main():
for b in range(1, max(vouchers)):
# Amount can be created with one voucher.
if b in vouchers:
continue
bins = []
ws = sorted(vouchers, reverse=True)
for w in ws:
for x in bins:
if sum(x) + w <= b:
x.append(w)
w = None
break
if w != None:
bins.append([w])
r = list(map(sum, bins))
if b not in list(map(sum, bins)):
print(b)
return
main()
|
vouchers = [1, 2, 3, 5, 8, 9, 18, 19, 46, 154, 313]
def main():
for b in range(1, max(vouchers)):
# Amount can be created with one voucher.
if b in vouchers:
continue
bins = []
ws = sorted(vouchers, reverse=True)
for w in ws:
for x in bins:
if sum(x) + w <= b:
x.append(w)
w = None
break
if w != None:
bins.append([w])
r = list(map(sum, bins))
if b not in list(map(sum, bins)):
print(b)
return
main()
|
apache-2.0
|
Python
|
241376f76d4175c98c8226998832b8054697504c
|
Fix xpath expression for tomorrows forecast
|
mpolden/jarvis2,mpolden/jarvis2,mpolden/jarvis2,Foxboron/Frank,Foxboron/Frank,martinp/jarvis2,martinp/jarvis2,martinp/jarvis2,Foxboron/Frank
|
app/jobs/yr.py
|
app/jobs/yr.py
|
#!/usr/bin/env python
import requests
from datetime import datetime, timedelta
from jobs import AbstractJob
from lxml import etree
class Yr(AbstractJob):
def __init__(self, conf):
self.url = conf['url']
self.interval = conf['interval']
def _parse_tree(self, tree, tabular_xpath=None):
if tabular_xpath is None:
tabular = tree.xpath('/weatherdata/forecast/tabular/time[1]').pop()
data_root = tree.xpath(
'/weatherdata/observations/weatherstation[1]').pop()
else:
tabular = tree.xpath(tabular_xpath).pop()
data_root = tabular
windSpeed = data_root.xpath('windSpeed').pop()
return {
'location': tree.xpath('/weatherdata/location/name').pop().text,
'temperature': data_root.xpath('temperature').pop().get('value'),
'description': tabular.xpath('symbol').pop().get('name'),
'wind': {
'speed': windSpeed.get('mps'),
'description': windSpeed.get('name'),
'direction': data_root.xpath('windDirection').pop().get('name')
}
}
def _parse(self, xml):
tree = etree.fromstring(xml)
data = self._parse_tree(tree)
tomorrow = datetime.now().date() + timedelta(days=1)
xpath = ('/weatherdata/forecast/tabular/time[@period=2 and'
' starts-with(@from, "%s")]') % (tomorrow.strftime('%F'),)
data.update({'tomorrow': self._parse_tree(tree, xpath)})
return data
def get(self):
r = requests.get(self.url)
if r.status_code == 200 and len(r.content) > 0:
return self._parse(r.content)
return {}
|
#!/usr/bin/env python
import requests
from jobs import AbstractJob
from lxml import etree
class Yr(AbstractJob):
def __init__(self, conf):
self.url = conf['url']
self.interval = conf['interval']
def _parse_tree(self, tree, tabular_xpath=None):
if tabular_xpath is None:
tabular = tree.xpath('/weatherdata/forecast/tabular/time[1]').pop()
data_root = tree.xpath(
'/weatherdata/observations/weatherstation[1]').pop()
else:
tabular = tree.xpath(tabular_xpath).pop()
data_root = tabular
windSpeed = data_root.xpath('windSpeed').pop()
return {
'location': tree.xpath('/weatherdata/location/name').pop().text,
'temperature': data_root.xpath('temperature').pop().get('value'),
'description': tabular.xpath('symbol').pop().get('name'),
'wind': {
'speed': windSpeed.get('mps'),
'description': windSpeed.get('name'),
'direction': data_root.xpath('windDirection').pop().get('name')
}
}
def _parse(self, xml):
tree = etree.fromstring(xml)
data = self._parse_tree(tree)
data.update({'tomorrow': self._parse_tree(
tree, '/weatherdata/forecast/tabular/time[3]')})
return data
def get(self):
r = requests.get(self.url)
if r.status_code == 200 and len(r.content) > 0:
return self._parse(r.content)
return {}
|
mit
|
Python
|
b6b522bbdde24f0e6eab0e7a91830171bcac63a5
|
Add logout url
|
abramconnelly/genevieve,PersonalGenomesOrg/archive-genevieve-201505,abramconnelly/genevieve,PersonalGenomesOrg/archive-genevieve-201505,PersonalGenomesOrg/archive-genevieve-201505
|
genevieve/urls.py
|
genevieve/urls.py
|
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth import views as auth_views
from .views import UserCreateView
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'genevieve.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
(r'^file_process/', include('file_process.urls')),
url(r'^accounts/signup/$', UserCreateView.as_view()),
url(r'^accounts/login/$', auth_views.login,
{'template_name': 'login.html',
'extra_context': {'next': '/file_process'}}, name='auth_login'),
url(r'^accounts/logout/$', auth_views.logout, {'next_page': '/file_process'},
name='auth_logout'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth import views as auth_views
from .views import UserCreateView
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'genevieve.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
(r'^file_process/', include('file_process.urls')),
url(r'^accounts/signup/$', UserCreateView.as_view()),
url(r'^accounts/login/$', auth_views.login,
{'template_name': 'login.html',
'extra_context': {'next': '/file_process'}}, name='auth_login'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
mit
|
Python
|
ba2161f6adf5a0e0782e322371d7071ca79d02e3
|
Update tornado for mypy
|
brettcannon/gidgethub,brettcannon/gidgethub
|
gidgethub/tornado.py
|
gidgethub/tornado.py
|
from typing import Mapping, Optional, Tuple
from tornado import gen
from tornado import httpclient
from . import abc as gh_abc
class GitHubAPI(gh_abc.GitHubAPI):
async def _request(self, method: str, url: str, headers: Mapping[str, str],
body: bytes = b'') -> Tuple[int, Mapping[str, str], bytes]:
"""Make an HTTP request."""
if method == "GET" and not body:
real_body = None
else:
real_body = body
request = httpclient.HTTPRequest(url, method, headers, real_body)
# Since Tornado has designed AsyncHTTPClient to be a singleton, there's
# no reason not to simply instantiate it every time.
client = httpclient.AsyncHTTPClient()
response = await client.fetch(request, raise_error=False)
return response.code, response.headers, response.body
async def sleep(self, seconds: float) -> None:
"""Sleep for the specified number of seconds."""
await gen.sleep(seconds)
|
from typing import Mapping, Optional, Tuple
from tornado import gen
from tornado import httpclient
from . import abc as gh_abc
class GitHubAPI(gh_abc.GitHubAPI):
async def _request(self, method: str, url: str, headers: Mapping,
body: bytes = b'') -> Tuple[int, Mapping, bytes]:
"""Make an HTTP request."""
if method == "GET" and not body:
real_body = None
else:
real_body = body
request = httpclient.HTTPRequest(url, method, headers, real_body)
# Since Tornado has designed AsyncHTTPClient to be a singleton, there's
# no reason not to simply instantiate it every time.
client = httpclient.AsyncHTTPClient()
response = await client.fetch(request, raise_error=False)
return response.code, response.headers, response.body
async def sleep(self, seconds: float) -> None:
"""Sleep for the specified number of seconds."""
await gen.sleep(seconds)
|
apache-2.0
|
Python
|
ad56d5aa6b2359098c4ed6bf9cd37cb58613a372
|
Update github3.repos.tag for consistency
|
sigmavirus24/github3.py
|
github3/repos/tag.py
|
github3/repos/tag.py
|
# -*- coding: utf-8 -*-
"""This module contains the RepoTag object for GitHub's tag API."""
from __future__ import unicode_literals
from . import commit
from .. import models
class RepoTag(models.GitHubCore):
"""Representation of a tag made on a GitHub repository.
.. note::
This is distinct from :class:`~github3.git.Tag`. This object
has information specific to a tag on a *GitHub* repository.
That includes URLs to the tarball and zipball files auto-generated
by GitHub.
See also: http://developer.github.com/v3/repos/#list-tags
This object has the following attributes:
.. attribute:: commit
.. versionchanged:: 1.0.0
This attribute used to be a two item dictionary.
A :class:`~github3.repos.commit.MiniCommit` object representing the
commit this tag references.
.. attribute:: name
The name of this tag, e.g., ``v1.0.0``.
.. attribute:: tarball_url
The URL for the tarball file generated by GitHub for this tag.
.. attribute:: zipball_url
The URL for the zipball file generated by GitHub for this tag.
"""
def _update_attributes(self, tag):
self.commit = commit.MiniCommit(tag['commit'], self)
self.name = tag['name']
self.tarball_url = tag['tarball_url']
self.zipball_url = tag['zipball_url']
def _repr(self):
return '<Repository Tag [{0}]>'.format(self)
def __str__(self):
return self.name
|
# -*- coding: utf-8 -*-
"""
github3.repos.tag
=================
This module contains the RepoTag object for GitHub's tag API.
"""
from __future__ import unicode_literals
from ..models import GitHubCore
class RepoTag(GitHubCore):
"""The :class:`RepoTag <RepoTag>` object. This stores the information
representing a tag that was created on a repository.
See also: http://developer.github.com/v3/repos/#list-tags
"""
def _update_attributes(self, tag):
#: Name of the tag.
self.name = self._get_attribute(tag, 'name')
#: URL for the GitHub generated zipball associated with the tag.
self.zipball_url = self._get_attribute(tag, 'zipball_url')
#: URL for the GitHub generated tarball associated with the tag.
self.tarball_url = self._get_attribute(tag, 'tarball_url')
#: Dictionary containing the SHA and URL of the commit.
self.commit = self._get_attribute(tag, 'commit', {})
def _repr(self):
return '<Repository Tag [{0}]>'.format(self)
def __str__(self):
return self.name
|
bsd-3-clause
|
Python
|
73f3c743139927a049c5e733f98e1fcb8125721a
|
Update release version
|
scolab-dot-eu/pygdaltools
|
gdaltools/metadata.py
|
gdaltools/metadata.py
|
# -*- coding: utf-8 -*-
"""Project metadata
Information describing the project.
"""
# The package name, which is also the "UNIX name" for the project.
package = 'pygdaltools'
project = 'pygdaltools'
project_no_spaces = project.replace(' ', '')
version = '0.3'
description = """Python wrapper for Gdal/OGR command line tools"""
authors = ['Cesar Martinez Izquierdo - SCOLAB']
authors_string = ', '.join(authors)
emails = []
license = 'AGPL3'
copyright = '2016 ' + authors_string
url = 'https://github.com/scolab-dot-eu/pygdaltools'
|
# -*- coding: utf-8 -*-
"""Project metadata
Information describing the project.
"""
# The package name, which is also the "UNIX name" for the project.
package = 'pygdaltools'
project = 'pygdaltools'
project_no_spaces = project.replace(' ', '')
version = '0.2'
description = """Python wrapper for Gdal/OGR command line tools"""
authors = ['Cesar Martinez Izquierdo - SCOLAB']
authors_string = ', '.join(authors)
emails = []
license = 'AGPL3'
copyright = '2016 ' + authors_string
url = 'https://github.com/scolab-dot-eu/pygdaltools'
|
agpl-3.0
|
Python
|
2c0dbf04f04b686cac79e40791c3ed298618dd07
|
add more info on process
|
pdxosgeo/map-gallery-util
|
gen-gallery-images.py
|
gen-gallery-images.py
|
'''Generates small and medium gallery images from a set of large originals. Some maps will be tall, some wide, some square so we want to simply maintain the ratio and resize down to a set maximum.
Original images need to be downloaded to the large image path below. They are accessible in this Dropbox folder
https://www.dropbox.com/sh/z9fjbfquwd1t5st/AAAxV22dpleDodnxJqiertt0a?dl=0
Once large, medium, and small images are in place the folders are copied into the foss4g Wordpress theme, in the uploads/mapgallery folder where the images are served from to the map gallery page. See the map gallery page template.
'''
from wand.image import Image
from os import listdir
from os.path import isfile, join
small_size = 400
med_size = 1280
img_path = "/Users/twelch/src/foss4g2014-wordpress/uploads/mapgallery/"
large_path = img_path+"large/"
med_path = img_path+"medium/"
small_path = img_path+"small/"
#Get list of files in directory
img_files = [ f for f in listdir(large_path) if isfile(join(large_path,f)) ]
print "Looking for images in: " + img_path
print "Found the following: " + str(img_files)
for f in img_files:
if f.startswith("."):
print "Not an image file: " + str(f)
else:
print "Processing image: "+f
#Create image objects for small and medium using original large
mi = Image(filename=join(large_path,f))
si = mi.clone()
print 'Original: '+str(mi.width)+'x'+str(mi.height)
#Resize maintaining aspect ratio
mi.transform(resize=str(med_size)+'x'+str(med_size)+'>')
print 'Medium: '+str(mi.width)+'x'+str(mi.height)
si.transform(resize=str(small_size)+'x'+str(small_size)+'>')
print 'Small: '+str(si.width)+'x'+str(si.height)
#Convert to JPEG if necessary and save as new file
mf = join(med_path,f)
if mi.format != 'JPEG':
mi.convert('jpeg')
mi.save(filename=mf)
sf = join(small_path,f)
if si.format != 'JPEG':
si.convert('jpeg')
si.save(filename=sf)
|
'''Generates small and medium gallery images from a set of large originals. Some maps will be tall, some wide, some square so we want to simply maintain the ratio and resize down to a set maximum.
Original images need to be downloaded to the large path below. They are accessible in this Dropbox folder
https://www.dropbox.com/sh/z9fjbfquwd1t5st/AAAxV22dpleDodnxJqiertt0a?dl=0
'''
from wand.image import Image
from os import listdir
from os.path import isfile, join
small_size = 400
med_size = 1280
img_path = "/Users/twelch/src/foss4g2014-wordpress/uploads/mapgallery/"
large_path = img_path+"large/"
med_path = img_path+"medium/"
small_path = img_path+"small/"
#Get list of files in directory
img_files = [ f for f in listdir(large_path) if isfile(join(large_path,f)) ]
print "Looking for images in: " + img_path
print "Found the following: " + str(img_files)
for f in img_files:
if f.startswith("."):
print "Not an image file: " + str(f)
else:
print "Processing image: "+f
#Create image objects for small and medium using original large
mi = Image(filename=join(large_path,f))
si = mi.clone()
print 'Original: '+str(mi.width)+'x'+str(mi.height)
#Resize maintaining aspect ratio
mi.transform(resize=str(med_size)+'x'+str(med_size)+'>')
print 'Medium: '+str(mi.width)+'x'+str(mi.height)
si.transform(resize=str(small_size)+'x'+str(small_size)+'>')
print 'Small: '+str(si.width)+'x'+str(si.height)
#Convert to JPEG if necessary and save as new file
mf = join(med_path,f)
if mi.format != 'JPEG':
mi.convert('jpeg')
mi.save(filename=mf)
sf = join(small_path,f)
if si.format != 'JPEG':
si.convert('jpeg')
si.save(filename=sf)
|
mit
|
Python
|
2fcca753e2877d21e158d5e4a3923e1d22e61608
|
Add mask A to causal atrous conv1d (WIP)
|
israelg99/eva
|
eva/layers/causal_atrous_convolution1d.py
|
eva/layers/causal_atrous_convolution1d.py
|
import keras.backend as K
from keras.layers import AtrousConvolution1D
from keras.utils.np_utils import conv_output_length
class CausalAtrousConvolution1D(AtrousConvolution1D):
def __init__(self, *args, mask_type='B', **kwargs):
super().__init__(*args, **kwargs)
if self.border_mode != 'valid':
raise ValueError("Causal mode dictates border_mode=valid.")
self.length = self.atrous_rate * (self.filter_length - 1)
# XXX debug.
if mask_type == 'A':
self.length = 3
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1] + self.length,
self.filter_length,
self.border_mode,
self.subsample[0],
dilation=self.atrous_rate)
return (input_shape[0], length, self.nb_filter)
def call(self, x, mask=None):
return super().call(K.asymmetric_temporal_padding(x, self.length, 0), mask)
|
import keras.backend as K
from keras.layers import AtrousConvolution1D
from keras.utils.np_utils import conv_output_length
class CausalAtrousConvolution1D(AtrousConvolution1D):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.border_mode != 'valid':
raise ValueError("Causal mode dictates border_mode=valid.")
self.length = self.atrous_rate * (self.filter_length - 1)
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1] + self.length,
self.filter_length,
self.border_mode,
self.subsample[0],
dilation=self.atrous_rate)
return (input_shape[0], length, self.nb_filter)
def call(self, x, mask=None):
return super().call(K.asymmetric_temporal_padding(x, self.length, 0), mask)
|
apache-2.0
|
Python
|
56de128ac7462a297505ec4b207d07c1af613c9b
|
connect annotations to api
|
varnish/zipnish,varnish/varnish-microservice-monitor,varnish/varnish-microservice-monitor,varnish/zipnish,varnish/zipnish,varnish/zipnish,varnish/varnish-microservice-monitor,varnish/varnish-microservice-monitor,varnish/zipnish,varnish/varnish-microservice-monitor
|
ui/app/api/__init__.py
|
ui/app/api/__init__.py
|
from flask import Blueprint
api = Blueprint('api', __name__)
#
# end-points to create
# query
from . import query
# services
from . import services
# spans
from . import spans
# annotations
from . import annotations
#
# traces
# services
# annotations
# dependencies
# pin
from . import pin
|
from flask import Blueprint
api = Blueprint('api', __name__)
#
# end-points to create
# query
from . import query
# services
from . import services
# spans
from . import spans
#
# traces
# services
# annotations
# dependencies
# pin
from . import pin
|
bsd-2-clause
|
Python
|
c5b00edd9b8acbe594e43ecce093cd1c695b8b01
|
Use user ID instead of username to get messages even with username changes
|
expectocode/telegram-analysis,expectocode/telegramAnalysis
|
getalltextfromuser.py
|
getalltextfromuser.py
|
#!/usr/bin/env python3
"""
A program to extract all text sent by a particular user from a Telegram chat log which is in json form
"""
import argparse
from json import loads
def main():
parser = argparse.ArgumentParser(
description="Extract raw text sent by a user from a json telegram chat log")
parser.add_argument(
'filepath', help='the json file to analyse')
parser.add_argument(
'username', help='the username of the person whose text you want')
args=parser.parse_args()
filepath = args.filepath
username = args.username
user_id = ""
#first, get the ID of the user with that username.
with open(filepath, 'r') as jsonfile:
events = (loads(line) for line in jsonfile)
for event in events:
#check the event is the sort we're looking for
if "from" in event and "text" in event:
if "username" in event["from"]:
#do i need "from" here?
if event["from"]["username"] == username:
#print(event["text"])
print(event['from']['id'])
user_id = event['from']['id']
break
if user_id == "":
print("user not found")
exit()
with open(filepath, 'r') as jsonfile:
events = (loads(line) for line in jsonfile)
for event in events:
#check the event is the sort we're looking for
if "from" in event and "text" in event:
if user_id == event["from"]["id"]:
print(event["text"])
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
"""
A program to extract all text sent by a particular user from a Telegram chat log which is in json form
"""
import argparse
from json import loads
def main():
parser = argparse.ArgumentParser(
description="Extract raw text sent by a user from a json telegram chat log")
parser.add_argument(
'filepath', help='the json file to analyse')
parser.add_argument(
'username', help='the username of the person whose text you want')
args=parser.parse_args()
filepath = args.filepath
username = args.username
with open(filepath, 'r') as jsonfile:
events = (loads(line) for line in jsonfile)
for event in events:
#check the event is the sort we're looking for
if "from" in event and "text" in event:
if "username" in event["from"]:
#do i need "from" here?
if event["from"]["username"] == username:
print(event["text"])
if __name__ == "__main__":
main()
|
mit
|
Python
|
48b227f0019fb28a5b96874f62662fee79998fe5
|
Add a TODO for diamondash metric snapshot request auth in diamondash proxy view
|
praekelt/vumi-go,praekelt/vumi-go,praekelt/vumi-go,praekelt/vumi-go
|
go/dashboard/views.py
|
go/dashboard/views.py
|
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import csrf_exempt
from go.dashboard import client
@login_required
@csrf_exempt
@require_http_methods(['GET'])
def diamondash_api_proxy(request):
"""
Proxies client snapshot requests to diamondash.
NOTE: This proxy is a fallback for dev purposes only. A more sensible
proxying solution should be used in production (eg. haproxy).
"""
api = client.get_diamondash_api()
_, url = request.path.split('/diamondash/api', 1)
response = api.raw_request(request.method, url, content=request.body)
# TODO for the case of snapshot requests, ensure the widgets requested are
# allowed for the given account
return HttpResponse(
response['content'],
status=response['code'],
content_type='application/json')
|
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import csrf_exempt
from go.dashboard import client
@login_required
@csrf_exempt
@require_http_methods(['GET'])
def diamondash_api_proxy(request):
"""
Proxies client snapshot requests to diamondash.
NOTE: This proxy is a fallback for dev purposes only. A more sensible
proxying solution should be used in production (eg. haproxy).
"""
api = client.get_diamondash_api()
_, url = request.path.split('/diamondash/api', 1)
response = api.raw_request(request.method, url, content=request.body)
return HttpResponse(
response['content'],
status=response['code'],
content_type='application/json')
|
bsd-3-clause
|
Python
|
e7d6f5fbd21819ba0c5d3b5e952331b2eabe32e8
|
move ballsearch para to config
|
markm541374/gpbo,markm541374/gpbo,markm541374/gpbo,markm541374/gpbo
|
gpbo/core/__init__.py
|
gpbo/core/__init__.py
|
from collections import defaultdict
debugoutput=defaultdict(lambda :False)
debugoutput['path']='dbout'
from .optimize import *
from .optutils import *
from .acquisitions import *
from .reccomenders import *
from .config import *
from .GPdc import *
from .ESutils import *
from .choosers import *
|
from collections import defaultdict
debugoutput=defaultdict(lambda :False)
debugoutput['path']='dbout'
from .optimize import *
from .optutils import *
from .acquisitions import *
from .reccomenders import *
from .config import *
from .GPdc import *
from .ESutils import *
from .choosers import *
|
agpl-3.0
|
Python
|
e964df34a7f1f7dc85da21429b2978b01034140f
|
Fix typo
|
rezoo/illustration2vec,rezoo/illustration2vec
|
i2v/__init__.py
|
i2v/__init__.py
|
from i2v.base import Illustration2VecBase
caffe_available = False
chainer_available = False
try:
from i2v.caffe_i2v import CaffeI2V, make_i2v_with_caffe
caffe_available = True
except ImportError:
pass
try:
from i2v.chainer_i2v import ChainerI2V, make_i2v_with_chainer
chainer_available = True
except ImportError:
pass
if not any([caffe_available, chainer_available]):
raise ImportError('i2v requires caffe or chainer package')
|
from i2v.base import Illustration2VecBase
caffe_available = False
chainer_available = False
try:
from i2v.caffe_i2v import CaffeI2V, make_i2v_with_caffe
caffe_available = True
except ImportError:
pass
try:
from i2v.chainer_i2v import ChainerI2V, make_i2v_with_chainer
caffe_available = True
except ImportError:
pass
if not any([caffe_available, chainer_available]):
raise ImportError('i2v requires caffe or chainer package')
|
mit
|
Python
|
5d32ee0e41aee95f30f972eef3d1abcf9de50a0c
|
Kill unused var
|
115100/untz_manager
|
untz_manager/__main__.py
|
untz_manager/__main__.py
|
"""Main entry point for untz."""
from concurrent.futures import ThreadPoolExecutor
import logging
import os
from .encoder import apply_gain, encode_file
from .utils import get_args, preflight_checks, recursive_file_search
ARGS = get_args()
LOGGER = logging.getLogger(__name__)
def _encode_on_filter(file_entry):
LOGGER.info('Encoding "%s"', file_entry)
if file_entry.lower().endswith('.flac'):
encode_file(file_entry,
ARGS.base_dir.rstrip('/'),
ARGS.pattern,
ARGS.quality,
ARGS.ogg_cli_parameters)
def main():
"""Main logic for untz."""
if ARGS.verbose:
logging.basicConfig(level=logging.DEBUG)
preflight_checks()
LOGGER.info('Starting %d threads.', ARGS.threads)
with ThreadPoolExecutor(max_workers=ARGS.threads) as tpe:
for i in ARGS.inputs:
if os.path.isdir(i):
tpe.map(_encode_on_filter, recursive_file_search(i))
else:
tpe.submit(_encode_on_filter, i)
if ARGS.replaygain:
apply_gain(ARGS.base_dir)
LOGGER.warning('Program exiting now.')
|
"""Main entry point for untz."""
from concurrent.futures import ThreadPoolExecutor
import logging
import os
from .encoder import apply_gain, encode_file
from .utils import get_args, preflight_checks, recursive_file_search
ARGS = get_args()
LOGGER = logging.getLogger(__name__)
threads = [] # pylint: disable=C0103
def _encode_on_filter(file_entry):
LOGGER.info('Encoding "%s"', file_entry)
if file_entry.lower().endswith('.flac'):
encode_file(file_entry,
ARGS.base_dir.rstrip('/'),
ARGS.pattern,
ARGS.quality,
ARGS.ogg_cli_parameters)
def main():
"""Main logic for untz."""
if ARGS.verbose:
logging.basicConfig(level=logging.DEBUG)
preflight_checks()
LOGGER.info('Starting %d threads.', ARGS.threads)
with ThreadPoolExecutor(max_workers=ARGS.threads) as tpe:
for i in ARGS.inputs:
if os.path.isdir(i):
tpe.map(_encode_on_filter, recursive_file_search(i))
else:
tpe.submit(_encode_on_filter, i)
if ARGS.replaygain:
apply_gain(ARGS.base_dir)
LOGGER.warning('Program exiting now.')
|
bsd-3-clause
|
Python
|
ae4da4d5d6af27ddab376cb41067f21b053fcf5e
|
make tokenz lazy
|
rshkv/goethe
|
goethe/corpora.py
|
goethe/corpora.py
|
import os
from . import util
import itertools as it
class Corpus:
def __init__(self, path, limit=None):
"""Pass path to corpus. Expects following structure:
path/to/my/corpus
corpus.txt
corpus.tokens.txt
"""
self.path = os.path.normpath(path)
self.limit = limit
def __iter__(self):
"""Return generator yielding tokens.
"""
return self.tokens()
def sents(self):
"""Yield sentences from file.
"""
path = self.file_path(use_tokens=False)
with open(path) as f:
yield from (l.strip() for l in f)
def tokens(self):
"""Yield from file a list of tokens per sentence.
"""
path = self.file_path(use_tokens=True)
with open(path) as f:
tokens = (line.strip().split() for line in f)
yield from limit_iter(tokens) if self.limit else tokens
def limit_iter(self, iterator):
"""Return iterator that yields self.limit elements of the passed
iterator.
"""
return it.islice(iterator, self.limit)
def file_path(self, use_tokens):
"""Return path to either sentence or token file.
Example:
'abc/def/corpus'
--> 'abc/def/corpus/corpus.txt'
--> 'abc/def/corpus/corpus.tokens.txt'
"""
corpus_name = os.path.basename(self.path)
file = ('%s.tokens.txt' if use_tokens else '%s.txt') % corpus_name
return os.path.join(self.path, file)
def random(self, k):
"""Randomly select a list of k token lists.
(Will load k elements into memory!)
"""
return util.rsample(self.tokens(), k)
|
import os
from . import util
import itertools as it
class Corpus:
def __init__(self, path, limit=None):
"""Pass path to corpus. Expects following structure:
path/to/my/corpus
corpus.txt
corpus.tokens.txt
"""
self.path = os.path.normpath(path)
self.limit = limit
def __iter__(self):
"""Return generator yielding tokens.
"""
return self.tokens()
def sents(self):
"""Yield sentences from file.
"""
path = self.file_path(use_tokens=False)
with open(path) as f:
yield from (l.strip() for l in f)
def tokens(self):
"""Yield from file a list of tokens per sentence.
"""
path = self.file_path(use_tokens=True)
with open(path) as f:
tokens = [line.strip().split() for line in f]
yield from limit_iter(tokens) if self.limit else tokens
def limit_iter(self, iterator):
"""Return iterator that yields self.limit elements of the passed
iterator.
"""
return it.islice(iterator, self.limit)
def file_path(self, use_tokens):
"""Return path to either sentence or token file.
Example:
'abc/def/corpus'
--> 'abc/def/corpus/corpus.txt'
--> 'abc/def/corpus/corpus.tokens.txt'
"""
corpus_name = os.path.basename(self.path)
file = ('%s.tokens.txt' if use_tokens else '%s.txt') % corpus_name
return os.path.join(self.path, file)
def random(self, k):
"""Randomly select a list of k token lists.
(Will load k elements into memory!)
"""
return util.rsample(self.tokens(), k)
|
mit
|
Python
|
c6fe6e7ae212dab3b8cc4615355f782664dc2d05
|
raise invalid error in relations if unable to get rid or rtype
|
sassoo/drfjsonapi
|
drfjsonapi/relations.py
|
drfjsonapi/relations.py
|
"""
drfjsonapi.relations
~~~~~~~~~~~~~~~~~~~~
DRF relationship fields to assist with a JSON API spec
compliant API.
"""
from django.utils.translation import ugettext_lazy as _
from rest_framework.relations import SlugRelatedField
class JsonApiRelatedField(SlugRelatedField):
""" JSON API related field for relationships """
default_error_messages = {
'does_not_exist': _('Does not exist.'),
'invalid': _('Invalid value.'),
'invalid_rtype': _('Invalid resource type of "{given}".'),
}
def __init__(self, slug_field='id', **kwargs):
""" Process our custom attrs so DRF doesn't barf """
self.rtype = kwargs.pop('rtype', None)
super().__init__(slug_field=slug_field, **kwargs)
def get_rtype(self, instance):
""" Return the "Resource Identifier" type member """
return self.rtype
def to_internal_value(self, data):
""" DRF override during deserialization
A JSON API normalized relationship will have the following
members at a minimum:
{
'id': '123',
'type': 'actors',
}
"""
try:
rid, rtype = data['id'], data['type']
except TypeError:
self.fail('invalid')
# raises exc if not found, instance guaranteed
instance = super().to_internal_value(rid)
_rtype = self.get_rtype(instance)
if _rtype != rtype:
self.fail('invalid_rtype', given=rtype)
return instance
def to_representation(self, obj):
""" DRF override during serialization
`to_representation` could return None if the relationship
was cleared (OneToOne) & deleted but still present in
memory.
"""
ret = super().to_representation(obj)
if ret is not None:
return {
'id': str(ret),
'type': self.get_rtype(obj),
}
return None
|
"""
drfjsonapi.relations
~~~~~~~~~~~~~~~~~~~~
DRF relationship fields to assist with a JSON API spec
compliant API.
"""
from django.utils.translation import ugettext_lazy as _
from rest_framework.relations import SlugRelatedField
class JsonApiRelatedField(SlugRelatedField):
""" JSON API related field for relationships """
default_error_messages = {
'does_not_exist': _('Does not exist.'),
'invalid': _('Invalid value.'),
'invalid_rtype': _('Invalid resource type of "{given}".'),
}
def __init__(self, slug_field='id', **kwargs):
""" Process our custom attrs so DRF doesn't barf """
self.rtype = kwargs.pop('rtype', None)
super().__init__(slug_field=slug_field, **kwargs)
def get_rtype(self, instance):
""" Return the "Resource Identifier" type member """
return self.rtype
def to_internal_value(self, data):
""" DRF override during deserialization
A JSON API normalized relationship will have the following
members at a minimum:
{
'id': '123',
'type': 'actors',
}
"""
rid, rtype = data['id'], data['type']
# raises exc if not found, instance guaranteed
instance = super().to_internal_value(rid)
_rtype = self.get_rtype(instance)
if _rtype != rtype:
self.fail('invalid_rtype', given=rtype)
return instance
def to_representation(self, obj):
""" DRF override during serialization
`to_representation` could return None if the relationship
was cleared (OneToOne) & deleted but still present in
memory.
"""
ret = super().to_representation(obj)
if ret is not None:
return {
'id': str(ret),
'type': self.get_rtype(obj),
}
|
isc
|
Python
|
6b8b2ebfd17cd96a08511a31d2f1159981b5c7cd
|
Update drakar.py
|
oksome/Crane-Old,oksome/Crane-Old
|
apps/drakar.py
|
apps/drakar.py
|
import os
import sys
import platform
from os.path import isfile, isdir, join
DRAKAR_PATH = os.environ.get('DRAKAR', '/mnt/drakar')
if not isdir(DRAKAR_PATH):
raise OSError("No such directory: '{}'".format(DRAKAR_PATH))
SYSTEM = sys.platform + '-' + platform.machine()
sources = {
'linux2-x86_64/processing-2.1-linux64.tgz': 'http://download.processing.org/processing-2.1-linux64.tgz',
}
def get_archive(filename):
archives_path = join(DRAKAR_PATH, 'archives', SYSTEM)
# => /mnt/drakar/archives/linux2-x86_64
file_path = join(archives_path, filename)
# => /mnt/drakar/archives/linux2-x86_64/filename.foo
if not isfile(file_path):
here = os.getcwd()
source = sources[join(SYSTEM, filename)]
os.makedirs(archives_path)
os.chdir(archives_path)
os.system('wget ' + source)
os.chdir(here)
if isfile(file_path):
return file_path
else:
raise IOError("Could not obtain '{}' in Drakar".format(filename))
print(get_archive('processing-2.1-linux64.tgz'))
|
import os
import sys
import platform
from os.path import isfile, isdir, join
DRAKAR_PATH = os.environ.get('DRAKAR', '/mnt/drakar')
if not isdir(DRAKAR_PATH):
raise OSError("No such directory: '{}'".format(DRAKAR_PATH))
SYSTEM = sys.platform + '-' + platform.machine()
sources = {
'linux2-x86_64/processing-2.1-linux64.tgz': 'http://download.processing.org/processing-2.1-linux64.tgz',
}
def get_archive(filename):
archives_path = join(DRAKAR_PATH, 'archives', SYSTEM)
# => /mnt/drakar/archives/linux2-x86_64
file_path = join(archives_path, filename)
# => /mnt/drakar/archives/linux2-x86_64/filename.foo
if not isfile(file_path):
here = os.getcwd()
source = sources[join(SYSTEM, filename)]
os.makedirs(archives_path)
os.chdir(archives_path)
os.system('wget ' + source)
os.chdir(here)
if isfile(file_path):
return file_path
else:
raise IOError("Could not obtain '{}' in Drakar".format(filename))
get_archive('processing-2.1-linux64.tgz')
|
agpl-3.0
|
Python
|
1c02294073c855fab8d6fc0965f3584b0ac0137b
|
clean up example file
|
openego/dingo,openego/dingo
|
examples/example.py
|
examples/example.py
|
#!/usr/bin/env python3
import matplotlib.pyplot as plt
from oemof import db
from dingo.core import NetworkDingo
from dingo.tools import config as cfg_dingo
plt.close('all')
cfg_dingo.load_config('config_db_tables')
cfg_dingo.load_config('config_calc')
cfg_dingo.load_config('config_files')
cfg_dingo.load_config('config_misc')
# database connection
conn = db.connection(section='oedb')
# instantiate dingo network object
nd = NetworkDingo(name='network')
# mv_grid_districts = [386,372,406,371,402,415,480,424,489,367,359,569,591]
mv_grid_districts=[480]
nd.import_mv_grid_districts(conn, mv_grid_districts)
nd.import_generators(conn)
nd.mv_parametrize_grid()
nd.mv_routing(debug=False, animation=False)
nd.connect_generators()
nd.set_branch_ids()
# DEBUG (Compare graphs to CLEAN UP THE SALT)
#conn.close()
#from dingo.tools.debug import compare_graphs
#compare_graphs(graph=nd._mv_grid_districts[0].mv_grid._graph,
# mode='compare')
nd.set_circuit_breakers()
# Open and close all circuit breakers in grid
[gd.mv_grid.open_circuit_breakers() for gd in nd._mv_grid_districts]
# Analyze grid by power flow analysis
for mv_grid_district in nd._mv_grid_districts:
mv_grid_district.mv_grid.run_powerflow(conn, method='onthefly')
nd.export_mv_grid(conn, mv_grid_districts)
conn.close()
# reinforce MV grid
#nd.reinforce_grid()
|
#!/usr/bin/env python3
import matplotlib.pyplot as plt
from oemof import db
conn = db.connection(section='oedb')
from dingo.core import NetworkDingo
from dingo.tools import config as cfg_dingo
from dingo.tools.debug import compare_graphs
plt.close('all')
cfg_dingo.load_config('config_db_tables')
cfg_dingo.load_config('config_calc')
cfg_dingo.load_config('config_files')
cfg_dingo.load_config('config_misc')
# get engine for database connection
#conn = db.connection(db_section='ontohub_wdb', cfg_file='~/.dingo/config') # <-- TODO: include custom config file from given path (+input for oemof)
# instantiate dingo network object
nd = NetworkDingo(name='network')
# mv_grid_districts=[360, 571, 593, 368, 491, 425, 416, 372, 387, 407, 403, 373, 482] # some MV grid_districts from SPF region
# mv_grid_districts=[360, 571, 593, 368, 491, 416, 372, 387, 407, 403, 373, 482] # some MV grid_districts from SPF region
# mv_grid_districts=[482]
# mv_grid_districts = [386,372,406,371,402,415,480,424,489,367,359,569,591]
mv_grid_districts=[480]
nd.import_mv_grid_districts(conn, mv_grid_districts)
nd.import_generators(conn)
nd.mv_parametrize_grid()
nd.mv_routing(debug=False, animation=False)
nd.connect_generators()
nd.set_branch_ids()
#conn.close()
# DEBUG (CLEAN UP THE SALT)
#compare_graphs(graph=nd._mv_grid_districts[0].mv_grid._graph,
# mode='compare')
nd.set_circuit_breakers()
# Open and close all circuit breakers in grid (for testing)
[gd.mv_grid.open_circuit_breakers() for gd in nd._mv_grid_districts]
#nd._mv_grid_districts[0].mv_grid.close_circuit_breakers()
# Analyze grid by power flow analysis
for mv_grid_district in nd._mv_grid_districts:
mv_grid_district.mv_grid.run_powerflow(conn, method='onthefly')
nd.export_mv_grid(conn, mv_grid_districts)
conn.close()
#nd.reinforce_grid()
# for edge in nd._mv_grid_districts[0].mv_grid.graph_edges():
# if edge['branch'].type is not None:
# print(edge['branch'].type['name'])
# else:
# print('None')
# lvrg = []
# for mv_grid_district in nd.mv_grid_districts():
# #print(mv_grid_district._lv_load_area_groups)
# #print(type(mv_grid_district._lv_load_area_groups))
# for lv_load_area_group in iter(mv_grid_district._lv_load_area_groups):
# lvrg.append([str(lv_load_area_group), lv_load_area_group.peak_load_sum, lv_load_area_group.branch_length_sum])
# lvrg = sorted(lvrg, key=lambda x: x[1])
#
# for lvrg_name, lvrg_load, lvrg_length in lvrg:
# print(lvrg_name, lvrg_load, lvrg_length)
#df = nx.to_pandas_dataframe(nd._mv_grid_districts[0].mv_grid._graph)
# import pprint
# for edge in nd._mv_grid_districts[0].mv_grid._graph.edge.keys():
# # print(edge, type(edge))
# pprint.pprint(edge)
# pprint.pprint(nd._mv_grid_districts[0].mv_grid._graph.edge[edge])
#nd._mv_grid_districts[0].mv_grid.graph_draw()
|
agpl-3.0
|
Python
|
2645ac98fd2698bcfbf4a23cdb6c9583e6b31a50
|
create test user from python updated
|
asmltd/faucet,asmltd/faucet,asmltd/faucet,asmltd/faucet,asmltd/faucet
|
src/apps/flow_manager/createdb.py
|
src/apps/flow_manager/createdb.py
|
import requests
import json
dbhost = "localhost"
dbport = "5984"
dbuser = "root"
dbpass = "asm123"
database = "faucet"
userdatabase = "users"
username = "[email protected]"
password = "testflowmgr"
role = "1"
data = {"username": username, "password": password, "role": role}
createdb = requests.put("http://"+dbuser+":"+dbpass+"@"+dbhost+":"+dbport+"/"+userdatabase+"/")
print createdb
view_data = {'_id': '_design/users','views': {'users': {'map': 'function(doc){ emit(doc._id, doc)}'}}}
view_data = json.dumps(view_data)
createvw = requests.put(url="http://" + dbuser + ":" + dbpass + "@" + dbhost + ":" + dbport + "/" + userdatabase + "/_design/users/",
data=view_data)
print createvw
createuser =requests.post(url="http://"+dbhost+":"+dbport+"/"+userdatabase+"/", json={"username": username, "password": password, "role": role})
print createuser
|
import requests
dbhost = "localhost"
dbport = "5984"
dbuser = "root"
dbpass = "asm123"
database = "faucet"
userdatabase = "users"
username = "[email protected]"
password = "testflowmgr"
role = "1"
data = {"username": username, "password": password, "role": role}
# createdb = requests.put("http://"+dbuser+":"+dbpass+"@"+dbhost+":"+dbport+"/"+userdatabase+"/")
# print createdb
view_data = "{_id: '_design/users',views: {'users': {'map': 'function(doc){ emit(doc._id, doc)}'}}}"
createvw = requests.put(
url="http://" + dbuser + ":" + dbpass + "@" + dbhost + ":" + dbport + "/" + userdatabase + "/_design/users/",
data=view_data)
requests.put(url="http://" + dbuser + ":" + dbpass + "@" + dbhost + ":" + dbport + "/" + userdatabase + "/_design/users/",
data={'_id': '_design/users','views': {'users': {'map': 'function(doc){ emit(doc._id, doc)}'}}})
print createvw.status_code, createvw.content
# createuser =requests.post(url="http://"+dbhost+":"+dbport+"/"+userdatabase+"/", json={"username": username, "password": password, "role": role})
# print createuser
|
apache-2.0
|
Python
|
547ee3fb5db9ebb0bed0443d865ec76f44904b9e
|
Add url_shortener.views.render_preview function
|
piotr-rusin/url-shortener,piotr-rusin/url-shortener
|
url_shortener/views.py
|
url_shortener/views.py
|
# -*- coding: utf-8 -*-
from flask import session, redirect, url_for, flash, render_template
from . import app
from .forms import ShortenedUrlForm
from .models import ShortenedUrl, register
@app.route('/', methods=['GET', 'POST'])
def shorten_url():
'''Display form and handle request for url shortening
If short url is successfully created or found for the
given url, its alias property is saved in session, and
the function redirects to its route. After redirection,
the alias is used to query for newly created shortened
url, and information about it is presented.
If there are any errors for data entered by the user into
the input tex field, they are displayed.
:returns: a response generated by rendering the template,
either directly or after redirection.
'''
form = ShortenedUrlForm()
if form.validate_on_submit():
shortened_url = ShortenedUrl.get_or_create(form.url.data)
register(shortened_url)
session['new_alias'] = str(shortened_url.alias)
return redirect(url_for(shorten_url.__name__))
else:
for error in form.url.errors:
flash(error, 'error')
try:
new_shortened_url = ShortenedUrl.get_or_404(session['new_alias'])
except KeyError:
new_shortened_url = None
return render_template(
'shorten_url.html',
form=form,
new_shortened_url=new_shortened_url
)
def render_preview(shortened_url, warning_message=None):
return render_template(
'preview.html',
shortened_url=shortened_url,
warning=warning_message
)
@app.route('/<alias>')
def redirect_for(alias):
''' Redirect to address assigned to given alias
:param alias: a string value by which we search for
an associated url. If it is not found, a 404 error
occurs
:returns: a redirect to target url of short url, if
found.
'''
shortened_url = ShortenedUrl.get_or_404(alias)
return redirect(shortened_url.target)
@app.route('/preview/<alias>')
def preview(alias):
''' Show the preview for given alias
The preview contains a short url and a target url
associated with it.
:param alias: a string value by which we search
for an associated url. If it is not found, a 404
error occurs.
:returns: a response generated from the preview template
'''
shortened_url = ShortenedUrl.get_or_404(alias)
return render_template(
'preview.html',
short_url=shortened_url.short_url,
target=shortened_url.target
)
@app.errorhandler(404)
def not_found(error):
return render_template('not_found.html')
@app.errorhandler(500)
def server_error(error):
return render_template('server_error.html')
|
# -*- coding: utf-8 -*-
from flask import session, redirect, url_for, flash, render_template
from . import app
from .forms import ShortenedUrlForm
from .models import ShortenedUrl, register
@app.route('/', methods=['GET', 'POST'])
def shorten_url():
'''Display form and handle request for url shortening
If short url is successfully created or found for the
given url, its alias property is saved in session, and
the function redirects to its route. After redirection,
the alias is used to query for newly created shortened
url, and information about it is presented.
If there are any errors for data entered by the user into
the input tex field, they are displayed.
:returns: a response generated by rendering the template,
either directly or after redirection.
'''
form = ShortenedUrlForm()
if form.validate_on_submit():
shortened_url = ShortenedUrl.get_or_create(form.url.data)
register(shortened_url)
session['new_alias'] = str(shortened_url.alias)
return redirect(url_for(shorten_url.__name__))
else:
for error in form.url.errors:
flash(error, 'error')
try:
new_shortened_url = ShortenedUrl.get_or_404(session['new_alias'])
except KeyError:
new_shortened_url = None
return render_template(
'shorten_url.html',
form=form,
new_shortened_url=new_shortened_url
)
@app.route('/<alias>')
def redirect_for(alias):
''' Redirect to address assigned to given alias
:param alias: a string value by which we search for
an associated url. If it is not found, a 404 error
occurs
:returns: a redirect to target url of short url, if
found.
'''
shortened_url = ShortenedUrl.get_or_404(alias)
return redirect(shortened_url.target)
@app.route('/preview/<alias>')
def preview(alias):
''' Show the preview for given alias
The preview contains a short url and a target url
associated with it.
:param alias: a string value by which we search
for an associated url. If it is not found, a 404
error occurs.
:returns: a response generated from the preview template
'''
shortened_url = ShortenedUrl.get_or_404(alias)
return render_template(
'preview.html',
short_url=shortened_url.short_url,
target=shortened_url.target
)
@app.errorhandler(404)
def not_found(error):
return render_template('not_found.html')
@app.errorhandler(500)
def server_error(error):
return render_template('server_error.html')
|
mit
|
Python
|
d166563f648d409f7039ce2df1149a8cb15b13ab
|
add sub-package: plot
|
shmilee/gdpy3,shmilee/gdpy3,shmilee/gdpy3,shmilee/gdpy3
|
gdpy3/__init__.py
|
gdpy3/__init__.py
|
__name__ = "gdpy3"
__doc__ = "gdpy3: Gyrokinetic Toroidal Code Data Processing tools"
__author__ = "shmilee"
__version__ = "0.0.1"
__status__ = "alpha"
__license__ = "MIT"
__email__ = "[email protected]"
__all__ = ['convert', 'plot', 'read']
|
__name__ = "gdpy3"
__doc__ = "gdpy3: Gyrokinetic Toroidal Code Data Processing tools"
__author__ = "shmilee"
__version__ = "0.0.1"
__status__ = "alpha"
__license__ = "MIT"
__email__ = "[email protected]"
__all__ = ['convert', 'read']
|
mit
|
Python
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.