commit
stringlengths
40
40
subject
stringlengths
1
3.25k
old_file
stringlengths
4
311
new_file
stringlengths
4
311
old_contents
stringlengths
0
26.3k
lang
stringclasses
3 values
proba
float64
0
1
diff
stringlengths
0
7.82k
9381657d8ad2e96c2537c89fad7a4b3d8d8ddff5
Add gpu parameter to htcondor_at_vispa example.
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. """ 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
Python
0
@@ -1502,24 +1502,205 @@ d.%0A %22%22%22%0A%0A + htcondor_gpus = luigi.IntParameter(default=law.NO_INT, significant=False, desription=%22number %22%0A %22of GPUs to request on the VISPA cluster, leave empty to use only CPUs%22)%0A%0A def htco @@ -2667,16 +2667,194 @@ _PATH%22)%0A + # tell the job config if GPUs are requested%0A if not law.is_no_param(self.htcondor_gpus):%0A config.custom_config = %5B(%22request_gpus%22, self.htcondor_gpus)%5D%0A
a5de78328cc2e63c901c409fb6c7b376abf921e2
reorganize code the object oriented way
src/scopus.py
src/scopus.py
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']
Python
0.000153
@@ -1,19 +1,944 @@ -import requests +from itertools import chain%0Aimport requests%0A%0A_HEADERS = %7B'Accept': 'application/json'%7D%0A%0Aclass ScopusResponse(object):%0A%0A def __init__(self, data):%0A self._data = data%0A%0A def __getitem__(self, key):%0A return self._data%5B'search-results'%5D%5Bkey%5D%0A%0A def __iter__(self):%0A resp = self%0A while resp:%0A yield resp%0A resp = resp.next()%0A%0A def entries(self):%0A return %5B%5D if self.is_empty() else self%5B'entry'%5D%0A%0A def is_empty(self):%0A return int(self%5B'opensearch:totalResults'%5D) == 0%0A%0A def next_page_url(self):%0A try: return next(l%5B'@href'%5D for l in self%5B'link'%5D if l%5B'@ref'%5D=='next')%0A except: return None%0A%0A def next(self):%0A url = self.next_page_url()%0A if not url: return None%0A return ScopusResponse(requests.get(url, headers=_HEADERS).json())%0A%0A def all_entries(self):%0A return list(chain.from_iterable(page.entries() for page in self))%0A %0A%0Acl @@ -1099,54 +1099,8 @@ pus' -%0A _HEADERS = %7B'Accept': 'application/json'%7D %0A%0A @@ -1189,37 +1189,24 @@ point, query -, parse=False ):%0A r @@ -1234,37 +1234,32 @@ dpoint, headers= -self. _HEADERS,%0A @@ -1335,563 +1335,35 @@ urn -resp.json() if parse else resp%0A%0A def _is_empty(self, resp):%0A return int(resp%5B'search-results'%5D%5B'opensearch:totalResults'%5D) == 0%0A%0A def _all_pages(self, resp):%0A if not self._is_empty(resp):%0A while True:%0A yield resp%0A try:%0A url = next(li%5B'@href'%5D%0A for li in resp%5B'search-results'%5D%5B'link'%5D%0A if li%5B'@ref'%5D == 'next')%0A resp = requests.get(url, headers=self._HEADERS).json()%0A except: break +ScopusResponse(resp.json()) %0A%0A @@ -1388,37 +1388,24 @@ (self, query -, parse=False ):%0A r @@ -1435,39 +1435,32 @@ UTHOR_API, query -, parse )%0A%0A def scopu @@ -1482,21 +1482,8 @@ uery -, parse=False ):%0A @@ -1529,23 +1529,16 @@ I, query -, parse )%0A%0A d @@ -1661,28 +1661,28 @@ )%0A re -sp = +turn self.scopus @@ -1697,145 +1697,23 @@ uery -, parse=True)%0A return %5Bentry for page in self._all_pages(resp)%0A for entry in page%5B'search-results'%5D%5B'entry'%5D%5D +).all_entries() %0A%0A @@ -1905,28 +1905,28 @@ )%0A re -sp = +turn self.author @@ -1941,97 +1941,20 @@ uery -, parse=True)%0A return %5B%5D if self._is_empty(resp) else resp%5B'search-results'%5D%5B'entry'%5D +).all_entries() %0A
28601b95720474a4f8701d6cb784ac6ec3618d49
add support for wheel DL proxy (#14010)
tools/download-wheels.py
tools/download-wheels.py
#!/usr/bin/env python """ Download SciPy wheels from Anaconda staging area. """ import sys import os import re import shutil import argparse import urllib3 from bs4 import BeautifulSoup __version__ = '0.1' # Edit these for other projects. STAGING_URL = 'https://anaconda.org/multibuild-wheels-staging/scipy' PREFIX = 'scipy' def get_wheel_names(version): """ Get wheel names from Anaconda HTML directory. This looks in the Anaconda multibuild-wheels-staging page and parses the HTML to get all the wheel names for a release version. Parameters ---------- version : str The release version. For instance, "1.5.0". """ http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED') tmpl = re.compile(rf"^.*{PREFIX}-{version}-.*\.whl$") index_url = f"{STAGING_URL}/files" index_html = http.request('GET', index_url) soup = BeautifulSoup(index_html.data, 'html.parser') return soup.findAll(text=tmpl) def download_wheels(version, wheelhouse): """Download release wheels. The release wheels for the given SciPy version are downloaded into the given directory. Parameters ---------- version : str The release version. For instance, "1.5.0". wheelhouse : str Directory in which to download the wheels. """ http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED') wheel_names = get_wheel_names(version) for i, wheel_name in enumerate(wheel_names): wheel_url = f"{STAGING_URL}/{version}/download/{wheel_name}" wheel_path = os.path.join(wheelhouse, wheel_name) with open(wheel_path, 'wb') as f: with http.request('GET', wheel_url, preload_content=False,) as r: print(f"{i + 1:<4}{wheel_name}") shutil.copyfileobj(r, f) print(f"\nTotal files downloaded: {len(wheel_names)}") if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( "version", help="SciPy version to download.") parser.add_argument( "-w", "--wheelhouse", default=os.path.join(os.getcwd(), "release", "installers"), help="Directory in which to store downloaded wheels\n" "[defaults to <cwd>/release/installers]") args = parser.parse_args() wheelhouse = os.path.expanduser(args.wheelhouse) if not os.path.isdir(wheelhouse): raise RuntimeError( f"{wheelhouse} wheelhouse directory is not present." " Perhaps you need to use the '-w' flag to specify one.") download_wheels(args.version, wheelhouse)
Python
0
@@ -134,16 +134,30 @@ argparse +%0Aimport urllib %0A%0Aimport @@ -337,16 +337,445 @@ scipy'%0A%0A +def http_manager():%0A %22%22%22%0A Return a urllib3 http request manager, leveraging%0A proxy settings when available.%0A %22%22%22%0A proxy_dict = urllib.request.getproxies()%0A if 'http' in proxy_dict:%0A http = urllib3.ProxyManager(proxy_dict%5B'http'%5D)%0A elif 'all' in proxy_dict:%0A http = urllib3.ProxyManager(proxy_dict%5B'all'%5D)%0A else:%0A http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED')%0A return http%0A%0A def get_ @@ -1112,53 +1112,21 @@ p = -urllib3.PoolManager(cert_reqs='CERT_REQUIRED' +http_manager( )%0A @@ -1730,53 +1730,21 @@ p = -urllib3.PoolManager(cert_reqs='CERT_REQUIRED' +http_manager( )%0A
c43bd7f829ce79577421374ba6c00b74adca05aa
add test for using glob matching in a directory tree in file iterator
src/test/file_iterator_tests.py
src/test/file_iterator_tests.py
import nose from nose.tools import * from unittest import TestCase import os from shutil import rmtree from tempfile import mkdtemp from file_iterator import FileIterator class FileIteratorTests(TestCase): def setUp(self): self.directory = mkdtemp('-gb-file-iterator-tests') self.file_iterator = FileIterator(self.directory) def tearDown(self): rmtree(self.directory) def test_iterate_files_in_single_directory(self): self._create_file(self.directory, 'file1') self._create_file(self.directory, 'file2') s = set(self.file_iterator.files()) eq_(set(self._prepend_dir(['file1', 'file2'])), s) def test_iterate_files_in_directory_tree(self): self._create_file(self.directory, 'file0') dir1 = self._create_dir(self.directory, 'dir1') self._create_file(dir1, 'file1') dir2 = self._create_dir(dir1, 'dir2') self._create_file(dir2, 'file2') dir3 = self._create_dir(self.directory, 'dir3') self._create_file(dir3, 'file3') expected = set() expected.add(os.path.join(self.directory, 'file0')) expected.add(os.path.join(dir1, 'file1')) expected.add(os.path.join(dir2, 'file2')) expected.add(os.path.join(dir3, 'file3')) s = set(self.file_iterator.files()) eq_(expected, s) def test_match_files_by_glob(self): self.file_iterator.set_glob("*.java") self._create_file(self.directory, 'file.txt') self._create_file(self.directory, 'file.java') s = set(self.file_iterator.files()) eq_(set([os.path.join(self.directory, 'file.java')]), s) @nottest def _create_file(self, directory, filename): filepath = os.path.join(directory, filename) with open(filepath, 'w') as f: f.write(filename) f.close() @nottest def _create_dir(self, directory, dirname): dirpath = os.path.join(directory, dirname) os.mkdir(dirpath) return dirpath @nottest def _prepend_dir(self, files, directory=None): if directory is None: directory = self.directory return [os.path.join(directory, f) for f in files]
Python
0
@@ -1669,16 +1669,691 @@ %5D), s)%0A%0A + def test_match_files_in_directory_tree_by_glob(self):%0A self.file_iterator.set_glob(%22*.java%22)%0A self._create_file(self.directory, 'file0.java')%0A dir1 = self._create_dir(self.directory, 'dir1')%0A self._create_file(dir1, 'file1.c')%0A dir2 = self._create_dir(dir1, 'dir2')%0A self._create_file(dir2, 'file2.java')%0A dir3 = self._create_dir(self.directory, 'dir3')%0A self._create_file(dir3, 'file3.py')%0A %0A expected = set()%0A expected.add(os.path.join(self.directory, 'file0.java'))%0A expected.add(os.path.join(dir2, 'file2.java'))%0A s = set(self.file_iterator.files())%0A eq_(expected, s)%0A%0A @not
f9be60fcbdd401e7b45917ba2d801ee255fdef68
Change to bare NotImplementedError.
cloud_browser/cloud/base.py
cloud_browser/cloud/base.py
"""Cloud API base abstraction.""" import mimetypes from cloud_browser.cloud import errors from cloud_browser.app_settings import settings from cloud_browser.common import SEP, path_join, basename DEFAULT_GET_OBJS_LIMIT = 20 class CloudObjectTypes(object): """Cloud object types helper.""" FILE = 'file' SUBDIR = 'subdirectory' class CloudObject(object): """Cloud object wrapper.""" type_cls = CloudObjectTypes def __init__(self, container, name, **kwargs): """Initializer. :param container: Container object. :param name: Object name / path. :kwarg size: Number of bytes in object. :kwarg content_type: Document 'content-type'. :kwarg content_encoding: Document 'content-encoding'. :kwarg last_modified: Last modified date. :kwarg obj_type: Type of object (e.g., file or subdirectory). """ self.container = container self.name = name.rstrip(SEP) self.size = kwargs.get('size', 0) self.content_type = kwargs.get('content_type', '') self.content_encoding = kwargs.get('content_encoding', '') self.last_modified = kwargs.get('last_modified', None) self.type = kwargs.get('obj_type', self.type_cls.FILE) self.__native = None @property def native_obj(self): """Native storage object.""" if self.__native is None: self.__native = self._get_object() return self.__native def _get_object(self): """Return native storage object.""" raise NotImplementedError("Must implement.") @property def is_subdir(self): """Is a subdirectory?""" return self.type == self.type_cls.SUBDIR @property def is_file(self): """Is a file object?""" return self.type == self.type_cls.FILE @property def path(self): """Full path (including container).""" return path_join(self.container.name, self.name) @property def basename(self): """Base name from rightmost separator.""" return basename(self.name) @property def smart_content_type(self): """Smart content type.""" content_type = self.content_type if content_type in (None, '', 'application/octet-stream'): content_type, _ = mimetypes.guess_type(self.name) return content_type @property def smart_content_encoding(self): """Smart content encoding.""" encoding = self.content_encoding if not encoding: base_list = self.basename.split('.') while (not encoding) and len(base_list) > 1: _, encoding = mimetypes.guess_type('.'.join(base_list)) base_list.pop() return encoding def read(self): """Return contents of object.""" return self._read() def _read(self): """Return contents of object.""" raise NotImplementedError("Must implement.") class CloudContainer(object): """Cloud container wrapper.""" obj_cls = CloudObject def __init__(self, conn, name=None, count=None, size=None): """Initializer.""" self.conn = conn self.name = name self.count = count self.size = size self.__native = None @property def native_container(self): """Native container object.""" if self.__native is None: self.__native = self._get_container() return self.__native def _get_container(self): """Return native container object.""" raise NotImplementedError("Must implement.") def get_objects(self, path, marker=None, limit=DEFAULT_GET_OBJS_LIMIT): """Get objects.""" raise NotImplementedError("Must implement.") def get_object(self, path): """Get single object.""" raise NotImplementedError("Must implement.") class CloudConnection(object): """Cloud connection wrapper.""" cont_cls = CloudContainer def __init__(self, account, secret_key, rs_servicenet=False): """Initializer.""" self.account = account self.secret_key = secret_key self.rs_servicenet = rs_servicenet self.__native = None @property def native_conn(self): """Native connection object.""" if self.__native is None: self.__native = self._get_connection() return self.__native def _get_connection(self): """Return native connection object.""" raise NotImplementedError("Must implement.") def get_containers(self): """Return available containers.""" permitted = lambda c: settings.container_permitted(c.name) return [c for c in self._get_containers() if permitted(c)] def _get_containers(self): """Return available containers.""" raise NotImplementedError("Must implement.") def get_container(self, path): """Return single container.""" if not settings.container_permitted(path): raise errors.NotPermittedException( "Access to container \"%s\" is not permitted." % path) return self._get_container(path) def _get_container(self, path): """Return single container.""" raise NotImplementedError("Must implement.")
Python
0
@@ -1577,36 +1577,17 @@ tedError -(%22Must implement.%22) %0A + %0A @pr @@ -2940,35 +2940,16 @@ tedError -(%22Must implement.%22) %0A%0A%0Aclass @@ -3567,35 +3567,16 @@ tedError -(%22Must implement.%22) %0A%0A de @@ -3705,35 +3705,16 @@ tedError -(%22Must implement.%22) %0A%0A de @@ -3805,35 +3805,16 @@ tedError -(%22Must implement.%22) %0A%0A%0Aclass @@ -4448,35 +4448,16 @@ tedError -(%22Must implement.%22) %0A%0A de @@ -4765,35 +4765,16 @@ tedError -(%22Must implement.%22) %0A%0A de @@ -5120,32 +5120,32 @@ e container.%22%22%22%0A + raise No @@ -5165,24 +5165,5 @@ rror -(%22Must implement.%22) %0A
048151e47b0fb2e5211a1a0d857f55c32d64d70b
Add appropiate get_default method to field.
django_pgjson/fields.py
django_pgjson/fields.py
# -*- coding: utf-8 -*- import json import re import django from django.db.backends.postgresql_psycopg2.version import get_version from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django import forms from django.utils import six import psycopg2 import psycopg2.extensions import psycopg2.extras class JsonAdapter(psycopg2.extras.Json): def dumps(self, obj): return json.dumps(obj, cls=DjangoJSONEncoder) psycopg2.extensions.register_adapter(dict, JsonAdapter) psycopg2.extras.register_default_json(loads=json.loads) # so that psycopg2 knows also to convert jsonb fields correctly # http://schinckel.net/2014/05/24/python,-postgres-and-jsonb/ psycopg2.extras.register_json(loads=json.loads, oid=3802, array_oid=3807) class JsonField(six.with_metaclass(models.SubfieldBase, models.Field)): empty_strings_allowed = False def db_type(self, connection): if get_version(connection) < 90200: raise RuntimeError("django_pgjson does not supports postgresql version < 9.2") return "json" def value_to_string(self, obj): value = self._get_val_from_obj(obj) return json.dumps(self.get_prep_value(value), cls=DjangoJSONEncoder) def to_python(self, value): if isinstance(value, six.string_types): try: value = json.loads(value) except ValueError: pass return value def formfield(self, **kwargs): defaults = {'form_class': JsonFormField} defaults.update(kwargs) return super(JsonField, self).formfield(**defaults) def get_db_prep_value(self, value, connection, prepared=False): value = super(JsonField, self).get_db_prep_value(value, connection, prepared=prepared) if self.null and value is None: return None return JsonAdapter(value) if django.get_version() >= '1.7': def get_transform(self, name): from .lookups import KeyTransformFactory transform = super(JsonField, self).get_transform(name) if transform: return transform if not re.match("at_\w+", name): return None _, key = name.split("_", 1) return KeyTransformFactory(key, self) class JsonBField(JsonField): def db_type(self, connection): if get_version(connection) < 90400: raise RuntimeError("django_pgjson: PostgreSQL >= 9.4 is required for jsonb support.") return "jsonb" def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): retval = super(JsonBField, self).get_db_prep_lookup(lookup_type, value, connection, prepared) if lookup_type == 'jcontains': # retval is [value] where value is either a string or a # dict / list. in the former case, we assume it's json # encoded and we do nothing. In the latter case, we have # to json-encode -- cpb if not isinstance(retval[0], six.string_types): newval = json.dumps(retval[0], cls=DjangoJSONEncoder) retval[0] = newval return retval if django.get_version() >= '1.7': from .lookups import ExactLookup from .lookups import ArrayLengthLookup, JsonBArrayLengthLookup, JsonBContainsLookup JsonField.register_lookup(ExactLookup) JsonField.register_lookup(ArrayLengthLookup) JsonBField.register_lookup(ExactLookup) JsonBField.register_lookup(JsonBArrayLengthLookup) JsonBField.register_lookup(JsonBContainsLookup) class JsonFormField(forms.CharField): widget = forms.Textarea def prepare_value(self, value): if isinstance(value, six.string_types): return value return json.dumps(value, cls=DjangoJSONEncoder) # South compatibility try: from south.modelsinspector import add_introspection_rules add_introspection_rules([( (JsonField,), [], { 'blank': ['blank', { 'default': True }], 'null': ['null', { 'default': True }], }, )], (r'^django_pgjson\.fields\.JsonField',)) add_introspection_rules([( (JsonBField,), [], { 'blank': ['blank', { 'default': True }], 'null': ['null', { 'default': True }], }, )], (r'^django_pgjson\.fields\.JsonBField',)) except ImportError: pass
Python
0
@@ -1233,16 +1233,205 @@ coder)%0A%0A + def get_default(self):%0A if self.has_default():%0A if callable(self.default):%0A return self.default()%0A return self.default%0A%0A return None%0A%0A def
758c33b216513ede90ebc139e6eae87ba60c7512
Remove django <= 1.4.x support.
djmail/template_mail.py
djmail/template_mail.py
# -*- encoding: utf-8 -*- from __future__ import print_function import functools import logging from django.conf import settings from django.core import mail from django.utils import translation try: # Django >= 1.4.5 from django.utils.six import string_types except ImportError: # Django < 1.4.5 string_types = basestring from django.template import loader, TemplateDoesNotExist from . import models from . import exceptions as exc log = logging.getLogger("djmail") def _get_body_template_prototype(): return getattr(settings, "DJMAIL_BODY_TEMPLATE_PROTOTYPE", "emails/{name}-body-{type}.{ext}") def _get_subject_template_prototype(): return getattr(settings, "DJMAIL_SUBJECT_TEMPLATE_PROTOTYPE", "emails/{name}-subject.{ext}") def _get_template_extension(): return getattr(settings, "DJMAIL_TEMPLATE_EXTENSION", "html") def _trap_exception(function): """ Simple decorator for catch template exceptions. If exception is throwed, this decorator by default returns an empty string. """ @functools.wraps(function) def _decorator(*args, **kwargs): try: return function(*args, **kwargs) except TemplateDoesNotExist as e: log.warning("Template '{0}' does not exists.".format(e)) return u"" return _decorator def _trap_language(function): """ Decorator that intercept a language attribute and set it on context of the execution. """ @functools.wraps(function) def _decorator(self, context): language_new = None language_old = translation.get_language() # If attr found on context, set a new language if "lang" in context: language_new = context["lang"] translation.activate(language_new) try: return function(self, context) finally: if language_new is not None: translation.activate(language_old) return _decorator class TemplateMail(object): name = None def __init__(self, name=None): self._email = None if name is not None: self.name = name self._initialize_settings() def _initialize_settings(self): self._body_template_name = _get_body_template_prototype() self._subject_template_name = _get_subject_template_prototype() @_trap_exception @_trap_language def _render_message_body_as_html(self, context): template_ext = _get_template_extension() template_name = self._body_template_name.format(**{ "ext": template_ext, "name": self.name, "type": "html"}) return loader.render_to_string(template_name, context) @_trap_exception @_trap_language def _render_message_body_as_txt(self, context): template_ext = _get_template_extension() template_name = self._body_template_name.format(**{ "ext": template_ext, "name": self.name, "type": "text"}) return loader.render_to_string(template_name, context) def _render_message_subject(self, context): template_ext = _get_template_extension() template_name = self._subject_template_name.format(**{ "ext": template_ext, "name": self.name}) try: subject = loader.render_to_string(template_name, context) except TemplateDoesNotExist as e: raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e)) return u" ".join(subject.strip().split()) def _attach_body_to_email_instance(self, email, context): body_html = self._render_message_body_as_html(context) body_txt = self._render_message_body_as_txt(context) if not body_txt and not body_html: raise exc.TemplateNotFound("Body of email message shouldn't be empty") email.body = body_txt if isinstance(email, mail.EmailMultiAlternatives): email.attach_alternative(body_html, "text/html") def _attach_subject_to_email_instance(self, email, context): email.subject = self._render_message_subject(context) def make_email_object(self, to, context, **kwargs): if not isinstance(to, (list, tuple)): to = [to] email = mail.EmailMultiAlternatives(**kwargs) email.to = to self._attach_body_to_email_instance(email, context) self._attach_subject_to_email_instance(email, context) return email def send(self, to, context, **kwargs): email = self.make_email_object(to, context, **kwargs) return email.send() class InlineCSSTemplateMail(TemplateMail): def _render_message_body_as_html(self, context): # Transform CSS into line style attributes import premailer return premailer.transform(super()._render_message_body_as_html(context)) class MagicMailBuilder(object): def __init__(self, email_attr="email", lang_attr="lang", template_mail_cls=TemplateMail): self._email_attr = email_attr self._lang_attr = lang_attr self._template_mail_cls = template_mail_cls def __getattr__(self, name): def _dynamic_email_generator(to, context, priority=models.PRIORITY_STANDARD): lang = None if not isinstance(to, string_types): if not hasattr(to, self._email_attr): raise AttributeError( "'to' parameter does not " "have '{0}' attribute".format(self._email_attr)) lang = getattr(to, self._lang_attr, None) to = getattr(to, self._email_attr) if lang is not None: context["lang"] = lang template_email = self._template_mail_cls(name=name) email_instance = template_email.make_email_object(to, context) email_instance.priority = priority return email_instance return _dynamic_email_generator
Python
0
@@ -1,16 +1,14 @@ # -*- -en coding: @@ -17,16 +17,16 @@ f-8 -*-%0A + %0Afrom __ @@ -88,16 +88,54 @@ logging +%0Afrom contextlib import contextmanager %0A%0Afrom d @@ -231,39 +231,8 @@ ion%0A -try:%0A # Django %3E= 1.4.5%0A from @@ -273,79 +273,8 @@ pes%0A -except ImportError:%0A # Django %3C 1.4.5%0A string_types = basestring%0A from @@ -348,16 +348,16 @@ models%0A + from . i @@ -381,17 +381,16 @@ as exc%0A%0A -%0A log = lo
0bf9c011ca36df2d72dfd3b8fc59f6320e837e43
Update __init__.py
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 class NullSecurity(defaultdict): def __init__(self): for i in xrange(SYSCALL_COUNT): self[i] = ALLOW
Python
0.000072
@@ -223,16 +223,67 @@ _COUNT%0A%0A +if sys.version_info.major == 2:%0A range = xrange%0A %0Aclass N @@ -349,17 +349,16 @@ or i in -x range(SY
ca050969d1267d13986a0494a86f7fd50616937e
Remove old code.
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() """set_custom_entity_kinds(zip(map(lambda x: x.lower(), CUSTOM_ENTITIES), CUSTOM_ENTITIES))""" pipeline = PreProcessPipeline(pipeline_steps, docs) pipeline.process_everything()
Python
0.000045
@@ -621,139 +621,8 @@ r()%0A - %22%22%22set_custom_entity_kinds(zip(map(lambda x: x.lower(), CUSTOM_ENTITIES),%0A CUSTOM_ENTITIES))%22%22%22%0A
8de499c725ac2a3028f5390f1c8d1b88115c6522
Add countdown
src/waldur_rancher/executors.py
src/waldur_rancher/executors.py
from celery import chain from waldur_core.core import executors as core_executors from waldur_core.core import tasks as core_tasks from waldur_core.core import utils as core_utils from waldur_core.core.models import StateMixin from . import models, tasks class ClusterCreateExecutor(core_executors.CreateExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance, user, install_longhorn): _tasks = [ core_tasks.BackendMethodTask().si( serialized_instance, 'create_cluster', state_transition='begin_creating' ) ] _tasks += cls.create_nodes(instance.node_set.all(), user) _tasks += [ core_tasks.PollRuntimeStateTask().si( serialized_instance, backend_pull_method='check_cluster_nodes', success_state=models.Cluster.RuntimeStates.ACTIVE, erred_state='error', ) ] _tasks += [ # NB: countdown is needed for synchronization: wait until cluster will get ready for usage core_tasks.BackendMethodTask() .si(serialized_instance, 'pull_cluster',) .set(countdown=120) ] if install_longhorn: _tasks += [ core_tasks.BackendMethodTask().si( serialized_instance, 'install_longhorn_to_cluster' ), tasks.PollLonghornApplicationTask().si(serialized_instance), core_tasks.BackendMethodTask().si( serialized_instance, 'pull_cluster_workloads', ), ] return chain(*_tasks) @classmethod def create_nodes(cls, nodes, user): _tasks = [] # schedule first controlplane nodes so that Rancher would be able to register other nodes # TODO: need to assure that also etcd is registered - probably parallel Node creation can be a solution # TODO: need to validate once controlled deployment is working for node in nodes.order_by('-controlplane_role'): _tasks.append(NodeCreateExecutor.as_signature(node, user_id=user.id)) return _tasks class ClusterDeleteExecutor(core_executors.DeleteExecutor): @classmethod def get_success_signature(cls, instance, serialized_instance, **kwargs): # deletion of Cluster object is performed in handlers.py return None @classmethod def get_task_signature(cls, instance, serialized_instance, user): if instance.node_set.count(): instance.begin_deleting() instance.save() _tasks = [] for node in instance.node_set.all(): _tasks.append(NodeDeleteExecutor.as_signature(node, user_id=user.id)) return chain(*_tasks) else: return core_tasks.BackendMethodTask().si( serialized_instance, 'delete_cluster', state_transition='begin_deleting' ) class ClusterUpdateExecutor(core_executors.UpdateExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance, **kwargs): if instance.backend_id and {'name'} & set(kwargs['updated_fields']): return core_tasks.BackendMethodTask().si( serialized_instance, 'update_cluster', state_transition='begin_updating' ) else: return core_tasks.StateTransitionTask().si( serialized_instance, state_transition='begin_updating' ) class NodeCreateExecutor(core_executors.CreateExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance, user_id): return chain( tasks.CreateNodeTask().si(serialized_instance, user_id=user_id,), tasks.PollRuntimeStateNodeTask().si(serialized_instance), ) class NodeDeleteExecutor(core_executors.BaseExecutor): @classmethod def get_failure_signature(cls, instance, serialized_instance, **kwargs): return core_tasks.ErrorStateTransitionTask().s(serialized_instance) @classmethod def get_task_signature(cls, instance, serialized_instance, user_id): return tasks.DeleteNodeTask().si(serialized_instance, user_id=user_id,) @classmethod def pre_apply(cls, instance, **kwargs): """ We can start deleting a node even if it does not have the status OK or Erred, because a virtual machine could already be created. """ instance.state = StateMixin.States.DELETION_SCHEDULED instance.save(update_fields=['state']) class ClusterPullExecutor(core_executors.ActionExecutor): @classmethod def get_task_signature(cls, cluster, serialized_cluster, **kwargs): return chain( core_tasks.BackendMethodTask().si( serialized_cluster, 'pull_cluster', state_transition='begin_updating' ), ) class NodePullExecutor(core_executors.ActionExecutor): @classmethod def get_task_signature(cls, node, serialized_node, **kwargs): return core_tasks.BackendMethodTask().si( serialized_node, 'pull_node', state_transition='begin_updating' ) class HPACreateExecutor(core_executors.CreateExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance): return core_tasks.BackendMethodTask().si( serialized_instance, 'create_hpa', state_transition='begin_creating' ) class HPAUpdateExecutor(core_executors.UpdateExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance, **kwargs): return core_tasks.BackendMethodTask().si( serialized_instance, 'update_hpa', state_transition='begin_updating' ) class HPADeleteExecutor(core_executors.DeleteExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance, **kwargs): if instance.backend_id: return core_tasks.BackendMethodTask().si( serialized_instance, 'delete_hpa', state_transition='begin_deleting' ) else: return core_tasks.StateTransitionTask().si( serialized_instance, state_transition='begin_deleting' ) class ApplicationCreateExecutor(core_executors.CreateExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance): return chain( core_tasks.BackendMethodTask().si( serialized_instance, 'create_app', state_transition='begin_creating' ), core_tasks.PollRuntimeStateTask().si( serialized_instance, backend_pull_method='check_application_state', success_state='active', erred_state='error', ), core_tasks.BackendMethodTask().si( core_utils.serialize_instance(instance.rancher_project), 'pull_project_workloads', ), ) class ApplicationDeleteExecutor(core_executors.DeleteExecutor): @classmethod def get_task_signature(cls, instance, serialized_instance, **kwargs): if instance.backend_id: return core_tasks.BackendMethodTask().si( serialized_instance, 'delete_app', state_transition='begin_deleting' ) else: return core_tasks.StateTransitionTask().si( serialized_instance, state_transition='begin_deleting' )
Python
0.000208
@@ -719,32 +719,45 @@ ntimeStateTask() +%0A .si(%0A @@ -951,32 +951,64 @@ ,%0A )%0A + .set(countdown=120)%0A %5D%0A
9bc1c77250d338ca93ff33d2832c2b3117b3550e
Use the raw domain for Netflix, because there's only one now
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_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']
Python
0.000001
@@ -1090,12 +1090,8 @@ main -s%5B0%5D , u'
87cc7ccb8626d9e236954cce0667167f5f9742be
fix prometheus test
restclients_core/tests/test_prometheus.py
restclients_core/tests/test_prometheus.py
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)
Python
0.000018
@@ -45,23 +45,20 @@ on.test_ -backend +live import @@ -91,16 +91,28 @@ TestCase +, skipUnless %0Afrom pr @@ -160,17 +160,104 @@ EGISTRY%0A -%0A +import os%0A%0A%0A@skipUnless(%22RUN_LIVE_TESTS%22 in os.environ, %22RUN_LIVE_TESTS=1 to run tests%22) %0Aclass T @@ -293,17 +293,16 @@ tCase):%0A -%0A def @@ -336,16 +336,61 @@ (self):%0A + response = TDAO().getURL('/ok', %7B%7D)%0A%0A
2b1cb336168e8ac72a768b03852ebe5a0c02a8a9
Remove unused import
corehq/apps/users/tests/fixture_status.py
corehq/apps/users/tests/fixture_status.py
from datetime import datetime from django.test import TestCase from mock import MagicMock, patch from django.contrib.auth.models import User from corehq.apps.users.models import CouchUser, CommCareUser from corehq.apps.domain.models import Domain from corehq.apps.fixtures.models import UserFixtureStatus, UserFixtureType class TestFixtureStatus(TestCase): def setUp(self): all_users = CouchUser.all() for user in all_users: user.delete() User.objects.all().delete() self.username = "joe@my-domain.commcarehq.org" password = "password" self.domain = Domain(name='my-domain') self.domain.save() self.couch_user = CommCareUser.create(self.domain.name, self.username, password) self.couch_user.save() def tearDown(self): UserFixtureStatus.objects.all().delete() def test_get_statuses(self): no_status = {UserFixtureType.CHOICES[0][0]: UserFixtureStatus.DEFAULT_LAST_MODIFIED} self.assertEqual(self.couch_user.get_fixture_statuses(), no_status) now = datetime.utcnow() UserFixtureStatus( user_id=self.couch_user._id, fixture_type=UserFixtureType.CHOICES[0][0], last_modified=now, ).save() expected_status = {UserFixtureType.CHOICES[0][0]: now} self.assertEqual(self.couch_user.get_fixture_statuses(), expected_status) def test_get_status(self): now = datetime.utcnow() couch_user = CommCareUser.get_by_username(self.username) UserFixtureStatus( user_id=self.couch_user._id, fixture_type=UserFixtureType.CHOICES[0][0], last_modified=now, ).save() self.assertEqual(self.couch_user.fixture_status("fake_status"), UserFixtureStatus.DEFAULT_LAST_MODIFIED) self.assertEqual(couch_user.fixture_status(UserFixtureType.CHOICES[0][0]), now) def test_update_status_set_location(self): fake_location = MagicMock() fake_location._id = "the_depths_of_khazad_dum" self.assertEqual(UserFixtureStatus.objects.all().count(), 0) self.couch_user.set_location(fake_location) self.assertEqual(UserFixtureStatus.objects.all().count(), 1) user_fixture_status = UserFixtureStatus.objects.first() self.assertEqual(user_fixture_status.user_id, self.couch_user._id) self.assertEqual(user_fixture_status.fixture_type, UserFixtureType.LOCATION) def test_update_status_unset_location(self): fake_location = MagicMock() fake_location._id = "the_mines_of_moria" self.couch_user.set_location(fake_location) previously_updated_time = UserFixtureStatus.objects.get(user_id=self.couch_user._id).last_modified self.couch_user.unset_location() new_updated_time = UserFixtureStatus.objects.get(user_id=self.couch_user._id).last_modified self.assertTrue(new_updated_time > previously_updated_time) def test_update_status_reset_location(self): fake_location = MagicMock() fake_location._id = "misty_mountains" self.couch_user.set_location(fake_location) previously_updated_time = UserFixtureStatus.objects.get(user_id=self.couch_user._id).last_modified fake_location._id = "lonely_mountain" self.couch_user.set_location(fake_location) new_updated_time = UserFixtureStatus.objects.get(user_id=self.couch_user._id).last_modified self.assertTrue(new_updated_time > previously_updated_time)
Python
0.000001
@@ -59,42 +59,8 @@ Case -%0Afrom mock import MagicMock, patch %0A%0Afr
550ef5aeb24bfc799a23091afc60ebbba7808793
fix #1353 (get and only get the specified part)
src/you_get/extractors/acfun.py
src/you_get/extractors/acfun.py
#!/usr/bin/env python __all__ = ['acfun_download'] from ..common import * from .le import letvcloud_download_by_vu from .qq import qq_download_by_vid from .sina import sina_download_by_vid from .tudou import tudou_download_by_iid from .youku import youku_download_by_vid, youku_open_download_by_vid import json, re def get_srt_json(id): url = 'http://danmu.aixifan.com/V2/%s' % id return get_html(url) def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False, **kwargs): """str, str, str, bool, bool ->None Download Acfun video by vid. Call Acfun API, decide which site to use, and pass the job to its extractor. """ #first call the main parasing API info = json.loads(get_html('http://www.acfun.tv/video/getVideo.aspx?id=' + vid)) sourceType = info['sourceType'] #decide sourceId to know which extractor to use if 'sourceId' in info: sourceId = info['sourceId'] # danmakuId = info['danmakuId'] #call extractor decided by sourceId if sourceType == 'sina': sina_download_by_vid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) elif sourceType == 'youku': youku_download_by_vid(sourceId, title=title, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs) elif sourceType == 'tudou': tudou_download_by_iid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) elif sourceType == 'qq': qq_download_by_vid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only) elif sourceType == 'letv': letvcloud_download_by_vu(sourceId, '2d8c027396', title, output_dir=output_dir, merge=merge, info_only=info_only) elif sourceType == 'zhuzhan': #As in Jul.28.2016, Acfun is using embsig to anti hotlink so we need to pass this embsig = info['encode'] a = 'http://api.aixifan.com/plays/%s' % vid s = json.loads(get_content(a, headers={'deviceType': '2'})) if s['data']['source'] == "zhuzhan-youku": sourceId = s['data']['sourceId'] youku_open_download_by_vid(client_id='908a519d032263f8', vid=sourceId, title=title, output_dir=output_dir,merge=merge, info_only=info_only, embsig = embsig, **kwargs) else: raise NotImplementedError(sourceType) if not info_only and not dry_run: if not kwargs['caption']: print('Skipping danmaku.') return try: title = get_filename(title) print('Downloading %s ...\n' % (title + '.cmt.json')) cmt = get_srt_json(vid) with open(os.path.join(output_dir, title + '.cmt.json'), 'w', encoding='utf-8') as x: x.write(cmt) except: pass def acfun_download(url, output_dir='.', merge=True, info_only=False, **kwargs): assert re.match(r'http://[^\.]+.acfun.[^\.]+/\D/\D\D(\d+)', url) html = get_html(url) title = r1(r'<h1 id="txt-title-view">([^<>]+)<', html) title = unescape_html(title) title = escape_file_path(title) assert title videos = re.findall("data-vid=\"(\d+)\".*href=\"[^\"]+\".*title=\"([^\"]+)\"", html) for video in videos: p_vid = video[0] p_title = title + " - " + video[1] if video[1] != '删除标签' else title acfun_download_by_vid(p_vid, p_title, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs) site_info = "AcFun.tv" download = acfun_download download_playlist = playlist_not_supported('acfun')
Python
0
@@ -543,20 +543,16 @@ -%3ENone%0A - %0A Dow @@ -577,20 +577,16 @@ by vid.%0A - %0A Cal @@ -3108,24 +3108,22 @@ ideo -s = re. -findall(%22 +search(' data @@ -3131,55 +3131,46 @@ vid= -%5C %22(%5Cd+) -%5C%22.*href=%5C%22%5B%5E%5C%22%5D+%5C%22.*title=%5C%22(%5B%5E%5C%22%5D+)%5C%22%22 +%22%5Cs*data-scode=%22%22.*%3E(%5B%5E%3C%5D+)%3C/a%3E' , ht @@ -3181,64 +3181,33 @@ -for video in videos:%0A p_vid = video%5B0%5D%0A p_ +vid = video.group(1)%0A titl @@ -3222,21 +3222,21 @@ e + -%22 - %22 +' - ' + video %5B1%5D @@ -3235,53 +3235,22 @@ ideo -%5B1%5D if video%5B1%5D != '%E5%88%A0%E9%99%A4%E6%A0%87%E7%AD%BE' else title%0A +.group(2)%0A - acfu @@ -3271,28 +3271,20 @@ vid( -p_ vid, -p_ title,%0A - @@ -3354,20 +3354,16 @@ - merge=me @@ -3367,20 +3367,16 @@ =merge,%0A - @@ -3414,20 +3414,16 @@ o_only,%0A -
c8a91d7891f4cba4e72ee192fc5599547d276d17
bring RTD cache down from 1 day to 30 minutes
crate_project/apps/packages/evaluators.py
crate_project/apps/packages/evaluators.py
import slumber from django.core.cache import cache from django.utils.safestring import mark_safe from evaluator import suite from packages.models import ReadTheDocsPackageSlug from packages.utils import verlib class PEP386Compatability(object): title = "PEP386 Compatibility" message = mark_safe("PEP386 defines a specific allowed syntax for Python package versions." "<br /><br />" "Previously it was impossible to accurately determine across any Python package what " "order the versions should go in, but with PEP386 we can now intelligently sort by version..." "<br /><br />" "But only if the version numbers are compatible!") def evaluate(self, release): normalized = verlib.suggest_normalized_version(release.version) if release.version == normalized: # Release Is Already Normalized return { "level": "success", "message": mark_safe('Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.'), } elif normalized is not None: # Release Isn't Normalized, But We Can Figure It Out return { "level": None, "message": mark_safe('Almost Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.'), } else: # We Can't Normalize the Release Version return { "level": "error", "message": mark_safe('Incompatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.'), } class PackageHosting(object): title = "Package Hosting" message = mark_safe("Did you know that packages listed on PyPI aren't required to host there?" "<br /><br />" "When your package manager tries to install a package from PyPI it looks in number " "of locations, one such location is an author specified url of where the package can " "be downloaded from." "<br /><br />" "Packages hosted by the author means that installing this package depends on the " "authors server staying up, adding another link in the chain that can cause your " "installation to fail") def evaluate(self, release): if release.files.all().exists(): return { "level": "success", "message": "Package is hosted on PyPI", } elif release.download_uri: return { "level": "error", "message": "Package isn't hosted on PyPI", } else: return { "level": "error", "message": "No Package Hosting", } class RTDocs(object): title = "Documentation hosted on Read The Docs" message = mark_safe("Documentation can be one of the most important parts of any library. " "Even more important than just having documentation, is making sure that people are " "able to find it easily." "<br /><br />" "Read The Docs is an open source platform for hosting documentation generated by Sphinx." "<br /><br />" "Hosting your documentation on Read The Docs is easy (even if it's just an additional copy), and " "it allows people who want to use your package the ability to locate your documentation in " "what is quickly becoming a one stop shop for online open source documentation." "<br /><br />" "<small>If this says you aren't hosted on Read The Docs and you are please contact " "<a href='mailto:support@crate.io'>support@crate.io</a></small>") def evaluate(self, release): qs = ReadTheDocsPackageSlug.objects.filter(slug=release.package.name) slug = qs[0].slug if qs else release.package.name key = "evaluate:rtd:%s" % slug if cache.get(key, version=3) is not None: hosted_on_rtd, url = cache.get(key, version=3) else: api = slumber.API(base_url="http://readthedocs.org/api/v1/") results = api.project.get(slug__iexact=slug) if results["objects"]: hosted_on_rtd = True url = results["objects"][0]["subdomain"] else: hosted_on_rtd = False url = None cache.set(key, (hosted_on_rtd, url), 60 * 60 * 24, version=3) # Cache This for a Day if hosted_on_rtd: return { "level": "success", "message": mark_safe('Docs Available on <a href="%s">Read The Docs</a>' % url), } else: return { "level": "unknown", "message": mark_safe('Docs Unavailable on <a href="http://readthedocs.org/">Read The Docs</a>') } suite.register(PEP386Compatability) suite.register(PackageHosting) suite.register(RTDocs)
Python
0
@@ -4118,17 +4118,17 @@ version= -3 +4 ) is not @@ -4190,17 +4190,17 @@ version= -3 +4 )%0A @@ -4609,15 +4609,10 @@ 0 * -60 * 24 +30 , ve @@ -4617,17 +4617,17 @@ version= -3 +4 ) # Cac @@ -4642,13 +4642,18 @@ for -a Day +30 Minutes %0A%0A
dcd7b8e990ff0f3d29807be78d7d3967c6ad46c4
Add trailing newline
gen_tmpfiles.py
gen_tmpfiles.py
#!/usr/bin/python '''Scan an existing directory tree and record installed directories. During build a number of directories under /var are created in the stateful partition. We want to make sure that those are always there so create a record of them using systemd's tempfiles config format so they are recreated during boot if they go missing for any reason. ''' import optparse import os import stat import sys import pwd import grp def main(): keep = set() parser = optparse.OptionParser(description=__doc__) parser.add_option('--root', help='Remove root prefix from output') parser.add_option('--output', help='Write output to the given file') opts, args = parser.parse_args() if opts.root: opts.root = os.path.abspath(opts.root) for path in args: path = os.path.abspath(path) if opts.root: assert path.startswith(opts.root) for dirpath, dirnames, filenames in os.walk(path): if any(f.startswith('.keep') for f in filenames): keep.add(dirpath) # Add all parent directories too for path in frozenset(keep): split = [] for pathbit in path.split('/'): split.append(pathbit) joined = '/'.join(split) if not joined: continue if opts.root and not joined.startswith(opts.root): continue if opts.root == joined: continue keep.add(joined) config = [] for path in sorted(keep): if opts.root: assert path.startswith(opts.root) stripped = path[len(opts.root):] assert len(stripped) > 1 else: stripped = path info = os.stat(path) assert stat.S_ISDIR(info.st_mode) mode = stat.S_IMODE(info.st_mode) try: owner = pwd.getpwuid(info.st_uid).pw_name except KeyError: owner = str(info.st_uid) try: group = grp.getgrgid(info.st_gid).gr_name except KeyError: group = str(info.st_gid) config.append('d %-22s %04o %-10s %-10s - -' % (stripped, mode, owner, group)) if opts.output: fd = open(opts.output, 'w') fd.write('\n'.join(config)) fd.close() else: print '\n'.join(config) if __name__ == '__main__': main()
Python
0.000001
@@ -2284,16 +2284,21 @@ (config) ++'%5Cn' )%0A
fe265f187f37b13721e5d59919e618be56aa1eb4
Remove debug code
generate-tex.py
generate-tex.py
#!/usr/bin/env python3 import yaml import glob from jinja2 import Template from os.path import basename, splitext from subprocess import check_output from collections import defaultdict def convert_markdown_to_tex(markdown): return check_output( ["pandoc", "--from=markdown", "--to=latex"], universal_newlines=True, input=markdown ).replace('??', '\+') def convert_map_values_to_tex(map): if map is not None: map.update({k: convert_markdown_to_tex(v) for k, v in map.items()}) return map def convert_list_entries_to_tex(list): if list is not None: return [convert_markdown_to_tex(e) for e in list] def convert_map_list_to_tex(list_of_maps): if list_of_maps is not None: return [convert_map_values_to_tex(e) for e in list_of_maps] ##### query cards with open('templates/query-card-template.tex', 'r') as f: query_card_template = Template(f.read()) with open('templates/short-description-template.tex', 'r') as f: short_description_template = Template(f.read()) with open('templates/standalone-query-card.tex', 'r') as f: standalone_query_card_template = Template(f.read()) with open('templates/parameters', 'r') as f: parameters_template = Template(f.read()) all_choke_points = set() all_queries = set() query_choke_point = defaultdict(list) # queries -> cps choke_point_references = defaultdict(list) # cps -> queries for filename in glob.glob("query-specifications/*.yaml"): print("Processing query specification: %s" % filename) query_id = splitext(basename(filename))[0] with open(filename, 'r') as f: doc = yaml.load(f, Loader=yaml.FullLoader) number = doc['number'] number_string = "%02d" % (number) workload = doc['workload'] title = doc['title'] description_markdown = doc['description'] operation = doc['operation'] query_tuple = (query_id, workload, operation, number) all_queries.add(query_tuple) choke_points = list(map(lambda e: str(e), doc.get('choke_points', []))) for choke_point in choke_points: choke_point_references[choke_point].append(query_tuple) all_choke_points.add(choke_point) query_choke_point[query_id] = choke_points # currently, there are no off-the-shelf solutions for Markdown to TeX conversion in Python 3, # so we use Pandoc -- it's hands down the best Markdown to Tex converter you can get anyways description_tex = convert_markdown_to_tex(description_markdown) # optional arguments parameters = doc.get('parameters') results = doc.get('result') sort = doc.get('sort') limit = doc.get('limit') relevance_markdown = doc.get('relevance') if relevance_markdown is None: relevance_tex = None else: relevance_tex = convert_markdown_to_tex(relevance_markdown) parameter_file_text = parameters_template.render( parameters = parameters, ) with open("parameters/%s.parameters" % query_id, 'w') as parameter_file: parameter_file.write(parameter_file_text) for p in parameters: print(p.get('description')) query_card_text = query_card_template.render( number = number, workload = workload, operation = operation, number_string = number_string, query_id = query_id, title = title, description = description_tex, parameters = convert_map_list_to_tex(parameters), result = convert_map_list_to_tex(results), sort = convert_map_list_to_tex(sort), limit = limit, choke_points = choke_points, relevance = relevance_tex, ) with open("query-cards/%s.tex" % query_id, 'w') as query_card_file: query_card_file.write(query_card_text) ##### short descriptions short_description_text = short_description_template.render( number = number, title = title, description = description_tex, ) short_description_text = short_description_text.replace("\n\n", "\n") with open("short-descriptions/%s.tex" % query_id, 'w') as short_description_file: short_description_file.write(short_description_text) ##### standalone query cards standalone_query_card_text = standalone_query_card_template.render( query_id=query_id ) with open("standalone-query-cards/%s.tex" % query_id, 'w') as standalone_query_card_file: standalone_query_card_file.write(standalone_query_card_text) ##### choke points with open('templates/choke-point-template.tex', 'r') as f: choke_point_template = Template(f.read()) for choke_point in choke_point_references: choke_point_filename = choke_point.replace('.', '-') queries = choke_point_references[choke_point] queries_sorted = sorted(queries, key=lambda tup: tup[0]) choke_point_text = choke_point_template.render( queries = queries_sorted, ) with open("choke-points/cp-%s.tex" % choke_point_filename, 'w') as choke_point_file: choke_point_file.write(choke_point_text) ##### table for choke points and queries all_queries_sorted = sorted(all_queries, key=lambda tup: tup[0]) all_choke_points_sorted = sorted(all_choke_points) with open('templates/choke-points-queries.tex', 'r') as f: choke_points_queries_template = Template(f.read()) choke_points_queries_text = choke_points_queries_template.render( choke_point_references = choke_point_references, query_choke_point = query_choke_point, queries = all_queries_sorted, choke_points = all_choke_points_sorted, ) with open("choke-points/choke-points-queries.tex", 'w') as choke_points_queries_template: choke_points_queries_template.write(choke_points_queries_text) with open('templates/choke-points-queries.csv', 'r') as f: choke_points_queries_template = Template(f.read()) choke_points_queries_text = choke_points_queries_template.render( choke_point_references=choke_point_references, query_choke_point=query_choke_point, queries=all_queries_sorted, choke_points=all_choke_points_sorted, ) with open("choke-points/choke-points-queries.csv", 'w') as choke_points_queries_template: choke_points_queries_template.write(choke_points_queries_text)
Python
0.000299
@@ -3077,70 +3077,8 @@ t)%0A%0A - for p in parameters:%0A print(p.get('description'))%0A%0A
738cc42fc0ee8e06a53842c27dd4a392403bea49
remove asgi warning
fiduswriter/manage.py
fiduswriter/manage.py
#!/usr/bin/env python3 import os import sys from importlib import import_module if "COVERAGE_PROCESS_START" in os.environ: import coverage coverage.process_startup() SRC_PATH = os.path.dirname(os.path.realpath(__file__)) os.environ.setdefault("SRC_PATH", SRC_PATH) def inner(default_project_path): sys.path.append(SRC_PATH) sys_argv = sys.argv PROJECT_PATH = False while "--pythonpath" in sys_argv: index = sys_argv.index("--pythonpath") PROJECT_PATH = os.path.join(os.getcwd(), sys_argv[index + 1]) sys.path.insert(0, PROJECT_PATH) # We prevent the pythonpath to be handled later on by removing it from # sys_argv sys_argv = sys_argv[:index] + sys_argv[index + 2 :] if not PROJECT_PATH: PROJECT_PATH = default_project_path sys.path.insert(0, PROJECT_PATH) os.environ.setdefault("PROJECT_PATH", PROJECT_PATH) if "--settings" in sys_argv: index = sys_argv.index("--settings") SETTINGS_MODULE = sys_argv[index + 1] else: SETTINGS_MODULE = "configuration" mod = False # There are three levels of settings, each overiding the previous one: # global_settings.py, settings.py and configuration.py from django.conf import global_settings as CONFIGURATION from base import settings as SETTINGS SETTINGS_PATHS = [SETTINGS.__file__] for setting in dir(SETTINGS): setting_value = getattr(SETTINGS, setting) setattr(CONFIGURATION, setting, setting_value) try: mod = import_module(SETTINGS_MODULE) except ModuleNotFoundError: SETTINGS_MODULE = None if mod: SETTINGS_PATHS.append(mod.__file__) for setting in dir(mod): if setting.isupper(): setattr(CONFIGURATION, setting, getattr(mod, setting)) INSTALLED_APPS = CONFIGURATION.BASE_INSTALLED_APPS + list( CONFIGURATION.INSTALLED_APPS ) for app in CONFIGURATION.REMOVED_APPS: INSTALLED_APPS.remove(app) from django.conf import settings settings.configure( CONFIGURATION, SETTINGS_MODULE=SETTINGS_MODULE, SETTINGS_PATHS=SETTINGS_PATHS, INSTALLED_APPS=INSTALLED_APPS, MIDDLEWARE=( CONFIGURATION.BASE_MIDDLEWARE + list(CONFIGURATION.MIDDLEWARE) ), ) os.environ["TZ"] = settings.TIME_ZONE if sys_argv[1] in ["version", "--version"]: from base import get_version sys.stdout.write(get_version() + "\n") return from django.core.management import execute_from_command_line execute_from_command_line(sys_argv) def entry(): os.environ.setdefault("NO_COMPILEMESSAGES", "true") inner(os.getcwd()) if __name__ == "__main__": inner(SRC_PATH)
Python
0.000006
@@ -75,16 +75,66 @@ odule%0A%0A%0A +os.environ%5B%22DJANGO_ALLOW_ASYNC_UNSAFE%22%5D = %22true%22%0A%0A if %22COVE
be3189249da8906d0e09d810a9c132e8af9a344c
update docs conf description
docs/source/conf.py
docs/source/conf.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # ChoiceModels documentation build configuration file, created by # sphinx-quickstart on Thu Nov 30 14:23:50 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # import os import sys # go up two levels from /docs/source to the package root sys.path.insert(0, os.path.abspath('../..')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ['sphinx.ext.autodoc', #'sphinx.ext.napoleon', 'sphinx.ext.viewcode', 'sphinx.ext.githubpages'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = 'ChoiceModels' copyright = '2018, Urban Data Science Toolkit' author = 'Urban Data Science Toolkit' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. #version = '0.1' # The full version, including alpha/beta/rc tags. #release = '0.1' import choicemodels version = release = choicemodels.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # This is required for the alabaster theme # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars html_sidebars = { '**': [ 'about.html', 'navigation.html', 'relations.html', # needs 'show_related': True theme option to display 'searchbox.html', 'donate.html', ] } # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = 'ChoiceModelsdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'ChoiceModels.tex', 'ChoiceModels Documentation', 'Urban Data Science Toolkit', 'manual'), ] # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'choicemodels', 'ChoiceModels Documentation', [author], 1) ] # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'ChoiceModels', 'ChoiceModels Documentation', author, 'ChoiceModels', 'Python package for discrete choice model estimation and simulation.', 'Miscellaneous'), ]
Python
0
@@ -5450,23 +5450,8 @@ tion - and simulation .',%0A
a439d226a8616f81c43915516c30a4ee3a59904b
Bring back incomplete sentence
docs/source/conf.py
docs/source/conf.py
# -*- coding: utf-8 -*- # # Paver documentation build configuration file, created by # sphinx-quickstart on Fri Apr 11 08:20:18 2008. # # This file is execfile()d with the current directory set to its containing dir. # # The contents of this file are pickled, so don't put values in the namespace # that aren't pickleable (module imports are okay, they're removed automatically). # # All configuration values have a default value; values that are commented out # serve to show the default value. import sys from sphinx.ext import autodoc # If your extensions are in another directory, add it here. #sys.path.append() # Add our autodoc extension class TaskDocumenter(autodoc.FunctionDocumenter): objtype = "task" directivetype = "function" @classmethod def can_document_member(cls, member, membername, isattr, parent): from paver.tasks import Task return isinstance(member, Task) def import_object(self): super(TaskDocumenter, self).import_object() obj = self.object self.object = obj.func return True autodoc.add_documenter(TaskDocumenter) # General configuration # --------------------- # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General substitutions. project = 'Paver' copyright = '2008, SitePen, Inc.' # The default replacements for |version| and |release|, also used in various # other places throughout the built documents. # # The short X.Y version. version = '1.2' # The full version, including alpha/beta/rc tags. release = '1.2.3' # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. today_fmt = '%B %d, %Y' # List of documents that shouldn't be included in the build. #unused_docs = [] # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # Options for HTML output # ----------------------- # The style sheet to use for HTML and HTML Help pages. A file of that name # must exist either in Sphinx' static/ path, or in one of the custom paths # given in html_static_path. html_style = 'default.css' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Content template for the index page. #html_index = '' # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_use_modindex = True # If true, the reST sources are included in the HTML build as _sources/<name>. #html_copy_source = True # Output file base name for HTML help builder. htmlhelp_basename = 'Paverdoc' # Options for LaTeX output # ------------------------ # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, document class [howto/manual]). latex_documents = [('index', 'paver.tex', 'Paver Manual', 'Kevin Dangoor', 'manual', False)] # Additional stuff for the LaTeX preamble. #latex_preamble = '' # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_use_modindex = True
Python
0.00007
@@ -1889,16 +1889,93 @@ '1.2.3'%0A +# There are two options for replacing %7Ctoday%7C: either, you set today to some%0A # non-fa
2fe38ad865afc1afc0b06edebf55929b99a64977
add more metadata to docs and package
docs/source/conf.py
docs/source/conf.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # PyBBN documentation build configuration file, created by # sphinx-quickstart on Tue Jan 17 17:44:12 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # import os import sys sys.path.insert(0, os.path.abspath('../../')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.mathjax', 'sphinx.ext.githubpages'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = 'PyBBN' copyright = '2017, Jee Vang' author = 'Jee Vang' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '1.0' # The full version, including alpha/beta/rc tags. release = '1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = 'PyBBNdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'PyBBN.tex', 'PyBBN Documentation', 'Jee Vang', 'manual'), ] # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'pybbn', 'PyBBN Documentation', [author], 1) ] # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'PyBBN', 'PyBBN Documentation', author, 'PyBBN', 'One line description of project.', 'Miscellaneous'), ]
Python
0
@@ -4741,39 +4741,26 @@ ', ' -One line description of project +Bayesian inference .',%0A
a363edd761e2c99bae6d4492d0ca44a404e5d904
Avoid py36 error when printing unicode chars in a stream
neutronclient/tests/unit/test_exceptions.py
neutronclient/tests/unit/test_exceptions.py
# All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import fixtures from oslo_utils import encodeutils import six import testtools from neutronclient._i18n import _ from neutronclient.common import exceptions class TestExceptions(testtools.TestCase): def test_exception_print_with_unicode(self): class TestException(exceptions.NeutronException): message = _('Exception with %(reason)s') multibyte_unicode_string = u'\uff21\uff22\uff23' e = TestException(reason=multibyte_unicode_string) fixture = fixtures.StringStream('stdout') self.useFixture(fixture) with fixtures.MonkeyPatch('sys.stdout', fixture.stream): print(e) self.assertEqual('Exception with %s' % multibyte_unicode_string, fixture.getDetails().get('stdout').as_text()) def test_exception_message_with_encoded_unicode(self): class TestException(exceptions.NeutronException): message = _('Exception with %(reason)s') multibyte_string = u'\uff21\uff22\uff23' multibyte_binary = encodeutils.safe_encode(multibyte_string) e = TestException(reason=multibyte_binary) self.assertEqual('Exception with %s' % multibyte_string, six.text_type(e))
Python
0.999789
@@ -598,24 +598,32 @@ %0Aimport -fixtures +sys%0A%0Aimport mock %0Afrom os @@ -1092,146 +1092,60 @@ -fixture = fixtures.StringStream('stdout')%0A self.useFixture(fixture)%0A with fixtures.MonkeyPatch('sys.stdout', fixture.stream) +with mock.patch.object(sys, 'stdout') as mock_stdout :%0A @@ -1163,24 +1163,25 @@ rint(e)%0A +%0A self.ass @@ -1172,33 +1172,26 @@ -self.assertEqual( +exc_str = 'Excepti @@ -1224,39 +1224,33 @@ icode_string -,%0A +%0A @@ -1241,64 +1241,63 @@ - fixture.getDetails().get('stdout').as_text() +mock_stdout.assert_has_calls(%5Bmock.call.write(exc_str)%5D )%0A%0A
62404979e69ccd129f8382e8a2fce5329c577a78
fix version
experimentator/__version__.py
experimentator/__version__.py
__version__ = '0.2.0.dev5'
Python
0.000001
@@ -13,15 +13,14 @@ = '0.2.0 -. dev5'%0A
b0e3b4fcd3d85989ebe72fa805cfab4576867835
Fix how node-caffe detects if GPU is supported on a machine
node-caffe/binding.gyp
node-caffe/binding.gyp
{ 'targets': [ { 'target_name': 'caffe', 'sources': [ 'src/caffe.cpp' ], 'include_dirs': [ '<!(node -e "require(\'nan\')")', '<!(echo $CAFFE_ROOT/include)', '/usr/local/cuda/include/', '<!(pwd)/caffe/src/', '<!(pwd)/caffe/include/', '<!(pwd)/caffe/build/include/', ], 'libraries': [ '-L<!(echo "$CAFFE_ROOT/lib")', '-L<!(pwd)/caffe/build/lib', '<!(if [ -d /usr/local/cuda/lib ]; then echo "-L/usr/local/cuda/lib"; fi)', '<!(if [ -d /usr/local/cuda/lib64 ]; then echo "-L/usr/local/cuda/lib64"; fi)', '<!(if [ -d /usr/local/cuda ]; then echo "-lcudart"; fi)', '-lcaffe', ], 'ldflags': [ '-Wl,-rpath,<!(echo $CAFFE_ROOT/lib)', '-Wl,-rpath,<!(pwd)/caffe/build/lib', '<!(if [ -d /usr/local/cuda/lib ]; then echo "-Wl,-rpath,/usr/local/cuda/lib"; fi)', '<!(if [ -d /usr/local/cuda/lib64 ]; then echo "-Wl,-rpath,/usr/local/cuda/lib64"; fi)', ], 'cflags_cc': [ '-std=c++11', '-fexceptions', '-Wno-ignored-qualifiers', ], 'defines': [ '<!(if [ -d /usr/local/cuda ]; then echo "HAVE_CUDA"; else echo "CPU_ONLY"; fi)', ], 'dependencies': [ ], 'conditions': [ ['OS=="win"', { 'dependencies': [ ] }], ['OS=="mac"', { 'defines': [ '<!(if [ -d /usr/local/cuda ]; then echo "HAVE_CUDA"; else echo "CPU_ONLY"; fi)', ], 'include_dirs': [ '<!(brew --prefix openblas)' + '/include', '<!(brew --prefix boost 2> /dev/null)' + '/include', '<!(brew --prefix gflags)' + '/include', '<!(brew --prefix glog)' + '/include', '<!(brew --prefix protobuf)' + '/include', ], 'libraries': [ '<!(brew --prefix boost 2> /dev/null)' + '/lib/libopencv_core.dylib', '-lboost_system', '-lboost_thread-mt', ], 'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', 'GCC_ENABLE_CPP_RTTI': 'YES', 'MACOSX_DEPLOYMENT_TARGET': '10.11', 'OTHER_LDFLAGS': [ '-Wl,-rpath,<!(echo $CAFFE_ROOT/lib)', '-Wl,-rpath,<!(pwd)/caffe/build/lib', '<!(if [ -d /usr/local/cuda/lib ]; then echo "-Wl,-rpath,/usr/local/cuda/lib"; fi)', '<!(if [ -d /usr/local/cuda/lib64 ]; then echo "-Wl,-rpath,/usr/local/cuda/lib64"; fi)', ], 'OTHER_CFLAGS': [ ] }, 'libraries': [ ], }] ] } ] }
Python
0.000082
@@ -94,24 +94,137 @@ p'%0A %5D,%0A + 'variables': %7B%0A 'has_gpu': '%3C!(if which nvidia-smi; then echo true; else echo false; fi)',%0A %7D,%0A 'inclu @@ -572,32 +572,57 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr/local/c @@ -681,32 +681,57 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr/local/c @@ -794,32 +794,57 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr/local/c @@ -1026,32 +1026,57 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr/local/c @@ -1144,32 +1144,57 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr/local/c @@ -1414,34 +1414,33 @@ %3C!(if %5B --d /usr/local/cuda +%22$has_gpu%22 = true %5D; then @@ -1499,41 +1499,8 @@ %5D,%0A - 'dependencies': %5B%0A %5D,%0A @@ -1661,34 +1661,33 @@ %3C!(if %5B --d /usr/local/cuda +%22$has_gpu%22 = true %5D; then @@ -2568,32 +2568,57 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr/local/c @@ -2700,16 +2700,41 @@ '%3C!(if %5B + %22$has_gpu%22 = true %5D && %5B -d /usr @@ -2825,52 +2825,8 @@ %5D,%0A - 'OTHER_CFLAGS': %5B%0A %5D%0A
3471381b5894536142a9460410e0efe5e8b1b294
make doc regex more lenient
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\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)
Python
0.000692
@@ -145,17 +145,16 @@ exable%0A%0A -%0A _doc_bod @@ -222,43 +222,55 @@ %3Cdiv -%5Cs+ +.*? class=%22 +.*? body -%22 +.*? %3E(.* -? ) +%0A %3Cdiv -%5Cs+ +.*? class=%22 +.*? sphi @@ -282,10 +282,8 @@ ebar -%22%3E %0A'''
9156a6263c3a0e6c0cf83d2fa9e7ed33634f99fd
refactor (output): ensure that Nonetype is output correctly
flattentool/output.py
flattentool/output.py
""" Code to output a parsed flattened JSON schema in various spreadsheet formats. """ import openpyxl from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE import csv import os import sys from warnings import warn from flattentool.exceptions import DataErrorWarning from odf.opendocument import OpenDocumentSpreadsheet import odf.table import odf.text import csv class SpreadsheetOutput(object): # output_name is given a default here, partly to help with tests, # but should have been defined by the time we get here. def __init__(self, parser, main_sheet_name='main', output_name='unflattened', sheet_prefix=''): self.parser = parser self.main_sheet_name = main_sheet_name self.output_name = output_name self.sheet_prefix = sheet_prefix def open(self): pass def write_sheet(self, sheet_name, sheet_header, sheet_lines=None): raise NotImplementedError def write_sheets(self): self.open() self.write_sheet(self.main_sheet_name, self.parser.main_sheet) for sheet_name, sub_sheet in sorted(self.parser.sub_sheets.items()): self.write_sheet(sheet_name, sub_sheet) self.close() def close(self): pass class XLSXOutput(SpreadsheetOutput): def open(self): self.workbook = openpyxl.Workbook() def write_sheet(self, sheet_name, sheet): sheet_header = list(sheet) worksheet = self.workbook.create_sheet() worksheet.title = self.sheet_prefix + sheet_name worksheet.append(sheet_header) for sheet_line in sheet.lines: line = [] for header in sheet_header: value = sheet_line.get(header) if isinstance(value, str): new_value = ILLEGAL_CHARACTERS_RE.sub('', value) if new_value != value: warn("Character(s) in '{}' are not allowed in a spreadsheet cell. Those character(s) will be removed".format(value), DataErrorWarning) value = new_value line.append(value) worksheet.append(line) def close(self): self.workbook.remove(self.workbook.active) self.workbook.save(self.output_name) class CSVOutput(SpreadsheetOutput): def open(self): try: os.makedirs(self.output_name) except OSError: pass def write_sheet(self, sheet_name, sheet): sheet_header = list(sheet) with open(os.path.join(self.output_name, self.sheet_prefix + sheet_name+'.csv'), 'w', encoding='utf-8') as csv_file: dictwriter = csv.DictWriter(csv_file, sheet_header) dictwriter.writeheader() for sheet_line in sheet.lines: dictwriter.writerow(sheet_line) class ODSOutput(SpreadsheetOutput): def open(self): self.workbook = OpenDocumentSpreadsheet() def _make_cell(self, value): """ Util for creating an ods cell """ try: # See if value parses as a float cell = odf.table.TableCell(valuetype="float", value=float(value)) except ValueError: cell = odf.table.TableCell(valuetype="string") p = odf.text.P(text=value) cell.addElement(p) return cell def write_sheet(self, sheet_name, sheet): worksheet = odf.table.Table(name=sheet_name) sheet_header = list(sheet) header_row = odf.table.TableRow() for header in sheet_header: header_row.addElement(self._make_cell(header)) worksheet.addElement(header_row) for sheet_line in sheet.lines: row = odf.table.TableRow() for value in sheet_line.values(): row.addElement(self._make_cell(value)) worksheet.addElement(row) self.workbook.spreadsheet.addElement(worksheet) def close(self): self.workbook.save(self.output_name) FORMATS = { 'xlsx': XLSXOutput, 'csv': CSVOutput, 'ods': ODSOutput } FORMATS_SUFFIX = { 'xlsx': '.xlsx', 'ods': '.ods', 'csv': '' # This is the suffix for the directory }
Python
0.000543
@@ -3015,16 +3015,38 @@ ll %22%22%22%0A%0A + if value:%0A @@ -3042,32 +3042,36 @@ try:%0A + # Se @@ -3103,32 +3103,36 @@ oat%0A + + cell = odf.table @@ -3196,24 +3196,25 @@ + value=float( @@ -3225,24 +3225,28 @@ e))%0A + except Value @@ -3256,32 +3256,36 @@ or:%0A + + cell = odf.table @@ -3314,16 +3314,91 @@ string%22) +%0A else:%0A cell = odf.table.TableCell(valuetype=%22Nonetype%22) %0A%0A @@ -3890,16 +3890,55 @@ for +header in sheet_header:%0A value -in += she @@ -3949,17 +3949,409 @@ ine. +get(header)%0A if isinstance(value, six.text_type):%0A new_value = ILLEGAL_CHARACTERS_RE.sub('', value)%0A if new_value != value:%0A warn(%22Character(s) in '%7B%7D' are not allowed in a spreadsheet cell. Those character(s) will be removed%22.format(value),%0A DataErrorWarning)%0A value = new_ value -s(): %0A @@ -4402,17 +4402,16 @@ value))%0A -%0A
43403cfca2ca217c03f4aaffdddd7a4d03a74520
Change string formatting
getMolecules.py
getMolecules.py
#!/usr/bin/env python # Copyright (c) 2016 Ryan Collins <rcollins@chgr.mgh.harvard.edu> # Distributed under terms of the MIT license. """ Estimate original molecule sizes and coordinates from 10X linked-read WGS barcodes """ import argparse from collections import defaultdict, Counter, namedtuple import pysam def get_gemcode_regions(ibam, dist): """ Estimates molecule coordinates from colinear reads with overlapping 10X barcodes Parameters ---------- ibam : pysam.AlignmentFile Input 10X bam dist : int Partitioning distance (bp) for separating reads with overlapping barcodes into independent fragments Yields ------ region : namedtuple chr, start, end, barcode, readcount """ #Create namedtuples for storing read coordinate and molecule info coords = namedtuple('coords', ['chr', 'pos']) molecule = namedtuple('molecule', ['chr', 'start', 'end', 'barcode', 'readcount']) #Create defaultdict for storing gemcode tuples #Key is gemcodes, value is coords namedtuple gemcodes = defaultdict(list) #Iterate over reads in bamfile for read in ibam: #Save 10X barcode for read as gem gem = read.get_tag('RX') #If barcode has been seen previously and new read is either from different #contig or is colinear but beyond dist, yield old barcode as interval #before adding new read to list if gem in gemcodes and (gemcodes[gem][-1].chr != read.reference_name or read.reference_start - gemcodes[gem][-1].pos > dist): yield molecule(gemcodes[gem][0].chr, min([pos for chr, pos in gemcodes[gem]]), max([pos for chr, pos in gemcodes[gem]]), gem, len(gemcodes[gem])) gemcodes[gem] = [coords(read.reference_name, read.reference_start)] else: #Else just add read to preexisting dictionary gemcodes[gem].append(coords(read.reference_name, read.reference_start)) #Write out all remaining molecules at end of bam for gem in gemcodes: yield molecule(gemcodes[gem][0].chr, min([pos for chr, pos in gemcodes[gem]]), max([pos for chr, pos in gemcodes[gem]]), gem, len(gemcodes[gem])) #Run def main(): #Add arguments parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('ibam', type=pysam.AlignmentFile, help='Input bam') parser.add_argument('outfile', help='Output bed file') parser.add_argument('-d', '--dist', type=int, default=50000, help='Molecule partitioning distance in bp (default: 50000)') args = parser.parse_args() #Open outfile fout = open(args.outfile, 'w') #Get gemcode regions for bed in get_gemcode_regions(args.ibam, args.dist): #Turn molecule object into string bed_str = '%s\t%s\t%s\t%s\t%s' % bed.chr, bed.start, bed.end, bed.barcode, bed.readcount #Write to file fout.write(bed_str + '\n') #Close outfile f.close() if __name__ == '__main__': main()
Python
0.000007
@@ -2950,30 +2950,40 @@ = ' -%25s%5Ct%25s%5Ct%25s%5Ct%25s%5Ct%25s' %25 +%7B0%7D%5Ct%7B1%7D%5Ct%7B2%7D%5Ct%7B3%7D%5Ct%7B4%7D'.format( bed. @@ -3033,16 +3033,17 @@ eadcount +) %0A%0A
98e899d5e76f8bee5c288bffe78ccf943665693c
Fix white space to be 4 spaces
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
Python
0.999999
@@ -378,17 +378,20 @@ as fd:%0A -%09 + c = pycu @@ -400,17 +400,20 @@ .Curl()%0A -%09 + c.setopt @@ -438,17 +438,20 @@ DPOINT)%0A -%09 + c.setopt @@ -468,17 +468,20 @@ TA, fd)%0A -%09 + c.perfor @@ -523,17 +523,20 @@ != 200:%0A -%09 + print('d @@ -556,17 +556,20 @@ ailed')%0A -%09 + exit(1)%0A @@ -781,17 +781,19 @@ e keys%0A# -%09 + CVE_data @@ -802,17 +802,19 @@ ersion%0A# -%09 + CVE_data @@ -822,17 +822,19 @@ format%0A# -%09 + CVE_Item @@ -836,17 +836,19 @@ _Items%0A# -%09 + CVE_data @@ -859,17 +859,19 @@ estamp%0A# -%09 + CVE_data @@ -885,17 +885,19 @@ OfCVEs%0A# -%09 + CVE_data @@ -1215,17 +1215,20 @@ tems'%5D:%0A -%09 + if 'cve' @@ -1237,18 +1237,24 @@ n item:%0A -%09%09 + if 'CVE_ @@ -1280,19 +1280,28 @@ 'cve'%5D:%0A -%09%09%09 + if 'ID' @@ -1333,20 +1333,32 @@ meta'%5D:%0A -%09%09%09%09 + #print(i @@ -1396,12 +1396,24 @@ '%5D)%0A -%09%09%09%09 + coun @@ -1426,8 +1426,9 @@ unt + 1%0A +%0A
5e3a4c84d31fe63a67fdb2e64c5edc1ffe8d24ab
Tweak return message
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='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)
Python
0
@@ -838,18 +838,22 @@ on=' -Return fil +Cached resourc e')%0A
16e38be365c939f7e74fb321280e88370606a6c3
Fix daemonizing on python 3.4+
flexget/task_queue.py
flexget/task_queue.py
from __future__ import unicode_literals, division, absolute_import from builtins import * import logging import queue import threading import time from sqlalchemy.exc import ProgrammingError, OperationalError from flexget.task import TaskAbort log = logging.getLogger('task_queue') class TaskQueue(object): """ Task processing thread. Only executes one task at a time, if more are requested they are queued up and run in turn. """ def __init__(self): self.run_queue = queue.PriorityQueue() self._shutdown_now = False self._shutdown_when_finished = False self.current_task = None # We don't override `threading.Thread` because debugging this seems unsafe with pydevd. # Overriding __len__(self) seems to cause a debugger deadlock. self._thread = threading.Thread(target=self.run, name='task_queue') self._thread.daemon = True def start(self): self._thread.start() def run(self): while not self._shutdown_now: # Grab the first job from the run queue and do it try: self.current_task = self.run_queue.get(timeout=0.5) except queue.Empty: if self._shutdown_when_finished: self._shutdown_now = True continue try: self.current_task.execute() except TaskAbort as e: log.debug('task %s aborted: %r' % (self.current_task.name, e)) except (ProgrammingError, OperationalError): log.critical('Database error while running a task. Attempting to recover.') self.current_task.manager.crash_report() except Exception: log.critical('BUG: Unhandled exception during task queue run loop.') self.current_task.manager.crash_report() finally: self.run_queue.task_done() self.current_task = None remaining_jobs = self.run_queue.qsize() if remaining_jobs: log.warning('task queue shut down with %s tasks remaining in the queue to run.' % remaining_jobs) else: log.debug('task queue shut down') def is_alive(self): return self._thread.is_alive() def put(self, task): """Adds a task to be executed to the queue.""" self.run_queue.put(task) def __len__(self): return self.run_queue.qsize() def shutdown(self, finish_queue=True): """ Request shutdown. :param bool finish_queue: Should all tasks be finished before ending thread. """ log.debug('task queue shutdown requested') if finish_queue: self._shutdown_when_finished = True if self.run_queue.qsize(): log.verbose('There are %s tasks to execute. Shutdown will commence when they have completed.' % self.run_queue.qsize()) else: self._shutdown_now = True def wait(self): """ Waits for the thread to exit. Allows abortion of task queue with ctrl-c """ try: while self._thread.is_alive(): time.sleep(0.5) except KeyboardInterrupt: log.error('Got ctrl-c, shutting down after running task (if any) completes') self.shutdown(finish_queue=False) # We still wait to finish cleanly, pressing ctrl-c again will abort while self._thread.is_alive(): time.sleep(0.5)
Python
0
@@ -112,16 +112,27 @@ t queue%0A +import sys%0A import t @@ -3157,32 +3157,382 @@ l-c%0A %22%22%22%0A + if sys.version_info %3E= (3, 4):%0A # Due to python bug, Thread.is_alive doesn't seem to work properly under our conditions on python 3.4+%0A # http://bugs.python.org/issue26793%0A # TODO: Is it important to have the clean abortion? Do we need to find a better way?%0A self._thread.join()%0A return%0A try:%0A
ec54ab484d9b8d2507a42fa7f0adba9e52975ddb
add new test for revoke function
github/tests.py
github/tests.py
from django.core.urlresolvers import resolve from django.test import TestCase from django.http import HttpRequest from django.test import LiveServerTestCase from django.contrib.auth.models import User from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.keys import Keys from github.views import * from github.models import Hiren import os class HomePageTest(TestCase): def test_root_url_resolves_to_index_page_view(self): found = resolve('/') self.assertEqual(found.func, index) def test_home_page_returns_correct_html(self): request = HttpRequest() response = index(request) self.assertTrue(response.content.startswith(b'<html>')) self.assertIn(b'<title>Hiren: The Bunny</title>', response.content) self.assertIn( b'<a href="/login"><i class="fa fa-sign-in"></i> Login</a>', response.content) self.assertTrue(response.content.endswith(b'</html>')) def test_uses_index_template(self): response = self.client.get('/') self.assertTemplateUsed(response, 'index.html') class HirenPageTest(TestCase): def setUp(self): User.objects.create_superuser( username='admin', password='admin', email='admin@admin.lol') def test_url_resolved_to_hiren_page_view(self): found = resolve('/hiren/') self.assertEqual(found.func, hiren) def test_displays_authorize_button(self): self.client.login(username='admin', password='admin') response = self.client.get('/hiren/') self.assertContains(response, 'Authorize') def test_access_denied_for_unauthorized_user(self): response = self.client.get('/hiren/', follow=True) self.assertRedirects(response, '/?next=/hiren/') def test_uses_index_template(self): self.client.login(username='admin', password='admin') response = self.client.get('/hiren/') self.assertTemplateUsed(response, 'hiren.html') class TestLoginView(TestCase): def setUp(self): User.objects.create_superuser( username='admin', password='admin', email='admin@admin.lol') def test_denies_anonymous(self): # self.client.login(username='admin', password='admin') response = self.client.post('/login/', data={'username': 'admi', 'password': 'admin'}) self.assertRedirects(response, '/') def test_correct_view_loads(self): response = self.client.get('/login/') self.assertTemplateUsed(response, 'login.html') def test_correct_login_works(self): response = self.client.post('/login/', data={'username': 'admin', 'password': 'admin'}, follow=True) self.assertRedirects(response, '/hiren/') class TestLogoutView(TestCase): def setUp(self): User.objects.create_superuser( username='admin', password='admin', email='admin@admin.lol') def test_logout_works(self): self.client.login(username='admin', password='admin') response = self.client.get('/logout', follow=True) self.assertRedirects(response, '/') # class LoginFunctionalTestCase(LiveServerTestCase): # # def setUp(self): # User.objects.create_superuser( # username='admin', password='admin', email='admin@admin.lol') # if 'TRAVIS' in os.environ: # username = os.environ["SAUCE_USERNAME"] # access_key = os.environ["SAUCE_ACCESS_KEY"] # hub_url = "%s:%s@ondemand.saucelabs.com:80" % (username, access_key) # capabilities = DesiredCapabilities.FIREFOX.copy() # # capabilities = {'browserName': "chrome"} # capabilities['platform'] = "Linux" # capabilities['version'] = "beta" # capabilities['screenResolution'] = "1024x768" # self.browser = webdriver.Remote(desired_capabilities=capabilities, # command_executor="http://%s/wd/hub" % hub_url) # self.browser.maximize_window() # self.browser.implicitly_wait(20) # else: # self.browser = webdriver.Firefox() # self.browser.maximize_window() # self.browser.implicitly_wait(5) # # def tearDown(self): # self.browser.quit() # # def test_login_user(self): # self.browser.get('%s%s' % (self.live_server_url, "/login/")) # import time # time.sleep(20) # username = self.browser.find_element_by_id("username") # username.send_keys('admin') # password = self.browser.find_element_by_id("password") # password.send_keys('admin') # self.browser.find_element_by_id("login").submit() # self.assertEqual(self.browser.current_url, '%s%s' % (self.live_server_url, '/hiren/')) class HirenModelTest(TestCase): def test_saving_and_retrieving_item(self): item = Hiren() item.access_token = "bla bla" item.authorized = True item.save() saved_item = Hiren.objects.all() self.assertEqual(saved_item.count(), 1) saved_item_content = saved_item[0] self.assertEqual(saved_item_content.access_token, "bla bla") self.assertEqual(saved_item_content.authorized, True)
Python
0.000001
@@ -2240,79 +2240,21 @@ mous -(self):%0A # self.client. +_ login( -u se -rname='admin', password='admin') +lf): %0A @@ -3099,16 +3099,798 @@ , '/')%0A%0A +%0Aclass TestRevokeView(TestCase):%0A%0A def setUp(self):%0A User.objects.create_superuser(%0A username='admin', password='admin', email='admin@admin.lol')%0A item = Hiren()%0A item.access_token = %22bla bla%22%0A item.authorized = True%0A item.save()%0A%0A def test_denies_anonymous_login(self):%0A response = self.client.post('/login/', data=%7B'username': 'admi', 'password': 'admin'%7D)%0A self.assertRedirects(response, '/')%0A%0A # def test_logged_in_user_can_delete_object(self):%0A # self.client.login(username='admin', password='admin')%0A # count = Hiren.objects.all().count()%0A # self.assertEqual(count, 1)%0A # response = self.client.get('/revoke/1/', follow=True)%0A # self.assertRedirects(response, '/hiren/')%0A%0A # class
081d4f32f0cc69a62b7ae23909d0327a1df56fb1
Introduce CleanChars filter
weboob/tools/browser2/filters.py
weboob/tools/browser2/filters.py
# -*- coding: utf-8 -*- # Copyright(C) 2014 Romain Bignon # # 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/>. from __future__ import absolute_import from decimal import Decimal import re _NO_DEFAULT = object() class _Filter(object): _creation_counter = 0 def __init__(self): self._creation_counter = _Filter._creation_counter _Filter._creation_counter += 1 class Filter(_Filter): """ Class used to filter on a HTML element given as call parameter to return matching elements. Filters can be chained, so the parameter supplied to constructor can be either a xpath selector string, or an other filter called before. >>> from lxml.html import etree >>> f = CleanDecimal(CleanText('//p')) >>> f(etree.fromstring('<html><body><p>blah: <span>229,90</span></p></body></html>')) Decimal('229.90') """ def __init__(self, selector=None): super(Filter, self).__init__() self.selector = selector def __call__(self, item): if isinstance(self.selector, basestring): value = item.xpath(self.selector) elif callable(self.selector): value = self.selector(item) else: value = self.selector return self.filter(value) def filter(self, value): """ This method have to be overrided by children classes. """ return value class Env(_Filter): """ Filter to get environment value of the item. It is used for example to get page parameters, or when there is a parse() method on ItemElement. """ def __init__(self, name): super(Env, self).__init__() self.name = name def __call__(self, item): return item.env[self.name] class TableCell(_Filter): """ Used with TableElement, it get the cell value from its name. For example: class table(TableElement): head_xpath = '//table/thead/th' item_xpath = '//table/tbody/tr' col_date = u'Date' col_label = [u'Name', u'Label'] class item(ItemElement): klass = Object obj_date = Date(TableCell('date')) obj_label = CleanText(TableCell('label')) """ def __init__(self, *names, **kwargs): super(TableCell, self).__init__() self.names = names self.default = kwargs.pop('default', _NO_DEFAULT) def __call__(self, item): for name in self.names: idx = item.parent.get_colnum(name) if idx is not None: return item.xpath('./td[%s]' % (idx + 1)) if self.default is not _NO_DEFAULT: return self.default raise KeyError('Unable to find column %s' % ' or '.join(self.names)) class CleanText(Filter): """ Get a cleaned text from an element. It replaces all tabs and multiple spaces to one space and strip the result string. """ def filter(self, txt): if isinstance(txt, (tuple,list)): txt = ' '.join(map(self.clean, txt)) return self.clean(txt) @classmethod def clean(self, txt): if not isinstance(txt, basestring): txt = [t.strip() for t in txt.itertext()] txt = u' '.join(txt) # 'foo bar' txt = re.sub(u'[\s\xa0\t]+', u' ', txt) # 'foo bar' return txt.strip() class CleanDecimal(CleanText): """ Get a cleaned Decimal value from an element. """ def filter(self, text): text = super(CleanDecimal, self).filter(text) text = text.replace('.','').replace(',','.') return Decimal(re.sub(u'[^\d\-\.]', '', text)) class Link(Filter): """ Get the link uri of an element. If the <a> tag is not found, an exception IndexError is raised. """ def filter(self, el): return el[0].attrib.get('href', '') class Attr(_Filter): """ Get the attribute of object. """ def __init__(self, name): super(Attr, self).__init__() self.name = name def __call__(self, item): return item.use_selector(getattr(item, 'obj_%s' % self.name)) class Regexp(Filter): """ Apply a regex. >>> from lxml.html import etree >>> f = Regexp(CleanText('//p'), r'Date: (\d+)/(\d+)/(\d+)', '\\3-\\2-\\1') >>> f(etree.fromstring('<html><body><p>Date: <span>13/08/1988</span></p></body></html>')) u'1988-08-13' """ def __init__(self, selector, pattern, template=None, flags=0, default=_NO_DEFAULT): super(Regexp, self).__init__(selector) self.pattern = pattern self.regex = re.compile(pattern, flags) self.template = template self.default = default def filter(self, txt): if isinstance(txt, (tuple,list)): txt = ' '.join([t.strip() for t in txt.itertext()]) mobj = self.regex.search(txt) if not mobj: if self.default is not _NO_DEFAULT: return self.default else: raise KeyError('Unable to match %s' % self.pattern) if self.template is None: return next(g for g in mobj.groups() if g is not None) else: return mobj.expand(self.template)
Python
0
@@ -4783,16 +4783,433 @@ name))%0A%0A +class CleanChars(Filter):%0A %22%22%22%0A Remove chars.%0A %22%22%22%0A def __init__(self, selector, symbols):%0A super(CleanChars, self).__init__(selector)%0A self.symbols = symbols%0A%0A def filter(self, txt):%0A if isinstance(txt, (tuple,list)):%0A txt = ' '.join(%5Bt.strip() for t in txt.itertext()%5D)%0A%0A for symbol in self.symbols:%0A txt = txt.replace(symbol, '')%0A return txt%0A %0Aclass R
f6fb41772726695a366798352e70e2c3644a44d4
Remove 'del_ins' third-party Markdown extension to prevent failing builds
website/project/views/comment.py
website/project/views/comment.py
# -*- coding: utf-8 -*- import pytz from datetime import datetime from flask import request from modularodm import Q from framework.auth.decorators import must_be_logged_in from website.addons.base.signals import file_updated from website.files.models import FileNode from website.notifications.constants import PROVIDERS from website.notifications.emails import notify from website.models import Comment from website.project.decorators import must_be_contributor_or_public from website.project.model import Node from website.project.signals import comment_added import markdown @file_updated.connect def update_comment_root_target_file(self, node, event_type, payload, user=None): if event_type == 'addon_file_moved': source = payload['source'] destination = payload['destination'] source_node = Node.load(source['node']['_id']) destination_node = node if (source.get('provider') == destination.get('provider') == 'osfstorage') and source_node._id != destination_node._id: old_file = FileNode.load(source.get('path').strip('/')) new_file = FileNode.resolve_class(destination.get('provider'), FileNode.FILE).get_or_create(destination_node, destination.get('path')) Comment.update(Q('root_target', 'eq', old_file._id), data={'node': destination_node}) # update node record of commented files if old_file._id in source_node.commented_files: destination_node.commented_files[new_file._id] = source_node.commented_files[old_file._id] del source_node.commented_files[old_file._id] source_node.save() destination_node.save() @comment_added.connect def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=markdown.markdown(comment.content, ['del_ins', 'markdown.extensions.tables', 'markdown.extensions.fenced_code']), page_type='file' if comment.page == Comment.FILES else node.project_or_component, page_title=comment.root_target.name if comment.page == Comment.FILES else '', provider=PROVIDERS[comment.root_target.provider] if comment.page == Comment.FILES else '', target_user=target.user if is_reply(target) else None, parent_comment=target.content if is_reply(target) else "", url=comment.get_comment_page_url() ) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify( event="comments", user=auth.user, node=node, timestamp=time_now, **context ) if is_reply(target): if target.user and target.user not in sent_subscribers: notify( event='comment_replies', user=auth.user, node=node, timestamp=time_now, **context ) def is_reply(target): return isinstance(target, Comment) def _update_comments_timestamp(auth, node, page=Comment.OVERVIEW, root_id=None): if node.is_contributor(auth.user): user_timestamp = auth.user.comments_viewed_timestamp node_timestamp = user_timestamp.get(node._id, None) if not node_timestamp: user_timestamp[node._id] = dict() timestamps = auth.user.comments_viewed_timestamp[node._id] # update node timestamp if page == Comment.OVERVIEW: timestamps[Comment.OVERVIEW] = datetime.utcnow() auth.user.save() return {node._id: auth.user.comments_viewed_timestamp[node._id][Comment.OVERVIEW].isoformat()} # set up timestamp dictionary for files page if not timestamps.get(page, None): timestamps[page] = dict() # if updating timestamp on a specific file page timestamps[page][root_id] = datetime.utcnow() auth.user.save() return {node._id: auth.user.comments_viewed_timestamp[node._id][page][root_id].isoformat()} else: return {} @must_be_logged_in @must_be_contributor_or_public def update_comments_timestamp(auth, node, **kwargs): timestamp_info = request.get_json() page = timestamp_info.get('page') root_id = timestamp_info.get('rootId') return _update_comments_timestamp(auth, node, page, root_id)
Python
0
@@ -1944,19 +1944,8 @@ t, %5B -'del_ins', 'mar
9df0c21bcefdeda4ca65ee4126ed965a6d099416
Fix line length on import statement
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)
Python
0.00979
@@ -51,16 +51,21 @@ elAdmin, +%5C%0A modelad @@ -81,14 +81,8 @@ ter, - %5C%0A Thu
a44484285b1b9ea4f072a3c0b3f933e44f1475c2
remove option --ids in formats.contig.frombed()
formats/contig.py
formats/contig.py
#!/usr/bin/env python # -*- coding: UTF-8 -*- """ TIGR contig format, see spec: <http://www.cbcb.umd.edu/research/contig_representation.shtml#contig> """ import sys import logging from optparse import OptionParser from collections import defaultdict from jcvi.formats.base import BaseFile, read_block from jcvi.apps.base import ActionDispatcher, debug debug() class ReadLine (object): def __init__(self, row, contig): # '#16(0) [RC] 3046 bases, 00000000 checksum. {3046 1} <1 3046>' assert row[0] == '#' self.id = row.strip("#").split('(')[0] coords = row.split("<")[1].split(">")[0] start, end = coords.split() self.contig = contig self.start = int(start) self.end = int(end) if self.start > self.end: self.start, self.end = self.end, self.start self.orientation = "-" if "[RC]" in row else "+" def __str__(self): return self.id @property def bedline(self): return "\t".join(str(x) for x in \ (self.contig, self.start - 1, self.end, self.id, "0", self.orientation)) __repr__ = __str__ class ContigLine (object): def __init__(self, row): # '##1 6 8914 bases, 00000000 checksum.' assert row[:2] == '##' self.id = row.strip("#").split()[0] self.reads = [] def __str__(self): return ":".join((self.id, str(self.reads))) __repr__ = __str__ class ContigFile (BaseFile): def __init__(self, filename): super(ContigFile, self).__init__(filename) self.fp = open(filename) def iter_records(self): c = None for a, b in read_block(self.fp, "#"): if a[:2] == '##': if c: yield c c = ContigLine(a) else: c.reads.append(ReadLine(a, c.id)) if c: # last one yield c def main(): actions = ( ('bed', 'convert read membership to bed format'), ('frombed', 'convert read placement to contig format'), ) p = ActionDispatcher(actions) p.dispatch(globals()) def frombed(args): """ %prog frombed bedfile contigfasta readfasta Convert read placement to contig format. This is useful before running BAMBUS. """ from jcvi.formats.fasta import Fasta, SeqIO from jcvi.formats.bed import Bed from jcvi.utils.cbook import fill p = OptionParser(frombed.__doc__) p.add_option("--ids", default=False, action="store_true", help="Only generate ids file [default: %default]") opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) bedfile, contigfasta, readfasta = args ids = opts.ids prefix = bedfile.rsplit(".", 1)[0] contigfile = prefix + ".contig" idsfile = prefix + ".ids" contigfasta = Fasta(contigfasta) readfasta = Fasta(readfasta) bed = Bed(bedfile) checksum = "00000000 checksum." fw_ids = open(idsfile, "w") if not ids: fw = open(contigfile, "w") for ctg, reads in bed.sub_beds(): ctgseq = contigfasta[ctg] ctgline = "##{0} {1} {2} bases, {3}".format(\ ctg, len(reads), len(ctgseq), checksum) print >> fw_ids, ctg if ids: continue print >> fw, ctgline print >> fw, fill(ctgseq.seq) for b in reads: read = b.accn strand = b.strand readseq = readfasta[read] rc = " [RC]" if strand == "-" else "" readlen = len(readseq) rstart, rend = 1, readlen if strand == "-": rstart, rend = rend, rstart readrange = "{{{0} {1}}}".format(rstart, rend) conrange = "<{0} {1}>".format(b.start, b.end) readline = "#{0}(0){1} {2} bases, {3} {4} {5}".format(\ read, rc, readlen, checksum, readrange, conrange) print >> fw, readline print >> fw, fill(readseq.seq) if not ids: logging.debug("Mapped contigs written to `{0}`.".format(contigfile)) logging.debug("Contig IDs written to `{0}`.".format(idsfile)) def bed(args): """ %prog bed contigfile Prints out the contigs and their associated reads. """ p = OptionParser(main.__doc__) opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) contigfile, = args bedfile = contigfile.rsplit(".", 1)[0] + ".bed" fw = open(bedfile, "w") c = ContigFile(contigfile) for rec in c.iter_records(): for r in rec.reads: print >> fw, r.bedline logging.debug("File written to `{0}`.".format(bedfile)) return bedfile if __name__ == '__main__': main()
Python
0
@@ -2492,139 +2492,8 @@ __)%0A - p.add_option(%22--ids%22, default=False, action=%22store_true%22,%0A help=%22Only generate ids file %5Bdefault: %25default%5D%22)%0A @@ -2633,27 +2633,8 @@ rgs%0A - ids = opts.ids%0A @@ -2897,36 +2897,16 @@ e, %22w%22)%0A - if not ids:%0A fw = @@ -3111,16 +3111,17 @@ ecksum)%0A +%0A @@ -3145,46 +3145,8 @@ ctg%0A - if ids:%0A continue%0A%0A @@ -3204,24 +3204,25 @@ ctgseq.seq)%0A +%0A for
d4d69ed62cbd726c92de9382136175e0fbdbb8af
Remove super-stale file paths
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))") 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)
Python
0.000002
@@ -654,767 +654,8 @@ %22)%0A%0A -%0A%0Adata=%5B%22opencog/scm/config.scm%22,%0A %22opencog/scm/core_types.scm%22,%0A %22spacetime/spacetime_types.scm%22,%0A %22opencog/nlp/types/nlp_types.scm%22,%0A %22opencog/attention/attention_types.scm%22,%0A %22opencog/embodiment/embodiment_types.scm%22,%0A %22opencog/scm/apply.scm%22,%0A %22opencog/scm/file-utils.scm%22,%0A %22opencog/scm/persistence.scm%22,%0A #%22opencog/scm/repl-shell.scm%22,%0A %22opencog/scm/utilities.scm%22,%0A %22opencog/scm/av-tv.scm%22,%0A %22opencog/nlp/scm/type-definitions.scm%22,%0A %22opencog/nlp/scm/config.scm%22,%0A %22opencog/nlp/scm/file-utils.scm%22,%0A %22opencog/nlp/scm/nlp-utils.scm%22,%0A %22opencog/nlp/scm/disjunct-list.scm%22,%0A %22opencog/nlp/scm/processing-utils.scm%22,%0A%0A %22opencog/nlp/anaphora/tests/atomspace.log%22%0A %5D%0A #sta @@ -730,60 +730,8 @@ %22)%0A%0A -# for item in data:%0A# load_scm(atomspace, item)%0A%0A #ini
f585a7cdf4ecbecfe240873a3b4b8e7d4376e69c
Move fallback URL pattern to the end of the list so it gets matched last.
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')), 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, } ), )
Python
0
@@ -368,72 +368,8 @@ )),%0A - url(r'%5E', include('campus02.base.urls', namespace='base')),%0A %5D%0A%0Ai @@ -913,12 +913,98 @@ ),%0A )%0A +%0Aurlpatterns.append(%0A url(r'%5E', include('campus02.base.urls', namespace='base'))%0A)%0A
c05a93d8993e14fc8521dd01a13a930e85fcb882
fix code style in `test_db_util` (#9594)
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 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"
Python
0
@@ -136,20 +136,8 @@ SE)%0A -import math%0A impo @@ -192,16 +192,24 @@ import +Constant RateLimi @@ -213,40 +213,32 @@ imit -ingTTLCache, ConstantRateLimiter +er, RateLimitingTTLCache %0A%0A%0Ad
a9a9b60d9994bc4780e74ddd01df833a85247b95
Change state serialiser to pass hex color values.
suddendev/game/state_encoder.py
suddendev/game/state_encoder.py
#!/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)
Python
0
@@ -96,16 +96,63 @@ coder)%0A%0A +def clamp(x): %0A return max(0, min(x, 255))%0A%0A class St @@ -1361,116 +1361,87 @@ urn -%7B%0A 'r': color.r,%0A 'g': color.g,%0A 'b': color.b%0A %7D +%22#%7B0:02x%7D%7B1:02x%7D%7B2:02x%7D%22.format(clamp(color.r), clamp(color.g), clamp(color.b)) %0A%0A
3e5c500eed84ca24ffc31e802e061833a5a43225
use unicode names in test
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': '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})
Python
0.000026
@@ -1,5 +1,4 @@ -%EF%BB%BF # -* @@ -213,16 +213,17 @@ 'name': +u 'Root1'%7D @@ -260,16 +260,17 @@ 'name': +u 'Ch1', ' @@ -322,24 +322,25 @@ te(%7B'name': +u 'Ch3', 'pare @@ -388,24 +388,25 @@ te(%7B'name': +u 'Ch2', 'pare @@ -451,16 +451,17 @@ 'name': +u 'Ch3-las @@ -594,22 +594,25 @@ ), %5B +u 'Ch1', +u 'Ch2', +u 'Ch3 @@ -773,24 +773,25 @@ te(%7B'name': +u 'Ch2-1', 'pa @@ -846,16 +846,17 @@ 'name': +u 'Ch2-2',
c300e70bb65da3678f27c4ba01b22f9a3d4fc717
Use spi_serial for tools
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)) 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')
Python
0.000001
@@ -343,17 +343,135 @@ S', 1))%0A -%0A + if serial_port.find('spi') %3E= 0:%0A import spi_serial%0A self.ser = spi_serial.SpiSerial()%0A else:%0A self
da3f842107e5f8062013b7a6412da2cb18592f5f
make the dt statement into an assertion
examples/basic_example.py
examples/basic_example.py
""" Basic Example ============= Here we demonstrate both the coordinate-based slicing notatation, which is unique to pySpecData, as well the way in which the axis coordinates for a Fourier transform are handled automatically. The case considered here is that of an NMR FID that has been acquired with a wider spectral width than the signal of interest, and with a longer acquisition time. """ from pylab import * from pyspecdata import * fig, (ax_time, ax_freq) = subplots(2,1) t = nddata(r_[0:0.5:1e-3], 't2') # 1 kHz SW fake_data = exp(1j*2*pi*100*t-10*t*pi) # 10 Hz wide line at 100 Hz offset fake_data.add_noise(0.3).set_units('t2','s') plot(fake_data, ax=ax_time, alpha=0.2, label='raw data') ax_freq.set_title("time domain") fake_data.ft('t2', shift=True) print("note that the original dwell time is",fake_data.get_ft_prop('t2','dt'), "and the original frequency resolution is",fake_data.get_ft_prop('t2','df')) plot(fake_data, ax=ax_freq, alpha=0.2, label='raw data') ax_time.set_title("frequency domain") fig.tight_layout() fake_data = fake_data['t2':(-200,200)] # filter the data in the frequency domain by slicing from -200 to 200 Hz plot(fake_data, '--', ax=ax_freq, alpha=0.2, label='after frequency slice') fake_data.ift('t2') # now, move back into the time domain, where it will have less noise, and with less points plot(fake_data, ax=ax_time, alpha=0.5, label='after frequency slice') # in the time domain, we can either slice simply: truncated_data = fake_data['t2':(0,0.2)] plot(truncated_data, ax=ax_time, alpha=0.5, label='after time slice') # or we can implement a matched filter: fake_data *= 2*exp(-10*pi*fake_data.fromaxis('t2')) plot(fake_data, ax=ax_time, alpha=0.5, label='apodized') truncated_data.ft('t2') # note that after we ft the first time, it "remembers" # whether or not we have frequency shifted, and will # use the existing start point in the frequency domain fake_data.ft('t2') plot(truncated_data, ax=ax_freq, alpha=0.5, label='after time slice') plot(fake_data, ax=ax_freq, alpha=0.5, label='after apodization') print("note that the new dwell time of the truncated data is",truncated_data.get_ft_prop('t2','dt'), "and the new frequency resolution is",truncated_data.get_ft_prop('t2','df')) # finally, show that we can zero fill truncated_data.ift('t2') truncated_data.ft('t2', pad=256) plot(truncated_data, ax=ax_freq, alpha=0.5, label='after time slice and zero filling') truncated_data.ift('t2') plot(truncated_data, '--', ax=ax_time, alpha=0.5, label='after time slice and zero filling') ax_time.legend(**dict(bbox_to_anchor=(1.05,1), loc=2, borderaxespad=0.)) ax_freq.legend(**dict(bbox_to_anchor=(1.05,1), loc=2, borderaxespad=0.)) fig.tight_layout() show()
Python
0.999999
@@ -757,16 +757,64 @@ t=True)%0A +assert fake_data.get_ft_prop('t2','dt') == 1e-3%0A print(%22n
73029223f54dc6c793c190e70a135d0bd3faa50b
Update download script
download_corpora.py
download_corpora.py
#!/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()
Python
0
@@ -103,28 +103,33 @@ rom -nltk import download +text.packages import nltk %0A%0ARE @@ -331,16 +331,21 @@ +nltk. download
c818007491fe10101a73beeb7adfa59f9aadf3c6
use private key instead of public
osf/management/commands/file_view_counts.py
osf/management/commands/file_view_counts.py
from __future__ import unicode_literals import logging import django django.setup() import json import requests import urllib from django.core.management.base import BaseCommand from django.db import transaction from osf.models import BaseFileNode, PageCounter from website import settings from keen import KeenClient from scripts import utils as script_utils logger = logging.getLogger(__name__) def set_file_view_counts(state, *args, **kwargs): # get all osfstorage files which is_deleted == False files = BaseFileNode.resolve_class('osfstorage', BaseFileNode.FILE).active.all() for file_node in files: # for each file get the file view counts from keen client = KeenClient( project_id=settings.KEEN['public']['project_id'], read_key=settings.KEEN['public']['read_key'], ) node_pageviews = client.count( event_collection='pageviews', timeframe='this_7_days', group_by='node.id', filters=[ { 'property_name': 'node.id', 'operator': 'exists', 'property_value': True } ] ) query = [{'property_name': 'page.info.path', 'operator': 'eq', 'property_value': file_node._id}] query = urllib.quote(json.dumps(query)) url = 'https://api.keen.io/3.0/projects/{}/queries/count' \ '?api_key={}&event_collection=pageviews&timezone=UTC&timeframe' \ '=this_14_days&filters={}'.format(settings.KEEN['public']['project_id'], settings.KEEN['public']['read_key'], query) resp = requests.get(url) file_view_count = int(resp.json()['result']) # udpate the pagecounter for file view counts PageCounter.set_basic_counters('view:{0}:{1}'.format(file_node.node._id, file_node._id), file_view_count) logger.info('File ID {0}: has inputed "{1}" view counts'.format(file_node._id, file_view_count)) logger.info('File view counts migration from keen completed.') class Command(BaseCommand): """ Backfill Retraction.date_retracted with `RETRACTION_APPROVED` log date. """ def add_arguments(self, parser): super(Command, self).add_arguments(parser) parser.add_argument( '--dry', action='store_true', dest='dry_run', help='Run migration and roll back changes to db', ) def handle(self, *args, **options): dry_run = options.get('dry_run', False) if not dry_run: script_utils.add_file_logger(logger, __file__) with transaction.atomic(): set_file_view_counts if dry_run: raise RuntimeError('Dry run, transaction rolled back.')
Python
0.000001
@@ -681,534 +681,8 @@ een%0A - client = KeenClient(%0A project_id=settings.KEEN%5B'public'%5D%5B'project_id'%5D,%0A read_key=settings.KEEN%5B'public'%5D%5B'read_key'%5D,%0A )%0A%0A node_pageviews = client.count(%0A event_collection='pageviews',%0A timeframe='this_7_days',%0A group_by='node.id',%0A filters=%5B%0A %7B%0A 'property_name': 'node.id',%0A 'operator': 'exists',%0A 'property_value': True%0A %7D%0A %5D%0A )%0A%0A @@ -782,16 +782,16 @@ e._id%7D%5D%0A + %0A @@ -1039,29 +1039,30 @@ ings.KEEN%5B'p -ublic +rivate '%5D%5B'project_ @@ -1087,13 +1087,14 @@ N%5B'p -ublic +rivate '%5D%5B'
986d134089d1ce9b026761a5d5bb7c6f528ca8d4
Use fmtlib-5.3.0
dreal/workspace.bzl
dreal/workspace.bzl
load("//third_party/com_github_robotlocomotion_drake:tools/workspace/github.bzl", "github_archive") load("//third_party/com_github_robotlocomotion_drake:tools/workspace/pkg_config.bzl", "pkg_config_repository") def dreal_workspace(): pkg_config_repository( name = "ibex", # LGPL3 modname = "ibex", pkg_config_paths = [ # macOS "/usr/local/opt/ibex@2.7.4/share/pkgconfig", "/usr/local/opt/ibex@2.7.2/share/pkgconfig", "/usr/local/opt/ibex@2.6.5/share/pkgconfig", # TODO(soonho): Remove this "/usr/local/opt/clp/lib/pkgconfig", # dep of ibex, EPL "/usr/local/opt/coinutils/lib/pkgconfig", # dep of clp, EPL # Linux "/opt/libibex/2.7.4/share/pkgconfig", "/opt/libibex/2.7.2/share/pkgconfig", ], ) pkg_config_repository( name = "nlopt", # LGPL2 + MIT modname = "nlopt", pkg_config_paths = [ "/usr/local/opt/nlopt/lib/pkgconfig", ], ) pkg_config_repository( name = "python2", modname = "python2", pkg_config_paths = [ "/usr/local/opt/python@2/lib/pkgconfig", ], ) pkg_config_repository( name = "python3", modname = "python3", pkg_config_paths = [ "/usr/local/opt/python@3/lib/pkgconfig", ], ) # We do not use this one, yet. pkg_config_repository( name = "python-3.5", modname = "python-3.5", pkg_config_paths = [ "/usr/local/opt/python@3/lib/pkgconfig", ], ) # We do not use this one, yet. pkg_config_repository( name = "python-3.6", modname = "python-3.6", pkg_config_paths = [ "/usr/local/opt/python@3/lib/pkgconfig", ], ) # We do not use this one, yet. pkg_config_repository( name = "python-3.7", modname = "python-3.7", pkg_config_paths = [ "/usr/local/opt/python@3/lib/pkgconfig", ], ) github_archive( name = "spdlog", # MIT repository = "gabime/spdlog", commit = "v1.2.1", sha256 = "867a4b7cedf9805e6f76d3ca41889679054f7e5a3b67722fe6d0eae41852a767", build_file = str(Label("//tools:spdlog.BUILD.bazel")), ) github_archive( name = "fmt", # BSD2 repository = "fmtlib/fmt", commit = "5.2.1", sha256 = "3c812a18e9f72a88631ab4732a97ce9ef5bcbefb3235e9fd465f059ba204359b", build_file = str(Label("//tools:fmt.BUILD.bazel")), ) github_archive( name = "picosat", # MIT repository = "dreal-deps/picosat", commit = "4ee7aa1d1c645df8fa9daa07f2be17c6d03b35fc", # v965 sha256 = "1be461d3659d4e3dc957a718ed295941c38dc822fd22a67f4cb5d180f0b6a7a3", build_file = str(Label("//tools:picosat.BUILD.bazel")), ) github_archive( name = "pybind11", # BSD repository = "pybind/pybind11", commit = "v2.2.4", sha256 = "b69e83658513215b8d1443544d0549b7d231b9f201f6fc787a2b2218b408181e", build_file = str(Label("//tools:pybind11.BUILD.bazel")), ) github_archive( name = "com_google_absl", # BSD repository = "abseil/abseil-cpp", commit = "13327debebc5c2d1d4991b69fe50450e340e50e4", # 20181127 sha256 = "39cbe974e02601c76fbb1619084064908be18bf33b0372c68f4ca05112c8332e", )
Python
0.000001
@@ -2451,19 +2451,19 @@ it = %225. -2.1 +3.0 %22,%0A @@ -2479,72 +2479,72 @@ = %22 -3c812a18e9f72a88631ab4732a97ce9ef5bcbefb3235e9fd465f059ba204359b +defa24a9af4c622a7134076602070b45721a43c51598c8456ec6f2c4dbb51c89 %22,%0A
02490615e82be65520a8d608cff467dcf1bd7b96
add picture commands help messages
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() 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))
Python
0.000001
@@ -137,34 +137,46 @@ ommands.command( +help=%22Awoo!%22 )%0A - async def aw @@ -509,32 +509,52 @@ ommands.command( +help=%22Shows a baka.%22 )%0A async def @@ -889,32 +889,69 @@ ommands.command( +help=%22Summons the anti-bully ranger.%22 )%0A async def @@ -1270,32 +1270,32 @@ ad pictures.%22)%0A%0A - @commands.co @@ -1300,16 +1300,42 @@ command( +help=%22Sad things are sad.%22 )%0A as
7761d1ef19ec3b8a1c6ef17115cca27e39fafaad
Replace non-latin1 characters
demosys/effects/text/effects/writer_2d.py
demosys/effects/text/effects/writer_2d.py
import numpy from pyrr import matrix44 import moderngl from demosys.opengl.vao import VAO from .base import BaseText, FontMeta class TextWriter2D(BaseText): runnable = False def __init__(self, area, text_lines=None, aspect_ratio=1.0): """ :param area: (x, y) Text area size (number of characters) :param size: Text size :param text: Initial text lines """ super().__init__() self.area = area self._text_lines = text_lines self._projection_bytes = None self._aspect_ratio = 1.0 self.aspect_ratio = aspect_ratio self._vao = None self._config = self.get_data('demosys.program.font_meta') self._texture = self.get_texture('demosys.text.font_texture') self._program = self.get_program('demosys.text.program_writer_2d') self._string_buffer = None self._init(FontMeta(self._config)) self._string_buffer = self.ctx.buffer(reserve=self.area[0] * 4 * self.area[1]) self._string_buffer.clear(chunk=b'\32') pos = self.ctx.buffer(data=bytes([0] * 4 * 3)) self._vao = VAO("textwriter", mode=moderngl.POINTS) self._vao.buffer(pos, '3f', 'in_position') self._vao.buffer(self._string_buffer, '1u', 'in_char_id', per_instance=True) self.text_lines = self._text_lines @property def text_lines(self): return self._text_lines @text_lines.setter def text_lines(self, value): self._text_lines = value self._string_buffer.clear(chunk=b'\32') for i, line in enumerate(self._text_lines): self.set_text_line(i, line) @property def aspect_ratio(self): return self._aspect_ratio @aspect_ratio.setter def aspect_ratio(self, value): self._aspect_ratio = value self._projection_bytes = matrix44.create_orthogonal_projection_matrix( -self.aspect_ratio, # left self.aspect_ratio, # right -1.0, # bottom 1.0, # top -100.0, # near 100.0, # far dtype=numpy.float32, ).tobytes() def set_text_line(self, line, text): if line >= self.area[1]: return self._string_buffer.clear(size=self.area[0] * 4, offset=self.area[0] * 4 * line, chunk=b'\32') self._string_buffer.write( numpy.fromiter( self._translate_string(text.encode('iso-8859-1'), self.area[0]), dtype=numpy.uint32 ).tobytes(), offset=(self.area[0] * 4) * line, ) def draw(self, pos, length=-1, size=1.0): if length < 0: length = self.area[0] * self.area[1] elif length > self.area[0] * self.area[1]: length = self.area[0] * self.area[1] csize = ( self._meta.character_width / self._meta.character_height * size, 1.0 * size, ) cpos = ( pos[0] - self._aspect_ratio + csize[0] / 2, -pos[1] + 1.0 - csize[1] / 2, ) self._texture.use(location=0) self._program["m_proj"].write(self._projection_bytes) self._program["text_pos"].value = cpos self._program["font_texture"].value = 0 self._program["char_size"].value = csize self._program["line_length"].value = self.area[0] self._vao.render(self._program, instances=length)
Python
0.999988
@@ -2556,16 +2556,34 @@ -8859-1' +, errors='replace' ), self.
6148e7cccc50023955ef7c3d86709c5197ae78e7
Make output more understandable
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("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())
Python
1
@@ -158,19 +158,36 @@ on(%22 -Bad usage +Usage: %3Cpassword%3E %3Cinput%3E %22) +; %0A%0A @@ -530,18 +530,65 @@ nt %22 -Oops -- %22, +Good news: bad password caused exception: %22%0A print e%0A%0A @@ -650,16 +650,49 @@ sword)%0A%0A + print %22Original input was: %22%0A prin
9c6001b5da9b28bf2f4e3d4028dacb4f0dec0a63
Change check_permission helper to accept non-staff
froide/helper/auth.py
froide/helper/auth.py
from functools import lru_cache from django.contrib.auth import get_permission_codename from django.db.models import Q from froide.team.models import Team AUTH_MAPPING = { 'read': 'view', 'write': 'change', } def check_permission(obj, request, verb): user = request.user if not user.is_staff: return False capability = AUTH_MAPPING.get(verb, verb) opts = obj._meta codename = get_permission_codename(capability, opts) if user.has_perm("%s.%s" % (opts.app_label, codename)): return True if user.has_perm("%s.%s" % (opts.app_label, codename), obj=obj): return True return False def has_authenticated_access(obj, request, verb='write', scope=None): user = request.user if not user.is_authenticated: # No authentication, no access return False # OAuth token token = getattr(request, 'auth', None) if token and (not scope or not token.is_valid([scope])): return False if hasattr(obj, 'user') and obj.user_id == user.id: # The object owner always has the capability return True if user.is_superuser: # Superusers can do everything return True if check_permission(obj, request, verb): return True if hasattr(obj, 'team') and obj.team and obj.team.can_do(verb, user): return True return False @lru_cache() def can_read_object(obj, request=None): if hasattr(obj, 'is_public') and obj.is_public(): return True if request is None: return False return has_authenticated_access(obj, request, verb='read') @lru_cache() def can_write_object(obj, request): return has_authenticated_access(obj, request) @lru_cache() def can_manage_object(obj, request): ''' Team owner permission ''' return has_authenticated_access(obj, request, 'manage') @lru_cache() def can_moderate_object(obj, request): if request.user.is_staff: return True return check_permission(obj, request, 'moderate') ACCESS_MAPPING = { 'read': can_read_object, 'write': can_write_object, 'manage': can_manage_object, 'moderate': can_moderate_object, } def can_access_object(verb, obj, request): try: access_func = ACCESS_MAPPING[verb] except KeyError: raise ValueError('Invalid auth verb') return access_func(obj, request) def get_read_queryset(qs, request, has_team=False, public_field=None, public_q=None, scope=None, fk_path=None): user = request.user filters = None if public_field is not None: filters = Q(**{public_field: True}) result_qs = qs.filter(filters) elif public_q is not None: filters = public_q result_qs = qs.filter(filters) else: result_qs = qs.none() if not user.is_authenticated: return result_qs # OAuth token token = getattr(request, 'auth', None) if token and (not scope or not token.is_valid([scope])): # API access, but no scope return result_qs if user.is_superuser: return qs model = qs.model opts = model._meta codename = get_permission_codename('view', opts) if user.is_staff and user.has_perm("%s.%s" % (opts.app_label, codename)): return qs teams = None if has_team: teams = Team.objects.get_for_user(user) user_filter = get_user_filter(request, teams=teams, fk_path=fk_path) if filters is None: filters = user_filter else: filters |= user_filter return qs.filter(filters) def get_write_queryset(qs, request, has_team=False, user_write_filter=None, scope=None, fk_path=None): user = request.user if not user.is_authenticated: return qs.none() # OAuth token token = getattr(request, 'auth', None) if token and (not scope or not token.is_valid([scope])): # API access, but no scope return qs.none() if user.is_superuser: return qs model = qs.model opts = model._meta codename = get_permission_codename('change', opts) if user.is_staff and user.has_perm("%s.%s" % (opts.app_label, codename)): return qs filters = None if user_write_filter is not None: filters = user_write_filter teams = None if has_team: teams = Team.objects.get_editor_owner_teams(user) user_filter = get_user_filter(request, teams=teams, fk_path=fk_path) if filters is None: filters = user_filter else: filters |= user_filter return qs.filter(filters) def make_q(lookup, value, fk_path=None): path = lookup if fk_path is not None: path = '{}__{}'.format(fk_path, lookup) return Q(**{path: value}) def get_user_filter(request, teams=None, fk_path=None): user = request.user filter_arg = make_q('user', user, fk_path=fk_path) if teams: # or their team filter_arg |= make_q('team__in', teams, fk_path=fk_path) return filter_arg def clear_lru_caches(): for f in ACCESS_MAPPING.values(): f.cache_clear()
Python
0.000001
@@ -289,51 +289,59 @@ -if not user.is_staff:%0A return False%0A +opts = obj._meta%0A%0A if verb in AUTH_MAPPING:%0A @@ -369,46 +369,19 @@ PING -.get(verb, +%5B verb -) +%5D %0A -opts = obj._meta%0A @@ -425,32 +425,67 @@ pability, opts)%0A + else:%0A codename = verb%0A%0A if user.has_
021802b9e937873e8108a3dc040a012c323173c1
increase time the updates stay in redis from 2 minutes to 10 minutes
totalimpact/tiredis.py
totalimpact/tiredis.py
import redis, logging, json, datetime, os, iso8601 from collections import defaultdict from totalimpact.providers.provider import ProviderFactory logger = logging.getLogger("ti.tiredis") def from_url(url, db=0): r = redis.from_url(url, db) return r def set_hash_value(self, key, hash_key, value, expire, pipe=None): if not pipe: pipe = self json_value = json.dumps(value) pipe.hset(key, hash_key, json_value) pipe.expire(key, expire) def get_hash_value(self, key, hash_key): try: json_value = self.hget(key, hash_key) value = json.loads(json_value) except TypeError: value = None return value def get_all_hash_values(self, key): return self.hgetall(key) def delete_hash_key(self, key, hash_key): return self.hdel(key, hash_key) def set_task_id(self, tiid, task_id, expire=60*2, pipe=None): if not pipe: pipe = self key = "tiid_task_id:{tiid}".format( tiid=tiid) pipe.set_value(key, task_id, expire, pipe=pipe) def get_task_id(self, tiid, pipe=None): if not pipe: pipe = self key = "tiid_task_id:{tiid}".format( tiid=tiid) return self.get_value(key, pipe) def set_tiid_task_ids(self, tiid_task_ids, expire=60*2): pipe = self.pipeline() for (tiid, task_id) in tiid_task_ids.iteritems(): self.set_task_id(tiid, task_id, expire, pipe=pipe) pipe.execute() def get_tiid_task_ids(self, tiids): pipe = self.pipeline() tiid_task_ids = {} for tiid in tiids: tiid_task_ids[tiid] = self.get_task_id(tiid, pipe) pipe.execute() return tiid_task_ids def set_value(self, key, value, expire, pipe=None): if not pipe: pipe = self json_value = json.dumps(value) pipe.set(key, json_value) pipe.expire(key, expire) def get_value(self, key, pipe=None): if not pipe: pipe = self try: json_value = pipe.get(key) value = json.loads(json_value) except TypeError: value = None return value def set_memberitems_status(self, memberitems_key, query_status): key = "memberitems:"+memberitems_key expire = 60*60*24 # for a day self.set_value(key, query_status, expire) def get_memberitems_status(self, memberitems_key): key = "memberitems:"+memberitems_key value = self.get_value(key) return value def set_confidence_interval_table(self, size, level, table): key = "confidence_interval_table:{size},{level}".format( size=size, level=level) expire = 60*60*24*7 # for a week self.set_value(key, table, expire) def get_confidence_interval_table(self, size, level): key = "confidence_interval_table:{size},{level}".format( size=size, level=level) value = self.get_value(key) return value def set_reference_histogram_dict(self, genre, refset_name, year, table): key = "refset_histogram:{genre},{refset_name},{year}".format( genre=genre, refset_name=refset_name, year=year) expire = 60*60*24 # for a day self.set_value(key, table, expire) def get_reference_histogram_dict(self, genre, refset_name, year): key = "refset_histogram:{genre},{refset_name},{year}".format( genre=genre, refset_name=refset_name, year=year) value = self.get_value(key) return value def set_reference_lookup_dict(self, genre, refset_name, year, table): key = "refset_lookup:{genre},{refset_name},{year}".format( genre=genre, refset_name=refset_name, year=year) expire = 60*60*24 # for a day self.set_value(key, table, expire) def get_reference_lookup_dict(self, genre, refset_name, year): key = "refset_lookup:{genre},{refset_name},{year}".format( genre=genre, refset_name=refset_name, year=year) value = self.get_value(key) return value redis.Redis.get_hash_value = get_hash_value redis.Redis.get_all_hash_values = get_all_hash_values redis.Redis.set_hash_value = set_hash_value redis.Redis.delete_hash_key = delete_hash_key redis.Redis.set_value = set_value redis.Redis.get_value = get_value redis.Redis.set_memberitems_status = set_memberitems_status redis.Redis.get_memberitems_status = get_memberitems_status redis.Redis.set_confidence_interval_table = set_confidence_interval_table redis.Redis.get_confidence_interval_table = get_confidence_interval_table redis.Redis.set_reference_histogram_dict = set_reference_histogram_dict redis.Redis.get_reference_histogram_dict = get_reference_histogram_dict redis.Redis.set_reference_lookup_dict = set_reference_lookup_dict redis.Redis.get_reference_lookup_dict = get_reference_lookup_dict redis.Redis.set_tiid_task_ids = set_tiid_task_ids redis.Redis.get_tiid_task_ids = get_tiid_task_ids redis.Redis.get_task_id = get_task_id redis.Redis.set_task_id = set_task_id
Python
0
@@ -856,17 +856,18 @@ pire=60* -2 +10 , pipe=N @@ -1256,17 +1256,18 @@ pire=60* -2 +10 ):%0A p
4dc6b726e5f685d01229bc6438b99f060fb63380
Add content type and accpet header checking, probaly too strict.
src/webapp.py
src/webapp.py
#!/usr/bin/env python import os import json import uuid import tornado.ioloop import tornado.web import tornado.options tornado.options.define('cookie_secret', default='sssecccc', help='Change this to a real secret') tornado.options.define('favicon', default='static/favicon.ico', help='Path to favicon.ico') tornado.options.define('static_path', default='static/', help='Path static items') tornado.options.define('port', default=8888, help='Port to run webservice') tornado.options.define('config', default='server.conf', help='Config file location') class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") def post(self): pass cache = {} class ProductHandler(tornado.web.RequestHandler): def get(self, shopid): if shopid not in cache: inventory = {'pizzas': [ {'id': 1, 'name': 'Pizza lagano', 'price': 45}, {'id': 2, 'name': 'Pizza vegan', 'price': 50}, {'id': 3, 'name': 'Pizza %s' % shopid, 'price': 55}, ], 'toppings': [ {'id': 1, 'name': 'garlic', 'price': 1}, {'id': 2, 'name': 'extra cheese', 'price': 5}, {'id': 3, 'name': 'pepperoni', 'price': 2} ], 'sizes': [ {'id': 28, 'name': '28 cm', 'price': -5}, {'id': 32, 'name': '32 cm', 'price': 0}, {'id': 36, 'name': '36 cm', 'price': 5} ] } cache[shopid] = json.dumps(inventory) self.set_header('Content-Type', 'application/vnd.api+json') if not self.get_cookie('user'): self.set_cookie('user', str(uuid.uuid1())) self.write(cache[shopid]) def post(self, shopid): if shopid not in cache: raise tornado.web.HTTPError(404) self.set_header('Content-Type', 'application/vnd.api+json') self.write(shopid) def main(): tornado.options.parse_command_line() options = tornado.options.options if os.path.exists(options.config): tornado.options.parse_config_file(options.config) handlers = [ (r'/api/products/([^/]+)/', ProductHandler), (r'/', MainHandler), ] settings = { 'static_path': os.path.join(os.path.dirname(__file__), '..', options.static_path), 'cookie_secret': options.cookie_secret, 'login_url': '/login', 'xsrf_cookies': False, 'autoreload': True } application = tornado.web.Application(handlers, **settings) application.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main()
Python
0
@@ -549,16 +549,59 @@ tion')%0A%0A +JSON_CONTENT = 'application/vnd.api+json'%0A%0A class Ma @@ -1752,34 +1752,20 @@ e', -'application/vnd.api+json' +JSON_CONTENT )%0A @@ -2001,32 +2001,38 @@ 04)%0A +if self. -set +_check _header('Con @@ -2045,63 +2045,357 @@ ype' -, 'application/vnd.api+json')%0A self.write(shopid +) and self._check_header('Accept'):%0A self.set_header('Content-Type', JSON_CONTENT)%0A self.write(shopid)%0A else:%0A raise tornado.web.HTTPError(406)%0A%0A def _check_header(self, key, value=None):%0A return key in self.request.headers and self.request.headers.get(key).lower() == (value or JSON_CONTENT).lower( )%0A%0Ad
c49daf9885e86ba08acdc8332d2a34bc5951a487
Increase limitancestorcount in tournament RPC test to showcase improved algorithm
test/functional/mempool_updatefromblock.py
test/functional/mempool_updatefromblock.py
#!/usr/bin/env python3 # Copyright (c) 2020-2021 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test mempool descendants/ancestors information update. Test mempool update of transaction descendants/ancestors information (count, size) when transactions have been re-added from a disconnected block to the mempool. """ import time from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal class MempoolUpdateFromBlockTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 self.extra_args = [['-limitdescendantsize=1000', '-limitancestorsize=1000']] def skip_test_if_missing_module(self): self.skip_if_no_wallet() def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', end_address='', fee=Decimal(0.00100000)): """Create an acyclic tournament (a type of directed graph) of transactions and use it for testing. Keyword arguments: size -- the order N of the tournament which is equal to the number of the created transactions n_tx_to_mine -- the number of transaction that should be mined into a block If all of the N created transactions tx[0]..tx[N-1] reside in the mempool, the following holds: the tx[K] transaction: - has N-K descendants (including this one), and - has K+1 ancestors (including this one) More details: https://en.wikipedia.org/wiki/Tournament_(graph_theory) """ if not start_input_txid: start_input_txid = self.nodes[0].getblock(self.nodes[0].getblockhash(1))['tx'][0] if not end_address: end_address = self.nodes[0].getnewaddress() first_block_hash = '' tx_id = [] tx_size = [] self.log.info('Creating {} transactions...'.format(size)) for i in range(0, size): self.log.debug('Preparing transaction #{}...'.format(i)) # Prepare inputs. if i == 0: inputs = [{'txid': start_input_txid, 'vout': 0}] inputs_value = self.nodes[0].gettxout(start_input_txid, 0)['value'] else: inputs = [] inputs_value = 0 for j, tx in enumerate(tx_id[0:i]): # Transaction tx[K] is a child of each of previous transactions tx[0]..tx[K-1] at their output K-1. vout = i - j - 1 inputs.append({'txid': tx_id[j], 'vout': vout}) inputs_value += self.nodes[0].gettxout(tx, vout)['value'] self.log.debug('inputs={}'.format(inputs)) self.log.debug('inputs_value={}'.format(inputs_value)) # Prepare outputs. tx_count = i + 1 if tx_count < size: # Transaction tx[K] is an ancestor of each of subsequent transactions tx[K+1]..tx[N-1]. n_outputs = size - tx_count output_value = ((inputs_value - fee) / Decimal(n_outputs)).quantize(Decimal('0.00000001')) outputs = {} for _ in range(n_outputs): outputs[self.nodes[0].getnewaddress()] = output_value else: output_value = (inputs_value - fee).quantize(Decimal('0.00000001')) outputs = {end_address: output_value} self.log.debug('output_value={}'.format(output_value)) self.log.debug('outputs={}'.format(outputs)) # Create a new transaction. unsigned_raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) signed_raw_tx = self.nodes[0].signrawtransactionwithwallet(unsigned_raw_tx) tx_id.append(self.nodes[0].sendrawtransaction(signed_raw_tx['hex'])) tx_size.append(self.nodes[0].getmempoolentry(tx_id[-1])['vsize']) if tx_count in n_tx_to_mine: # The created transactions are mined into blocks by batches. self.log.info('The batch of {} transactions has been accepted into the mempool.'.format(len(self.nodes[0].getrawmempool()))) block_hash = self.generate(self.nodes[0], 1)[0] if not first_block_hash: first_block_hash = block_hash assert_equal(len(self.nodes[0].getrawmempool()), 0) self.log.info('All of the transactions from the current batch have been mined into a block.') elif tx_count == size: # At the end all of the mined blocks are invalidated, and all of the created # transactions should be re-added from disconnected blocks to the mempool. self.log.info('The last batch of {} transactions has been accepted into the mempool.'.format(len(self.nodes[0].getrawmempool()))) start = time.time() self.nodes[0].invalidateblock(first_block_hash) end = time.time() assert_equal(len(self.nodes[0].getrawmempool()), size) self.log.info('All of the recently mined transactions have been re-added into the mempool in {} seconds.'.format(end - start)) self.log.info('Checking descendants/ancestors properties of all of the in-mempool transactions...') for k, tx in enumerate(tx_id): self.log.debug('Check transaction #{}.'.format(k)) entry = self.nodes[0].getmempoolentry(tx) assert_equal(entry['descendantcount'], size - k) assert_equal(entry['descendantsize'], sum(tx_size[k:size])) assert_equal(entry['ancestorcount'], k + 1) assert_equal(entry['ancestorsize'], sum(tx_size[0:(k + 1)])) def run_test(self): # Use batch size limited by DEFAULT_ANCESTOR_LIMIT = 25 to not fire "too many unconfirmed parents" error. self.transaction_graph_test(size=100, n_tx_to_mine=[25, 50, 75]) if __name__ == '__main__': MempoolUpdateFromBlockTest().main()
Python
0
@@ -779,16 +779,43 @@ ze=1000' +, '-limitancestorcount=100' %5D%5D%0A%0A
6a8bae5e796b842ae9dd8ab51beb9cadea961305
version bump
transitions/version.py
transitions/version.py
__version__ = '0.2.2'
Python
0.000001
@@ -12,11 +12,11 @@ = '0.2. -2 +3 '%0A
6174580057cc1c54539f9f05bc09c6a80df1fe4b
Fix issue following rebase
app/questionnaire/create_questionnaire_manager.py
app/questionnaire/create_questionnaire_manager.py
from app.validation.validator import Validator from app.routing.routing_engine import RoutingEngine from app.navigation.navigator import Navigator from app.questionnaire.questionnaire_manager import QuestionnaireManager from app.main import errors from app.utilities.factory import factory from app.metadata.metadata_store import MetaDataStore from flask_login import current_user import logging from app.main.views.root import load_and_parse_schema logger = logging.getLogger(__name__) def create_questionnaire_manager(): metadata = MetaDataStore.get_instance(current_user) eq_id = metadata.get_eq_id() form_type = metadata.get_form_type() logger.debug("Requested questionnaire %s for form type %s", eq_id, form_type) schema = load_and_parse_schema(eq_id, form_type) if not schema: return errors.page_not_found() # load the response store response_store = factory.create("response-store") # load the validation store validation_store = factory.create("validation-store") # Create the validator validator = Validator(schema, validation_store, response_store) # Create the routing engine routing_engine = RoutingEngine(schema, response_store) # load the navigation history navigation_history = factory.create("navigation-history") # create the navigator navigator = Navigator(schema, navigation_history) # if navigator.get_current_location() == "introduction" or navigator.get_current_location() is None: # navigator.go_to('questionnaire') # instantiate the questionnaire manager questionnaire_manager = QuestionnaireManager(schema, response_store, validator, validation_store, routing_engine, navigator, navigation_history, metadata) return questionnaire_manager def create_test_survey_manager(): metadata = factory.create("metadata-store") logger.debug("Requested test questionnaire") from app.test_survey.test_survey import test_questionnaire as schema # load the response store response_store = factory.create("response-store") # load the validation store validation_store = factory.create("validation-store") # Create the validator validator = Validator(schema, validation_store, response_store) # Create the routing engine routing_engine = RoutingEngine(schema, response_store) # load the navigation history navigation_history = factory.create("navigation-history") # create the navigator navigator = Navigator(schema, navigation_history) # if navigator.get_current_location() == "introduction" or navigator.get_current_location() is None: # navigator.go_to('questionnaire') # instantiate the questionnaire manager questionnaire_manager = QuestionnaireManager(schema, response_store, validator, validation_store, routing_engine, navigator, navigation_history, metadata) return questionnaire_manager
Python
0.000001
@@ -2174,39 +2174,47 @@ a = -factory.create(%22metadata-store%22 +MetaDataStore.get_instance(current_user )%0A%0A
b7b78a9282e2a4ee776020f83812e3abd437467b
Corrige erro de QuerySet immutable
djangosige/apps/cadastro/views/cliente.py
djangosige/apps/cadastro/views/cliente.py
# -*- coding: utf-8 -*- from django.core.urlresolvers import reverse_lazy from djangosige.apps.cadastro.forms import ClienteForm from djangosige.apps.cadastro.models import Cliente from .base import AdicionarPessoaView, PessoasListView, EditarPessoaView class AdicionarClienteView(AdicionarPessoaView): template_name = "cadastro/pessoa_add.html" success_url = reverse_lazy('cadastro:listaclientesview') success_message = "Cliente <b>%(nome_razao_social)s </b>adicionado com sucesso." permission_codename = 'add_cliente' def get_context_data(self, **kwargs): context = super(AdicionarClienteView, self).get_context_data(**kwargs) context['title_complete'] = 'CADASTRAR CLIENTE' context['return_url'] = reverse_lazy('cadastro:listaclientesview') context['tipo_pessoa'] = 'cliente' return context def get(self, request, *args, **kwargs): form = ClienteForm(prefix='cliente_form') return super(AdicionarClienteView, self).get(request, form, *args, **kwargs) def post(self, request, *args, **kwargs): request.POST._mutable = True request.POST['cliente_form-limite_de_credito'] = request.POST['cliente_form-limite_de_credito'].replace( '.', '') form = ClienteForm(request.POST, request.FILES, prefix='cliente_form', request=request) return super(AdicionarClienteView, self).post(request, form, *args, **kwargs) class ClientesListView(PessoasListView): template_name = 'cadastro/pessoa_list.html' model = Cliente context_object_name = 'all_clientes' success_url = reverse_lazy('cadastro:listaclientesview') permission_codename = 'view_cliente' def get_context_data(self, **kwargs): context = super(ClientesListView, self).get_context_data(**kwargs) context['title_complete'] = 'CLIENTES CADASTRADOS' context['add_url'] = reverse_lazy('cadastro:addclienteview') context['tipo_pessoa'] = 'cliente' return context class EditarClienteView(EditarPessoaView): form_class = ClienteForm model = Cliente template_name = "cadastro/pessoa_edit.html" success_url = reverse_lazy('cadastro:listaclientesview') success_message = "Cliente <b>%(nome_razao_social)s </b>editado com sucesso." permission_codename = 'change_cliente' def get_context_data(self, **kwargs): context = super(EditarClienteView, self).get_context_data(**kwargs) context['return_url'] = reverse_lazy('cadastro:listaclientesview') context['tipo_pessoa'] = 'cliente' return context def get(self, request, *args, **kwargs): self.object = self.get_object() form_class = self.get_form_class() form_class.prefix = "cliente_form" form = self.get_form(form_class) return super(EditarClienteView, self).get(request, form, *args, **kwargs) def post(self, request, *args, **kwargs): request.POST['cliente_form-limite_de_credito'] = request.POST['cliente_form-limite_de_credito'].replace( '.', '') self.object = self.get_object() form_class = self.get_form_class() form = form_class(request.POST, request.FILES, prefix='cliente_form', instance=self.object, request=request) return super(EditarClienteView, self).post(request, form, *args, **kwargs)
Python
0.000001
@@ -1096,33 +1096,35 @@ req -uest.POST._mutable = True +_post = request.POST.copy() %0A @@ -1127,33 +1127,29 @@ %0A req -uest.POST +_post %5B'cliente_fo @@ -1172,33 +1172,29 @@ dito'%5D = req -uest.POST +_post %5B'cliente_fo @@ -1238,32 +1238,64 @@ '.', '')%0A + request.POST = req_post%0A form = C @@ -2991,33 +2991,68 @@ %0A req -uest.POST +_post = request.POST.copy()%0A req_post %5B'cliente_fo @@ -3079,25 +3079,21 @@ '%5D = req -uest.POST +_post %5B'client @@ -3141,32 +3141,64 @@ '.', '')%0A + request.POST = req_post%0A self.obj
a2a26ed8b216c4a40db7a384571d05c690e25cef
Update test expectation
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' 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)
Python
0.000001
@@ -207,16 +207,40 @@ Top.D.%5Cn +%5CnFail Check A.mA.axA.%5Cn '%0A%0AGET_E
aba35816752dabc67ec0382d769fd1a39e0f7275
change address
dwitter/settings/base.py
dwitter/settings/base.py
""" Django settings for dwitter project. Generated by 'django-admin startproject' using Django 1.9. For more information on this file, see https://docs.djangoproject.com/en/1.9/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.9/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_URL = 'http://lionleaf.org/dwitter' REGISTRATION_OPEN = True # If True, users can register ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value. REGISTRATION_AUTO_LOGIN = True # If True, the user will be automatically logged in. LOGIN_REDIRECT_URL = BASE_URL # The page you want users to arrive at after they successful log in LOGIN_URL = BASE_URL + '/accounts/login/' # The page users are directed to if they are not logged in, # and are trying to access pages requiring authentication # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ ALLOWED_HOSTS = [] TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, }, ] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'registration', 'dwitter', 'dwitter.user', 'dwitter.feed', ] # List of callables that know how to import templates from various sources. #TEMPLATE_LOADERS = ( # 'django.template.loaders.filesystem.Loader', # 'django.template.loaders.app_directories.Loader', # # 'django.template.loaders.eggs.Loader', # ) MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'dwitter.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'dwitter.wsgi.application' # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/1.9/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, "static/")
Python
0.000003
@@ -472,16 +472,24 @@ 'http:// +dwitter. lionleaf @@ -493,23 +493,16 @@ eaf.org/ -dwitter '%0A%0AREGIS
48a89b4cdb2e084f4b349e9ca12a91daba9e0734
Fix build with Python 3
spyne/test/transport/test_msgpack.py
spyne/test/transport/test_msgpack.py
# # spyne - Copyright (C) Spyne contributors. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 # import msgpack from spyne import Application, ServiceBase, rpc from spyne.model import Unicode from spyne.protocol.msgpack import MessagePackDocument from twisted.trial import unittest class TestMessagePackServer(unittest.TestCase): def gen_prot(self, app): from spyne.server.twisted.msgpack import TwistedMessagePackProtocol from twisted.test.proto_helpers import StringTransportWithDisconnection from spyne.server.msgpack import MessagePackServerBase prot = TwistedMessagePackProtocol(MessagePackServerBase(app)) transport = StringTransportWithDisconnection() prot.makeConnection(transport) transport.protocol = prot return prot def test_roundtrip(self): v = "yaaay!" class SomeService(ServiceBase): @rpc(Unicode, _returns=Unicode) def yay(ctx, u): return u app = Application([SomeService], 'tns', in_protocol=MessagePackDocument(), out_protocol=MessagePackDocument()) prot = self.gen_prot(app) request = msgpack.packb({'yay': [v]}) prot.dataReceived(msgpack.packb([1, request])) val = prot.transport.value() print repr(val) val = msgpack.unpackb(val) print repr(val) self.assertEquals(val, [0, msgpack.packb(v)]) def test_roundtrip_deferred(self): from twisted.internet import reactor from twisted.internet.task import deferLater v = "yaaay!" p_ctx = [] class SomeService(ServiceBase): @rpc(Unicode, _returns=Unicode) def yay(ctx, u): def _cb(): return u p_ctx.append(ctx) return deferLater(reactor, 0.1, _cb) app = Application([SomeService], 'tns', in_protocol=MessagePackDocument(), out_protocol=MessagePackDocument()) prot = self.gen_prot(app) request = msgpack.packb({'yay': [v]}) def _ccb(_): val = prot.transport.value() print repr(val) val = msgpack.unpackb(val) print repr(val) self.assertEquals(val, [0, msgpack.packb(v)]) prot.dataReceived(msgpack.packb([1, request])) return p_ctx[0].out_object[0].addCallback(_ccb)
Python
0.000001
@@ -2028,33 +2028,33 @@ ()%0A print - +( repr(val)%0A @@ -2038,32 +2038,33 @@ print(repr(val) +) %0A val = m @@ -2088,33 +2088,33 @@ l)%0A print - +( repr(val)%0A%0A @@ -2098,32 +2098,33 @@ print(repr(val) +) %0A%0A self.a @@ -2935,33 +2935,33 @@ print - +( repr(val)%0A @@ -2949,24 +2949,25 @@ nt(repr(val) +) %0A @@ -3011,17 +3011,17 @@ print - +( repr(val @@ -3021,16 +3021,17 @@ epr(val) +) %0A%0A
6cdc05abb5777656684d18cfb215aa7dbcb10c43
Create indexes if not created
scripts/install/create_tables_cloudsql.py
scripts/install/create_tables_cloudsql.py
#! /usr/bin/env python import sys import os sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "engine", "src")) import MySQLdb import time from juliabox.db import JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxInstanceProps, JBPluginDB, JBoxAPISpec, JBoxUserProfile from juliabox.jbox_util import JBoxCfg # import any plugins that contribute tables import juliabox.plugins.course_homework import juliabox.plugins.usage_accounting def table_exists(table_name): try: c.execute("select * from %s where 1=0" % (table_name,)) c.fetchall() return c.description is not None except: return False def table_create(table_name, columns=None, types=None, keys=None, keys_types=None): stmt = [] if keys is not None: for k, t in zip(keys, keys_types): stmt.append('`' + k + '` ' + t) if columns is not None: for col, t in zip(columns, types): stmt.append('`' + col + '` ' + t) sql = 'create table `%s` (%s' % (table_name, ', '.join(stmt)) if keys is not None: sql += (', primary key (%s)' % (', '.join(keys),)) sql += ')' c.execute(sql) conn.commit() def indexes_create(table_name, indexes): if indexes == None: return for idx in indexes: name = idx['name'] cols = ', '.join('`' + idx['cols'] + '`') sql = "CREATE INDEX `%s` ON `%s`(%s)" % (name, table_name, cols) c.execute(sql) conn.commit() def get_connection(): # Copy from /jboxengine/conf/jbox.user conf = None with open('/jboxengine/conf/jbox.user') as f: conf = eval(f.read()) db = conf['db'] user = db['user'] passwd = db['passwd'] unix_socket = db['unix_socket'] db = db['db'] return MySQLdb.connect(user=user, passwd=passwd, db=db, unix_socket=unix_socket) conn = get_connection() c = conn.cursor() tables = [JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxInstanceProps, JBoxAPISpec, JBoxUserProfile] for plugin in JBPluginDB.jbox_get_plugins(JBPluginDB.JBP_TABLE_DYNAMODB): tables.append(plugin) for cls in tables: print("Creating %s..." % (cls.NAME,)) if table_exists(cls.NAME): print("\texists already!") else: table_create(cls.NAME, cls.ATTRIBUTES, cls.TYPES, cls.KEYS, cls.KEYS_TYPES) indexes_create(cls.NAME, cls.SQL_INDEXES) print("\tcreated.") print('Creating scale_up_time') if table_exists('scale_up_time'): print('\texists already!') else: table_create('scale_up_time', ['scale_up_time'], ['INT']) c.execute('INSERT INTO scale_up_time (scale_up_time) VALUES (%d)' % int(time.time())) conn.commit() print('\tcreated.') print('Creating mails') if table_exists('mails'): print('\texists already!') else: table_create('mails', ['rcpt', 'sender', 'timestamp'], ['VARCHAR(200)', 'VARCHAR(200)', 'INT']) print('\tcreated.')
Python
0.000002
@@ -1173,24 +1173,159 @@ n.commit()%0A%0A +def index_exists(tname, iname):%0A f = c.execute(%22show index from %60%25s%60 where Key_name=%5C%22%25s%5C%22%22 %25 (tname, iname))%0A return f is not 0%0A %0Adef indexes @@ -1374,24 +1374,62 @@ es == None:%0A + print(%22No indexes to create%22)%0A retu @@ -1482,16 +1482,129 @@ 'name'%5D%0A + if index_exists(table_name, name):%0A print(%22Index %25s already exists%22 %25 name)%0A else:%0A @@ -1625,16 +1625,37 @@ in('%60' + + col + '%60' for col in idx%5B'co @@ -1662,16 +1662,14 @@ ls'%5D - + '%60')%0A +)%0A @@ -1737,32 +1737,36 @@ , cols)%0A + + c.execute(sql)%0A @@ -1768,24 +1768,28 @@ ql)%0A + conn.commit( @@ -1790,16 +1790,60 @@ ommit()%0A + print(%22Created index %25s%22 & name) %0A%0Adef ge @@ -2674,24 +2674,121 @@ _TYPES)%0A + print(%22%5Ctcreated.%22)%0A%0Afor cls in tables:%0A print(%22Creating indexes for %25s...%22 %25 (cls.NAME))%0A indexes_ @@ -2824,36 +2824,8 @@ XES) -%0A print(%22%5Ctcreated.%22) %0A%0Apr
0dcad3ac5f3754fedf12c7aca7050ec6ab85840d
fix merge cleaning
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", <<<<<<< HEAD "MobtechMlHttpTransport", "SmsghSmppTransport", ======= "TtcBfHttpTransport", >>>>>>> feature/burkina "ForwardHttp"]
Python
0
@@ -770,21 +770,8 @@ t%22,%0A -%3C%3C%3C%3C%3C%3C%3C HEAD%0A @@ -840,16 +840,8 @@ t%22,%0A -=======%0A @@ -873,32 +873,8 @@ t%22,%0A -%3E%3E%3E%3E%3E%3E%3E feature/burkina%0A
14e437772c50dfb35f394f4aa99a2aefd188c077
fix unused i
scripts/monitoring/cron-send-build-app.py
scripts/monitoring/cron-send-build-app.py
#!/usr/bin/env python ''' Quick and dirty create application check for v3 ''' # Adding the ignore because it does not like the naming of the script # to be different than the class name # pylint: disable=invalid-name # the to-many-branches import subprocess import json import time import re import urllib import sys import os # Our jenkins server does not include these rpms. # In the future we might move this to a container where these # libs might exist #pylint: disable=import-error from openshift_tools.monitoring.zagg_sender import ZaggSender class OpenShiftOC(object): ''' Class to wrap the oc command line tools ''' @staticmethod def get_pod(pod_name, proj_name, verbose=False): '''return a pod by name ''' pods = OpenShiftOC.get_pods(proj_name=proj_name, verbose=verbose) #get pod except the build pod regex = re.compile('%s-[0-9]-(?!build)[a-z0-9]{5}$' % pod_name) for pod in pods['items']: results = regex.search(pod['metadata']['name']) if results: if verbose: print 'find normal pod' return pod return None @staticmethod def get_build_pod(pod_name, proj_name, verbose=False): '''return a pod by name ''' pods = OpenShiftOC.get_pods(proj_name=proj_name, verbose=verbose) #get the build pod regex = re.compile('%s-[0-9]-build' % pod_name) for pod in pods['items']: results = regex.search(pod['metadata']['name']) if results: if verbose: print 'find build pod' return pod return None @staticmethod def get_pods(pod_name='', proj_name='', verbose=False): '''return all pods ''' cmd = ['get', 'pods', '--no-headers', '-o', 'json'] if pod_name: cmd = ['get', 'pods', '--no-headers', pod_name, '-o', 'json'] if proj_name: cmd.append('-n%s'%proj_name) return json.loads(OpenShiftOC.oc_cmd(cmd, verbose)) @staticmethod def new_app(path, proj_name, verbose=False): '''run new-app ''' cmd = ['new-app', path, '-n', proj_name] return OpenShiftOC.oc_cmd(cmd, verbose) @staticmethod def delete_project(name, verbose=False): '''delete project ''' cmd = ['delete', 'project', name] results = OpenShiftOC.oc_cmd(cmd, verbose) time.sleep(5) return results @staticmethod def new_project(name, verbose=False): '''create new project ''' cmd = ['project'] results = OpenShiftOC.oc_cmd(cmd, verbose) curr_project = results.split()[2].strip('"') cmd = ['new-project', name] rval = OpenShiftOC.oc_cmd(cmd, verbose) cmd = ['project', curr_project] results = OpenShiftOC.oc_cmd(cmd, verbose) return rval @staticmethod def get_projects(verbose=False): '''get all projects ''' cmd = ['get', 'projects', '--no-headers'] results = [proj.split()[0] for proj in OpenShiftOC.oc_cmd(cmd).split('\n') if proj and len(proj) > 0] if verbose: print results return results @staticmethod def get_route(proj_name='', verbose=False): '''return all the route ''' cmd = ['get', 'route', '--no-headers', '-o', 'json'] if proj_name: cmd.append('-n%s'%proj_name) return json.loads(OpenShiftOC.oc_cmd(cmd, verbose)) @staticmethod def oc_cmd(cmd, verbose=False): '''Base command for oc ''' cmds = ['/usr/bin/oc'] cmds.extend(cmd) if verbose: print ' '.join(cmds) proc = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, \ env={'KUBECONFIG': '/etc/origin/master/admin.kubeconfig'}) proc.wait() if proc.returncode == 0: output = proc.stdout.read() if verbose: print output print return output return "Error: %s. Return: %s" % (proc.returncode, proc.stderr.read()) def curl(ip_addr, port): ''' Open an http connection to the url and read ''' return urllib.urlopen('http://%s:%s' % (ip_addr, port)).code def check_route(app, proj_name='', verbose=False): ''' after the pod been deployed ,check the route if get 200 ''' pod = OpenShiftOC.get_pod(app, proj_name, verbose) create_app_func = 1 if pod and pod['status']['phase'] == 'Running' and pod['status'].has_key('podIP'): myroute = OpenShiftOC.get_route(proj_name, verbose) if myroute: hostip = myroute["items"][0]["spec"]["host"] httpstatus = curl(hostip, 80) if verbose: print 'The route is : %s' % myroute["items"][0]["spec"]["host"] print 'The httpstatus of route is : %s' % httpstatus if httpstatus == 200: create_app_func = 0 return create_app_func def main(): ''' Do the application creation ''' proj_name = 'ops-monitor-appbuild' + os.environ['ZAGG_CLIENT_HOSTNAME'] app = 'nodejs-example' verbose = False verbose = True start_time = time.time() if proj_name in OpenShiftOC.get_projects(verbose): OpenShiftOC.delete_project(proj_name, verbose) OpenShiftOC.new_project(proj_name, verbose) OpenShiftOC.new_app(app, proj_name, verbose) #1 is error create_app = 1 BuildTime = 0 CreateTime = 0 # Now we wait until the pod comes up for _ in range(24): time.sleep(10) #checking the building pod buildPod = OpenShiftOC.get_build_pod(app, proj_name, verbose) if buildPod and buildPod['status']['phase'] == 'Failed': print 'fail' break if buildPod and buildPod['status']['phase'] == 'Succeeded': BuildTime = time.time() - start_time for i in range(24): time.sleep(5) create_app = check_route(app, proj_name, verbose) if create_app == 0: CreateTime = time.time() - start_time print 'success' print 'Time: %s' % CreateTime print 'BuildTime: %s' % BuildTime break if create_app == 0: break else: if verbose: print 'Time: %s' % str(time.time() - start_time) print 'fail' if proj_name in OpenShiftOC.get_projects(verbose): OpenShiftOC.delete_project(proj_name, verbose) zgs = ZaggSender() zgs.add_zabbix_keys({'openshift.master.app.build.create': create_app}) zgs.add_zabbix_keys({'openshift.master.app.create.time': CreateTime}) zgs.add_zabbix_keys({'openshift.master.app.build.time': BuildTime}) zgs.send_metrics() if __name__ == "__main__": main()
Python
0
@@ -305,16 +305,17 @@ urllib%0A +# import s @@ -6074,17 +6074,17 @@ for -i +_ in rang
6e213791d63267088c5bceaa98ce21dbff196167
Remove cpu restriction from android task.
scripts/slave/recipes/swarming/staging.py
scripts/slave/recipes/swarming/staging.py
# Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Swarming staging recipe: runs tests for HEAD of chromium using HEAD of swarming_client toolset on Swarming staging server instances (*-dev.appspot.com). Intended to catch bugs in swarming_client and Swarming servers early on, before full roll out. Waterfall page: https://build.chromium.org/p/chromium.swarm/waterfall """ DEPS = [ 'bot_update', 'chromium', 'commit_position', 'file', 'gclient', 'isolate', 'json', 'path', 'platform', 'properties', 'step', 'swarming', 'swarming_client', 'test_results', 'test_utils', ] def RunSteps(api): # Configure isolate & swarming modules to use staging instances. api.isolate.isolate_server = 'https://isolateserver-dev.appspot.com' api.swarming.swarming_server = 'https://chromium-swarm-dev.appspot.com' api.swarming.verbose = True # Run tests from chromium.swarm buildbot with a relatively high priority # so that they take precedence over manually triggered tasks. api.swarming.default_priority = 20 # Do not care about the OS specific version on Canary. api.swarming.set_default_dimension( 'os', api.swarming.prefered_os_dimension(api.platform.name).split('-', 1)[0]) api.swarming.set_default_dimension('pool', 'Chrome') api.swarming.add_default_tag('project:chromium') api.swarming.add_default_tag('purpose:staging') api.swarming.default_idempotent = True # We are building simplest Chromium flavor possible. if api.properties.get('platform') == 'android': api.chromium.set_config( 'android', BUILD_CONFIG=api.properties.get('configuration', 'Release')) else: api.chromium.set_config( 'chromium', BUILD_CONFIG=api.properties.get('configuration', 'Release')) # We are checking out Chromium with swarming_client dep unpinned and pointing # to ToT of swarming_client repo, see recipe_modules/gclient/config.py. api.gclient.set_config('chromium') if api.properties.get('platform') == 'android': api.gclient.apply_config('android') api.gclient.c.solutions[0].custom_vars['swarming_revision'] = '' api.gclient.c.revisions['src/tools/swarming_client'] = 'HEAD' # Enable test isolation. Modifies GYP_DEFINES used in 'runhooks' below. api.isolate.set_isolate_environment(api.chromium.c) api.chromium.cleanup_temp() # Checkout chromium + deps (including 'master' of swarming_client). step_result = api.bot_update.ensure_checkout() if not step_result.json.output['did_run']: api.gclient.checkout() # Ensure swarming_client version is fresh enough. api.swarming.check_client_version() targets = ['chromium_swarm_tests'] if api.properties.get('platform') == 'android': targets = ['ui_android_unittests_apk_run'] # Build all supported tests. api.chromium.runhooks() api.isolate.clean_isolated_files(api.chromium.output_dir) api.chromium.compile(targets=targets) api.isolate.remove_build_metadata() # Will search for *.isolated.gen.json files in the build directory and isolate # corresponding targets. api.isolate.isolate_tests( api.chromium.output_dir, verbose=True, env={'SWARMING_PROFILE': '1'}) # Make swarming tasks that run isolated tests. tasks = [ api.swarming.gtest_task( test, isolated_hash, shards=2, test_launcher_summary_output=api.test_utils.gtest_results( add_json_log=False)) for test, isolated_hash in sorted(api.isolate.isolated_tests.iteritems()) ] for task in tasks: if task.title.endswith('_apk'): # pragma: no cover task.dimensions['os'] = 'Android' task.dimensions['android_devices'] = '1' for task in tasks: api.swarming.trigger_task(task) # And wait for ALL them to finish. with api.step.defer_results(): for task in tasks: api.swarming.collect_task(task) # TODO(estaab): Move this into the swarming recipe_module behind a flag # after testing on staging. step_result = api.step.active_result gtest_results = getattr(step_result.test_utils, 'gtest_results', None) if gtest_results and gtest_results.raw: # This is a potentially large json file (on the order of 10s of MiB) but # swarming/api.py is already parsing it to get failed shards so we reuse # it here. parsed_gtest_data = gtest_results.raw chrome_revision_cp = api.bot_update.properties.get( 'got_revision_cp', 'x@{#0}') chrome_revision = str(api.commit_position.parse_revision( chrome_revision_cp)) webkit_revision = api.bot_update.properties.get( 'got_webkit_revision', '0') api.test_results.upload( api.json.input(parsed_gtest_data), chrome_revision=chrome_revision, webkit_revision=webkit_revision, test_type=task.title, test_results_server='test-results-test.appspot.com') def GenTests(api): for platform in ('linux', 'win', 'mac'): for configuration in ('Debug', 'Release'): yield ( api.test('%s_%s' % (platform, configuration)) + api.platform.name(platform) + api.properties.scheduled() + api.properties(configuration=configuration) ) # One 'collect' fails due to a missing shard and failing test, should not # prevent the second 'collect' from running. yield ( api.test('one_fails') + api.platform.name('linux') + api.properties.scheduled() + api.properties(configuration='Debug') + api.override_step_data( 'dummy_target_1 on Ubuntu', api.test_utils.canned_gtest_output( passing=False, minimal=True, extra_json={'missing_shards': [1]}), ) ) yield ( api.test('android') + api.platform.name('linux') + api.properties.scheduled() + api.properties(configuration='Release', platform='android') #api.override_step_data( # 'dummy_target_1 on Android', # # TODO(maruel): It's not going to generate gtest output. # #api.test_utils.canned_gtest_output(True) #) )
Python
0.999996
@@ -3771,16 +3771,49 @@ '%5D = '1' +%0A del task.dimensions%5B'cpu'%5D %0A%0A for
9c7b79cab06a955f4f2b8909b9bd0590069ee7d7
remove pdb
temp_script/inventory.py
temp_script/inventory.py
# -*- coding: utf-8 -*- ############################################################################### # # Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>). # # 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/>. # ############################################################################### import os import sys import logging import openerp import xlsxwriter import openerp.netsvc as netsvc import openerp.addons.decimal_precision as dp from openerp.osv import fields, osv, expression, orm from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from openerp import SUPERUSER_ID, api from openerp import tools from openerp.tools.translate import _ from openerp.tools.float_utils import float_round as round from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare) from inventory_present import product_present _logger = logging.getLogger(__name__) class ResCompany(orm.Model): """ Model name: ResCompany """ _inherit = 'res.company' def force_first_supplier(self, cr, uid, ids, context=None): ''' Force first supplier ''' product_pool = self.pool.get('product.product') product_ids = product_pool.search(cr, uid, [], context=context) first_supplier = {} import pdb; pdb.set_trace() for product in product_pool.browse( cr, uid, product_ids, context=context): old_date = False supplier_id = False for seller in product.seller_ids: for pl in seller.pricelist_ids: current_date = pl.write_date if not old_date or old_date < current_date: old_date = current_date supplier_id = seller.name.id if supplier_id: first_supplier[product.id] = supplier_id # Loop for write: import pdb; pdb.set_trace() for product_id, seller_id in first_supplier.iteritems(): product_pool.write(cr, uid, product_id, { 'first_supplier_id': seller_id, }, context=context) return True def export_mailing_list(self, cr, uid, ids, context=None): ''' Export mailing list ''' def write_xls_line(line): ''' Write line in correct WS with mode selection ''' col = 0 for item in line: self.WS.write(self.counter, col, item) col += 1 self.counter += 1 return # XLS generate file: xls = '/home/administrator/photo/output/mailing.xlsx' _logger.warning('Log file: %s' % xls) WB = xlsxwriter.Workbook(xls) self.WS = WB.add_worksheet('Partner') self.counter = 0 # Write Header line: write_xls_line(( 'Ciente', 'Fornitore', 'Azienda', 'Indirizzo', 'Camcard', 'Email', 'Nome', 'Citta', 'Nazione', 'Email', 'Sito', 'Telefono', 'Cat. Stat.', 'Newsletter', 'Tipo', 'Zona', )) partner_pool = self.pool.get('res.partner') partner_ids = partner_pool.search(cr, uid, [], order='name', context=context) for partner in partner_pool.browse( cr, uid, partner_ids, context=context): write_xls_line(( 'X' if partner.customer else '', 'X' if partner.supplier else '', 'X' if partner.is_company else '', 'X' if partner.is_address else '', 'X' if partner.camcard_text else '', 'X' if partner.email else '', partner.name, partner.city, partner.country_id.name, partner.email, partner.website, partner.phone, partner.statistic_category_id.name, partner.newsletter_category_id.name, partner.type_id.name, partner.zone_id.name, )) return True def lavoration_inventory_modification(self, cr, uid, ids, context=None): ''' Export data from lavoration ''' out_file = '/home/administrator/photo/output/lavoration_problem.csv' out_f = open(out_file, 'w') _logger.warning('Export lavoration problem: %s' % out_file) pick_pool = self.pool.get('stock.picking') pick_ids = pick_pool.search(cr, uid, [], order='name', context=context) out_f.write('Doc.|Create|Write|Date|Code|Qty|INV.\n') for pick in pick_pool.browse(cr, uid, pick_ids, context=context): for line in pick.sl_quants_ids: row = '%s|%s|%s|%s|%s|%s|%s\n' % ( # Header: pick.name, pick.create_date, pick.write_date, pick.date, # Line: line.product_id.default_code, line.qty, line.product_id.mx_start_qty, ) out_f.write(row.replace('.', ',')) _logger.warning('End export lavoration') out_f.close() return True def inventory_to_reset(self, cr, uid, ids, context=None): ''' Check error during operation on bom ''' out_file = '/home/administrator/photo/log/product_to_reset' out_file_jump = '/home/administrator/photo/log/product_to_reset_jumped' out_f = open(out_file, 'w') out_jump = open(out_file_jump, 'w') # Pool used: product_pool = self.pool.get('product.product') # Check HW bon link: product_ids = product_pool.search(cr, uid, [ ('default_code', 'not in', product_present), ], context=context) for product in product_pool.browse( cr, uid, product_ids, context=context): if not product.default_code or product.default_code[:1] not in \ '1234567890G': out_jump.write('%s|0\n' % product.default_code) continue out_f.write('%s|0\n' % product.default_code) out_f.close() out_jump.close()
Python
0.000024
@@ -2003,43 +2003,8 @@ %7B%7D%0A - import pdb; pdb.set_trace() %0A @@ -2593,44 +2593,8 @@ te:%0A - import pdb; pdb.set_trace()%0A
6722b8494a847ca62f77874f41ee47abc08c2a09
Move the images to the left
flumotion/component/converters/overlay/genimg.py
flumotion/component/converters/overlay/genimg.py
# -*- Mode: Python -*- # vi:si:et:sw=4:sts=4:ts=4 # # flumotion/component/converters/overlay/genimg.py: overlay image generator # # Flumotion - a streaming media server # Copyright (C) 2004 Fluendo (www.fluendo.com) # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # See "LICENSE.GPL" in the source distribution for more information. # This program is also licensed under the Flumotion license. # See "LICENSE.Flumotion" in the source distribution for more information. import os from PIL import Image from PIL import ImageChops from PIL import ImageDraw from PIL import ImageFont from PIL import ImageOps directory = os.path.split(os.path.abspath(__file__))[0] fontpath = os.path.join(directory, 'Vera.ttf') logopath = directory fluendoLogoPath = os.path.join(logopath, 'fluendo.24x24.png') ccLogoPath = os.path.join(logopath, 'cc.24x24.png') xiphLogoPath = os.path.join(logopath, 'xiph.24x24.png') TEXT_XOFFSET = 4 TEXT_YOFFSET = 4 WIDTH = 24 BORDER = 4 FONT_SIZE = 22 def generate_overlay(filename, text, show_fluendo, show_cc, show_xiph, width, height): image = Image.new("RGBA", (width, height)) draw = ImageDraw.Draw(image) # inheriting color mode font = ImageFont.truetype(fontpath, FONT_SIZE) draw.text((TEXT_XOFFSET+2, TEXT_YOFFSET+2), text, font=font, fill='black') draw.text((TEXT_XOFFSET, TEXT_YOFFSET), text, font=font) # How many logos we're going to show logos = len([i for i in (show_fluendo, show_cc, show_xiph) if i]) # This is really *NOT* the optimal way of doing this. # We should really find out a better way of adding an image on # another image (with an offset) imax = max(width, height) y_corr = -(abs(width - height) + WIDTH + BORDER) if show_xiph: xiph = Image.open(xiphLogoPath) xiph = ImageOps.expand(xiph, imax) xiph = ImageChops.offset(xiph, logos * -(WIDTH + BORDER), y_corr) image = ImageChops.add_modulo(image, xiph) logos -= 1 if show_cc: cc = Image.open(ccLogoPath) cc = ImageOps.expand(cc, imax) cc = ImageChops.offset(cc, logos * -(WIDTH + BORDER), y_corr) image = ImageChops.add_modulo(image, cc) logos -= 1 if show_fluendo: fluendo = Image.open(fluendoLogoPath) fluendo = ImageOps.expand(fluendo, imax) fluendo = ImageChops.offset(fluendo, -(WIDTH + BORDER), y_corr) image = ImageChops.add_modulo(image, fluendo) if os.path.exists(filename): os.unlink(filename) image.save(filename, 'png') if __name__ == '__main__': generate_overlay('test.png', 'Testing', True, True, True, 320, 240)
Python
0.000003
@@ -1714,17 +1714,21 @@ ) if i%5D) + - 1 %0A - %0A # T @@ -2111,32 +2111,29 @@ ph, -logos * -(WIDTH + BORDER +-width + (WIDTH*logos ), y @@ -2348,32 +2348,29 @@ cc, -logos * -(WIDTH + BORDER +-width + (WIDTH*logos ), y @@ -2611,24 +2611,13 @@ o, - -(WIDTH + BORDER) +width , y_ @@ -2780,16 +2780,16 @@ 'png')%0A%0A - if __nam @@ -2807,24 +2807,97 @@ ain__': %0A + #generate_overlay('test.png', 'Testing', True, True, True, 320, 240)%0A generate
f66cee94d2ae4ba12cc8d56c40be0d2e07f69a5a
Tag 0.0.2
swingtix/bookkeeper/__init__.py
swingtix/bookkeeper/__init__.py
__VERSION__='0.0.1.1'
Python
0.000002
@@ -13,10 +13,23 @@ '0.0.1.1 +-29-gdc751f0M '%0A
88a7b3251d96513111e20282e840d5e0f68aa9c8
Remove unused import
InvenTree/label/apps.py
InvenTree/label/apps.py
import os import shutil import logging from django.db.utils import IntegrityError from django.apps import AppConfig from django.conf import settings logger = logging.getLogger(__name__) class LabelConfig(AppConfig): name = 'label' def ready(self): """ This function is called whenever the label app is loaded """ self.create_stock_item_labels() self.create_stock_location_labels() def create_stock_item_labels(self): """ Create database entries for the default StockItemLabel templates, if they do not already exist """ try: from .models import StockItemLabel except: # Database might not by ready yet return src_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'templates', 'stockitem', ) dst_dir = os.path.join( settings.MEDIA_ROOT, 'label', 'inventree', 'stockitem', ) if not os.path.exists(dst_dir): logger.info(f"Creating missing directory: '{dst_dir}'") os.makedirs(dst_dir, exist_ok=True) labels = [ { 'file': 'qr.html', 'name': 'QR Code', 'description': 'Simple QR code label', }, ] for label in labels: filename = os.path.join( 'label', 'inventree', 'stockitem', label['file'], ) # Check if the file exists in the media directory src_file = os.path.join(src_dir, label['file']) dst_file = os.path.join(settings.MEDIA_ROOT, filename) if not os.path.exists(dst_file): logger.info(f"Copying label template '{dst_file}'") shutil.copyfile(src_file, dst_file) try: # Check if a label matching the template already exists if StockItemLabel.objects.filter(label=filename).exists(): continue logger.info(f"Creating entry for StockItemLabel '{label['name']}'") StockItemLabel.objects.create( name=label['name'], description=label['description'], label=filename, filters='', enabled=True ) except: pass def create_stock_location_labels(self): """ Create database entries for the default StockItemLocation templates, if they do not already exist """ try: from .models import StockLocationLabel except: # Database might not yet be ready return src_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'templates', 'stocklocation', ) dst_dir = os.path.join( settings.MEDIA_ROOT, 'label', 'inventree', 'stocklocation', ) if not os.path.exists(dst_dir): logger.info(f"Creating missing directory: '{dst_dir}'") os.makedirs(dst_dir, exist_ok=True) labels = [ { 'file': 'qr.html', 'name': 'QR Code', 'description': 'Simple QR code label', }, { 'file': 'qr_and_text.html', 'name': 'QR and text', 'description': 'Label with QR code and name of location', } ] for label in labels: filename = os.path.join( 'label', 'inventree', 'stocklocation', label['file'], ) # Check if the file exists in the media directory src_file = os.path.join(src_dir, label['file']) dst_file = os.path.join(settings.MEDIA_ROOT, filename) if not os.path.exists(dst_file): logger.info(f"Copying label template '{dst_file}'") shutil.copyfile(src_file, dst_file) try: # Check if a label matching the template already exists if StockLocationLabel.objects.filter(label=filename).exists(): continue logger.info(f"Creating entry for StockLocationLabel '{label['name']}'") StockLocationLabel.objects.create( name=label['name'], description=label['description'], label=filename, filters='', enabled=True ) except: pass
Python
0.000001
@@ -37,51 +37,8 @@ ng%0A%0A -from django.db.utils import IntegrityError%0A from
2b05069ffb00c1174a0286b20ebef7b2914d3402
Fix python2 but
xpathwebdriver/solve_settings.py
xpathwebdriver/solve_settings.py
# -*- coding: utf-8 -*- ''' xpathwebdriver Copyright (c) 2014 Juju. Inc Code Licensed under MIT License. See LICENSE file. ''' import rel_imp; rel_imp.init() import imp import importlib import logging import json import os logger = logging.getLogger('solve_settings') class ConfigVar(object): def __init__(self, doc=None, default=None, parser=None, experimental=False): self.value = default self.parser = parser or self._solve_parser(default) self.name = None self.doc = doc self.experimental = experimental def _solve_parser(self, value): parser = type(value) if parser == bool: parser = eval return parser def parse(self, value_str): return self.parser(value_str) def __bool__(self): return bool(self.value) class BaseSettings(object): def __init__(self): self._load_env_vars() if self.webdriver_remote_credentials_path: path = self.webdriver_remote_credentials_path.value with open(path, 'r') as fp: cred = json.load(fp) self._set_and_warn(path, 'webdriver_remote_command_executor', cred) self._set_and_warn(path, 'webdriver_remote_session_id', cred) def _set_and_warn(self, path, attr, values): if getattr(self, attr): logger.warning('Replacing value for %s with values in file %s', attr, path) setattr(self, attr, values[attr]) def _load_env_vars(self): ''' Support loading from environment variables ''' config_vars = self._get_config_vars() self._check_mispelling_deprecated(config_vars) for env_var, cfg_var in config_vars.items(): if env_var in os.environ: logger.debug('Using %s=%r => %s', env_var, os.environ[env_var], cfg_var.name) setattr(self, cfg_var.name, cfg_var.parse(os.environ[env_var])) def _check_mispelling_deprecated(self, config_vars): name2cfg = {cfg.name:cfg for cfg in config_vars.values()} for n in dir(self): if n.startswith('_'): continue if n not in name2cfg: logger.warning('Config variable %r not supported (mispelled/deprecated?)', n) def _get_config_vars(self): #Import here to avoid chicken-egg problem from .default_settings import DefaultSettings config = {} for n in dir(DefaultSettings): if n.startswith('_'): continue cfg_var = getattr(self, n) if not isinstance(cfg_var, ConfigVar): cfg_var = ConfigVar(cfg_var) cfg_var.name = cfg_var.name or n config['XPATHWD_' + n.upper()] = cfg_var return config class SettingsWrapper(object): ''' Provide the .get(name, default=None) method for accessing an object's attributes. Useful for configuration. ''' def __init__(self, settings): self._settings = settings def _get_config_vars(self): return self._settings._get_config_vars() def get(self, name, default=None): if hasattr(self._settings, name): value = getattr(self._settings, name) value = value.value if isinstance(value, ConfigVar) else value return value return default def set(self, name, value): setattr(self._settings, name, value) def register_settings(settings_path): ''' Register settings given specific module path. :param settings_path: ''' if isinstance(settings_path, str): # http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path mod = imp.load_source('specific_xpathwebdriver_settings', settings_path) _register_settings_module(mod) else: register_settings_instance(settings_path) set_log_level() def _register_settings_module(mod): if hasattr(mod, 'Settings'): settings_cls = mod.Settings else: settings_cls = mod.DefaultSettings register_settings_instance(settings_cls()) global_settings = None def register_settings_instance(settings): if not settings: logging.debug('Provided settings object evals to False', settings) return global global_settings if global_settings: logging.debug('Replacing existing settings %r (old) with %r (new)', global_settings, settings) global_settings = SettingsWrapper(settings) def set_log_level(): # Set the level of the root logger # import here due chicke-egg problem from .base import XpathWdBase from .logger import Logger _set_log_level(XpathWdBase, Logger) def _set_log_level(base_cls, logger_cls): logger_cls.default_level = global_settings.get('log_level_default') base_cls.log.setLevel(global_settings.get('log_level_default')) def solve_settings(): return _solve_settings('xpathwebdriver.default_settings') def _solve_settings(default_mod): ''' Main function for getting xpathwebdrivertest global settings. #TODO: this goes against any Encapsulated Environment Pattern (context) ''' global global_settings if not global_settings: _register_settings_module(importlib.import_module(default_mod)) return global_settings def smoke_test_module(): from .logger import log_test global called_once called_once = True log_test(solve_settings()) #set_log_level() if __name__ == "__main__": smoke_test_module()
Python
0.000069
@@ -948,24 +948,30 @@ entials_path +.value :%0A @@ -4233,16 +4233,22 @@ rovided +empty settings @@ -4252,29 +4252,10 @@ ngs -object evals to False +%25s ', s
101dae4f5a12605a791b0f81fb2ff599cbf2facb
Return early
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) 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))
Python
0.000233
@@ -1547,18 +1547,21 @@ -else:%0A + return 0%0A @@ -1570,36 +1570,32 @@ r r in renames:%0A - r.execut @@ -1610,28 +1610,24 @@ op_dir)%0A - - org.remove_e @@ -1650,20 +1650,16 @@ op_dir)%0A - path @@ -1700,20 +1700,16 @@ es)%0A - - with api @@ -1739,28 +1739,24 @@ er:%0A - for p in pat @@ -1759,20 +1759,16 @@ paths:%0A -
6035ef056f6ca028828faad68a0a0954e581300e
Set L=4 to try other topology
ext/viro_constant.py
ext/viro_constant.py
# 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' }
Python
0.000002
@@ -14,17 +14,17 @@ t L%0AL = -3 +4 %0A%0A# OPER
252376693ae28f901321d1141e86508d4be29a74
add iOS 7.0 DistroVersion enum
cerbero/enums.py
cerbero/enums.py
# cerbero - a multi-platform build system for Open Source software # Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. class Platform: ''' Enumeration of supported platforms ''' LINUX = 'linux' WINDOWS = 'windows' DARWIN = 'darwin' ANDROID = 'android' IOS = 'ios' class Architecture: ''' Enumeration of supported acrchitectures ''' X86 = 'x86' X86_64 = 'x86_64' PPC = 'ppc' UNIVERSAL = 'universal' ARM = 'arm' ARMv7 = 'armv7' class Distro: ''' Enumeration of supported distributions ''' DEBIAN = 'debian' REDHAT = 'redhat' SUSE = 'suse' WINDOWS = 'windows' OS_X = 'osx' IOS = 'ios' ANDROID = 'android' class DistroVersion: ''' Enumeration of supported distribution versions ''' DEBIAN_SQUEEZE = 'debian_squeeze' DEBIAN_WHEEZY = 'debian_wheezy' DEBIAN_JESSIE = 'debian_jessy' UBUNTU_MAVERICK = 'ubuntu_maverick' UBUNTU_LUCID = 'ubuntu_lucid' UBUNTU_NATTY = 'ubuntu_natty' UBUNTU_ONEIRIC = 'ubuntu_oneiric' UBUNTU_PRECISE = 'ubuntu_precise' UBUNTU_QUANTAL = 'ubuntu_quantal' UBUNTU_RARING = 'ubuntu_raring' UBUNTU_SAUCY = 'ubuntu_saucy' FEDORA_16 = 'fedora_16' FEDORA_17 = 'fedora_17' FEDORA_18 = 'fedora_18' FEDORA_19 = 'fedora_19' FEDORA_20 = 'fedora_20' REDHAT_6 = 'redhat_6' OPENSUSE_12_1 = 'opensuse_12_1' OPENSUSE_12_2 = 'opensuse_12_2' OPENSUSE_12_3 = 'opensuse_12_3' WINDOWS_XP = 'windows_xp' WINDOWS_VISTA = 'windows_vista' WINDOWS_7 = 'windows_7' WINDOWS_8 = 'windows_8' OS_X_MAVERICKS = 'osx_mavericks' OS_X_MOUNTAIN_LION = 'osx_mountain_lion' OS_X_LION = 'osx_lion' OS_X_SNOW_LEOPARD = 'osx_snow_leopard' OS_X_LEOPARD = 'osx_leopard' IOS_6_0 = 'ios_6_0' IOS_6_1 = 'ios_6_1' ANDROID_GINGERBREAD = 'android_gingerbread' # API Level 9 ANDROID_ICE_CREAM_SANDWICH = 'android_ice_cream_sandwich' # API Level 14 ANDROID_JELLY_BEAN = 'android_jelly_bean' # API Level 16 class LicenseDescription: def __init__(self, acronym, pretty_name): self.acronym = acronym self.pretty_name = pretty_name class License: ''' Enumeration of licensesversions ''' AFLv2_1 = LicenseDescription('AFL-2.1', 'Academic Free License, version 2.1') Apachev2 = LicenseDescription('Apache-2.0', 'Apache License, version 2.0') BSD = LicenseDescription('BSD', 'BSD License') BSD_like = LicenseDescription('BSD-like', 'BSD-like License') CC_BY_SA = LicenseDescription('CC-BY-SA', 'Creative Commons Attribution-ShareAlike') FreeType = LicenseDescription('FreeType', 'FreeType License') Jasperv2 = LicenseDescription('Jasper-2.0', 'JasPer LicenseVersion 2.0') JPEG = LicenseDescription('JPEG', 'JasPer LicenseVersion 2.0') GFDL = LicenseDescription('GFDL', 'GNU Free Documentation License') GPL = LicenseDescription('GPL', 'GNU General Public License') GPLv1 = LicenseDescription('GPL-1', 'GNU General Public License, version 1') GPLv1Plus = LicenseDescription('GPL-1+', 'GNU General Public License, version 1 or later') GPLv2 = LicenseDescription('GPL-2', 'GNU General Public License, version 2') GPLv2Plus = LicenseDescription('GPL-2+', 'GNU General Public License, version 2 or later') GPLv3 = LicenseDescription('GPL-3', 'GNU General Public License, version 3') GPLv3Plus = LicenseDescription('GPL-3+', 'GNU General Public License, version 3 or later') LGPL = LicenseDescription('LGPL', 'GNU Lesser General Public License') LGPLv2 = LicenseDescription('LGPL-2', 'GNU Lesser General Public License, version 2') LGPLv2Plus = LicenseDescription('LGPL-2+', 'GNU Lesser General Public License, version 2 or later') LGPLv2_1 = LicenseDescription('LGPL-2.1', 'GNU Lesser General Public License, version 2.1') LGPLv2_1Plus = LicenseDescription('LGPL-2.1+', 'GNU Lesser General Public License, version 2.1 or later') LGPLv3 = LicenseDescription('LGPL-3', 'GNU Lesser General Public License, version 3') LGPLv3Plus = LicenseDescription('LGPL-3+', 'GNU Lesser General Public License, version 3 or later') LibPNG = LicenseDescription('LibPNG', 'LibPNG License') MIT = LicenseDescription('MIT', 'MIT License') Proprietary = LicenseDescription('Proprietary', 'Proprietary License')
Python
0.000011
@@ -2536,24 +2536,48 @@ = 'ios_6_1'%0A + IOS_7_0 = 'ios_7_0'%0A ANDROID_
fd1a6abb003832919eea99fce05e06188889527c
Change the urls import line. Fix #6
cerberos/urls.py
cerberos/urls.py
# -*- coding: utf-8 -*- from django.conf.urls.defaults import * from cerberos.views import * urlpatterns = patterns('', )
Python
0.000657
@@ -42,17 +42,8 @@ urls -.defaults imp
60034bb753c96a6773ea70d37f5fa3b438f7bed8
Update Chatbot._chain_filters() and _filter_recursive() to output a dictionary filters to a list of strings a given filter passed
chatbot_brain.py
chatbot_brain.py
import nltk import random import os from nltk import pos_tag from nltk.tokenize import wordpunct_tokenize from trainbot import Trainbot import input_filters import output_filters class Chatbot(Trainbot): def __init__(self, training_file=u"tell_tale_heart.txt"): super(Chatbot, self).__init__(training_file=u"tell_tale_heart.txt") self.training_file = training_file # self.funct_dict = {"filter_content": input_filters.filter_content, # "filter_length_words": input_filters.filter_length_words, # "filter_content_priority": input_filters.filter_content_priority} def i_filter_random(self, words, lexicon=None): u"""Return randomly selected, non-punctuation word from words.""" count = 0 while count < len(words): seed = random.choice(words) if (seed in self.bi_lexicon) and (seed not in self.stop_puncts): return seed count += 1 return u"What a funny thing to say!" def o_filter_random(self, sentences): u"""Return randomly selected sentence from sentecnces""" if len(sentences) > 0: return random.choice(sentences) else: return u"I'm not sure what to say about that." def _create_chains(self, pair, size=10): u"""Return list of markov generated strings spawned from the seed.""" candidates = [] w_1 = pair[0] w_2 = pair[1] while len(candidates) < size: word_1, word_2 = w_1, w_2 candidate = [word_1, word_2] pair = u"{} {}".format(word_1, word_2) done = False while not done: try: next_word = random.choice(self.tri_lexicon[pair]) candidate.append(next_word) word_1, word_2 = word_2, next_word pair = u"{} {}".format(word_1, word_2) except KeyError: candidates.append(" ".join(candidate)) done = True if next_word in self.stop_puncts: candidates.append(" ".join(candidate)) done = True return candidates def _pair_seed(self, seed): word_1 = seed word_2 = None while word_2 is None: try: next_ = random.choice(self.bi_lexicon[seed]) if next_ not in self.stop_puncts: word_2 = next_ pair = [word_1, word_2] except KeyError: continue return pair def _chain_filters(self, strings, filters): u"""Return a list of strings that satisfiy the requirements of all filters. Expects: A list of filter functions. Returns: A list of strings. """ return self._filter_recursive(strings, filters) def _filter_recursive(self, strings, filters): u"""Return list of strings or call the next filter function.""" if filters == []: return strings else: return self._filter_recursive(filters[0](strings), filters[1:]) def apply_o_filter(self, filter_, chains): if filter_ == u"filter_length": return output_filters.filter_length(chains) if filter_ == u"filter_pos": return output_filters.filter_pos(chains) else: return chains def compose_response( self, input_sent, input_key=None, output_filter=None, ): u"""Return a response sentence based on the input.""" # Tokenize input seeds = wordpunct_tokenize(input_sent) # Select seed based on input filter if input_key: print u"Input filter: {}".format(input_key) seeds = input_filters.input_funcs[input_key](seeds) if isinstance(seeds, basestring): return seeds # Randomly pick a seed from the returned possibilities. print seeds seed = self.i_filter_random(seeds) if seed == u"What a funny thing to say!": return seed # Create chains pair = self._pair_seed(seed) chains = self._create_chains(pair) # Return output of filter if output_filter != "default": print u"Output filter: {}".format(output_filter) filtered = output_filters.funct_dict[output_filter](chains) else: output = chains if len(filtered) > 0: output = self.o_filter_random(filtered) return output if __name__ == u'__main__': bot = Chatbot(training_file="Doctorow.txt") bot.fill_lexicon() print u"Filled the lexicon!" print bot.compose_response( u"My beautiful carriage is red and blue and it hums while I drive it!", u"Content Filter", u"filter_NN_VV" )
Python
0.000023
@@ -2859,38 +2859,54 @@ %22%22%22%0A -return +strings, output_dict = self._filter_re @@ -2930,16 +2930,52 @@ filters) +%0A return strings, output_dict %0A%0A de @@ -3008,32 +3008,48 @@ strings, filters +, output_dict=%7B%7D ):%0A u%22%22%22R @@ -3159,16 +3159,29 @@ strings +, output_dict %0A @@ -3179,32 +3179,99 @@ t%0A else:%0A + output_dict%5Bfilters%5B0%5D.__name__%5D = filters%5B0%5D(strings)%0A retu @@ -3328,16 +3328,29 @@ ters%5B1:%5D +, output_dict )%0A%0A d @@ -5099,28 +5099,202 @@ u%22 -filter_NN_VV%22%0A )%0A +Noun-Verb Filter%22%0A )%0A # strings = bot._create_chains(bot._pair_seed(%22carriage%22))%0A # filters = %5Boutput_filters.funct_dict%5B%22Length Filter%22%5D, output_filters.funct_dict%5B%22Noun-Verb Filter%22%5D%5D
95778ca8d83a7c3b4c87cfd5b89b470abfc58f6a
support to assign version and additional filter
check_version.py
check_version.py
#!/usr/bin/env python # 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 LICENSE for more details. # # Copyright (c) 2018 ScyllaDB import logging from avocado import Test class CheckVersionDB(object): def __init__(self, host, user, passwd): self.host = host self.user = user self.passwd = passwd self.db_name = 'housekeeping' self.connect() self.log = logging.getLogger('check_version_db') def connect(self): import MySQLdb self.db = MySQLdb.connect(host=self.host, user=self.user, passwd=self.passwd, db=self.db_name) self.cursor = self.db.cursor() def close(self): self.db.close() def reconnect(self): self.close() self.connect() def commit(self): self.db.commit() def execute(self, sql, verbose=True): self.log.debug('SQL: {}'.format(sql)) self.cursor.execute(sql) ret = self.cursor.fetchall() self.log.debug('RET: {}'.format(ret)) return ret def get_last_id(self, uuid, repoid, version, table='housekeeping.repo'): # get last id of test uuid last_id = 0 ret = self.execute('select * from {} where uuid="{}" and repoid="{}" and version="{}" order by -dt limit 1'.format(table, uuid, repoid, version)) if len(ret) > 0: last_id = ret[0][0] return last_id def check_new_record(self, uuid, repoid, version, last_id, table='housekeeping.repo'): # verify download repo of test uuid is collected to repo table self.commit() ret = self.execute('select * from {} where uuid="{}" and repoid="{}" and version="{}" and id > {}'.format(table, uuid, repoid, version, last_id)) return len(ret) > 0 class EmptyTest(Test): """ Workaround: We want Avocado to copy this module to VM, it will be used by scylla-artifacts.py But Avocado will raise error if the module doesn't contain valid subtest. So we add this empty test. :avocado: enable """ def test_empty(self): pass
Python
0
@@ -1566,16 +1566,21 @@ version +=None , table= @@ -1590,32 +1590,49 @@ usekeeping.repo' +, add_filter=None ):%0A # get @@ -1681,35 +1681,22 @@ -ret = self.execute( +sql = 'select @@ -1740,84 +1740,251 @@ %22%7B%7D%22 - and version=%22%7B%7D%22 order by -dt limit 1'.format(table, uuid, repoid, version) +'.format(table, uuid, repoid)%0A if version:%0A sql += ' and version=%22%7B%7D%22 '.format(version)%0A if add_filter:%0A sql += ' %7B%7D'.format(add_filter)%0A sql += ' order by -dt limit 1'%0A%0A ret = self.execute(sql )%0A @@ -2106,32 +2106,37 @@ repoid, version +=None , last_id, table @@ -2128,16 +2128,18 @@ last_id +=0 , table= @@ -2157,16 +2157,33 @@ ng.repo' +, add_filter=None ):%0A @@ -2278,35 +2278,22 @@ -ret = self.execute( +sql = 'select @@ -2337,84 +2337,257 @@ %22%7B%7D%22 - and version=%22%7B%7D%22 and id %3E %7B%7D'.format(table, uuid, repoid, version, last_id) +'.format(table, uuid, repoid)%0A if version:%0A sql += ' and version=%22%7B%7D%22 '.format(version)%0A if add_filter:%0A sql += ' %7B%7D'.format(add_filter)%0A sql += ' and id %3E %7B%7D'.format(last_id)%0A ret = self.execute(sql )%0A
bdcdeaea6eb760d91690439da43d72ef0673df48
change replace statement
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('_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()
Python
0.000266
@@ -523,9 +523,9 @@ e('_ -8 +n .jpg
54282a1b7c2ea707506078483cf806e9521f264c
update version number
fabsetup/_version.py
fabsetup/_version.py
__version__ = "0.7.6"
Python
0.000002
@@ -16,7 +16,7 @@ 0.7. -6 +7 %22%0A
7bc86a2cc5edbf17ed9cd80748ffe09ce5647fec
Remove %x usage
gtk/__init__.py
gtk/__init__.py
# -*- Mode: Python; py-indent-offset: 4 -*- # pygtk - Python bindings for the GTK toolkit. # Copyright (C) 1998-2003 James Henstridge # # gtk/__init__.py: initialisation file for gtk package. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA # this can go when things are a little further along try: import ltihooks del ltihooks except ImportError: pass # TRUE and FALSE constants ... import __builtin__ if not hasattr(__builtin__, 'True'): __builtin__.True = (1 == 1) __builtin__.False = (1 != 1) del __builtin__ FALSE = False TRUE = True import gobject as _gobject # load the required modules: import keysyms from _gtk import * import gdk # this is created by the _gtk import threads_init = gdk.threads_init threads_enter = gdk.threads_enter threads_leave = gdk.threads_leave idle_add = _gobject.idle_add idle_remove = _gobject.source_remove timeout_add = _gobject.timeout_add timeout_remove = _gobject.source_remove input_add = _gobject.io_add_watch input_add_full = _gobject.io_add_watch input_remove = _gobject.source_remove gdk.INPUT_READ = _gobject.IO_IN | _gobject.IO_HUP | _gobject.IO_ERR gdk.INPUT_WRITE = _gobject.IO_OUT | _gobject.IO_HUP gdk.INPUT_EXCEPTION = _gobject.IO_PRI # _gobject deprecation from types import ModuleType as _module class _GObjectWrapper(_module): from warnings import warn warn = staticmethod(warn) _gobject = _gobject def __getattr__(self, attr): self.warn('gtk._gobject is deprecated, use gobject directly instead') return getattr(self._gobject, attr) _gobject = _GObjectWrapper('gtk._gobject') del _GObjectWrapper, _module # other deprecated symbols class _Deprecated: from warnings import warn warn = staticmethod(warn) def __init__(self, func, oldname, module=''): self.func = func self.oldname = oldname self.name = func.__name__ if module: self.module = 'gtk.' + module else: self.module = 'gtk' def __repr__(self): return '<deprecated function %s at 0x%x>' % (self.oldname, id(self)) def __call__(self, *args, **kwargs): message = 'gtk.%s is deprecated, use %s.%s instead' % (self.oldname, self.module, self.name) # DeprecationWarning is imported from _gtk, so it's not the same # as the one found in exceptions. self.warn(message, DeprecationWarning) return self.func(*args, **kwargs) # old names compatibility ... mainloop = _Deprecated(main, 'mainloop') mainquit = _Deprecated(main_quit, 'mainquit') mainiteration = _Deprecated(main_iteration, 'mainiteration') load_font = _Deprecated(gdk.Font, 'load_font', 'gdk') load_fontset = _Deprecated(gdk.fontset_load, 'load_fontset', 'gdk') create_pixmap = _Deprecated(gdk.Pixmap, 'create_pixmap', 'gdk') create_pixmap_from_xpm = _Deprecated(gdk.pixmap_create_from_xpm, 'pixmap_create_from_xpm', 'gdk') create_pixmap_from_xpm_d = _Deprecated(gdk.pixmap_create_from_xpm_d, 'pixmap_create_from_xpm_d', 'gdk') del _Deprecated
Python
0.000001
@@ -2910,16 +2910,8 @@ n %25s - at 0x%25x %3E' %25 @@ -2928,18 +2928,8 @@ name -, id(self) )%0A @@ -4047,16 +4047,17 @@ 'gdk')%0A +%0A del _Dep
7e168cb4fbcf8c8cdca3dcf80557534f5ab647af
Remove invalid mentions from message entities (#1049)
telethon/client/messageparse.py
telethon/client/messageparse.py
import itertools import re from .users import UserMethods from .. import utils from ..tl import types class MessageParseMethods(UserMethods): # region Public properties @property def parse_mode(self): """ This property is the default parse mode used when sending messages. Defaults to `telethon.extensions.markdown`. It will always be either ``None`` or an object with ``parse`` and ``unparse`` methods. When setting a different value it should be one of: * Object with ``parse`` and ``unparse`` methods. * A ``callable`` to act as the parse method. * A ``str`` indicating the ``parse_mode``. For Markdown ``'md'`` or ``'markdown'`` may be used. For HTML, ``'htm'`` or ``'html'`` may be used. The ``parse`` method should be a function accepting a single parameter, the text to parse, and returning a tuple consisting of ``(parsed message str, [MessageEntity instances])``. The ``unparse`` method should be the inverse of ``parse`` such that ``assert text == unparse(*parse(text))``. See :tl:`MessageEntity` for allowed message entities. """ return self._parse_mode @parse_mode.setter def parse_mode(self, mode): self._parse_mode = utils.sanitize_parse_mode(mode) # endregion # region Private methods async def _replace_with_mention(self, entities, i, user): """ Helper method to replace ``entities[i]`` to mention ``user``, or do nothing if it can't be found. """ try: entities[i] = types.InputMessageEntityMentionName( entities[i].offset, entities[i].length, await self.get_input_entity(user) ) except (ValueError, TypeError): pass async def _parse_message_text(self, message, parse_mode): """ Returns a (parsed message, entities) tuple depending on ``parse_mode``. """ if parse_mode is (): parse_mode = self._parse_mode else: parse_mode = utils.sanitize_parse_mode(parse_mode) if not parse_mode: return message, [] message, msg_entities = parse_mode.parse(message) for i, e in enumerate(msg_entities): if isinstance(e, types.MessageEntityTextUrl): m = re.match(r'^@|\+|tg://user\?id=(\d+)', e.url) if m: user = int(m.group(1)) if m.group(1) else e.url await self._replace_with_mention(msg_entities, i, user) elif isinstance(e, (types.MessageEntityMentionName, types.InputMessageEntityMentionName)): await self._replace_with_mention(msg_entities, i, e.user_id) return message, msg_entities def _get_response_message(self, request, result, input_chat): """ Extracts the response message known a request and Update result. The request may also be the ID of the message to match. """ # Telegram seems to send updateMessageID first, then updateNewMessage, # however let's not rely on that just in case. if isinstance(request, int): msg_id = request else: msg_id = None for update in result.updates: if isinstance(update, types.UpdateMessageID): if update.random_id == request.random_id: msg_id = update.id break if isinstance(result, types.UpdateShort): updates = [result.update] entities = {} elif isinstance(result, (types.Updates, types.UpdatesCombined)): updates = result.updates entities = {utils.get_peer_id(x): x for x in itertools.chain(result.users, result.chats)} else: return found = None for update in updates: if isinstance(update, ( types.UpdateNewChannelMessage, types.UpdateNewMessage)): if update.message.id == msg_id: found = update.message break elif (isinstance(update, types.UpdateEditMessage) and not isinstance(request.peer, types.InputPeerChannel)): if request.id == update.message.id: found = update.message break elif (isinstance(update, types.UpdateEditChannelMessage) and utils.get_peer_id(request.peer) == utils.get_peer_id(update.message.to_id)): if request.id == update.message.id: found = update.message break if found: found._finish_init(self, entities, input_chat) return found # endregion
Python
0.000001
@@ -1795,16 +1795,52 @@ )%0A + return True %0A @@ -1887,12 +1887,20 @@ -pass +return False %0A%0A @@ -2346,39 +2346,79 @@ or i -, e in -enumerate(msg_entities): +reversed(range(len(msg_entities))):%0A e = msg_entities%5Bi%5D %0A @@ -2639,32 +2639,45 @@ + is_mention = await self._rep @@ -2713,24 +2713,107 @@ s, i, user)%0A + if not is_mention:%0A del msg_entities%5Bi%5D%0A @@ -2942,32 +2942,45 @@ %0A + is_mention = await self._rep @@ -3024,16 +3024,91 @@ user_id) +%0A if not is_mention:%0A del msg_entities%5Bi%5D %0A%0A
a0ac28b8d55654e6da02b96cb7c85270a3267f3d
Add links for development_status and maintainers keys
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", "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", ] }
Python
0
@@ -207,16 +207,77 @@ 1.0.0%22,%0A + # see https://odoo-community.org/page/development-status%0A %22dev @@ -542,24 +542,163 @@ -%22maintainers%22: %5B +# see https://odoo-community.org/page/maintainer-role for a description of the maintainer role and responsibilities%0A %22maintainers%22: %5B%22your-github-login%22 %5D,%0A
7f63e544c914ae4f08436f64d679d6965937a43c
fix login
login.py
login.py
#!/usr/bin/env python # -*- coding: utf-8 -*- # Author: Yuande Liu <miracle (at) gmail.com> from settings import USERNAME, PASSWORD import requests import lxml.html requests.adapters.DEFAULT_RETRIES = 3 def get_session(): """.. :py:method:: """ if not hasattr(get_session, 'session'): session = requests.Session() session.mount('http://', requests.adapters.HTTPAdapter(pool_connections=30, pool_maxsize=30, max_retries=3)) get_session.session = session return get_session.session class Login(object): uselsess_headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip,deflate,sdch', 'Accept-Language': 'zh-CN,en-US;q=0.8,en;q=0.6', 'Connection': 'keep-alive', 'Host': 'login.weibo.cn', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36', } data = { 'mobile': USERNAME, 'remember': 'on', 'submit': '登录', # 'password_8202': PASSWORD, # 'backURL': 'http%3A%2F%2Fweibo.cn%2Flogin', # 'backTitle': '新浪微博', # 'tryCount': '', # 'vk': '8202_653a_2216381998', # 'code': 'kwlj', # 'capId': '2_ccbdc8398cb418de', } posturl = 'http://login.weibo.cn/login/?rand=1759580283&backURL=http%3A%2F%2Fweibo.cn&backTitle=%E6%89%8B%E6%9C%BA%E6%96%B0%E6%B5%AA%E7%BD%91&vt=4' def __init__(self): self._login = None self.loginurl = 'http://login.weibo.cn/login/' self.session = get_session() def login(self): """ data `password_??` and `vk??` need update as time goes by. So, we get them in login page and post them all. `rand` in `posturl` also in login page's `form action`, but it is not important. """ back = self.session.get(self.loginurl) html = lxml.html.fromstring(back.content) password = html.cssselect('.c form input[type=password]')[0].get('name') for i in html.cssselect('.c form input[type=hidden]'): self.data[i.get('name')] = i.get('value') self.data[password] = PASSWORD self.session.post(self.posturl, data=self.data) self._login = True def get_login_session(self): if self._login != True: self.login() return self.session
Python
0.000002
@@ -1330,24 +1330,25 @@ de',%0A %7D%0A%0A +# posturl @@ -2226,32 +2226,286 @@ SSWORD%0A%0A +posturl = self.loginurl + html.cssselect('.c form%5Bmethod=post%5D')%5B0%5D.get('action')%0A%0A print('http://weibo.cn/interface/f/ttt/captcha/show.php?cpt=%7B%7D'.format(self.data%5B'capId'%5D))%0A self.data%5B'code'%5D = raw_input('input captcha code: ')%0A%0A self.session.pos @@ -2506,21 +2506,16 @@ on.post( -self. posturl,
2666ccea834598a1627a34da201bce0651011303
Remove discrete variables.
Orange/projection/pca.py
Orange/projection/pca.py
import sklearn.decomposition as skl_decomposition import Orange.data from Orange.misc.wrapper_meta import WrapperMeta from Orange.projection import SklProjector, Projection __all__ = ["PCA", "SparsePCA", "RandomizedPCA", "IncrementalPCA"] class PCA(SklProjector): __wraps__ = skl_decomposition.PCA name = 'pca' def __init__(self, n_components=None, copy=True, whiten=False, preprocessors=None): super().__init__(preprocessors=preprocessors) self.params = vars() def fit(self, X, Y=None): proj = self.__wraps__(**self.params) proj = proj.fit(X, Y) return PCAModel(proj, self.domain) class SparsePCA(SklProjector): __wraps__ = skl_decomposition.SparsePCA name = 'sparse pca' def __init__(self, n_components=None, alpha=1, ridge_alpha=0.01, max_iter=1000, tol=1e-8, method='lars', n_jobs=1, U_init=None, V_init=None, verbose=False, random_state=None, preprocessors=None): super().__init__(preprocessors=preprocessors) self.params = vars() def fit(self, X, Y=None): proj = self.__wraps__(**self.params) proj = proj.fit(X, Y) return PCAModel(proj, self.domain) class RandomizedPCA(SklProjector): __wraps__ = skl_decomposition.RandomizedPCA name = 'randomized pca' def __init__(self, n_components=None, copy=True, iterated_power=3, whiten=False, random_state=None, preprocessors=None): super().__init__(preprocessors=preprocessors) self.params = vars() def fit(self, X, Y=None): proj = self.__wraps__(**self.params) proj = proj.fit(X, Y) return PCAModel(proj, self.domain) class _LinearCombination: def __init__(self, attrs, weights, mean=None): self.attrs = attrs self.weights = weights self.mean = mean def __call__(self): if self.mean is None: return ' + '.join('{} * {}'.format(w, a.to_sql()) for a, w in zip(self.attrs, self.weights)) return ' + '.join('{} * ({} - {})'.format(w, a.to_sql(), m, w) for a, m, w in zip(self.attrs, self.mean, self.weights)) class PCAModel(Projection, metaclass=WrapperMeta): def __init__(self, proj, domain): def pca_variable(i): v = Orange.data.ContinuousVariable('PC %d' % i) v.compute_value = Projector(self, i) v.to_sql = _LinearCombination( domain.attributes, self.components_[:, i], getattr(self, 'mean_', None)) return v super().__init__(proj=proj) self.n_components = self.components_.shape[0] self.domain = Orange.data.Domain( [pca_variable(i) for i in range(self.n_components)], domain.class_vars, domain.metas) class IncrementalPCA(SklProjector): __wraps__ = skl_decomposition.IncrementalPCA name = 'incremental pca' def __init__(self, n_components=None, whiten=False, copy=True, batch_size=None, preprocessors=None): super().__init__(preprocessors=preprocessors) self.params = vars() def fit(self, X, Y=None): proj = self.__wraps__(**self.params) proj = proj.fit(X, Y) return IncrementalPCAModel(proj, self.domain) class IncrementalPCAModel(PCAModel): def partial_fit(self, data): if isinstance(data, Orange.data.Storage): self.proj.partial_fit(data.X) else: self.proj.partial_fit(data) self.__dict__.update(self.proj.__dict__) return self class Projector: def __init__(self, projection, feature): self.projection = projection self.feature = feature self.transformed = None def __call__(self, data): if data.domain != self.projection.pre_domain: data = data.from_table(self.projection.pre_domain, data) self.transformed = self.projection.transform(data.X) return self.transformed[:, self.feature] def __getstate__(self): d = dict(self.__dict__) d['transformed'] = None return d class RemotePCA: def __new__(cls, data, address='localhost:9465', batch=100, max_iter=100): from orangecontrib.remote import aborted, save_state import Orange.data.sql.table pca = Orange.projection.IncrementalPCA() percent = batch / data.approx_len() * 100 if percent < 100: data_sample = data.sample_percentage(percent, no_cache=True) else: data_sample = data data_sample.download_data(1000000) data_sample = Orange.data.Table.from_numpy( Orange.data.Domain(data_sample.domain.attributes), data_sample.X) model = pca(data_sample) save_state(model) for i in range(max_iter if percent < 100 else 0): data_sample = data.sample_percentage(percent, no_cache=True) data_sample.download_data(1000000) data_sample = Orange.data.Table.from_numpy( Orange.data.Domain(data_sample.domain.attributes), data_sample.X) model.partial_fit(data_sample) model.iteration = i save_state(model) if aborted(): break return model
Python
0.000018
@@ -112,16 +112,57 @@ perMeta%0A +from Orange.preprocess import Continuize%0A from Ora @@ -4372,16 +4372,162 @@ .table%0A%0A + cont = Continuize(multinomial_treatment=Continuize.Remove,%0A normalize_continuous=None)%0A data = cont(data)%0A
d45a0d97b978c18bb0a40e4cec6d3dab6ec2d566
fix loading crystal.json
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 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()
Python
0.000001
@@ -1655,16 +1655,81 @@ rt load%0A + from cctbx.crystal.crystal_model.serialize import load_crystal%0A reg_sw @@ -1806,33 +1806,33 @@ g_crystal = load -. +_ crystal(os.path. @@ -1957,17 +1957,17 @@ l = load -. +_ crystal(
eca33ec2a4307009b049e001e49329496bb0ce93
Update test_ethiopia.py
test/countries/test_ethiopia.py
test/countries/test_ethiopia.py
# -*- coding: utf-8 -*- # python-holidays # --------------- # A fast, efficient Python library for generating country, province and state # specific sets of holidays on the fly. It aims to make determining whether a # specific date is a holiday as fast and flexible as possible. # # Author: ryanss <ryanssdev@icloud.com> (c) 2014-2017 # dr-prodigy <maurizio.montel@gmail.com> (c) 2017-2021 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) import sys import unittest from datetime import date import holidays class TestEthiopia(unittest.TestCase): def setUp(self): self.holidays = holidays.ET() def test_2019(self): self.assertIn(date(2019, 1, 7), self.holidays) self.assertIn(date(2019, 1, 19), self.holidays) self.assertIn(date(2019, 3, 2), self.holidays) self.assertIn(date(2019, 4, 28), self.holidays) self.assertIn(date(2019, 4, 26), self.holidays) self.assertIn(date(2019, 5, 1), self.holidays) self.assertIn(date(2019, 5, 28), self.holidays) self.assertIn(date(2019, 9, 12), self.holidays) self.assertIn(date(2019, 9, 28), self.holidays) self.assertIn(date(2019, 11, 10), self.holidays) def test_ethiopian_christmas(self): self.assertIn(date(2019, 1, 7), self.holidays) def test_labour_day(self): self.assertIn(date(2019, 5, 1), self.holidays) def test_hijri_based(self): if sys.version_info >= (3, 6): import importlib.util if importlib.util.find_spec("hijri_converter"): self.holidays = holidays.EG(years=[2010]) self.assertIn(date(2019, 6, 5), self.holidays self.assertIn(date(2019, 8, 11), self.holidays) self.assertIn(date(2019, 11, 9), self.holidays) # eid_alfitr self.assertIn(date(2019, 6, 4), self.holidays) # eid_aladha self.assertIn(date(2019, 8, 11), self.holidays) # eid_elfetr_2010 self.assertIn(date(2010, 11, 15), self.holidays) # muhammad's birthday self.assertIn(date(2010, 2, 26), self.holidays)
Python
0.000001
@@ -1721,16 +1721,17 @@ holidays +) %0A
e318497949a340b3b821efbc4492c8605441fa47
reformat code
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 = 'you@whatever.com' DEFAULT_CONFIRMATION_SUBJECT = 'Please confirm your registration' DEFAULT_RESET_TEMPLATE = ( "{}/flask_praetorian/templates/reset_email.html".format( dirname(dirname(abspath(__file__))), ) ) DEFAULT_RESET_SENDER = 'you@whatever.com' 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'
Python
0.999729
@@ -82,21 +82,16 @@ ACES = %5B -%0A 'header' @@ -100,17 +100,16 @@ 'cookie' -%0A %5D%0ADEFAUL
028068ff338c2ac5ee2696a68a1574d84dd33900
Add Tiezi function
guba/yueping.py
guba/yueping.py
# -*- coding: utf-8 -*- import time import re from functools import * import grequests from bs4 import BeautifulSoup URL1 = 'http://guba.eastmoney.com/list,%s_1.html' URL2 = 'http://guba.eastmoney.com/list,%s_2.html' TIEZI_URL = 'http://guba.eastmoney.com/' tiezi_list = {} tiezi_ids = {} def gcrawler(urls): rs = (grequests.get(u, timeout=10) for u in urls) return grequests.map(rs, size=1000) def get_codes(cf): return list(map(lambda x: x.rstrip(), cf.readlines())) def init_tiezi_set(code): urls = [URL1 % (code), URL2 % (code)] resps = gcrawler(urls) try: list_pages = list(map(lambda x: BeautifulSoup(x.text, 'html.parser'), resps)) except: print(urls) tiezi_urls = extract_list_pages(list_pages) for tu in tiezi_urls: tiezi_ids[tu] = tu.split(',')[2].split('.')[0] return tiezi_urls def update_tiezi_set(code): gp_tiezi_set = tiezi_list[code] urls = [URL1 % (code)] resps = gcrawler(urls) try: list_pages = list(map(lambda x: BeautifulSoup(x.text, 'html.parser'), resps)) except: print(urls) new_tiezi_urls = extract_list_pages(list_pages) for tu in new_tiezi_urls: tiezi_ids[tu] = tu.split(',')[2].split('.')[0] gp_tiezi_set.update(new_tiezi_urls) tiezi_list[code] = gp_tiezi_set def extract_list_pages(list_pages): tiezi_doms = list(map(lambda x: x.select('div#articlelistnew div.articleh'), list_pages)) tiezi_list = reduce(lambda x, y: x+y, tiezi_doms) tiezi_urls = [] for x in tiezi_list: url_doms = x.select('span.l3 a') if not url_doms: continue url = url_doms[0]['href'] if 'http' in url: continue if '/' in url: url = url[1:] tiezi_urls.append(TIEZI_URL+url) return set(tiezi_urls) def get_yueping(urls): resps = gcrawler(urls) tiezis = [] for idx, x in enumerate(resps): try: x.encoding = 'utf-8' tiezis.append(BeautifulSoup(x.text, 'html.parser')) except Exception as e: print('Error: ' + urls[idx], 'URL error. ', e) continue yuedus = [] pingluns = [] titles = [] t_ids = [] for u in urls: t_ids.append(tiezi_ids[u]) for idx, t in enumerate(tiezis): zhuanping_doms = t.select('div#zwlist script') try: zhuanping_content = reduce(lambda x,y: x.text+y.text, zhuanping_doms) except Exception as e: print('Error: ', urls[idx], 'None Zhuan Ping content. ', e) continue yuedu = re.search('var num=(.*?);.*', zhuanping_content).group(1) pinglun_pattern = re.compile('.*var pinglun_num=(.*?);.*', re.S) pinglun = re.search(pinglun_pattern, zhuanping_content).group(1) title = t.select('div#zwconttbt')[0].text yuedus.append(yuedu) pingluns.append(pinglun) titles.append(title.strip()) return (t_ids, titles, yuedus, pingluns) def writecsv(t_ids, titles, yuedus, pingluns, wf): ttime = time.strftime("%Y-%m-%d %H:%M", time.localtime()) for t_id, t, y, p in zip(t_ids, titles, yuedus, pingluns): wf.write(t_id + ','+'"'+t+'"'+','+y+','+p+','+ttime+'\n') def main(): with open('code.txt', 'r') as rf: gupiaos = get_codes(rf) for gp in gupiaos: tiezi_list[gp] = init_tiezi_set(gp) with open('%s.csv' % gp, 'w', encoding='utf-8') as wf: wf.write('id,title,yuedu,pinglun,time\n') while True: print('start') s_time = time.time() try: for gp in gupiaos: update_tiezi_set(gp) print('Start to get %s: ....' % (gp)) tiezi_urls = list(tiezi_list[gp]) t_ids, titles, yuedus, pingluns = get_yueping(tiezi_urls) with open('%s.csv' % gp, 'a', encoding='utf-8') as wf: writecsv(t_ids, titles, yuedus, pingluns, wf) print('end') wait_time = 300 - (time.time() - s_time) if wait_time > 0: time.sleep(300) else: print('Longer than 5mins: ', len(tiezi_ids)) continue except KeyboardInterrupt: return 0 except Exception as e: print(e) continue if __name__ == '__main__': main()
Python
0.000001
@@ -4269,19 +4269,25 @@ e.sleep( -300 +wait_time )%0D%0A
df3960a00760138fe3837a8fe40ef99e28a721d0
Fix SSHExecuteOperator crash when using a custom ssh port
airflow/contrib/hooks/ssh_hook.py
airflow/contrib/hooks/ssh_hook.py
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # Ported to Airflow by Bolke de Bruin # # 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. # # This is a port of Luigi's ssh implementation. All credits go there. import subprocess from contextlib import contextmanager from airflow.hooks.base_hook import BaseHook from airflow.exceptions import AirflowException import logging class SSHHook(BaseHook): """ Light-weight remote execution library and utilities. Using this hook (which is just a convenience wrapper for subprocess), is created to let you stream data from a remotely stored file. As a bonus, :class:`SSHHook` also provides a really cool feature that let's you set up ssh tunnels super easily using a python context manager (there is an example in the integration part of unittests). :param key_file: Typically the SSHHook uses the keys that are used by the user airflow is running under. This sets the behavior to use another file instead. :type key_file: str :param connect_timeout: sets the connection timeout for this connection. :type connect_timeout: int :param no_host_key_check: whether to check to host key. If True host keys will not be checked, but are also not stored in the current users's known_hosts file. :type no_host_key_check: bool :param tty: allocate a tty. :type tty: bool :param sshpass: Use to non-interactively perform password authentication by using sshpass. :type sshpass: bool """ def __init__(self, conn_id='ssh_default'): conn = self.get_connection(conn_id) self.key_file = conn.extra_dejson.get('key_file', None) self.connect_timeout = conn.extra_dejson.get('connect_timeout', None) self.no_host_key_check = conn.extra_dejson.get('no_host_key_check', False) self.tty = conn.extra_dejson.get('tty', False) self.sshpass = conn.extra_dejson.get('sshpass', False) self.conn = conn def get_conn(self): pass def _host_ref(self): if self.conn.login: return "{0}@{1}".format(self.conn.login, self.conn.host) else: return self.conn.host def _prepare_command(self, cmd): connection_cmd = ["ssh", self._host_ref(), "-o", "ControlMaster=no"] if self.sshpass: connection_cmd = ["sshpass", "-e"] + connection_cmd else: connection_cmd += ["-o", "BatchMode=yes"] # no password prompts if self.conn.port: connection_cmd += ["-p", self.conn.port] if self.connect_timeout: connection_cmd += ["-o", "ConnectionTimeout={}".format(self.connect_timeout)] if self.no_host_key_check: connection_cmd += ["-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"] if self.key_file: connection_cmd += ["-i", self.key_file] if self.tty: connection_cmd += ["-t"] connection_cmd += cmd logging.debug("SSH cmd: {} ".format(connection_cmd)) return connection_cmd def Popen(self, cmd, **kwargs): """ Remote Popen :param cmd: command to remotely execute :param kwargs: extra arguments to Popen (see subprocess.Popen) :return: handle to subprocess """ prefixed_cmd = self._prepare_command(cmd) return subprocess.Popen(prefixed_cmd, **kwargs) def check_output(self, cmd): """ Executes a remote command and returns the stdout a remote process. Simplified version of Popen when you only want the output as a string and detect any errors. :param cmd: command to remotely execute :return: stdout """ p = self.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, stderr = p.communicate() if p.returncode != 0: # I like this better: RemoteCalledProcessError(p.returncode, cmd, self.host, output=output) raise AirflowException("Cannot execute {} on {}. Error code is: {}. Output: {}, Stderr: {}".format( cmd, self.conn.host, p.returncode, output, stderr)) return output @contextmanager def tunnel(self, local_port, remote_port=None, remote_host="localhost"): """ Creates a tunnel between two hosts. Like ssh -L <LOCAL_PORT>:host:<REMOTE_PORT>. Remember to close() the returned "tunnel" object in order to clean up after yourself when you are done with the tunnel. :param local_port: :type local_port: int :param remote_port: :type remote_port: int :param remote_host: :type remote_host: str :return: """ tunnel_host = "{0}:{1}:{2}".format(local_port, remote_host, remote_port) proc = self.Popen(["-L", tunnel_host, "echo -n ready && cat"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, ) ready = proc.stdout.read(5) assert ready == b"ready", "Did not get 'ready' from remote" yield proc.communicate() assert proc.returncode == 0, "Tunnel process did unclean exit (returncode {}".format(proc.returncode)
Python
0
@@ -3042,16 +3042,20 @@ %5B%22-p%22, +str( self.con @@ -3060,16 +3060,17 @@ onn.port +) %5D%0A%0A
3024d4628044a22d9fc1ec0032351d1da0d4ed1a
make code more concise and fix spelling
h5py/_hl/vds.py
h5py/_hl/vds.py
# This file is part of h5py, a Python interface to the HDF5 library. # # http://www.h5py.org # # Copyright 2008-2013 Andrew Collette and contributors # # License: Standard 3-clause BSD; see "license.txt" for full license terms # and contributor agreement. """ High-level interface for creating HDF5 virtual datasets """ from copy import deepcopy as copy from collections import namedtuple from .selections import SimpleSelection from .. import h5s, h5 from .. import version class VDSmap(namedtuple('VDSmap', ('vspace', 'file_name', 'dset_name', 'src_space'))): '''Defines a region in a virtual dataset mapping to part of a source dataset ''' vds_support = False hdf5_version = version.hdf5_version_tuple[0:3] if hdf5_version >= h5.get_config().vds_min_hdf5_version: vds_support = True class VirtualSource(object): """Source definition for virtual data sets. Instantiate this class to represent an entire source dataset, and then slice it to indicate which regions should be used in the virtual dataset. path_or_dataset The path to a file, or an h5py dataset. If a dataset is given, the other parameters are ignored, and the relevant values taken from the dataset instead. name The name of the source dataset within the file. shape A tuple giving the shape of the dataset. dtype Numpy dtype or string. maxshape The source dataset is resizable up to this shape. Use None for axes you want to be unlimited. """ def __init__(self, path_or_dataset, name=None, shape=None, dtype=None, maxshape=None): from .dataset import Dataset if isinstance(path_or_dataset, Dataset): if any(inp is not None for inp in [name, shape, dtype, maxshape]): failed = {k: v for k, v in {'name': name, 'shape': shape, 'dtype': dtype, 'maxshape': maxshape}.items() if v is not None} raise TypeError("If a Dataset is passed as the first argument " "then no other arguments maybe passed. You " "passed {failed}".format(failed=failed)) ds = path_or_dataset path = ds.file.filename name = ds.name shape = ds.shape dtype = ds.dtype maxshape = ds.maxshape else: path = path_or_dataset if name is None: raise TypeError("The name parameter is required when " "specifying a source by path") if shape is None: raise TypeError("The shape parameter is required when " "specifying a source by path") self.path = path self.name = name self.dtype = dtype if maxshape is None: self.maxshape = shape else: self.maxshape = tuple([h5s.UNLIMITED if ix is None else ix for ix in maxshape]) self.sel = SimpleSelection(shape) @property def shape(self): return self.sel.mshape def __getitem__(self, key): tmp = copy(self) tmp.sel = SimpleSelection(self.shape)[key] return tmp class VirtualLayout(object): """Object for building a virtual dataset. Instantiate this class to define a virtual dataset, assign to slices of it (using VirtualSource objects), and then pass it to group.create_virtual_dataset() to add the virtual dataset to a file. This class does not allow access to the data; the virtual dataset must be created in a file before it can be used. shape A tuple giving the shape of the dataset. dtype Numpy dtype or string. maxshape The source dataset is resizable up to this shape. Use None for axes you want to be unlimited. """ def __init__(self, shape, dtype=None, maxshape=None): self.shape = shape self.dtype = dtype self.maxshape = maxshape self.sources = [] def __setitem__(self, key, source): sel = SimpleSelection(self.shape)[key] self.sources.append(VDSmap(sel.id, source.path, source.name, source.sel.id))
Python
0.000123
@@ -1773,110 +1773,8 @@ t):%0A - if any(inp is not None%0A for inp in %5Bname, shape, dtype, maxshape%5D):%0A @@ -1814,28 +1814,24 @@ - - for k, v in%0A @@ -1830,20 +1830,16 @@ k, v in%0A - @@ -1883,20 +1883,16 @@ shape,%0A - @@ -1974,20 +1974,16 @@ - if v is @@ -1992,16 +1992,38 @@ t None%7D%0A + if failed: %0A @@ -2095,16 +2095,16 @@ ument %22%0A - @@ -2155,16 +2155,17 @@ ents may + be passe
ed54991dc764cb5374cc33e7b98c7284b75d4651
byte strings are byte strings
tests/hazmat/backends/test_commoncrypto.py
tests/hazmat/backends/test_commoncrypto.py
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import, division, print_function import binascii import pytest from cryptography import utils from cryptography.exceptions import InternalError, _Reasons from cryptography.hazmat.backends import _available_backends from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.ciphers.base import Cipher from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM from ...utils import raises_unsupported_algorithm @utils.register_interface(interfaces.CipherAlgorithm) class DummyCipher(object): name = "dummy-cipher" block_size = 128 @pytest.mark.skipif("commoncrypto" not in [i.name for i in _available_backends()], reason="CommonCrypto not available") class TestCommonCrypto(object): def test_supports_cipher(self): from cryptography.hazmat.backends.commoncrypto.backend import backend assert backend.cipher_supported(None, None) is False def test_register_duplicate_cipher_adapter(self): from cryptography.hazmat.backends.commoncrypto.backend import backend with pytest.raises(ValueError): backend._register_cipher_adapter( AES, backend._lib.kCCAlgorithmAES128, CBC, backend._lib.kCCModeCBC ) def test_handle_response(self): from cryptography.hazmat.backends.commoncrypto.backend import backend with pytest.raises(ValueError): backend._check_cipher_response(backend._lib.kCCAlignmentError) with pytest.raises(InternalError): backend._check_cipher_response(backend._lib.kCCMemoryFailure) with pytest.raises(InternalError): backend._check_cipher_response(backend._lib.kCCDecodeError) def test_nonexistent_aead_cipher(self): from cryptography.hazmat.backends.commoncrypto.backend import Backend b = Backend() cipher = Cipher( DummyCipher(), GCM(b"fake_iv_here"), backend=b, ) with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER): cipher.encryptor() def test_gcm_tag_with_only_aad(self): from cryptography.hazmat.backends.commoncrypto.backend import Backend b = Backend() key = binascii.unhexlify("1dde380d6b04fdcb004005b8a77bd5e3") iv = binascii.unhexlify("5053bf901463f97decd88c33") aad = binascii.unhexlify("f807f5f6133021d15cb6434d5ad95cf7d8488727") tag = binascii.unhexlify("4bebf3ff2cb67bb5444dda53bd039e22") cipher = Cipher(AES(key), GCM(iv), backend=b) encryptor = cipher.encryptor() encryptor.authenticate_additional_data(aad) encryptor.finalize() assert encryptor.tag == tag def test_gcm_ciphertext_with_no_aad(self): from cryptography.hazmat.backends.commoncrypto.backend import Backend b = Backend() key = binascii.unhexlify("e98b72a9881a84ca6b76e0f43e68647a") iv = binascii.unhexlify("8b23299fde174053f3d652ba") ct = binascii.unhexlify("5a3c1cf1985dbb8bed818036fdd5ab42") tag = binascii.unhexlify("23c7ab0f952b7091cd324835043b5eb5") pt = binascii.unhexlify("28286a321293253c3e0aa2704a278032") cipher = Cipher(AES(key), GCM(iv), backend=b) encryptor = cipher.encryptor() computed_ct = encryptor.update(pt) + encryptor.finalize() assert computed_ct == ct assert encryptor.tag == tag
Python
0.999999
@@ -2904,16 +2904,17 @@ hexlify( +b %221dde380 @@ -2973,16 +2973,17 @@ hexlify( +b %225053bf9 @@ -3035,16 +3035,17 @@ hexlify( +b %22f807f5f @@ -3113,16 +3113,17 @@ hexlify( +b %224bebf3f @@ -3542,16 +3542,17 @@ hexlify( +b %22e98b72a @@ -3611,16 +3611,17 @@ hexlify( +b %228b23299 @@ -3672,16 +3672,17 @@ hexlify( +b %225a3c1cf @@ -3742,16 +3742,17 @@ hexlify( +b %2223c7ab0 @@ -3811,16 +3811,17 @@ hexlify( +b %2228286a3
34f453262f956ae0cd9a0999e0e9f5ff798b0872
Allow a tail path to passed to create_job
tests/integration/base_integration_test.py
tests/integration/base_integration_test.py
#!/usr/bin/env python # -*- coding: utf-8 -*- ############################################################################### # Copyright 2015 Kitware 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. ############################################################################### import argparse import unittest import json import time import os import traceback import tempfile import hashlib import sys from StringIO import StringIO from girder_client import GirderClient, HttpError class BaseIntegrationTest(unittest.TestCase): def __init__(self, name, girder_url, girder_user, girder_password, job_timeout=60, cleanup=True): super(BaseIntegrationTest, self).__init__(name) self._job_id = None self._script_id = None self._output_folder_id = None self._input_folder_id = None self._girder_url = girder_url self._girder_user = girder_user self._girder_password = girder_password self._job_timeout = job_timeout self._data = 'Need more input!' self._cleanup = cleanup def setUp(self): url = '%s/api/v1' % self._girder_url self._client = GirderClient(apiUrl=url) self._client.authenticate(self._girder_user, self._girder_password) user = self._client.get('user/me') self._user_id = user['_id'] r = self._client.listFolder(self._user_id, 'user', name='Private') self.assertEqual(len(r), 1) self._private_folder_id = r[0]['_id'] def tearDown(self): if not self._cleanup: return if self._job_id: try: url = 'jobs/%s' % self._job_id self._client.delete(url) except Exception as e: traceback.print_exc() if self._script_id: try: url = 'scripts/%s' % self._script_id self._client.delete(url) except Exception: traceback.print_exc() if self._output_folder_id: try: url = 'folder/%s' % self._output_folder_id self._client.delete(url) except Exception: traceback.print_exc() if self._input_folder_id: try: url = 'folder/%s' % self._input_folder_id self._client.delete(url) except Exception: traceback.print_exc() def create_script(self, commands=[ 'sleep 10', 'cat CumulusIntegrationTestInput' ]): body = { 'commands': commands, 'name': 'CumulusIntegrationTestLob' } r = self._client.post('scripts', data=json.dumps(body)) self._script_id = r['_id'] def create_input(self, folder_name='CumulusInput'): r = self._client.createFolder(self._private_folder_id, 'CumulusInput') self._input_folder_id = r['_id'] size = len(self._data) item = self._client.uploadFile(self._input_folder_id, StringIO(self._data), 'CumulusIntegrationTestInput', size, parentType='folder') self._item_id = item['itemId'] def create_output_folder(self, folder_name='CumulusOutput'): r = self._client.createFolder(self._private_folder_id, folder_name) self._output_folder_id = r['_id'] def create_job(self, job_name='CumulusIntegrationTestJob'): body = { 'name': job_name, 'scriptId': self._script_id, 'output': [{ 'folderId': self._output_folder_id, 'path': '.' }], 'input': [ { 'folderId': self._input_folder_id, 'path': '.' } ] } job = self._client.post('jobs', data=json.dumps(body)) self._job_id = job['_id'] def submit_job(self, job_params={}): url = 'clusters/%s/job/%s/submit' % (self._cluster_id, self._job_id) self._client.put(url, data=json.dumps(job_params)) start = time.time() while True: time.sleep(1) r = self._client.get('jobs/%s' % self._job_id) if r['status'] in ['error', 'unexpectederror']: r = self._client.get('jobs/%s/log' % self._job_id) self.fail(str(r)) elif r['status'] == 'complete': break if time.time() - start > self._job_timeout: self.fail('Job didn\'t complete in timeout') def assert_output(self): r = self._client.listItem(self._output_folder_id) self.assertEqual(len(r), 4) stdout_item = None for i in r: if i['name'].startswith('CumulusIntegrationTestJob-%s.o' % self._job_id): stdout_item = i break self.assertIsNotNone(stdout_item) r = self._client.get('item/%s/files' % i['_id']) self.assertEqual(len(r), 1) path = os.path.join(tempfile.gettempdir(), self._job_id) try: self._client.downloadFile(r[0]['_id'], path) with open(path, 'rb') as fp: self.assertEqual(fp.read(), self._data) finally: if os.path.exists(path): os.remove(path) BaseIntegrationTest.parser = argparse.ArgumentParser(description='Run integration test', add_help=False) BaseIntegrationTest.parser.add_argument('-g', '--girder_user', help='', required=True) BaseIntegrationTest.parser.add_argument('-p', '--girder_password', help='', required=True) BaseIntegrationTest.parser.add_argument('-r', '--girder_url', help='', required=True)
Python
0.000001
@@ -3964,16 +3964,27 @@ TestJob' +, tail=None ):%0A @@ -4334,32 +4334,160 @@ %5D%0A %7D%0A%0A + if tail:%0A body%5B'output'%5D.append(%7B%0A %22path%22: tail,%0A %22tail%22: True%0A %7D)%0A%0A job = se
6410dd998d8b65674941b3f4d217d27a8084ec25
fix commit getter
hal/cvs/gits.py
hal/cvs/gits.py
#!/usr/bin/env python # coding: utf-8 """ Handles main models in git repository """ from git import Repo from unidiff import PatchSet from hal.cvs.versioning import Version class Diff: """ Git diff result """ ADD = 'added' DEL = 'removed' def __init__(self, diff): """ :param diff: git.Diff Diff between 2 commits """ self.d = diff def __str__(self): totals = self.get_totals() return "+", totals[self.ADD], " -", totals[self.DEL] def get_totals(self): """ :return: {} Dictionary with total additions and deletions """ total_added = 0 total_removed = 0 patch = PatchSet(self.d) total_added += sum([ edit.added for edit in patch ]) total_removed += sum([ edit.removed for edit in patch ]) return { self.ADD: total_added, self.DEL: total_removed } class Commit: """ Git repository commit """ def __init__(self, commit): """ :param commit: git.Commit Commit of repository """ self.c = commit def __str__(self, date_format="%H:%M:%S %y-%m-%d %z"): """ :param date_format: str Format date and time with this format :return: str Pretty description of commit """ hash_value = self.c.hexsha date_time = self.c.authored_datetime.strftime(date_format) return "(" + hash_value + ") at " + date_time def get_author(self): author = self.c.author out = "" if author.name is not None: out += author.name if author.email is not None: out += " (" + author.email + ")" return out class Repository: """ Git repository """ def __init__(self, repo_path): """ :param repo_path: str Path to repository """ self.r = Repo(repo_path) def get_last_commit(self): """ :return: git.Commit Last commit of repository """ return self.r.head.commit def get_diff_amounts(self): """ :return: [] List of total diff between 2 consecutive commits since start """ diffs = [] last_commit = None for commit in self.r.iter_commits(): if last_commit is not None: diff = self.get_diff(commit, last_commit) total_changed = diff[Diff.ADD] + diff[Diff.DEL] diffs.append(total_changed) return diffs def get_diff(self, commit, other_commit): """ :param commit: git.Commit First commit :param other_commit: git.Commit Second commit :return: {} Dictionary with total additions and deletions """ diff = self.r.git.diff(commit.hexsha, other_commit.hexsha) return Diff(diff).get_totals() def get_version(self): """ :return: Version Version of this code, based on commits diffs """ diffs = self.get_diff_amounts() diff_to_increase_ratio = 1 / 100 version = Version() for diff in diffs: version.increase_by_changes(diff, diff_to_increase_ratio) return version def get_pretty_version(self): """ :return: str Pretty version of this repository """ version = self.get_version() last = self.get_last_commit() return str(version) + " " + str(last)
Python
0.000001
@@ -2632,16 +2632,50 @@ anged)%0A%0A + last_commit = commit%0A%0A @@ -3680,10 +3680,18 @@ str( +Commit( last) +) %0A
0ff88a6f75072b8bed822799b5ecf5b4d3412c66
fix params
firebase/__init__.py
firebase/__init__.py
import requests import urlparse #for urlparse and urljoin import os #for os.path.dirname import json #for dumps class Firebase(): ROOT_URL = '' #no trailing slash def __init__(self, root_url, auth_token=None): self.ROOT_URL = root_url.rstrip('/') self.auth_token = auth_token #These methods are intended to mimic Firebase API calls. def child(self, path): root_url = '%s/' % self.ROOT_URL url = urlparse.urljoin(root_url, path.lstrip('/')) return Firebase(url) def parent(self): url = os.path.dirname(self.ROOT_URL) #If url is the root of your Firebase, return None up = urlparse.urlparse(url) if up.path == '': return None #maybe throw exception here? return Firebase(url) def name(self): return os.path.basename(self.ROOT_URL) def toString(self): return self.__str__() def __str__(self): return self.ROOT_URL def set(self, value): return self.put(value) def push(self, data): return self.post(data) def update(self, data): return self.patch(data) def remove(self): return self.delete() #These mirror REST API functionality def put(self, data): return self.__request('put', data = data) def patch(self, data): return self.__request('patch', data = data) def get(self): return self.__request('get') #POST differs from PUT in that it is equivalent to doing a 'push()' in #Firebase where a new child location with unique name is generated and #returned def post(self, data): return self.__request('post', data = data) def delete(self): return self.__request('delete') #Private def __request(self, method, **kwargs): #Firebase API does not accept form-encoded PUT/POST data. It needs to #be JSON encoded. if 'data' in kwargs: kwargs['data'] = json.dumps(kwargs['data']) if self.auth_token: kwargs['auth'] = self.auth_token r = requests.request(method, self.__url(), **kwargs) r.raise_for_status() #throw exception if error return r.json def __url(self): #We append .json to end of ROOT_URL for REST API. return '%s.json' % self.ROOT_URL
Python
0.000004
@@ -2004,16 +2004,36 @@ ata'%5D)%0A%0A + params = %7B%7D%0A @@ -2068,24 +2068,144 @@ -kwargs%5B +if 'params' in kwargs:%0A params = kwargs%5B'params'%5D%0A del kwargs%5B'params'%5D%0A params.update(%7B 'auth' -%5D = +: sel @@ -2212,24 +2212,26 @@ f.auth_token +%7D) %0A%0A r @@ -2270,16 +2270,31 @@ __url(), + params=params, **kwarg
16c8d9b66b41cf5342591201c5eabe9f873b2762
Allow passing a `Region` as mask to `is_screen_black`
_stbt/black.py
_stbt/black.py
# coding: utf-8 """ Copyright 2014 YouView TV Ltd. Copyright 2014-2018 stb-tester.com Ltd. License: LGPL v2.1 or (at your option) any later version (see https://github.com/stb-tester/stb-tester/blob/master/LICENSE for details). """ import cv2 from .config import get_config from .imgutils import (crop, _frame_repr, load_image, pixel_bounding_box, _validate_region) from .logging import debug, ImageLogger from .types import Region def is_screen_black(frame=None, mask=None, threshold=None, region=Region.ALL): """Check for the presence of a black screen in a video frame. :type frame: `stbt.Frame` or `numpy.ndarray` :param frame: If this is specified it is used as the video frame to check; otherwise a new frame is grabbed from the device-under-test. This is an image in OpenCV format (for example as returned by `frames` and `get_frame`). :type mask: str or `numpy.ndarray` :param mask: A black & white image that specifies which part of the image to analyse. White pixels select the area to analyse; black pixels select the area to ignore. This can be a string (a filename that will be resolved as per `stbt.load_image`) or a single-channel image in OpenCV format. If you specify ``region``, the mask must be the same size as the region. Otherwise the mask must be the same size as the frame. :param int threshold: Even when a video frame appears to be black, the intensity of its pixels is not always 0. To differentiate almost-black from non-black pixels, a binary threshold is applied to the frame. The ``threshold`` value is in the range 0 (black) to 255 (white). The global default (20) can be changed by setting ``threshold`` in the ``[is_screen_black]`` section of :ref:`.stbt.conf`. :type region: `Region` :param region: Only analyze the specified region of the video frame. :returns: An object that will evaluate to true if the frame was black, or false if not black. The object has the following attributes: * **black** (*bool*) – True if the frame was black. * **frame** (`stbt.Frame`) – The video frame that was analysed. """ if threshold is None: threshold = get_config('is_screen_black', 'threshold', type_=int) if frame is None: from stbt_core import get_frame frame = get_frame() if mask is not None: mask = load_image(mask, color_channels=1) region = _validate_region(frame, region) imglog = ImageLogger("is_screen_black", region=region, threshold=threshold) imglog.imwrite("source", frame) greyframe = cv2.cvtColor(crop(frame, region), cv2.COLOR_BGR2GRAY) if mask is not None: imglog.imwrite("mask", mask) cv2.bitwise_and(greyframe, mask, dst=greyframe) maxVal = greyframe.max() result = _IsScreenBlackResult(bool(maxVal <= threshold), frame) debug("is_screen_black: {found} black screen using mask={mask}, " "threshold={threshold}, region={region}: " "{result}, maximum_intensity={maxVal}".format( found="Found" if result.black else "Didn't find", mask=mask, threshold=threshold, region=region, result=result, maxVal=maxVal)) if imglog.enabled: imglog.imwrite("grey", greyframe) _, thresholded = cv2.threshold(greyframe, threshold, 255, cv2.THRESH_BINARY) imglog.imwrite("non_black", thresholded) imglog.set(maxVal=maxVal, non_black_region=pixel_bounding_box(thresholded)) _log_image_debug(imglog, result) return result class _IsScreenBlackResult(): def __init__(self, black, frame): self.black = black self.frame = frame def __bool__(self): return self.black def __repr__(self): return ("_IsScreenBlackResult(black=%r, frame=%s)" % ( self.black, _frame_repr(self.frame))) def _log_image_debug(imglog, result): if not imglog.enabled: return template = """\ <h4>is_screen_black: {{result.black}}</h4> {{ annotated_image(non_black_region) }} {% if "mask" in images %} <h5>Mask:</h5> <img src="mask.png" /> {% endif %} <h5>Greyscale, masked:</h5> <img src="grey.png"> <ul> <li>Maximum pixel intensity: {{maxVal}} <li>threshold={{threshold}} </ul> {% if not result.black %} <h5>Non-black pixels in region:</h5> <img src="non_black.png" /> {% endif %} """ imglog.html(template, result=result)
Python
0
@@ -318,21 +318,20 @@ r, load_ -i ma -ge +sk , pixel_ @@ -2450,24 +2450,69 @@ et_frame()%0A%0A + region = _validate_region(frame, region)%0A if mask @@ -2548,82 +2548,57 @@ oad_ -i ma -ge +sk (mask, -color_channels=1)%0A%0A region = _validate_region(frame, region +shape=(region.height, region.width, 1) )%0A%0A
3109bd9a1d01e926e4fce3373db93db8a2d091e0
Update 4.8_subtree.py
CrackingCodingInterview/4.8_subtree.py
CrackingCodingInterview/4.8_subtree.py
""" is a a subtree of b both are bst """
Python
0
@@ -30,12 +30,735 @@ are bst%0A%22%22%22%0A +%0Aclass Node:%0A02%0A ...%0A03%0A def compare_trees(self, node):%0A04%0A %22%22%22%0A05%0A Compare 2 trees%0A06%0A %0A07%0A @param node tree's root node to compare to%0A08%0A @returns True if the tree passed is identical to this tree%0A09%0A %22%22%22%0A %0Adef compare_trees(self, node):%0A if node is None:%0A return False%0A if self.data != node.data:%0A return False%0A res = True%0A if self.left is None:%0A if node.left:%0A return False%0A else:%0A res = self.left.compare_trees(node.left)%0A if res is False:%0A return False%0A if self.right is None:%0A if node.right:%0A return False%0A else:%0A res = self.right.compare_trees(node.right)%0A return res%0A%0A
42cefe67849fd97c52210ba750077238d938fe6a
Fix TZ issue in order_by_score
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)" , } 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)), [])
Python
0
@@ -1035,16 +1035,137 @@ ,%0A %7D%0A + now_tz_sqls = %7B%0A %22mysql%22: %22UTC_TIMESTAMP()%22,%0A %22postgresql_psycopg2%22: %22NOW() AT TIME ZONE 'utc'%22,%0A %7D%0A db_e @@ -1281,16 +1281,90 @@ _engine) +%0A now_sql = now_tz_sqls.get(db_engine) if settings.USE_TZ else %22NOW()%22, %0A%0A if @@ -1377,16 +1377,28 @@ tamp_sql + and now_sql :%0A @@ -1507,23 +1507,23 @@ p_sql %25 -%22NOW()%22 +now_sql ,%0A
7a10f8eccc4085933fb415b59dfee41a02572d6a
Add missing imports
sqlitebiter/subcommand/_file.py
sqlitebiter/subcommand/_file.py
# encoding: utf-8 """ .. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com> """ from __future__ import absolute_import, unicode_literals import os import stat from copy import deepcopy import msgfy import path import pytablereader as ptr import six from .._const import IPYNB_FORMAT_NAME_LIST, TABLE_NOT_FOUND_MSG_FORMAT from .._ipynb_converter import is_ipynb_file_path, load_ipynb_file from ._base import SourceInfo, TableConverter def _get_format_type_from_path(file_path): return file_path.ext.lstrip(".") class FileConverter(TableConverter): SKIP_MSG_FORMAT = "skip '{source:s}': {message:s}" def __init__( self, logger, con, symbol_replace_value, index_list, verbosity_level, format_name, encoding, exclude_pattern, follow_symlinks, ): super(FileConverter, self).__init__( logger, con, symbol_replace_value, index_list, verbosity_level, format_name, encoding ) self.__exclude_pattern = exclude_pattern self.__follow_symlinks = follow_symlinks def convert(self, file_path): file_path = path.Path(file_path) logger = self._logger result_counter = self._result_counter if not self.__is_file(file_path): return if self.__exclude_pattern and file_path.fnmatch(self.__exclude_pattern): logger.debug( self.SKIP_MSG_FORMAT.format(source=file_path, message="matching an exclude pattern") ) self._result_counter.inc_skip() return False logger.debug("converting '{}'".format(file_path)) success_count = result_counter.success_count source_info_record_base = self.__get_source_info_base(file_path.realpath()) source_info_record_base.source_id = self._fetch_next_source_id() if self._format_name in IPYNB_FORMAT_NAME_LIST or is_ipynb_file_path(file_path): import nbformat try: changed_table_name_set = self._convert_nb( nb=load_ipynb_file(file_path, encoding=self._encoding), source_info=source_info_record_base, ) except (nbformat.reader.NotJSONError, RuntimeError) as e: logger.error(e) return for table_name in changed_table_name_set: record = deepcopy(source_info_record_base) record.format_name = "ipynb" record.dst_table = table_name SourceInfo.insert(record) else: self.__convert(file_path, source_info_record_base) if result_counter.success_count == success_count: logger.warn(TABLE_NOT_FOUND_MSG_FORMAT.format(file_path)) def __convert(self, file_path, source_info_record_base): logger = self._logger result_counter = self._result_counter try: loader = ptr.TableFileLoader( file_path, format_name=self._format_name, encoding=self._encoding ) except ptr.InvalidFilePathError as e: logger.debug(msgfy.to_debug_message(e)) result_counter.inc_fail() return except ptr.LoaderNotFoundError: logger.debug("loader not found that coincide with '{}'".format(file_path)) result_counter.inc_fail() return source_info_record_base.format_name = loader.format_name try: for table_data in loader.load(): logger.debug("loaded tabledata: {}".format(six.text_type(table_data))) sqlite_tabledata = self.normalize_table(table_data) try: self._table_creator.create( sqlite_tabledata, self._index_list, source_info=source_info_record_base ) except (ValueError, IOError) as e: logger.debug( "exception={:s}, path={}, message={}".format(type(e).__name__, file_path, e) ) result_counter.inc_fail() return record = deepcopy(source_info_record_base) record.dst_table = sqlite_tabledata.table_name SourceInfo.insert(record) except ptr.OpenError as e: logger.error( "{:s}: open error: file={}, message='{}'".format( e.__class__.__name__, file_path, str(e) ) ) result_counter.inc_fail() except ptr.ValidationError as e: if loader.format_name == "json": for table_name in self._convert_complex_json( loader.loader, source_info_record_base ): record = deepcopy(source_info_record_base) record.dst_table = table_name SourceInfo.insert(record) else: logger.error( "{:s}: invalid {} data format: path={}, message={}".format( e.__class__.__name__, _get_format_type_from_path(file_path), file_path, str(e), ) ) result_counter.inc_fail() except ptr.DataError as e: logger.error( "{:s}: invalid {} data: path={}, message={}".format( e.__class__.__name__, _get_format_type_from_path(file_path), file_path, str(e) ) ) result_counter.inc_fail() def __is_fifo(self, file_path): try: return stat.S_ISFIFO(os.stat(file_path).st_mode) except OSError as e: if e.errno not in (EBADF, ENAMETOOLONG, ENOENT, ENOTDIR): raise return False except ValueError: return False def __is_file(self, file_path): if not file_path.exists(): self._logger.debug( self.SKIP_MSG_FORMAT.format(source=file_path, message="no such file or directory") ) self._result_counter.inc_skip() return False if file_path.islink() and not self.__follow_symlinks: self._logger.debug( self.SKIP_MSG_FORMAT.format(source=file_path, message="skip a symlink to a file") ) self._result_counter.inc_skip() return False if not file_path.isfile() and not self.__is_fifo(file_path): self._logger.warn(self.SKIP_MSG_FORMAT.format(source=file_path, message="not a file")) self._result_counter.inc_skip() return False if file_path.realpath() == self._con.database_path: self._logger.warn( self.SKIP_MSG_FORMAT.format( source=file_path, message="same path as the output file" ) ) self._result_counter.inc_skip() return False return True @staticmethod def __get_source_info_base(source): return SourceInfo( dir_name=source.dirname(), base_name=source.basename(), size=source.getsize(), mtime=int(source.getmtime()), )
Python
0.000479
@@ -190,16 +190,71 @@ deepcopy +%0Afrom errno import EBADF, ENAMETOOLONG, ENOENT, ENOTDIR %0A%0Aimport
239eaf0078db0549232ef6eca54dabf75e9752c5
Remove timezone specific value
test/mitmproxy/test_examples.py
test/mitmproxy/test_examples.py
import json import os import six from mitmproxy import options from mitmproxy import contentviews from mitmproxy.builtins import script from mitmproxy.flow import master from mitmproxy.flow import state import netlib.utils from netlib import tutils as netutils from netlib.http import Headers from netlib.http import cookies from . import tutils, mastertest example_dir = netlib.utils.Data(__name__).push("../../examples") class ScriptError(Exception): pass class RaiseMaster(master.FlowMaster): def add_log(self, e, level): if level in ("warn", "error"): raise ScriptError(e) def tscript(cmd, args=""): o = options.Options() cmd = example_dir.path(cmd) + " " + args m = RaiseMaster(o, None, state.State()) sc = script.Script(cmd) m.addons.add(o, sc) return m, sc class TestScripts(mastertest.MasterTest): def test_add_header(self): m, _ = tscript("add_header.py") f = tutils.tflow(resp=netutils.tresp()) m.response(f) assert f.response.headers["newheader"] == "foo" def test_custom_contentviews(self): m, sc = tscript("custom_contentviews.py") pig = contentviews.get("pig_latin_HTML") _, fmt = pig(b"<html>test!</html>") assert any(b'esttay!' in val[0][1] for val in fmt) assert not pig(b"gobbledygook") def test_iframe_injector(self): with tutils.raises(ScriptError): tscript("iframe_injector.py") m, sc = tscript("iframe_injector.py", "http://example.org/evil_iframe") f = tutils.tflow(resp=netutils.tresp(content=b"<html>mitmproxy</html>")) m.response(f) content = f.response.content assert b'iframe' in content and b'evil_iframe' in content def test_modify_form(self): m, sc = tscript("modify_form.py") form_header = Headers(content_type="application/x-www-form-urlencoded") f = tutils.tflow(req=netutils.treq(headers=form_header)) m.request(f) assert f.request.urlencoded_form[b"mitmproxy"] == b"rocks" f.request.headers["content-type"] = "" m.request(f) assert list(f.request.urlencoded_form.items()) == [(b"foo", b"bar")] def test_modify_querystring(self): m, sc = tscript("modify_querystring.py") f = tutils.tflow(req=netutils.treq(path="/search?q=term")) m.request(f) assert f.request.query["mitmproxy"] == "rocks" f.request.path = "/" m.request(f) assert f.request.query["mitmproxy"] == "rocks" def test_modify_response_body(self): with tutils.raises(ScriptError): tscript("modify_response_body.py") m, sc = tscript("modify_response_body.py", "mitmproxy rocks") f = tutils.tflow(resp=netutils.tresp(content=b"I <3 mitmproxy")) m.response(f) assert f.response.content == b"I <3 rocks" def test_redirect_requests(self): m, sc = tscript("redirect_requests.py") f = tutils.tflow(req=netutils.treq(host="example.org")) m.request(f) assert f.request.host == "mitmproxy.org" class TestHARDump(): def flow(self, resp_content=b'message'): times = dict( timestamp_start=746203272, timestamp_end=746203272, ) # Create a dummy flow for testing return tutils.tflow( req=netutils.treq(method=b'GET', **times), resp=netutils.tresp(content=resp_content, **times) ) def test_no_file_arg(self): with tutils.raises(ScriptError): tscript("har_dump.py") def test_simple(self): with tutils.tmpdir() as tdir: path = os.path.join(tdir, "somefile") m, sc = tscript("har_dump.py", six.moves.shlex_quote(path)) m.addons.invoke(m, "response", self.flow()) m.addons.remove(sc) with open(path, "r") as inp: har = json.load(inp) assert len(har["log"]["entries"]) == 1 def test_base64(self): with tutils.tmpdir() as tdir: path = os.path.join(tdir, "somefile") m, sc = tscript("har_dump.py", six.moves.shlex_quote(path)) m.addons.invoke(m, "response", self.flow(resp_content=b"foo" + b"\xFF" * 10)) m.addons.remove(sc) with open(path, "r") as inp: har = json.load(inp) assert har["log"]["entries"][0]["response"]["content"]["encoding"] == "base64" def test_format_cookies(self): m, sc = tscript("har_dump.py", "-") format_cookies = sc.ns.ns["format_cookies"] CA = cookies.CookieAttrs f = format_cookies([("n", "v", CA([("k", "v")]))])[0] assert f['name'] == "n" assert f['value'] == "v" assert not f['httpOnly'] assert not f['secure'] f = format_cookies([("n", "v", CA([("httponly", None), ("secure", None)]))])[0] assert f['httpOnly'] assert f['secure'] f = format_cookies([("n", "v", CA([("expires", "Mon, 24-Aug-2037 00:00:00 GMT")]))])[0] assert f['expires'] == "2037-08-24T05:30:00+00:00"
Python
0.668778
@@ -5114,36 +5114,5 @@ es'%5D - == %222037-08-24T05:30:00+00:00%22 %0A
a38f2690ddcc72d24ab152b0c4c21ae51db7afa0
Update evaluate_task.py
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 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)
Python
0.000007
@@ -585,16 +585,8 @@ s a -task in BIG- @@ -591,16 +591,26 @@ G-bench +task in a docker c
e675431d8d2930ae4a110feb94990a75308695cb
Change startup sequence
svr_record.py
svr_record.py
from tkinter import * from pcf8591read import * import threading root = Tk() def testytesty(): print ('oh look we used a callback') # words from https://www.randomlists.com/random-words # reader_worker = reader.run class svr_interface(): def __init__(self): self.current = 0 self.words = ['dusty','march','direful','complete','superb','poised','wait','quaint','save','copy','interest','separate','bright','utter','bored','nondescript','license','vest','dance','money','languid','swim','enthusiastic','quartz','planes','spiritual','imperfect','coal','hobbies','sound','bow','squirrel','push','treatment','mine','precede','weather','amazing','round','stingy','signal','marry','country','uncle','dust','certain','loose','knock','advice','confuse','animated','loving','feeling','absorbing','trick','spare','rod','caption','raspy','throne','clumsy','vague','tow','hang','rely','tired','barbarous','pan','innocent','combative','low','rub','mixed','actually','faulty','thirsty','dam','doubtful','flowers','defective','frogs','outstanding','ducks','icicle','fry','load','cracker','efficient','hop','fax','fancy','reading','real','addicted','motion','clean','unsuitable','race','aspiring','gold','check','bouncy','regret','chop','various','eminent','wander','living','equable','cluttered','geese','tightfisted','aftermath','quince','division','board','amuck','pretty','extra-large','sun','person','magical','invent','flap','stomach','black','river','town','type','stereotyped','paddle','expand','puncture','cakes','measly','kitty','courageous','shoe','number','third','ugliest','haircut','increase','wrathful','jog','straw','whisper','kick','talented','curious'] self.reader = adc_reader() self.suffix = 0 self.current_word = self.words[self.current] self.filename = self.current_word + '-' + str(self.suffix) self.r_t = threading.Thread(target=self.reader.run,args=[self.filename]) self.r_t.daemon = True def key(event): print ("pressed", repr(event.char)) # current_word = self.words[self.current] # filename = current_word + '-' + str(suffix) if event.char.isdigit(): suffix = event.char print ('file series will take',suffix,'as suffix in filename') if event.char==' ': print('starting thread') print(self.current_word) self.reader.record = True # Get the next word # Start the recording for that word # reader.run(filename) # r_t.run([filename]) # self.r_t.start() # If the recording is running: if event.char=='s': self.reader.record = False # Stop the recording self.current += 1 print('terminating thread',self.current) # print('r_t:',vars(self.r_t),'r_t._target:',vars(self.r_t._target)) # Iterate the word def callback(event): frame.focus_set() print ("clicked at", event.x, event.y) frame = Frame(root, width=100, height=100) frame.current = 0 frame.bind("<Key>", key) frame.bind("<Button-1>", callback) frame.pack() root.mainloop() s_inter = svr_interface()
Python
0.000032
@@ -1966,16 +1966,41 @@ n = True +%0A self.r_t.start() %0A%0A @@ -2654,43 +2654,8 @@ e%5D)%0A - # self.r_t.start()%0A
10a510dc3234860c697945c8c37393a9b5790b6c
Update lims.py
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 getlist(self, term): # r = requests.get(self.uri + , auth=(self.user, self.pwd)) # uri = node.attrib.get('uri')
Python
0
@@ -1616,16 +1616,410 @@ urn hit%0A + %0A def getattribute(self, searchattribute, searchvalue, attribute):%0A r = requests.get(self.uri + searchattribute + '/' + searchvalue, auth=(self.user, self.pwd))%0A tree = ElementTree.fromstring(r.text)%0A hit = %22No hit%22%0A for node in tree:%0A for key in node.attrib:%0A if (key == attribute)%0A hit = node.text%0A# hit = node.attrib%5Battribute%5D%0A return hit%0A%0A %0A# def
c2c21fabd144ec25fa46fefdfe7c460a39aa2454
Update lims.py
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')
Python
0
@@ -1864,24 +1864,41 @@ de in tree:%0A + print node%0A for ke @@ -1915,16 +1915,34 @@ attrib:%0A + print key%0A
79b119befb556b7c3665c51d8f7b7a2e25e8a220
Update rv_transformation_tests.py
GPy/testing/rv_transformation_tests.py
GPy/testing/rv_transformation_tests.py
# Written by Ilias Bilionis """ Test if hyperparameters in models are properly transformed. """ import unittest import numpy as np import scipy.stats as st import GPy class TestModel(GPy.core.Model): """ A simple GPy model with one parameter. """ def __init__(self): GPy.core.Model.__init__(self, 'test_model') theta = GPy.core.Param('theta', 1.) self.link_parameter(theta) def log_likelihood(self): return 0. class RVTransformationTestCase(unittest.TestCase): def _test_trans(self, trans): m = TestModel() prior = GPy.priors.LogGaussian(.5, 0.1) m.theta.set_prior(prior) m.theta.unconstrain() m.theta.constrain(trans) # The PDF of the transformed variables p_phi = lambda phi : np.exp(-m._objective_grads(phi)[0]) # To the empirical PDF of: theta_s = prior.rvs(1e6) phi_s = trans.finv(theta_s) # which is essentially a kernel density estimation kde = st.gaussian_kde(phi_s) # We will compare the PDF here: phi = np.linspace(phi_s.min(), phi_s.max(), 100) # The transformed PDF of phi should be this: pdf_phi = np.array([p_phi(p) for p in phi]) # UNCOMMENT TO SEE GRAPHICAL COMPARISON #import matplotlib.pyplot as plt #fig, ax = plt.subplots() #ax.hist(phi_s, normed=True, bins=100, alpha=0.25, label='Histogram') #ax.plot(phi, kde(phi), '--', linewidth=2, label='Kernel Density Estimation') #ax.plot(phi, pdf_phi, ':', linewidth=2, label='Transformed PDF') #ax.set_xlabel(r'transformed $\theta$', fontsize=16) #ax.set_ylabel('PDF', fontsize=16) #plt.legend(loc='best') #plt.show(block=True) # END OF PLOT # The following test cannot be very accurate self.assertTrue(np.linalg.norm(pdf_phi - kde(phi)) / np.linalg.norm(kde(phi)) <= 1e-1) # Check the gradients at a few random points checks_failes = 0. checks = 40. for i in range(checks): m.theta = theta_s[i] print(m.theta, m.optimizer_array, m.param_array) if not m.checkgrad(): checks_failes += 1. self.assertTrue(checks_failed/checks > .5) def test_Logexp(self): self._test_trans(GPy.constraints.Logexp()) def test_Exponent(self): self._test_trans(GPy.constraints.Exponent()) if __name__ == '__main__': unittest.main() quit() m = TestModel() prior = GPy.priors.LogGaussian(0., .9) m.theta.set_prior(prior) # The following should return the PDF in terms of the transformed quantities p_phi = lambda phi : np.exp(-m._objective_grads(phi)[0]) # Let's look at the transformation phi = log(exp(theta - 1)) trans = GPy.constraints.Exponent() m.theta.constrain(trans) # Plot the transformed probability density phi = np.linspace(-8, 8, 100) fig, ax = plt.subplots() # Let's draw some samples of theta and transform them so that we see # which one is right theta_s = prior.rvs(10000) # Transform it to the new variables phi_s = trans.finv(theta_s) # And draw their histogram ax.hist(phi_s, normed=True, bins=100, alpha=0.25, label='Empirical') # This is to be compared to the PDF of the model expressed in terms of these new # variables ax.plot(phi, [p_phi(p) for p in phi], label='Transformed PDF', linewidth=2) ax.set_xlim(-3, 10) ax.set_xlabel(r'transformed $\theta$', fontsize=16) ax.set_ylabel('PDF', fontsize=16) plt.legend(loc='best') # Now let's test the gradients m.checkgrad(verbose=True) # And show the plot plt.show(block=True)
Python
0.000002
@@ -2185,16 +2185,17 @@ eckgrad( +1 ):%0A