commit
stringlengths 40
40
| old_file
stringlengths 4
150
| new_file
stringlengths 4
150
| old_contents
stringlengths 0
3.26k
| new_contents
stringlengths 1
4.43k
| subject
stringlengths 15
501
| message
stringlengths 15
4.06k
| lang
stringclasses 4
values | license
stringclasses 13
values | repos
stringlengths 5
91.5k
| diff
stringlengths 0
4.35k
|
|---|---|---|---|---|---|---|---|---|---|---|
5c41066e9c93c417253cbde325a18079c1c69d1a
|
scipy/sparse/linalg/isolve/__init__.py
|
scipy/sparse/linalg/isolve/__init__.py
|
"Iterative Solvers for Sparse Linear Systems"
#from info import __doc__
from iterative import *
from minres import minres
from lgmres import lgmres
from lsqr import lsqr
__all__ = filter(lambda s:not s.startswith('_'),dir())
from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
|
"Iterative Solvers for Sparse Linear Systems"
#from info import __doc__
from iterative import *
from minres import minres
from lgmres import lgmres
from lsqr import lsqr
from lsmr import lsmr
__all__ = filter(lambda s:not s.startswith('_'),dir())
from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
|
Add lsmr to isolve module.
|
ENH: Add lsmr to isolve module.
|
Python
|
bsd-3-clause
|
bkendzior/scipy,mikebenfield/scipy,anielsen001/scipy,nonhermitian/scipy,aeklant/scipy,apbard/scipy,jjhelmus/scipy,giorgiop/scipy,sonnyhu/scipy,befelix/scipy,jor-/scipy,gfyoung/scipy,piyush0609/scipy,pbrod/scipy,Shaswat27/scipy,pschella/scipy,chatcannon/scipy,Newman101/scipy,ilayn/scipy,Newman101/scipy,mtrbean/scipy,Shaswat27/scipy,newemailjdm/scipy,behzadnouri/scipy,woodscn/scipy,sonnyhu/scipy,jonycgn/scipy,behzadnouri/scipy,lukauskas/scipy,rgommers/scipy,efiring/scipy,newemailjdm/scipy,Eric89GXL/scipy,WillieMaddox/scipy,andim/scipy,ogrisel/scipy,ogrisel/scipy,FRidh/scipy,anielsen001/scipy,pnedunuri/scipy,mortonjt/scipy,gdooper/scipy,haudren/scipy,gertingold/scipy,lhilt/scipy,Srisai85/scipy,zerothi/scipy,pizzathief/scipy,futurulus/scipy,rgommers/scipy,mortonjt/scipy,piyush0609/scipy,piyush0609/scipy,piyush0609/scipy,Eric89GXL/scipy,matthewalbani/scipy,ilayn/scipy,fredrikw/scipy,pyramania/scipy,Kamp9/scipy,Gillu13/scipy,jonycgn/scipy,chatcannon/scipy,nvoron23/scipy,fernand/scipy,witcxc/scipy,Newman101/scipy,efiring/scipy,Newman101/scipy,argriffing/scipy,sargas/scipy,gertingold/scipy,raoulbq/scipy,minhlongdo/scipy,ChanderG/scipy,jjhelmus/scipy,maniteja123/scipy,felipebetancur/scipy,Gillu13/scipy,anntzer/scipy,maciejkula/scipy,jakevdp/scipy,Kamp9/scipy,trankmichael/scipy,woodscn/scipy,jjhelmus/scipy,zerothi/scipy,matthewalbani/scipy,josephcslater/scipy,apbard/scipy,mtrbean/scipy,richardotis/scipy,mortonjt/scipy,mortada/scipy,teoliphant/scipy,jonycgn/scipy,ilayn/scipy,ndchorley/scipy,Srisai85/scipy,zerothi/scipy,sonnyhu/scipy,anntzer/scipy,vigna/scipy,gef756/scipy,cpaulik/scipy,WarrenWeckesser/scipy,ndchorley/scipy,pnedunuri/scipy,jamestwebber/scipy,anielsen001/scipy,FRidh/scipy,vanpact/scipy,Newman101/scipy,pbrod/scipy,raoulbq/scipy,vigna/scipy,jakevdp/scipy,jsilter/scipy,sauliusl/scipy,e-q/scipy,aarchiba/scipy,piyush0609/scipy,cpaulik/scipy,gdooper/scipy,andim/scipy,teoliphant/scipy,hainm/scipy,behzadnouri/scipy,Stefan-Endres/scipy,petebachant/scipy,Shaswat27/scipy,gef756/scipy,jakevdp/scipy,kalvdans/scipy,ales-erjavec/scipy,kleskjr/scipy,mdhaber/scipy,mgaitan/scipy,perimosocordiae/scipy,pizzathief/scipy,aeklant/scipy,niknow/scipy,dch312/scipy,WarrenWeckesser/scipy,jjhelmus/scipy,mhogg/scipy,sargas/scipy,dominicelse/scipy,sriki18/scipy,jor-/scipy,petebachant/scipy,woodscn/scipy,vanpact/scipy,nonhermitian/scipy,futurulus/scipy,dominicelse/scipy,scipy/scipy,mdhaber/scipy,kalvdans/scipy,jsilter/scipy,ortylp/scipy,perimosocordiae/scipy,gfyoung/scipy,fernand/scipy,anntzer/scipy,aman-iitj/scipy,sauliusl/scipy,mikebenfield/scipy,matthew-brett/scipy,mgaitan/scipy,lukauskas/scipy,rmcgibbo/scipy,haudren/scipy,surhudm/scipy,sriki18/scipy,jonycgn/scipy,person142/scipy,befelix/scipy,jor-/scipy,efiring/scipy,vberaudi/scipy,pyramania/scipy,josephcslater/scipy,grlee77/scipy,zerothi/scipy,jsilter/scipy,larsmans/scipy,efiring/scipy,ales-erjavec/scipy,nvoron23/scipy,felipebetancur/scipy,jseabold/scipy,dch312/scipy,Gillu13/scipy,mortada/scipy,gef756/scipy,trankmichael/scipy,ortylp/scipy,Gillu13/scipy,ogrisel/scipy,nmayorov/scipy,e-q/scipy,witcxc/scipy,jseabold/scipy,vhaasteren/scipy,maniteja123/scipy,vigna/scipy,gfyoung/scipy,lhilt/scipy,giorgiop/scipy,grlee77/scipy,haudren/scipy,Eric89GXL/scipy,jamestwebber/scipy,raoulbq/scipy,zxsted/scipy,andim/scipy,mortada/scipy,befelix/scipy,richardotis/scipy,tylerjereddy/scipy,larsmans/scipy,jonycgn/scipy,niknow/scipy,jakevdp/scipy,nonhermitian/scipy,aman-iitj/scipy,teoliphant/scipy,lhilt/scipy,mortonjt/scipy,vanpact/scipy,felipebetancur/scipy,person142/scipy,woodscn/scipy,sriki18/scipy,Srisai85/scipy,FRidh/scipy,mhogg/scipy,behzadnouri/scipy,njwilson23/scipy,mingwpy/scipy,ilayn/scipy,ChanderG/scipy,Kamp9/scipy,minhlongdo/scipy,tylerjereddy/scipy,kleskjr/scipy,jseabold/scipy,aarchiba/scipy,josephcslater/scipy,andyfaff/scipy,dch312/scipy,mingwpy/scipy,raoulbq/scipy,Dapid/scipy,endolith/scipy,scipy/scipy,Srisai85/scipy,zxsted/scipy,fernand/scipy,pbrod/scipy,Stefan-Endres/scipy,rmcgibbo/scipy,zaxliu/scipy,rgommers/scipy,pschella/scipy,Eric89GXL/scipy,bkendzior/scipy,endolith/scipy,hainm/scipy,jonycgn/scipy,witcxc/scipy,zxsted/scipy,vberaudi/scipy,perimosocordiae/scipy,juliantaylor/scipy,grlee77/scipy,sriki18/scipy,Shaswat27/scipy,sonnyhu/scipy,bkendzior/scipy,nmayorov/scipy,Dapid/scipy,ales-erjavec/scipy,WillieMaddox/scipy,arokem/scipy,kleskjr/scipy,newemailjdm/scipy,mgaitan/scipy,aman-iitj/scipy,lukauskas/scipy,maciejkula/scipy,Dapid/scipy,niknow/scipy,ortylp/scipy,giorgiop/scipy,newemailjdm/scipy,WarrenWeckesser/scipy,lukauskas/scipy,mortada/scipy,jamestwebber/scipy,WillieMaddox/scipy,juliantaylor/scipy,juliantaylor/scipy,newemailjdm/scipy,nvoron23/scipy,FRidh/scipy,ilayn/scipy,Dapid/scipy,e-q/scipy,niknow/scipy,WarrenWeckesser/scipy,ndchorley/scipy,mgaitan/scipy,pizzathief/scipy,zaxliu/scipy,richardotis/scipy,pizzathief/scipy,gfyoung/scipy,matthew-brett/scipy,pbrod/scipy,nmayorov/scipy,mikebenfield/scipy,sauliusl/scipy,aarchiba/scipy,gertingold/scipy,zxsted/scipy,sriki18/scipy,zerothi/scipy,jamestwebber/scipy,surhudm/scipy,giorgiop/scipy,matthew-brett/scipy,scipy/scipy,lukauskas/scipy,pschella/scipy,felipebetancur/scipy,perimosocordiae/scipy,maniteja123/scipy,haudren/scipy,futurulus/scipy,ogrisel/scipy,surhudm/scipy,woodscn/scipy,jor-/scipy,niknow/scipy,perimosocordiae/scipy,mhogg/scipy,rmcgibbo/scipy,ales-erjavec/scipy,grlee77/scipy,mdhaber/scipy,fredrikw/scipy,pschella/scipy,Gillu13/scipy,vhaasteren/scipy,mtrbean/scipy,aeklant/scipy,dominicelse/scipy,giorgiop/scipy,vhaasteren/scipy,ales-erjavec/scipy,nvoron23/scipy,kalvdans/scipy,jakevdp/scipy,dominicelse/scipy,vberaudi/scipy,pizzathief/scipy,ChanderG/scipy,matthewalbani/scipy,fernand/scipy,gef756/scipy,ChanderG/scipy,FRidh/scipy,maniteja123/scipy,grlee77/scipy,nonhermitian/scipy,hainm/scipy,felipebetancur/scipy,zaxliu/scipy,vanpact/scipy,Newman101/scipy,cpaulik/scipy,ndchorley/scipy,nmayorov/scipy,gdooper/scipy,trankmichael/scipy,FRidh/scipy,richardotis/scipy,Gillu13/scipy,anntzer/scipy,lhilt/scipy,vigna/scipy,dch312/scipy,newemailjdm/scipy,maciejkula/scipy,efiring/scipy,tylerjereddy/scipy,gdooper/scipy,pyramania/scipy,mtrbean/scipy,gertingold/scipy,nonhermitian/scipy,apbard/scipy,bkendzior/scipy,giorgiop/scipy,Kamp9/scipy,piyush0609/scipy,WarrenWeckesser/scipy,fernand/scipy,ndchorley/scipy,Shaswat27/scipy,cpaulik/scipy,jor-/scipy,matthewalbani/scipy,pbrod/scipy,dch312/scipy,Kamp9/scipy,fredrikw/scipy,Shaswat27/scipy,cpaulik/scipy,larsmans/scipy,ortylp/scipy,mortonjt/scipy,njwilson23/scipy,ChanderG/scipy,mingwpy/scipy,hainm/scipy,scipy/scipy,vhaasteren/scipy,Dapid/scipy,haudren/scipy,Stefan-Endres/scipy,zxsted/scipy,sriki18/scipy,sauliusl/scipy,endolith/scipy,mingwpy/scipy,aeklant/scipy,argriffing/scipy,pnedunuri/scipy,futurulus/scipy,matthew-brett/scipy,fredrikw/scipy,juliantaylor/scipy,futurulus/scipy,teoliphant/scipy,scipy/scipy,petebachant/scipy,Eric89GXL/scipy,mortada/scipy,argriffing/scipy,behzadnouri/scipy,kalvdans/scipy,nmayorov/scipy,mtrbean/scipy,Stefan-Endres/scipy,befelix/scipy,hainm/scipy,surhudm/scipy,sargas/scipy,anielsen001/scipy,rmcgibbo/scipy,petebachant/scipy,mikebenfield/scipy,raoulbq/scipy,vhaasteren/scipy,person142/scipy,efiring/scipy,richardotis/scipy,jsilter/scipy,zaxliu/scipy,kleskjr/scipy,gertingold/scipy,petebachant/scipy,aarchiba/scipy,ales-erjavec/scipy,Srisai85/scipy,maciejkula/scipy,juliantaylor/scipy,arokem/scipy,zerothi/scipy,pyramania/scipy,endolith/scipy,e-q/scipy,rgommers/scipy,chatcannon/scipy,aman-iitj/scipy,nvoron23/scipy,pyramania/scipy,trankmichael/scipy,mortonjt/scipy,Stefan-Endres/scipy,chatcannon/scipy,trankmichael/scipy,apbard/scipy,ortylp/scipy,anntzer/scipy,jamestwebber/scipy,njwilson23/scipy,pnedunuri/scipy,argriffing/scipy,mingwpy/scipy,andim/scipy,Srisai85/scipy,zaxliu/scipy,person142/scipy,mhogg/scipy,aman-iitj/scipy,WillieMaddox/scipy,maniteja123/scipy,endolith/scipy,bkendzior/scipy,larsmans/scipy,kleskjr/scipy,sauliusl/scipy,Kamp9/scipy,cpaulik/scipy,richardotis/scipy,jseabold/scipy,dominicelse/scipy,surhudm/scipy,tylerjereddy/scipy,mgaitan/scipy,befelix/scipy,e-q/scipy,Dapid/scipy,ChanderG/scipy,perimosocordiae/scipy,witcxc/scipy,argriffing/scipy,Eric89GXL/scipy,rgommers/scipy,apbard/scipy,andyfaff/scipy,hainm/scipy,vhaasteren/scipy,woodscn/scipy,fernand/scipy,mgaitan/scipy,argriffing/scipy,tylerjereddy/scipy,andyfaff/scipy,arokem/scipy,behzadnouri/scipy,minhlongdo/scipy,felipebetancur/scipy,fredrikw/scipy,rmcgibbo/scipy,ndchorley/scipy,andyfaff/scipy,Stefan-Endres/scipy,vanpact/scipy,gef756/scipy,chatcannon/scipy,anielsen001/scipy,sauliusl/scipy,gfyoung/scipy,raoulbq/scipy,aman-iitj/scipy,mortada/scipy,zxsted/scipy,zaxliu/scipy,kalvdans/scipy,pnedunuri/scipy,minhlongdo/scipy,arokem/scipy,aeklant/scipy,sonnyhu/scipy,fredrikw/scipy,mingwpy/scipy,witcxc/scipy,njwilson23/scipy,minhlongdo/scipy,matthew-brett/scipy,larsmans/scipy,arokem/scipy,vberaudi/scipy,pnedunuri/scipy,andyfaff/scipy,mdhaber/scipy,gdooper/scipy,vigna/scipy,anntzer/scipy,andim/scipy,vanpact/scipy,pschella/scipy,matthewalbani/scipy,sargas/scipy,mdhaber/scipy,sonnyhu/scipy,njwilson23/scipy,endolith/scipy,maciejkula/scipy,jseabold/scipy,ortylp/scipy,sargas/scipy,teoliphant/scipy,njwilson23/scipy,josephcslater/scipy,gef756/scipy,andim/scipy,scipy/scipy,andyfaff/scipy,mikebenfield/scipy,WarrenWeckesser/scipy,pbrod/scipy,jsilter/scipy,niknow/scipy,jjhelmus/scipy,vberaudi/scipy,trankmichael/scipy,haudren/scipy,mhogg/scipy,lukauskas/scipy,nvoron23/scipy,mdhaber/scipy,mtrbean/scipy,larsmans/scipy,ogrisel/scipy,ilayn/scipy,mhogg/scipy,person142/scipy,rmcgibbo/scipy,lhilt/scipy,josephcslater/scipy,maniteja123/scipy,petebachant/scipy,anielsen001/scipy,vberaudi/scipy,jseabold/scipy,WillieMaddox/scipy,aarchiba/scipy,WillieMaddox/scipy,surhudm/scipy,chatcannon/scipy,minhlongdo/scipy,kleskjr/scipy,futurulus/scipy
|
---
+++
@@ -5,6 +5,7 @@
from minres import minres
from lgmres import lgmres
from lsqr import lsqr
+from lsmr import lsmr
__all__ = filter(lambda s:not s.startswith('_'),dir())
from numpy.testing import Tester
|
493cfa88dae90a19a4173deaae5f4af8934b47b5
|
datastore/tests/services/test_export.py
|
datastore/tests/services/test_export.py
|
from django.test import TestCase
from django.contrib.auth.models import User
from datastore import models, services
class ExportServiceTestCase(TestCase):
def setUp(self):
user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
project = models.Project.objects.create(
project_owner=user.projectowner,
project_id="PROJECTID_6",
)
consumptionmetadata = models.ConsumptionMetadata.objects.create(
project=project,
fuel_type="E",
energy_unit="KWH",
)
self.meterrun = models.MeterRun.objects.create(
project=project,
consumption_metadata=consumptionmetadata,
)
def test_export(self):
data = services.meterruns_export()
assert 'headers' in data
assert 'meter_runs' in data
assert len(data['meter_runs']) == 1
|
Add test of export service
|
Add test of export service
|
Python
|
mit
|
impactlab/oeem-energy-datastore,impactlab/oeem-energy-datastore,impactlab/oeem-energy-datastore
|
---
+++
@@ -0,0 +1,28 @@
+from django.test import TestCase
+from django.contrib.auth.models import User
+
+from datastore import models, services
+
+class ExportServiceTestCase(TestCase):
+
+ def setUp(self):
+ user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
+ project = models.Project.objects.create(
+ project_owner=user.projectowner,
+ project_id="PROJECTID_6",
+ )
+ consumptionmetadata = models.ConsumptionMetadata.objects.create(
+ project=project,
+ fuel_type="E",
+ energy_unit="KWH",
+ )
+ self.meterrun = models.MeterRun.objects.create(
+ project=project,
+ consumption_metadata=consumptionmetadata,
+ )
+
+ def test_export(self):
+ data = services.meterruns_export()
+ assert 'headers' in data
+ assert 'meter_runs' in data
+ assert len(data['meter_runs']) == 1
|
|
993ada8e5e970399b98b40832b5a3d23874ae7fb
|
plugins/vetting/ontarget/system_info.py
|
plugins/vetting/ontarget/system_info.py
|
#!/usr/bin/env python
'''
Automatron: Fact Finder
Identify facts about a specified host
* Hostname
'''
import os
import json
# pylint: disable=C0103
system_info = {
'hostname' : os.uname()[1],
'os' : os.uname()[0],
'kernel' : os.uname()[2],
}
print json.dumps(system_info)
|
#!/usr/bin/env python
'''
Automatron: Fact Finder
Identify facts about a specified host
* Hostname
* Networking
'''
import os
import json
import subprocess
def get_linux_networking():
''' Gather linux networking information '''
interfaces = []
if os.path.isdir("/sys/class/net/"):
interfaces = os.listdir("/sys/class/net/")
network_info = {}
for interface in interfaces:
network_info[interface] = { 'v4' : [], 'v6' : [] }
results = subprocess.Popen("ip addr show {0}".format(interface), shell=True, stdout=subprocess.PIPE)
for line in results.stdout.readlines():
if "inet" in line:
line_data = line.split()
ip = line_data[1].split("/")[0]
if line_data[0] == "inet6":
network_info[interface]['v6'].append(ip)
elif line_data[0] == "inet":
network_info[interface]['v4'].append(ip)
return network_info
if __name__ == "__main__":
# pylint: disable=C0103
system_info = {}
# Add information from uname
system_info.update({
'hostname' : os.uname()[1],
'os' : os.uname()[0],
'kernel' : os.uname()[2],
})
if "Linux" in system_info['os']:
system_info.update({
'network' : get_linux_networking()
})
print json.dumps(system_info)
|
Revert "Revert "Adding ip interface facts""
|
Revert "Revert "Adding ip interface facts""
|
Python
|
apache-2.0
|
madflojo/automatron,madflojo/automatron,madflojo/automatron,madflojo/automatron
|
---
+++
@@ -5,18 +5,51 @@
Identify facts about a specified host
* Hostname
+ * Networking
'''
import os
import json
+import subprocess
-# pylint: disable=C0103
-system_info = {
- 'hostname' : os.uname()[1],
- 'os' : os.uname()[0],
- 'kernel' : os.uname()[2],
-}
+def get_linux_networking():
+ ''' Gather linux networking information '''
+ interfaces = []
+ if os.path.isdir("/sys/class/net/"):
+ interfaces = os.listdir("/sys/class/net/")
+ network_info = {}
+ for interface in interfaces:
+ network_info[interface] = { 'v4' : [], 'v6' : [] }
+ results = subprocess.Popen("ip addr show {0}".format(interface), shell=True, stdout=subprocess.PIPE)
+ for line in results.stdout.readlines():
+ if "inet" in line:
+ line_data = line.split()
+ ip = line_data[1].split("/")[0]
+ if line_data[0] == "inet6":
+ network_info[interface]['v6'].append(ip)
+ elif line_data[0] == "inet":
+ network_info[interface]['v4'].append(ip)
+ return network_info
-print json.dumps(system_info)
+
+
+if __name__ == "__main__":
+ # pylint: disable=C0103
+ system_info = {}
+
+
+ # Add information from uname
+ system_info.update({
+ 'hostname' : os.uname()[1],
+ 'os' : os.uname()[0],
+ 'kernel' : os.uname()[2],
+ })
+
+ if "Linux" in system_info['os']:
+ system_info.update({
+ 'network' : get_linux_networking()
+ })
+
+ print json.dumps(system_info)
|
ff0631c625cda7c1aac3d86cbc7074a996ef0fc1
|
powerline/bindings/bar/powerline-bar.py
|
powerline/bindings/bar/powerline-bar.py
|
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
import sys
import time
from threading import Lock
from argparse import ArgumentParser
from powerline import Powerline
from powerline.lib.monotonic import monotonic
from powerline.lib.encoding import get_unicode_writer
if __name__ == '__main__':
parser = ArgumentParser(description='Powerline BAR bindings.')
parser.add_argument(
'--i3', action='store_true',
help='Subscribe for i3 events.'
)
args = parser.parse_args()
powerline = Powerline('wm', renderer_module='bar')
powerline.update_renderer()
interval = 0.5
lock = Lock()
write = get_unicode_writer(encoding='utf-8')
def render(event=None, data=None, sub=None):
global lock
with lock:
write(powerline.render())
write('\n')
sys.stdout.flush()
if args.i3:
import i3
sub = i3.Subscription(render, 'workspace')
while True:
start_time = monotonic()
render()
time.sleep(max(interval - (monotonic() - start_time), 0.1))
|
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
import sys
import time
from threading import Lock
from argparse import ArgumentParser
from powerline import Powerline
from powerline.lib.monotonic import monotonic
from powerline.lib.encoding import get_unicode_writer
class BarPowerline(Powerline):
get_encoding = staticmethod(lambda: 'utf-8')
def init(self):
super(BarPowerline, self).init(ext='wm', renderer_module='bar')
def render(event=None, data=None, sub=None):
global lock
with lock:
write(powerline.render())
write('\n')
sys.stdout.flush()
if __name__ == '__main__':
parser = ArgumentParser(description='Powerline BAR bindings.')
parser.add_argument(
'--i3', action='store_true',
help='Subscribe for i3 events.'
)
args = parser.parse_args()
powerline = BarPowerline()
interval = 0.5
lock = Lock()
write = get_unicode_writer(encoding='utf-8')
if args.i3:
import i3
sub = i3.Subscription(render, 'workspace')
while True:
start_time = monotonic()
render()
time.sleep(max(interval - (monotonic() - start_time), 0.1))
|
Make sure powerline class knows that it will use UTF-8
|
Make sure powerline class knows that it will use UTF-8
|
Python
|
mit
|
darac/powerline,darac/powerline,junix/powerline,dragon788/powerline,kenrachynski/powerline,junix/powerline,areteix/powerline,russellb/powerline,seanfisk/powerline,Liangjianghao/powerline,lukw00/powerline,xxxhycl2010/powerline,bezhermoso/powerline,bartvm/powerline,EricSB/powerline,cyrixhero/powerline,DoctorJellyface/powerline,blindFS/powerline,DoctorJellyface/powerline,Liangjianghao/powerline,areteix/powerline,DoctorJellyface/powerline,xxxhycl2010/powerline,dragon788/powerline,EricSB/powerline,kenrachynski/powerline,s0undt3ch/powerline,Liangjianghao/powerline,prvnkumar/powerline,seanfisk/powerline,S0lll0s/powerline,bezhermoso/powerline,bezhermoso/powerline,S0lll0s/powerline,junix/powerline,lukw00/powerline,lukw00/powerline,russellb/powerline,bartvm/powerline,QuLogic/powerline,russellb/powerline,xfumihiro/powerline,IvanAli/powerline,areteix/powerline,cyrixhero/powerline,IvanAli/powerline,s0undt3ch/powerline,seanfisk/powerline,s0undt3ch/powerline,darac/powerline,EricSB/powerline,Luffin/powerline,bartvm/powerline,cyrixhero/powerline,S0lll0s/powerline,xfumihiro/powerline,xxxhycl2010/powerline,Luffin/powerline,IvanAli/powerline,QuLogic/powerline,dragon788/powerline,blindFS/powerline,kenrachynski/powerline,QuLogic/powerline,xfumihiro/powerline,prvnkumar/powerline,prvnkumar/powerline,blindFS/powerline,Luffin/powerline
|
---
+++
@@ -13,6 +13,21 @@
from powerline.lib.encoding import get_unicode_writer
+class BarPowerline(Powerline):
+ get_encoding = staticmethod(lambda: 'utf-8')
+
+ def init(self):
+ super(BarPowerline, self).init(ext='wm', renderer_module='bar')
+
+
+def render(event=None, data=None, sub=None):
+ global lock
+ with lock:
+ write(powerline.render())
+ write('\n')
+ sys.stdout.flush()
+
+
if __name__ == '__main__':
parser = ArgumentParser(description='Powerline BAR bindings.')
parser.add_argument(
@@ -20,20 +35,12 @@
help='Subscribe for i3 events.'
)
args = parser.parse_args()
- powerline = Powerline('wm', renderer_module='bar')
- powerline.update_renderer()
+ powerline = BarPowerline()
interval = 0.5
lock = Lock()
write = get_unicode_writer(encoding='utf-8')
-
- def render(event=None, data=None, sub=None):
- global lock
- with lock:
- write(powerline.render())
- write('\n')
- sys.stdout.flush()
if args.i3:
import i3
|
f99a898d66c9f88496dee73ec574c7b9b69e8dc2
|
ocds/storage/backends/design/tenders.py
|
ocds/storage/backends/design/tenders.py
|
from ocds.storage.helpers import CouchView
class AllDocs(CouchView):
design = 'docs'
@staticmethod
def map(doc):
yield (doc['tenderID'], doc)
class DateView(CouchView):
design = 'dates'
@staticmethod
def map(doc):
yield (doc['dateModified'], doc)
views = [
AllDocs(),
DateView()
]
|
from ocds.storage.helpers import CouchView
class AllDocs(CouchView):
design = 'docs'
@staticmethod
def map(doc):
if 'doc_type' in doc and doc['doc_type'] != 'Tender':
return
yield doc['_id'], doc
class DateView(CouchView):
design = 'dates'
@staticmethod
def map(doc):
if 'doc_type' in doc and doc['doc_type'] != 'Tender':
return
yield doc['_id'], doc['dateModified']
views = [
AllDocs(),
DateView()
]
|
Add filter in design docs
|
Add filter in design docs
|
Python
|
apache-2.0
|
yshalenyk/openprocurement.ocds.export,yshalenyk/ocds.export,yshalenyk/openprocurement.ocds.export
|
---
+++
@@ -7,7 +7,10 @@
@staticmethod
def map(doc):
- yield (doc['tenderID'], doc)
+ if 'doc_type' in doc and doc['doc_type'] != 'Tender':
+ return
+
+ yield doc['_id'], doc
class DateView(CouchView):
@@ -16,7 +19,10 @@
@staticmethod
def map(doc):
- yield (doc['dateModified'], doc)
+ if 'doc_type' in doc and doc['doc_type'] != 'Tender':
+ return
+
+ yield doc['_id'], doc['dateModified']
views = [
|
d3f33af2fa7d4e7bf9969752e696aaf8120642bc
|
panoptes/environment/weather_station.py
|
panoptes/environment/weather_station.py
|
import datetime
import zmq
from . import monitor
from panoptes.utils import logger, config, messaging, threads
@logger.has_logger
@config.has_config
class WeatherStation(monitor.EnvironmentalMonitor):
"""
This object is used to determine the weather safe/unsafe condition. It inherits
from the monitor.EnvironmentalMonitor base class. It listens on the 'weather'
channel of the messaging system.
Config:
weather_station.port (int): Port to publish to. Defaults to 6500
weather_station.channel (str): the channel topic to publish on. Defaults to 'weather'
Args:
messaging (panoptes.messaging.Messaging): A messaging Object for creating new
sockets.
"""
def __init__(self, messaging=None, connect_on_startup=False):
super().__init__(messaging=messaging, name='WeatherStation')
# Get the messaging information
self.port = self.config.get('messaging').get('messaging_port', 6500)
self.channel = self.config.get('messaging').get('channel', 'weather')
# Create our Publishing socket
self.socket = self.messaging.create_subscriber(port=self.port, channel=self.channel)
if connect_on_startup:
self.start_monitoring()
def monitor(self):
"""
Reads serial information off the attached weather station and publishes
message with status
"""
self.send_message('UNSAFE')
|
import datetime
import zmq
from . import monitor
from panoptes.utils import logger, config, messaging, threads
@logger.has_logger
@config.has_config
class WeatherStation(monitor.EnvironmentalMonitor):
"""
This object is used to determine the weather safe/unsafe condition. It inherits
from the monitor.EnvironmentalMonitor base class. It listens on the 'weather'
channel of the messaging system.
Config:
weather_station.port (int): Port to publish to. Defaults to 6500
weather_station.channel (str): the channel topic to publish on. Defaults to 'weather'
Args:
messaging (panoptes.messaging.Messaging): A messaging Object for creating new
sockets.
"""
def __init__(self, messaging=None, connect_on_startup=False):
super().__init__(messaging=messaging, name='WeatherStation')
# Get the messaging information
self.port = self.config.get('messaging').get('messaging_port', 6500)
self.channel = self.config.get('messaging').get('channel', 'weather')
# Create our Publishing socket
self.socket = self.messaging.create_subscriber(port=self.port, channel=self.channel)
if connect_on_startup:
self.start_monitoring()
def monitor(self):
"""
Reads serial information off the attached weather station
"""
msg = self.socket.recv_json()
|
Set up weather station to receive updates
|
Set up weather station to receive updates
|
Python
|
mit
|
Guokr1991/POCS,fmin2958/POCS,AstroHuntsman/POCS,panoptes/POCS,panoptes/POCS,fmin2958/POCS,Guokr1991/POCS,AstroHuntsman/POCS,AstroHuntsman/POCS,panoptes/POCS,panoptes/POCS,joshwalawender/POCS,Guokr1991/POCS,AstroHuntsman/POCS,fmin2958/POCS,joshwalawender/POCS,joshwalawender/POCS,Guokr1991/POCS
|
---
+++
@@ -38,7 +38,6 @@
def monitor(self):
"""
- Reads serial information off the attached weather station and publishes
- message with status
+ Reads serial information off the attached weather station
"""
- self.send_message('UNSAFE')
+ msg = self.socket.recv_json()
|
dc40793ad27704c83dbbd2e923bf0cbcd7cb00ed
|
polyaxon/event_manager/event_service.py
|
polyaxon/event_manager/event_service.py
|
from libs.services import Service
class EventService(Service):
__all__ = ('record', 'setup')
event_manager = None
def can_handle(self, event_type):
return isinstance(event_type, str) and self.event_manager.knows(event_type)
def get_event(self, event_type, instance, **kwargs):
return self.event_manager.get(
event_type,
).from_instance(instance, **kwargs)
def record(self, event_type, instance=None, **kwargs):
""" Validate and record an event.
>>> record('event.action', object_instance)
"""
if not self.is_setup:
return
if not self.can_handle(event_type=event_type):
return
event = self.get_event(event_type=event_type, instance=instance, **kwargs)
self.record_event(event)
def record_event(self, event):
""" Record an event.
>>> record_event(Event())
"""
pass
|
from libs.services import Service
class EventService(Service):
__all__ = ('record', 'setup')
event_manager = None
def can_handle(self, event_type):
return isinstance(event_type, str) and self.event_manager.knows(event_type)
def get_event(self, event_type, event_data=None, instance=None, **kwargs):
if instance or not event_data:
return self.event_manager.get(
event_type,
).from_instance(instance, **kwargs)
return self.event_manager.get(
event_type,
).from_event_data(event_data=event_data, **kwargs)
def record(self, event_type, event_data=None, instance=None, **kwargs):
""" Validate and record an event.
>>> record('event.action', object_instance)
"""
if not self.is_setup:
return
if not self.can_handle(event_type=event_type):
return
event = self.get_event(event_type=event_type,
event_data=event_data,
instance=instance,
**kwargs)
self.record_event(event)
return event
def record_event(self, event):
""" Record an event.
>>> record_event(Event())
"""
pass
|
Handle both event instanciation from object and from serialized events
|
Handle both event instanciation from object and from serialized events
|
Python
|
apache-2.0
|
polyaxon/polyaxon,polyaxon/polyaxon,polyaxon/polyaxon
|
---
+++
@@ -9,12 +9,16 @@
def can_handle(self, event_type):
return isinstance(event_type, str) and self.event_manager.knows(event_type)
- def get_event(self, event_type, instance, **kwargs):
+ def get_event(self, event_type, event_data=None, instance=None, **kwargs):
+ if instance or not event_data:
+ return self.event_manager.get(
+ event_type,
+ ).from_instance(instance, **kwargs)
return self.event_manager.get(
event_type,
- ).from_instance(instance, **kwargs)
+ ).from_event_data(event_data=event_data, **kwargs)
- def record(self, event_type, instance=None, **kwargs):
+ def record(self, event_type, event_data=None, instance=None, **kwargs):
""" Validate and record an event.
>>> record('event.action', object_instance)
@@ -24,8 +28,12 @@
if not self.can_handle(event_type=event_type):
return
- event = self.get_event(event_type=event_type, instance=instance, **kwargs)
+ event = self.get_event(event_type=event_type,
+ event_data=event_data,
+ instance=instance,
+ **kwargs)
self.record_event(event)
+ return event
def record_event(self, event):
""" Record an event.
|
38d298a81aa8fcd85b16b3879c1665085e5450be
|
exercises/control_flow/prime.py
|
exercises/control_flow/prime.py
|
#!/bin/python
def is_prime(integer):
"""Determines weather integer is prime, returns a boolean value"""
for i in range(2, integer):
if integer % i == 0:
return False
return True
print("Should be False (0): %r" % is_prime(0))
print("Should be False (1): %r" % is_prime(1))
print("Should be True (2): %r" % is_prime(2))
print("Should be False (8): %r" % is_prime(8))
print("Should be True (17): %r"% is_prime(17))
# Your code below:
|
#!/bin/python
def is_prime(integer):
"""Determines weather integer is prime, returns a boolean value"""
# add logic here to make sure number < 2 are not prime
for i in range(2, integer):
if integer % i == 0:
return False
return True
print("Should be False (0): %r" % is_prime(0))
print("Should be False (1): %r" % is_prime(1))
print("Should be True (2): %r" % is_prime(2))
print("Should be False (8): %r" % is_prime(8))
print("Should be True (17): %r"% is_prime(17))
# Your code below:
|
Add description where student should add logic
|
Add description where student should add logic
|
Python
|
mit
|
introprogramming/exercises,introprogramming/exercises,introprogramming/exercises
|
---
+++
@@ -3,6 +3,8 @@
def is_prime(integer):
"""Determines weather integer is prime, returns a boolean value"""
+ # add logic here to make sure number < 2 are not prime
+
for i in range(2, integer):
if integer % i == 0:
return False
|
d5b326d8d368d2ac75c6e078572df8c28704c163
|
vcs/models.py
|
vcs/models.py
|
from django.db import models
class Activity(models.Model):
group = models.CharField(max_length=4)
grouptype = models.TextField()
groupdetail = models.TextField()
details = models.TextField()
disabled = models.BooleanField()
time = models.DecimalField(decimal_places=2, max_digits=10)
unique_together = (("group", "grouptype", "disabled", "time"),)
class ActivityEntry(models.Model):
from timetracker.tracker.models import Tbluser
user = models.ManyToManyField(
Tbluser,
related_name="user_foreign"
)
activity = models.ManyToManyField(
Activity,
related_name="activity_foreign"
)
amount = models.BigIntegerField()
def time(self):
return self.activity.time * self.amount
|
from django.db import models
class Activity(models.Model):
group = models.CharField(max_length=4)
grouptype = models.TextField()
groupdetail = models.TextField()
details = models.TextField()
disabled = models.BooleanField()
time = models.DecimalField(decimal_places=2, max_digits=10)
unique_together = (("group", "grouptype", "disabled", "time"),)
class ActivityEntry(models.Model):
user = models.ManyToManyField(
'tracker.Tbluser',
related_name="user_foreign"
)
activity = models.ManyToManyField(
Activity,
related_name="activity_foreign"
)
amount = models.BigIntegerField()
def time(self):
return self.activity.time * self.amount
|
Use the app string version of foreign keying. It prevents a circular import.
|
Use the app string version of foreign keying. It prevents a circular import.
|
Python
|
bsd-3-clause
|
AeroNotix/django-timetracker,AeroNotix/django-timetracker,AeroNotix/django-timetracker
|
---
+++
@@ -10,9 +10,8 @@
unique_together = (("group", "grouptype", "disabled", "time"),)
class ActivityEntry(models.Model):
- from timetracker.tracker.models import Tbluser
user = models.ManyToManyField(
- Tbluser,
+ 'tracker.Tbluser',
related_name="user_foreign"
)
activity = models.ManyToManyField(
|
1163bc40a15eb2461c6ead570db8a8d211f1f5be
|
web/blueprints/facilities/tables.py
|
web/blueprints/facilities/tables.py
|
from web.blueprints.helpers.table import BootstrapTable, Column
class SiteTable(BootstrapTable):
def __init__(self, *a, **kw):
super().__init__(*a, columns=[
Column('site', 'Site', formatter='table.linkFormatter'),
Column('buildings', 'Buildings', formatter='table.multiBtnFormatter'),
], **kw)
class BuildingLevelRoomTable(BootstrapTable):
def __init__(self, *a, **kw):
super().__init__(*a, columns=[
Column('room', 'Raum', formatter='table.linkFormatter'),
Column('inhabitants', 'Bewohner', formatter='table.multiBtnFormatter'),
], table_args={
'data-query-params': 'perhaps_all_users_query_params',
}, **kw)
def generate_toolbar(self):
"""Generate a toolbar with a "Display all users" button
"""
yield '<a href="#" id="rooms-toggle-all-users" class="btn btn-default" role="button">'
yield '<span class="glyphicon glyphicon-user"></span>'
yield 'Display all users'
yield '</a>'
class RoomLogTable(BootstrapTable):
def __init__(self, *a, **kw):
super().__init__(*a, columns=[
Column('created_at', 'Erstellt um'),
Column('user', 'Nutzer', formatter='table.linkFormatter'),
Column('message', 'Nachricht'),
], **kw)
|
from web.blueprints.helpers.table import BootstrapTable, Column
class SiteTable(BootstrapTable):
def __init__(self, *a, **kw):
super().__init__(*a, columns=[
Column('site', 'Site', formatter='table.linkFormatter'),
Column('buildings', 'Buildings', formatter='table.multiBtnFormatter'),
], **kw)
class BuildingLevelRoomTable(BootstrapTable):
def __init__(self, *a, **kw):
super().__init__(*a, columns=[
Column('room', 'Raum', formatter='table.linkFormatter'),
Column('inhabitants', 'Bewohner', formatter='table.multiBtnFormatter'),
], table_args={
'data-sort-name': 'room',
'data-query-params': 'perhaps_all_users_query_params',
}, **kw)
def generate_toolbar(self):
"""Generate a toolbar with a "Display all users" button
"""
yield '<a href="#" id="rooms-toggle-all-users" class="btn btn-default" role="button">'
yield '<span class="glyphicon glyphicon-user"></span>'
yield 'Display all users'
yield '</a>'
class RoomLogTable(BootstrapTable):
def __init__(self, *a, **kw):
super().__init__(*a, columns=[
Column('created_at', 'Erstellt um'),
Column('user', 'Nutzer', formatter='table.linkFormatter'),
Column('message', 'Nachricht'),
], **kw)
|
Sort room table by room name by default
|
Sort room table by room name by default
|
Python
|
apache-2.0
|
agdsn/pycroft,lukasjuhrich/pycroft,agdsn/pycroft,lukasjuhrich/pycroft,agdsn/pycroft,lukasjuhrich/pycroft,agdsn/pycroft,lukasjuhrich/pycroft,agdsn/pycroft
|
---
+++
@@ -15,6 +15,7 @@
Column('room', 'Raum', formatter='table.linkFormatter'),
Column('inhabitants', 'Bewohner', formatter='table.multiBtnFormatter'),
], table_args={
+ 'data-sort-name': 'room',
'data-query-params': 'perhaps_all_users_query_params',
}, **kw)
|
1abbca6200fa3da0a3216b18b1385f3575edb49a
|
registration/__init__.py
|
registration/__init__.py
|
from django.utils.version import get_version as django_get_version
VERSION = (0, 9, 0, 'beta', 1)
def get_version():
return django_get_version(VERSION) # pragma: no cover
|
VERSION = (0, 9, 0, 'beta', 1)
def get_version():
from django.utils.version import get_version as django_get_version
return django_get_version(VERSION) # pragma: no cover
|
Move import of Django's get_version into django-registration's get_version, to avoid dependency-order problems.
|
Move import of Django's get_version into django-registration's get_version, to avoid dependency-order problems.
|
Python
|
bsd-3-clause
|
myimages/django-registration,Troyhy/django-registration,futurecolors/django-registration,hacklabr/django-registration,akvo/django-registration,sandipagr/django-registration,futurecolors/django-registration,liberation/django-registration,euanlau/django-registration,tdruez/django-registration,Troyhy/django-registration,gone/django-registration,hacklabr/django-registration,mypebble/djregs,ubernostrum/django-registration,euanlau/django-registration,sandipagr/django-registration,dirtycoder/django-registration,danielsamuels/django-registration,liberation/django-registration,awakeup/django-registration,gone/django-registration,kennydude/djregs,akvo/django-registration
|
---
+++
@@ -1,8 +1,6 @@
-from django.utils.version import get_version as django_get_version
-
-
VERSION = (0, 9, 0, 'beta', 1)
def get_version():
+ from django.utils.version import get_version as django_get_version
return django_get_version(VERSION) # pragma: no cover
|
37d01f6088b1cf5673f66f4532dd51c73a0156f1
|
rest_framework/authtoken/serializers.py
|
rest_framework/authtoken/serializers.py
|
from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
class AuthTokenSerializer(serializers.Serializer):
username = serializers.CharField()
password = serializers.CharField()
def validate(self, attrs):
username = attrs.get('username')
password = attrs.get('password')
if username and password:
user = authenticate(username=username, password=password)
if user:
if not user.is_active:
msg = _('User account is disabled.')
raise serializers.ValidationError(msg)
attrs['user'] = user
return attrs
else:
msg = _('Unable to login with provided credentials.')
raise serializers.ValidationError(msg)
else:
msg = _('Must include "username" and "password"')
raise serializers.ValidationError(msg)
|
from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
class AuthTokenSerializer(serializers.Serializer):
username = serializers.CharField()
password = serializers.CharField()
def validate(self, attrs):
username = attrs.get('username')
password = attrs.get('password')
if username and password:
user = authenticate(username=username, password=password)
if user:
if not user.is_active:
msg = _('User account is disabled.')
raise serializers.ValidationError(msg)
attrs['user'] = user
return attrs
else:
msg = _('Unable to log in with provided credentials.')
raise serializers.ValidationError(msg)
else:
msg = _('Must include "username" and "password"')
raise serializers.ValidationError(msg)
|
Fix grammar in login error message
|
Fix grammar in login error message
|
Python
|
bsd-2-clause
|
sehmaschine/django-rest-framework,arpheno/django-rest-framework,ajaali/django-rest-framework,adambain-vokal/django-rest-framework,buptlsl/django-rest-framework,aericson/django-rest-framework,YBJAY00000/django-rest-framework,VishvajitP/django-rest-framework,werthen/django-rest-framework,xiaotangyuan/django-rest-framework,thedrow/django-rest-framework-1,maryokhin/django-rest-framework,James1345/django-rest-framework,hnakamur/django-rest-framework,andriy-s/django-rest-framework,abdulhaq-e/django-rest-framework,tomchristie/django-rest-framework,HireAnEsquire/django-rest-framework,kgeorgy/django-rest-framework,cyberj/django-rest-framework,johnraz/django-rest-framework,rhblind/django-rest-framework,canassa/django-rest-framework,nhorelik/django-rest-framework,jness/django-rest-framework,potpath/django-rest-framework,krinart/django-rest-framework,justanr/django-rest-framework,vstoykov/django-rest-framework,leeahoward/django-rest-framework,canassa/django-rest-framework,qsorix/django-rest-framework,paolopaolopaolo/django-rest-framework,canassa/django-rest-framework,sheppard/django-rest-framework,pombredanne/django-rest-framework,ambivalentno/django-rest-framework,linovia/django-rest-framework,HireAnEsquire/django-rest-framework,agconti/django-rest-framework,cyberj/django-rest-framework,ticosax/django-rest-framework,gregmuellegger/django-rest-framework,ticosax/django-rest-framework,rafaelcaricio/django-rest-framework,sbellem/django-rest-framework,xiaotangyuan/django-rest-framework,kezabelle/django-rest-framework,gregmuellegger/django-rest-framework,wzbozon/django-rest-framework,xiaotangyuan/django-rest-framework,yiyocx/django-rest-framework,yiyocx/django-rest-framework,jerryhebert/django-rest-framework,wedaly/django-rest-framework,rafaelang/django-rest-framework,jpulec/django-rest-framework,callorico/django-rest-framework,buptlsl/django-rest-framework,wangpanjun/django-rest-framework,jpadilla/django-rest-framework,hnakamur/django-rest-framework,delinhabit/django-rest-framework,jerryhebert/django-rest-framework,ossanna16/django-rest-framework,jerryhebert/django-rest-framework,werthen/django-rest-framework,jness/django-rest-framework,elim/django-rest-framework,lubomir/django-rest-framework,uploadcare/django-rest-framework,agconti/django-rest-framework,jpulec/django-rest-framework,tigeraniya/django-rest-framework,waytai/django-rest-framework,akalipetis/django-rest-framework,sheppard/django-rest-framework,atombrella/django-rest-framework,d0ugal/django-rest-framework,pombredanne/django-rest-framework,kgeorgy/django-rest-framework,antonyc/django-rest-framework,wangpanjun/django-rest-framework,nryoung/django-rest-framework,alacritythief/django-rest-framework,tigeraniya/django-rest-framework,adambain-vokal/django-rest-framework,cyberj/django-rest-framework,rafaelcaricio/django-rest-framework,hnakamur/django-rest-framework,VishvajitP/django-rest-framework,linovia/django-rest-framework,jpadilla/django-rest-framework,rhblind/django-rest-framework,maryokhin/django-rest-framework,ticosax/django-rest-framework,wwj718/django-rest-framework,potpath/django-rest-framework,tcroiset/django-rest-framework,tomchristie/django-rest-framework,bluedazzle/django-rest-framework,andriy-s/django-rest-framework,uruz/django-rest-framework,raphaelmerx/django-rest-framework,kennydude/django-rest-framework,mgaitan/django-rest-framework,raphaelmerx/django-rest-framework,YBJAY00000/django-rest-framework,damycra/django-rest-framework,iheitlager/django-rest-framework,tcroiset/django-rest-framework,HireAnEsquire/django-rest-framework,simudream/django-rest-framework,werthen/django-rest-framework,kgeorgy/django-rest-framework,justanr/django-rest-framework,iheitlager/django-rest-framework,ebsaral/django-rest-framework,edx/django-rest-framework,kennydude/django-rest-framework,James1345/django-rest-framework,jpulec/django-rest-framework,edx/django-rest-framework,callorico/django-rest-framework,rafaelang/django-rest-framework,hunter007/django-rest-framework,rafaelcaricio/django-rest-framework,hnarayanan/django-rest-framework,akalipetis/django-rest-framework,sehmaschine/django-rest-framework,hnarayanan/django-rest-framework,edx/django-rest-framework,pombredanne/django-rest-framework,tcroiset/django-rest-framework,antonyc/django-rest-framework,zeldalink0515/django-rest-framework,AlexandreProenca/django-rest-framework,rubendura/django-rest-framework,hnarayanan/django-rest-framework,ezheidtmann/django-rest-framework,justanr/django-rest-framework,yiyocx/django-rest-framework,jpadilla/django-rest-framework,paolopaolopaolo/django-rest-framework,kennydude/django-rest-framework,ossanna16/django-rest-framework,nhorelik/django-rest-framework,AlexandreProenca/django-rest-framework,atombrella/django-rest-framework,gregmuellegger/django-rest-framework,callorico/django-rest-framework,kylefox/django-rest-framework,simudream/django-rest-framework,dmwyatt/django-rest-framework,douwevandermeij/django-rest-framework,douwevandermeij/django-rest-framework,agconti/django-rest-framework,wangpanjun/django-rest-framework,nryoung/django-rest-framework,sbellem/django-rest-framework,wedaly/django-rest-framework,damycra/django-rest-framework,cheif/django-rest-framework,davesque/django-rest-framework,zeldalink0515/django-rest-framework,sehmaschine/django-rest-framework,alacritythief/django-rest-framework,uploadcare/django-rest-framework,cheif/django-rest-framework,mgaitan/django-rest-framework,vstoykov/django-rest-framework,elim/django-rest-framework,jness/django-rest-framework,kezabelle/django-rest-framework,uploadcare/django-rest-framework,fishky/django-rest-framework,aericson/django-rest-framework,paolopaolopaolo/django-rest-framework,damycra/django-rest-framework,MJafarMashhadi/django-rest-framework,ambivalentno/django-rest-framework,delinhabit/django-rest-framework,abdulhaq-e/django-rest-framework,krinart/django-rest-framework,rhblind/django-rest-framework,sheppard/django-rest-framework,ajaali/django-rest-framework,arpheno/django-rest-framework,akalipetis/django-rest-framework,tomchristie/django-rest-framework,wwj718/django-rest-framework,ossanna16/django-rest-framework,alacritythief/django-rest-framework,mgaitan/django-rest-framework,arpheno/django-rest-framework,cheif/django-rest-framework,bluedazzle/django-rest-framework,ambivalentno/django-rest-framework,uruz/django-rest-framework,rubendura/django-rest-framework,vstoykov/django-rest-framework,fishky/django-rest-framework,elim/django-rest-framework,jtiai/django-rest-framework,qsorix/django-rest-framework,lubomir/django-rest-framework,antonyc/django-rest-framework,waytai/django-rest-framework,rubendura/django-rest-framework,nhorelik/django-rest-framework,bluedazzle/django-rest-framework,atombrella/django-rest-framework,aericson/django-rest-framework,d0ugal/django-rest-framework,jtiai/django-rest-framework,rafaelang/django-rest-framework,d0ugal/django-rest-framework,wzbozon/django-rest-framework,ashishfinoit/django-rest-framework,dmwyatt/django-rest-framework,wedaly/django-rest-framework,kylefox/django-rest-framework,raphaelmerx/django-rest-framework,hunter007/django-rest-framework,nryoung/django-rest-framework,wzbozon/django-rest-framework,hunter007/django-rest-framework,ebsaral/django-rest-framework,zeldalink0515/django-rest-framework,abdulhaq-e/django-rest-framework,buptlsl/django-rest-framework,lubomir/django-rest-framework,douwevandermeij/django-rest-framework,tigeraniya/django-rest-framework,thedrow/django-rest-framework-1,johnraz/django-rest-framework,iheitlager/django-rest-framework,kylefox/django-rest-framework,dmwyatt/django-rest-framework,maryokhin/django-rest-framework,ashishfinoit/django-rest-framework,ebsaral/django-rest-framework,MJafarMashhadi/django-rest-framework,davesque/django-rest-framework,YBJAY00000/django-rest-framework,sbellem/django-rest-framework,andriy-s/django-rest-framework,kezabelle/django-rest-framework,krinart/django-rest-framework,leeahoward/django-rest-framework,brandoncazander/django-rest-framework,wwj718/django-rest-framework,uruz/django-rest-framework,brandoncazander/django-rest-framework,fishky/django-rest-framework,adambain-vokal/django-rest-framework,jtiai/django-rest-framework,James1345/django-rest-framework,ashishfinoit/django-rest-framework,thedrow/django-rest-framework-1,linovia/django-rest-framework,simudream/django-rest-framework,davesque/django-rest-framework,delinhabit/django-rest-framework,ezheidtmann/django-rest-framework,potpath/django-rest-framework,VishvajitP/django-rest-framework,leeahoward/django-rest-framework,AlexandreProenca/django-rest-framework,ajaali/django-rest-framework,waytai/django-rest-framework,johnraz/django-rest-framework,qsorix/django-rest-framework,ezheidtmann/django-rest-framework,brandoncazander/django-rest-framework,MJafarMashhadi/django-rest-framework
|
---
+++
@@ -22,7 +22,7 @@
attrs['user'] = user
return attrs
else:
- msg = _('Unable to login with provided credentials.')
+ msg = _('Unable to log in with provided credentials.')
raise serializers.ValidationError(msg)
else:
msg = _('Must include "username" and "password"')
|
cd9a51ab2fe6b99c0665b8f499363a4d557b4a4d
|
DataWrangling/CaseStudy/sample_file.py
|
DataWrangling/CaseStudy/sample_file.py
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET # Use cElementTree or lxml if too slow
import os
OSM_FILE = "san-francisco-bay_california.osm" # Replace this with your osm file
SAMPLE_FILE = "sample_sfb.osm"
k = 20 # Parameter: take every k-th top level element
def get_element(osm_file, tags=('node', 'way', 'relation')):
"""Yield element if it is the right type of tag
Reference:
http://stackoverflow.com/questions/3095434/inserting-newlines-in-xml-file-generated-via-xml-etree-elementtree-in-python
"""
context = iter(ET.iterparse(osm_file, events=('start', 'end')))
_, root = next(context)
for event, elem in context:
if event == 'end' and elem.tag in tags:
yield elem
root.clear()
def main():
os.chdir('./data')
with open(SAMPLE_FILE, 'wb') as output:
output.write('<?xml version="1.0" encoding="UTF-8"?>\n')
output.write('<osm>\n ')
# Write every kth top level element
for i, element in enumerate(get_element(OSM_FILE)):
if i % k == 0:
output.write(ET.tostring(element, encoding='utf-8'))
output.write('</osm>')
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET # Use cElementTree or lxml if too slow
import os
OSM_FILE = "san-francisco-bay_california.osm" # Replace this with your osm file
SAMPLE_FILE = "sample_sfb.osm"
k = 20 # Parameter: take every k-th top level element
def get_element(osm_file, tags=('node', 'way', 'relation')):
"""Yield element if it is the right type of tag
Reference:
http://stackoverflow.com/questions/3095434/inserting-newlines-in-xml-file-generated-via-xml-etree-elementtree-in-python
"""
context = iter(ET.iterparse(osm_file, events=('start', 'end')))
_, root = next(context)
for event, elem in context:
if event == 'end' and elem.tag in tags:
yield elem
root.clear()
def main():
os.chdir('./data')
with open(SAMPLE_FILE, 'wb') as output:
output.write('<?xml version="1.0" encoding="UTF-8"?>\n')
output.write('<osm>\n ')
# Write every kth top level element
for i, element in enumerate(get_element(OSM_FILE)):
if i % k == 0:
output.write(ET.tostring(element, encoding='utf-8'))
output.write('</osm>')
if __name__ == '__main__':
main()
|
Modify script which split your region in smaller sample
|
feat: Modify script which split your region in smaller sample
|
Python
|
mit
|
aguijarro/DataSciencePython
|
---
+++
@@ -34,3 +34,6 @@
output.write(ET.tostring(element, encoding='utf-8'))
output.write('</osm>')
+
+if __name__ == '__main__':
+ main()
|
828e75919bd71912baf75a64010efcfcd93d07f1
|
library_magic.py
|
library_magic.py
|
import sys
import subprocess
import shutil
executable = sys.argv[1]
execfolder = sys.argv[1].rsplit("/",1)[0]
libdir = execfolder+"/lib"
otool_cmd = ["otool", "-L",executable]
# Run otool
otool_out = subprocess.check_output(otool_cmd).split("\n\t")
# Find all the dylib files
for l in otool_out:
s = l.split(".dylib")
if len(s) > 1:
lib = s[0]+".dylib"
libname = lib.rsplit("/",1)[1]
shutil.copyfile(lib, libdir+"/"+libname)
install_name_tool = ["install_name_tool", "-change", lib, "@executable_path/lib/"+libname, executable]
subprocess.call(install_name_tool)
|
import sys
import subprocess
import shutil
copied = []
def update_libraries(executable):
# Find all the dylib files and recursively add dependencies
print "\nChecking dependencies of " + executable
otool_cmd = ["otool", "-L",executable]
execfolder = executable.rsplit("/",1)[0]
otool_out = subprocess.check_output(otool_cmd).split("\n\t")
execname = executable.rsplit("/",1)[1]
for l in otool_out:
s = l.split(".dylib")
if len(s) > 1:
lib = s[0]+".dylib"
libname = lib.rsplit("/",1)[1]
if libname not in copied:
print "Requires: " + lib
new_lib = execfolder+"/"+libname
if (lib != new_lib):
shutil.copyfile(lib, new_lib)
copied.append(libname)
install_name_tool = ["install_name_tool", "-change", lib, "./"+libname, executable]
print "Installing "+lib
subprocess.call(install_name_tool)
new_library = execfolder+"/"+libname
print "Calling on " + new_library
update_libraries(new_library)
# Update libraries on the default executable
update_libraries(sys.argv[1])
|
Update library magic to be recursive
|
Update library magic to be recursive
|
Python
|
bsd-3-clause
|
baubie/SpikeDB,baubie/SpikeDB,baubie/SpikeDB,baubie/SpikeDB
|
---
+++
@@ -2,20 +2,35 @@
import subprocess
import shutil
-executable = sys.argv[1]
-execfolder = sys.argv[1].rsplit("/",1)[0]
-libdir = execfolder+"/lib"
-otool_cmd = ["otool", "-L",executable]
+copied = []
-# Run otool
-otool_out = subprocess.check_output(otool_cmd).split("\n\t")
+def update_libraries(executable):
+
+ # Find all the dylib files and recursively add dependencies
+ print "\nChecking dependencies of " + executable
+ otool_cmd = ["otool", "-L",executable]
+ execfolder = executable.rsplit("/",1)[0]
+ otool_out = subprocess.check_output(otool_cmd).split("\n\t")
+ execname = executable.rsplit("/",1)[1]
-# Find all the dylib files
-for l in otool_out:
- s = l.split(".dylib")
- if len(s) > 1:
- lib = s[0]+".dylib"
- libname = lib.rsplit("/",1)[1]
- shutil.copyfile(lib, libdir+"/"+libname)
- install_name_tool = ["install_name_tool", "-change", lib, "@executable_path/lib/"+libname, executable]
- subprocess.call(install_name_tool)
+ for l in otool_out:
+ s = l.split(".dylib")
+ if len(s) > 1:
+ lib = s[0]+".dylib"
+ libname = lib.rsplit("/",1)[1]
+ if libname not in copied:
+ print "Requires: " + lib
+ new_lib = execfolder+"/"+libname
+ if (lib != new_lib):
+ shutil.copyfile(lib, new_lib)
+ copied.append(libname)
+ install_name_tool = ["install_name_tool", "-change", lib, "./"+libname, executable]
+ print "Installing "+lib
+ subprocess.call(install_name_tool)
+ new_library = execfolder+"/"+libname
+ print "Calling on " + new_library
+ update_libraries(new_library)
+
+
+# Update libraries on the default executable
+update_libraries(sys.argv[1])
|
dfa39db42cc5ce2c29da2ec0c388865ec7f41030
|
oauth2_provider/forms.py
|
oauth2_provider/forms.py
|
from django import forms
class AllowForm(forms.Form):
redirect_uri = forms.URLField(widget=forms.HiddenInput())
scopes = forms.CharField(required=False, widget=forms.HiddenInput())
client_id = forms.CharField(widget=forms.HiddenInput())
state = forms.CharField(required=False, widget=forms.HiddenInput())
response_type = forms.CharField(widget=forms.HiddenInput())
|
from django import forms
class AllowForm(forms.Form):
allow = forms.BooleanField(required=False)
redirect_uri = forms.URLField(widget=forms.HiddenInput())
scopes = forms.CharField(required=False, widget=forms.HiddenInput())
client_id = forms.CharField(widget=forms.HiddenInput())
state = forms.CharField(required=False, widget=forms.HiddenInput())
response_type = forms.CharField(widget=forms.HiddenInput())
|
Add allow field to form
|
Add allow field to form
|
Python
|
bsd-2-clause
|
trbs/django-oauth-toolkit,DeskConnect/django-oauth-toolkit,jensadne/django-oauth-toolkit,vmalavolta/django-oauth-toolkit,JensTimmerman/django-oauth-toolkit,JensTimmerman/django-oauth-toolkit,Gr1N/django-oauth-toolkit,andrefsp/django-oauth-toolkit,jensadne/django-oauth-toolkit,drgarcia1986/django-oauth-toolkit,bleib1dj/django-oauth-toolkit,CloudNcodeInc/django-oauth-toolkit,lzen/django-oauth-toolkit,Gr1N/django-oauth-toolkit,DeskConnect/django-oauth-toolkit,drgarcia1986/django-oauth-toolkit,vmalavolta/django-oauth-toolkit,mjrulesamrat/django-oauth-toolkit,andrefsp/django-oauth-toolkit,StepicOrg/django-oauth-toolkit,bleib1dj/django-oauth-toolkit,trbs/django-oauth-toolkit,CloudNcodeInc/django-oauth-toolkit,mjrulesamrat/django-oauth-toolkit,cheif/django-oauth-toolkit,Knotis/django-oauth-toolkit,lzen/django-oauth-toolkit,svetlyak40wt/django-oauth-toolkit,natgeo/django-oauth-toolkit,cheif/django-oauth-toolkit,Knotis/django-oauth-toolkit,StepicOrg/django-oauth-toolkit,Natgeoed/django-oauth-toolkit
|
---
+++
@@ -2,6 +2,7 @@
class AllowForm(forms.Form):
+ allow = forms.BooleanField(required=False)
redirect_uri = forms.URLField(widget=forms.HiddenInput())
scopes = forms.CharField(required=False, widget=forms.HiddenInput())
client_id = forms.CharField(widget=forms.HiddenInput())
|
11cd074f67668135d606f68dddb66c465ec01756
|
opps/core/tags/models.py
|
opps/core/tags/models.py
|
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from opps.core.models import Date, Slugged
class Tag(Date, Slugged):
name = models.CharField(_(u'Name'), max_length=255, unique=True)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super(Tag, self).save(*args, **kwargs)
__unicode__ = lambda self: self.name
class Meta:
verbose_name = _(u'Tag')
verbose_name_plural = _(u'Tags')
class Tagged(models.Model):
tags = models.CharField(_(u'Tags'), max_length=4000, blank=True,
help_text=_(u'A comma-separated list of tags.'))
def save(self, *args, **kwargs):
if self.tags:
tags = set(self.tags.split(','))
for tag in tags:
Tag.objects.get_or_create(name=tag)
self.tags = ','.join(tags)
super(Tagged, self).save(*args, **kwargs)
def get_tags(self):
if self.tags:
tags = []
for tag in self.tags.aplit(','):
t, created = Tag.objects.get_or_create(name=tag)
tags.append(t)
return tags
class Meta:
abstract = True
|
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from opps.core.models import Date, Slugged
class Tag(Date, Slugged):
name = models.CharField(_(u'Name'), max_length=255, unique=True,
db_index=True)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super(Tag, self).save(*args, **kwargs)
__unicode__ = lambda self: self.name
class Meta:
verbose_name = _(u'Tag')
verbose_name_plural = _(u'Tags')
unique_together = ['slug', 'name']
class Tagged(models.Model):
tags = models.CharField(_(u'Tags'), max_length=4000, db_index=True,
blank=True, null=True,
help_text=_(u'A comma-separated list of tags.'))
def save(self, *args, **kwargs):
if self.tags:
tags = set(self.tags.split(','))
for tag in tags:
Tag.objects.get_or_create(name=tag)
self.tags = ','.join(tags)
super(Tagged, self).save(*args, **kwargs)
def get_tags(self):
if self.tags:
tags = []
for tag in self.tags.aplit(','):
t, created = Tag.objects.get_or_create(name=tag)
tags.append(t)
return tags
class Meta:
abstract = True
|
Add db index on field tag name
|
Add db index on field tag name
|
Python
|
mit
|
jeanmask/opps,YACOWS/opps,williamroot/opps,YACOWS/opps,opps/opps,opps/opps,YACOWS/opps,YACOWS/opps,opps/opps,opps/opps,jeanmask/opps,jeanmask/opps,jeanmask/opps,williamroot/opps,williamroot/opps,williamroot/opps
|
---
+++
@@ -7,7 +7,8 @@
class Tag(Date, Slugged):
- name = models.CharField(_(u'Name'), max_length=255, unique=True)
+ name = models.CharField(_(u'Name'), max_length=255, unique=True,
+ db_index=True)
def save(self, *args, **kwargs):
if not self.slug:
@@ -19,10 +20,12 @@
class Meta:
verbose_name = _(u'Tag')
verbose_name_plural = _(u'Tags')
+ unique_together = ['slug', 'name']
class Tagged(models.Model):
- tags = models.CharField(_(u'Tags'), max_length=4000, blank=True,
+ tags = models.CharField(_(u'Tags'), max_length=4000, db_index=True,
+ blank=True, null=True,
help_text=_(u'A comma-separated list of tags.'))
def save(self, *args, **kwargs):
|
38a2d86aed4ea1e94691993c5f49722f9a69ac8d
|
lisa/__init__.py
|
lisa/__init__.py
|
#! /usr/bin/env python3
import warnings
import os
import sys
from lisa.version import __version__
# Raise an exception when a deprecated API is used from within a lisa.*
# submodule. This ensures that we don't use any deprecated APIs internally, so
# they are only kept for external backward compatibility purposes.
warnings.filterwarnings(
action='error',
category=DeprecationWarning,
module=r'{}\..*'.format(__name__),
)
# When the deprecated APIs are used from __main__ (script or notebook), always
# show the warning
warnings.filterwarnings(
action='always',
category=DeprecationWarning,
module=r'__main__',
)
# Prevent matplotlib from trying to connect to X11 server, for headless testing.
# Must be done before importing matplotlib.pyplot or pylab
try:
import matplotlib
except ImportError:
pass
else:
if not os.getenv('DISPLAY'):
matplotlib.use('Agg')
if sys.version_info < (3, 6):
warnings.warn(
'Python 3.6 will soon be required to run LISA, please upgrade from {} to any version higher than 3.6'.format(
'.'.join(
map(str, tuple(sys.version_info)[:3])
),
),
DeprecationWarning,
)
# vim :set tabstop=4 shiftwidth=4 textwidth=80 expandtab
|
#! /usr/bin/env python3
import warnings
import os
import sys
from lisa.version import __version__
# Raise an exception when a deprecated API is used from within a lisa.*
# submodule. This ensures that we don't use any deprecated APIs internally, so
# they are only kept for external backward compatibility purposes.
warnings.filterwarnings(
action='error',
category=DeprecationWarning,
module=r'{}\..*'.format(__name__),
)
# When the deprecated APIs are used from __main__ (script or notebook), always
# show the warning
warnings.filterwarnings(
action='always',
category=DeprecationWarning,
module=r'__main__',
)
# Prevent matplotlib from trying to connect to X11 server, for headless testing.
# Must be done before importing matplotlib.pyplot or pylab
try:
import matplotlib
except ImportError:
pass
else:
if not os.getenv('DISPLAY'):
matplotlib.use('Agg')
# vim :set tabstop=4 shiftwidth=4 textwidth=80 expandtab
|
Remove Python < 3.6 version check
|
lisa: Remove Python < 3.6 version check
Since Python >= 3.6 is now mandatory, remove the check and the warning.
|
Python
|
apache-2.0
|
ARM-software/lisa,credp/lisa,credp/lisa,credp/lisa,credp/lisa,ARM-software/lisa,ARM-software/lisa,ARM-software/lisa
|
---
+++
@@ -34,14 +34,4 @@
if not os.getenv('DISPLAY'):
matplotlib.use('Agg')
-if sys.version_info < (3, 6):
- warnings.warn(
- 'Python 3.6 will soon be required to run LISA, please upgrade from {} to any version higher than 3.6'.format(
- '.'.join(
- map(str, tuple(sys.version_info)[:3])
- ),
- ),
- DeprecationWarning,
- )
-
# vim :set tabstop=4 shiftwidth=4 textwidth=80 expandtab
|
7fd76d87cfda8f02912985cb3cf650ee8ff2e11e
|
mica/report/tests/test_write_report.py
|
mica/report/tests/test_write_report.py
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import tempfile
import os
import shutil
import pytest
from .. import report
try:
import Ska.DBI
with Ska.DBI.DBI(server='sqlsao', dbi='sybase', user='aca_ops', database='axafocat') as db:
assert db.conn._is_connected == 1
HAS_SYBASE_ACCESS = True
except:
HAS_SYBASE_ACCESS = False
HAS_SC_ARCHIVE = os.path.exists(report.starcheck.FILES['data_root'])
@pytest.mark.skipif('not HAS_SYBASE_ACCESS', reason='Report test requires Sybase/OCAT access')
@pytest.mark.skipif('not HAS_SC_ARCHIVE', reason='Report test requires mica starcheck archive')
def test_write_reports():
"""
Make a report and database
"""
tempdir = tempfile.mkdtemp()
# Get a temporary file, but then delete it, because report.py will only
# make a new table if the supplied file doesn't exist
fh, fn = tempfile.mkstemp(dir=tempdir, suffix='.db3')
os.unlink(fn)
report.REPORT_ROOT = tempdir
report.REPORT_SERVER = fn
for obsid in [20001, 15175, 54778]:
report.main(obsid)
os.unlink(fn)
shutil.rmtree(tempdir)
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import tempfile
import os
import shutil
import pytest
from .. import report
try:
import Ska.DBI
with Ska.DBI.DBI(server='sqlsao', dbi='sybase', user='aca_ops', database='axafocat') as db:
HAS_SYBASE_ACCESS = True
except:
HAS_SYBASE_ACCESS = False
HAS_SC_ARCHIVE = os.path.exists(report.starcheck.FILES['data_root'])
@pytest.mark.skipif('not HAS_SYBASE_ACCESS', reason='Report test requires Sybase/OCAT access')
@pytest.mark.skipif('not HAS_SC_ARCHIVE', reason='Report test requires mica starcheck archive')
def test_write_reports():
"""
Make a report and database
"""
tempdir = tempfile.mkdtemp()
# Get a temporary file, but then delete it, because report.py will only
# make a new table if the supplied file doesn't exist
fh, fn = tempfile.mkstemp(dir=tempdir, suffix='.db3')
os.unlink(fn)
report.REPORT_ROOT = tempdir
report.REPORT_SERVER = fn
for obsid in [20001, 15175, 54778]:
report.main(obsid)
os.unlink(fn)
shutil.rmtree(tempdir)
|
Remove py2 Ska.DBI assert in report test
|
Remove py2 Ska.DBI assert in report test
|
Python
|
bsd-3-clause
|
sot/mica,sot/mica
|
---
+++
@@ -9,7 +9,6 @@
try:
import Ska.DBI
with Ska.DBI.DBI(server='sqlsao', dbi='sybase', user='aca_ops', database='axafocat') as db:
- assert db.conn._is_connected == 1
HAS_SYBASE_ACCESS = True
except:
HAS_SYBASE_ACCESS = False
|
ed0821bd41a10dd00727f09cf9ba82123bd2cf93
|
scripts/import_permissions_and_roles.py
|
scripts/import_permissions_and_roles.py
|
#!/usr/bin/env python
"""Import permissions, roles, and their relations from a TOML file.
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""
import click
from byceps.services.authorization import impex_service
from byceps.util.system import get_config_filename_from_env_or_exit
from _util import app_context
@click.command()
@click.argument('data_file', type=click.File())
def execute(data_file):
permission_count, role_count = impex_service.import_from_file(data_file)
click.secho(
'Imported {permission_count} permissions and {role_count} roles.',
fg='green',
)
if __name__ == '__main__':
config_filename = get_config_filename_from_env_or_exit()
with app_context(config_filename):
execute()
|
#!/usr/bin/env python
"""Import permissions, roles, and their relations from a TOML file.
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""
import click
from byceps.services.authorization import impex_service
from byceps.util.system import get_config_filename_from_env_or_exit
from _util import app_context
@click.command()
@click.argument('data_file', type=click.File())
def execute(data_file):
permission_count, role_count = impex_service.import_from_file(data_file)
click.secho(
f'Imported {permission_count} permissions and {role_count} roles.',
fg='green',
)
if __name__ == '__main__':
config_filename = get_config_filename_from_env_or_exit()
with app_context(config_filename):
execute()
|
Fix output of permissions import script
|
Fix output of permissions import script
|
Python
|
bsd-3-clause
|
homeworkprod/byceps,homeworkprod/byceps,homeworkprod/byceps
|
---
+++
@@ -19,7 +19,7 @@
def execute(data_file):
permission_count, role_count = impex_service.import_from_file(data_file)
click.secho(
- 'Imported {permission_count} permissions and {role_count} roles.',
+ f'Imported {permission_count} permissions and {role_count} roles.',
fg='green',
)
|
f20c911285cc83f2cfe2b4650ba85f4b82eae43c
|
plyer/facades/temperature.py
|
plyer/facades/temperature.py
|
class Temperature(object):
'''Temperature facade.
Temperature sensor is used to measure the ambient room temperature in degrees Celsius
With method `enable` you can turn on temperature sensor and 'disable'
method stops the sensor.
Use property `temperature` to get ambient air temperature in degree C.
'''
@property
def temperature(self):
'''Current air temperature in degree C.'''
return self._get_temperature()
def enable(self):
'''Enable temperature sensor.'''
self._enable()
def disable(self):
'''Disable temperature sensor.'''
self._disable()
#private
def _get_temperature(self, **kwargs):
raise NotImplementedError()
def _enable(self, **kwargs):
raise NotImplementedError()
def _disable(self, **kwargs):
raise NotImplementedError()
|
class Temperature(object):
'''Temperature facade.
Temperature sensor is used to measure the ambient room temperature in
degrees Celsius (°C)
With method `enable` you can turn on temperature sensor and 'disable'
method stops the sensor.
Use property `temperature` to get ambient air temperature in degree C.
'''
@property
def temperature(self):
'''Current air temperature in degree C.'''
return self._get_temperature()
def enable(self):
'''Enable temperature sensor.'''
self._enable()
def disable(self):
'''Disable temperature sensor.'''
self._disable()
#private
def _get_temperature(self, **kwargs):
raise NotImplementedError()
def _enable(self, **kwargs):
raise NotImplementedError()
def _disable(self, **kwargs):
raise NotImplementedError()
|
Improve description about the api
|
Improve description about the api
|
Python
|
mit
|
KeyWeeUsr/plyer,kivy/plyer,kivy/plyer,kived/plyer,KeyWeeUsr/plyer,kived/plyer,kivy/plyer,KeyWeeUsr/plyer
|
---
+++
@@ -1,6 +1,7 @@
class Temperature(object):
'''Temperature facade.
- Temperature sensor is used to measure the ambient room temperature in degrees Celsius
+ Temperature sensor is used to measure the ambient room temperature in
+ degrees Celsius (°C)
With method `enable` you can turn on temperature sensor and 'disable'
method stops the sensor.
Use property `temperature` to get ambient air temperature in degree C.
|
d6c81135077867283738bcf9cceb0ce8198808d6
|
unicornclient/config.py
|
unicornclient/config.py
|
import os
import logging
ENV = os.getenv('PYTHONENV', 'prod')
LOG_LEVEL = logging.DEBUG
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
HOST = 'localhost'
PORT = 8080
SSL_VERIFY = False
DEFAULT_ROUTINES = ['auth', 'ping', 'status', 'system']
if ENV == 'prod':
LOG_LEVEL = logging.INFO
HOST = 'unicorn.ahst.fr'
#SSL_VERIFY = True
|
import os
import logging
ENV = os.getenv('PYTHONENV', 'prod')
LOG_LEVEL = logging.DEBUG
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
HOST = 'localhost'
PORT = 8080
SSL_VERIFY = False
DEFAULT_ROUTINES = ['auth', 'ping', 'status', 'system']
if ENV == 'prod':
LOG_LEVEL = logging.INFO
HOST = 'unicorn.ahst.fr'
SSL_VERIFY = True
|
Enable SSL verify for prod
|
Enable SSL verify for prod
|
Python
|
mit
|
amm0nite/unicornclient,amm0nite/unicornclient
|
---
+++
@@ -16,4 +16,4 @@
if ENV == 'prod':
LOG_LEVEL = logging.INFO
HOST = 'unicorn.ahst.fr'
- #SSL_VERIFY = True
+ SSL_VERIFY = True
|
462312c3acf2d6daf7d8cd27f251b8cb92647f5e
|
pybossa/auth/category.py
|
pybossa/auth/category.py
|
from flaskext.login import current_user
def create(app=None):
if current_user.is_authenticated():
if current_user.admin is True:
return True
else:
return False
else:
return False
def read(app=None):
return True
def update(app):
return create(app)
def delete(app):
return create(app)
|
from flaskext.login import current_user
def create(category=None):
if current_user.is_authenticated():
if current_user.admin is True:
return True
else:
return False
else:
return False
def read(category=None):
return True
def update(category):
return create(category)
def delete(category):
return create(category)
|
Fix a typo in the variable name
|
Fix a typo in the variable name
|
Python
|
agpl-3.0
|
jean/pybossa,geotagx/geotagx-pybossa-archive,OpenNewsLabs/pybossa,stefanhahmann/pybossa,proyectos-analizo-info/pybossa-analizo-info,stefanhahmann/pybossa,proyectos-analizo-info/pybossa-analizo-info,Scifabric/pybossa,geotagx/geotagx-pybossa-archive,geotagx/geotagx-pybossa-archive,OpenNewsLabs/pybossa,harihpr/tweetclickers,geotagx/pybossa,proyectos-analizo-info/pybossa-analizo-info,CulturePlex/pybossa,CulturePlex/pybossa,geotagx/pybossa,geotagx/geotagx-pybossa-archive,CulturePlex/pybossa,harihpr/tweetclickers,geotagx/geotagx-pybossa-archive,PyBossa/pybossa,jean/pybossa,inteligencia-coletiva-lsd/pybossa,Scifabric/pybossa,PyBossa/pybossa,inteligencia-coletiva-lsd/pybossa
|
---
+++
@@ -1,7 +1,7 @@
from flaskext.login import current_user
-def create(app=None):
+def create(category=None):
if current_user.is_authenticated():
if current_user.admin is True:
return True
@@ -11,13 +11,13 @@
return False
-def read(app=None):
+def read(category=None):
return True
-def update(app):
- return create(app)
+def update(category):
+ return create(category)
-def delete(app):
- return create(app)
+def delete(category):
+ return create(category)
|
1ee2e880872c4744f4159df7fc64bb64b3f35632
|
pygametemplate/button.py
|
pygametemplate/button.py
|
import time
class Button(object):
"""Class representing keyboard keys."""
def __init__(self, game, number):
self.game = game
self.number = number
self.event = None # The last event that caused the button press
self.pressed = 0 # If the button was just pressed
self.held = 0 # If the button is held
self.released = 0 # If the button was just released
self.press_time = 0.0
def press(self):
self.pressed = 1
self.held = 1
self.press_time = time.time()
def release(self):
self.held = 0
self.released = 1
def reset(self):
self.pressed = 0
self.released = 0
def time_held(self):
if self.held:
return time.time() - self.press_time
else:
return 0.0
|
import time
class Button(object):
"""Class representing keyboard keys."""
def __init__(self, game, number):
self.game = game
self.number = number
self.event = None # The last event that caused the button press
self.pressed = 0 # If the button was just pressed
self.held = 0 # If the button is held
self.released = 0 # If the button was just released
self.press_time = 0.0
def press(self):
self.pressed = 1
self.held = 1
self.press_time = time.time()
def release(self):
self.held = 0
self.released = 1
def reset(self):
self.pressed = 0
self.released = 0
def time_held(self) -> float:
"""Return the amount of time this button has been held for in seconds."""
if self.held:
return time.time() - self.press_time
else:
return 0.0
|
Add docstring to Button.time_held() method
|
Add docstring to Button.time_held() method
|
Python
|
mit
|
AndyDeany/pygame-template
|
---
+++
@@ -27,7 +27,8 @@
self.pressed = 0
self.released = 0
- def time_held(self):
+ def time_held(self) -> float:
+ """Return the amount of time this button has been held for in seconds."""
if self.held:
return time.time() - self.press_time
else:
|
6708830ab2bde841bbc3da2befbbe5ab9f3d21aa
|
ansi_str.py
|
ansi_str.py
|
import re
_ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')
def strip_ansi(value):
return _ansi_re.sub('', value)
def len_exclude_ansi(value):
return len(strip_ansi(value))
class ansi_str(str):
"""A str subclass, specialized for strings containing ANSI escapes.
When you call the ``len`` method, it discounts ANSI color escape codes.
This is beneficial, because ANSI color escape codes won't mess up code
that tries to do alignment, padding, printing in columns, etc.
"""
_stripped = None
def __len__(self, exclude_ansi=True):
if exclude_ansi is False:
return len(self[:])
if self._stripped is None:
self._stripped = strip_ansi(self[:])
return len(self._stripped)
# s = ansi_str('abc')
# print s
# print len(s)
s = ansi_str(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m')
print s
print len(s)
print s.__len__()
print s.__len__(exclude_ansi=False)
print(len_exclude_ansi(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m'))
|
import re
_ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')
def strip_ansi(value):
return _ansi_re.sub('', value)
def len_exclude_ansi(value):
return len(strip_ansi(value))
class ansi_str(str):
"""A str subclass, specialized for strings containing ANSI escapes.
When you call the ``len`` method, it discounts ANSI color escape codes.
This is beneficial, because ANSI color escape codes won't mess up code
that tries to do alignment, padding, printing in columns, etc.
"""
_stripped = None
def __len__(self, exclude_ansi=True):
if exclude_ansi is False:
return len(self[:])
if self._stripped is None:
self._stripped = strip_ansi(self[:])
return len(self._stripped)
if __name__ == '__main__':
# s = ansi_str('abc')
# print s
# print len(s)
s = ansi_str(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m')
print s
print len(s)
print s.__len__()
print s.__len__(exclude_ansi=False)
print(len_exclude_ansi(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m'))
|
Put test stuff inside `if __name__ == '__main__'`
|
Put test stuff inside `if __name__ == '__main__'`
|
Python
|
mit
|
msabramo/ansi_str
|
---
+++
@@ -28,13 +28,15 @@
self._stripped = strip_ansi(self[:])
return len(self._stripped)
-# s = ansi_str('abc')
-# print s
-# print len(s)
-s = ansi_str(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m')
-print s
-print len(s)
-print s.__len__()
-print s.__len__(exclude_ansi=False)
-print(len_exclude_ansi(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m'))
+if __name__ == '__main__':
+ # s = ansi_str('abc')
+ # print s
+ # print len(s)
+
+ s = ansi_str(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m')
+ print s
+ print len(s)
+ print s.__len__()
+ print s.__len__(exclude_ansi=False)
+ print(len_exclude_ansi(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m'))
|
1056c3f489b162d77b6c117fad2b45bfa06beee1
|
app/urls.py
|
app/urls.py
|
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
#from . import views
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'app.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^$', 'app.views.splash', name='splash'),
url(r'^feed', 'app.views.feed', name='feed'),
url(r'^about', 'app.views.about', name='about'),
url(r'^explore', 'app.views.explore', name='explore'),
url(r'^profile_picture', 'app.views.profile_picture', name='profile_picture'),
url(r'^dashboard', 'app.views.dashboard', name='dashboard'),
url(r'^login', 'app.views.login', name='login'),
url(r'^logout', 'app.views.logout', name='logout'),
url(r'^temp', 'app.views.temp', name='temp'), #delete eventually
url(r'^posts', 'app.views.posts', name='posts'),
url(r'^admin/', include(admin.site.urls))
)
|
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
#from . import views
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'app.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^$', 'app.views.splash', name='splash'),
url(r'^feed', 'app.views.feed', name='feed'),
url(r'^about', 'app.views.about', name='about'),
url(r'^explore', 'app.views.explore', name='explore'),
url(r'^profile_picture', 'app.views.profile_picture', name='profile_picture'),
url(r'^dashboard', 'app.views.dashboard', name='dashboard'),
url(r'^login', 'app.views.login', name='login'),
url(r'^logout', 'app.views.logout', name='logout'),
url(r'^temp', 'app.views.temp', name='temp'),
url(r'^admin/', include(admin.site.urls))
)
|
Revert "Added a post view"
|
Revert "Added a post view"
This reverts commit b1063480e7b2e1128c457e9e65c52f742109d90d.
|
Python
|
unlicense
|
yourbuddyconner/cs399-social,yourbuddyconner/cs399-social
|
---
+++
@@ -2,8 +2,6 @@
from django.contrib import admin
from django.conf import settings
#from . import views
-
-
urlpatterns = patterns('',
# Examples:
@@ -18,8 +16,7 @@
url(r'^dashboard', 'app.views.dashboard', name='dashboard'),
url(r'^login', 'app.views.login', name='login'),
url(r'^logout', 'app.views.logout', name='logout'),
- url(r'^temp', 'app.views.temp', name='temp'), #delete eventually
- url(r'^posts', 'app.views.posts', name='posts'),
+ url(r'^temp', 'app.views.temp', name='temp'),
+
url(r'^admin/', include(admin.site.urls))
)
-
|
1165c923145be18d40fda1fc4303cac3e1613078
|
app/util.py
|
app/util.py
|
# Various utility functions
import os
SHOULD_CACHE = os.environ.get('ENV', 'development') == 'production'
def cached_function(func):
data = {}
def wrapper(*args):
if not SHOULD_CACHE:
return func(*args)
cache_key = ' '.join([str(x) for x in args])
if cache_key not in data:
data[cache_key] = func(*args)
return data[cache_key]
wrapper.__name__ = func.__name__
return wrapper
|
# Various utility functions
import os
SHOULD_CACHE = os.environ.get('ENV', 'development') == 'production'
def cached_function(func):
data = {}
def wrapper(*args):
if not SHOULD_CACHE:
return func(*args)
cache_key = ' '.join([str(x) for x in args])
if cache_key not in data:
data[cache_key] = func(*args)
return data[cache_key]
wrapper.__qualname__ = func.__qualname__
return wrapper
|
Update cached_function wrapper to set qualname instead of name
|
Update cached_function wrapper to set qualname instead of name
|
Python
|
mit
|
albertyw/albertyw.com,albertyw/albertyw.com,albertyw/albertyw.com,albertyw/albertyw.com,albertyw/albertyw.com
|
---
+++
@@ -16,5 +16,5 @@
data[cache_key] = func(*args)
return data[cache_key]
- wrapper.__name__ = func.__name__
+ wrapper.__qualname__ = func.__qualname__
return wrapper
|
4e74723aac53956fb0316ae0d438da623de133d5
|
tests/extensions/video/test_renderer.py
|
tests/extensions/video/test_renderer.py
|
import pytest
from mfr.core.provider import ProviderMetadata
from mfr.extensions.video import VideoRenderer
@pytest.fixture
def metadata():
return ProviderMetadata('test', '.mp4', 'text/plain', '1234', 'http://wb.osf.io/file/test.mp4?token=1234')
@pytest.fixture
def file_path():
return '/tmp/test.mp4'
@pytest.fixture
def url():
return 'http://osf.io/file/test.mp4'
@pytest.fixture
def assets_url():
return 'http://mfr.osf.io/assets'
@pytest.fixture
def export_url():
return 'http://mfr.osf.io/export?url=' + url()
@pytest.fixture
def renderer(metadata, file_path, url, assets_url, export_url):
return VideoRenderer(metadata, file_path, url, assets_url, export_url)
class TestVideoRenderer:
def test_render_video(self, renderer, url):
body = renderer.render()
assert '<video controls' in body
assert 'src="{}"'.format(metadata().download_url) in body
def test_render_video_file_required(self, renderer):
assert renderer.file_required is False
def test_render_video_cache_result(self, renderer):
assert renderer.cache_result is False
|
import pytest
from mfr.core.provider import ProviderMetadata
from mfr.extensions.video import VideoRenderer
@pytest.fixture
def metadata():
return ProviderMetadata('test', '.mp4', 'text/plain', '1234',
'http://wb.osf.io/file/test.mp4?token=1234')
@pytest.fixture
def file_path():
return '/tmp/test.mp4'
@pytest.fixture
def url():
return 'http://osf.io/file/test.mp4'
@pytest.fixture
def assets_url():
return 'http://mfr.osf.io/assets'
@pytest.fixture
def export_url():
return 'http://mfr.osf.io/export?url=' + url()
@pytest.fixture
def renderer(metadata, file_path, url, assets_url, export_url):
return VideoRenderer(metadata, file_path, url, assets_url, export_url)
class TestVideoRenderer:
def test_render_video(self, renderer, url):
body = renderer.render()
assert '<video controls' in body
assert 'src="{}"'.format(metadata().download_url) in body
assert '<style>body{margin:0;padding:0;}</style>' in ''.join(body.split())
def test_render_video_file_required(self, renderer):
assert renderer.file_required is False
def test_render_video_cache_result(self, renderer):
assert renderer.cache_result is False
|
Add and update tests for video renderer
|
Add and update tests for video renderer
|
Python
|
apache-2.0
|
felliott/modular-file-renderer,CenterForOpenScience/modular-file-renderer,felliott/modular-file-renderer,CenterForOpenScience/modular-file-renderer,CenterForOpenScience/modular-file-renderer,CenterForOpenScience/modular-file-renderer,felliott/modular-file-renderer,felliott/modular-file-renderer
|
---
+++
@@ -1,13 +1,13 @@
import pytest
from mfr.core.provider import ProviderMetadata
-
from mfr.extensions.video import VideoRenderer
@pytest.fixture
def metadata():
- return ProviderMetadata('test', '.mp4', 'text/plain', '1234', 'http://wb.osf.io/file/test.mp4?token=1234')
+ return ProviderMetadata('test', '.mp4', 'text/plain', '1234',
+ 'http://wb.osf.io/file/test.mp4?token=1234')
@pytest.fixture
@@ -41,6 +41,7 @@
body = renderer.render()
assert '<video controls' in body
assert 'src="{}"'.format(metadata().download_url) in body
+ assert '<style>body{margin:0;padding:0;}</style>' in ''.join(body.split())
def test_render_video_file_required(self, renderer):
assert renderer.file_required is False
|
0b048cef1f0efd190d8bf8f50c69df35c59b91a3
|
xdc-plugin/tests/compare_output_json.py
|
xdc-plugin/tests/compare_output_json.py
|
#!/usr/bin/env python3
"""
This script extracts the top module cells and their corresponding parameters
from json files produced by Yosys.
The return code of this script is used to check if the output is equivalent.
"""
import sys
import json
def read_cells(json_file):
with open(json_file) as f:
data = json.load(f)
f.close()
cells = data['modules']['top']['cells']
cells_parameters = dict()
for cell, opts in cells.items():
cells_parameters[cell] = opts['parameters']
return cells_parameters
def main():
if len(sys.argv) < 3:
print("Incorrect number of arguments")
exit(1)
cells1 = read_cells(sys.argv[1])
cells2 = read_cells(sys.argv[2])
if cells1 == cells2:
exit(0)
else:
exit(1)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
"""
This script extracts the top module cells and their corresponding parameters
from json files produced by Yosys.
The return code of this script is used to check if the output is equivalent.
"""
import sys
import json
parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]
def read_cells(json_file):
with open(json_file) as f:
data = json.load(f)
f.close()
cells = data['modules']['top']['cells']
cells_parameters = dict()
for cell, opts in cells.items():
attributes = opts['parameters']
if len(attributes.keys()):
if any([x in parameters for x in attributes.keys()]):
cells_parameters[cell] = attributes
return cells_parameters
def main():
if len(sys.argv) < 3:
print("Incorrect number of arguments")
exit(1)
cells1 = read_cells(sys.argv[1])
cells2 = read_cells(sys.argv[2])
if cells1 == cells2:
exit(0)
else:
print(json.dumps(cells1, indent=4))
print("VS")
print(json.dumps(cells2, indent=4))
exit(1)
if __name__ == "__main__":
main()
|
Add verbosity on JSON compare fail
|
XDC: Add verbosity on JSON compare fail
Signed-off-by: Tomasz Michalak <a2fdaa543b4cc5e3d6cd8672ec412c0eb393b86e@antmicro.com>
|
Python
|
apache-2.0
|
SymbiFlow/yosys-symbiflow-plugins,SymbiFlow/yosys-symbiflow-plugins,SymbiFlow/yosys-f4pga-plugins,SymbiFlow/yosys-symbiflow-plugins,chipsalliance/yosys-f4pga-plugins,antmicro/yosys-symbiflow-plugins,chipsalliance/yosys-f4pga-plugins,antmicro/yosys-symbiflow-plugins,antmicro/yosys-symbiflow-plugins,SymbiFlow/yosys-f4pga-plugins,SymbiFlow/yosys-f4pga-plugins
|
---
+++
@@ -9,6 +9,8 @@
import sys
import json
+parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]
+
def read_cells(json_file):
with open(json_file) as f:
data = json.load(f)
@@ -16,7 +18,10 @@
cells = data['modules']['top']['cells']
cells_parameters = dict()
for cell, opts in cells.items():
- cells_parameters[cell] = opts['parameters']
+ attributes = opts['parameters']
+ if len(attributes.keys()):
+ if any([x in parameters for x in attributes.keys()]):
+ cells_parameters[cell] = attributes
return cells_parameters
@@ -29,6 +34,9 @@
if cells1 == cells2:
exit(0)
else:
+ print(json.dumps(cells1, indent=4))
+ print("VS")
+ print(json.dumps(cells2, indent=4))
exit(1)
if __name__ == "__main__":
|
b82f21ea92aad44ca101744a3f5300280f081524
|
sweettooth/review/context_processors.py
|
sweettooth/review/context_processors.py
|
from extensions.models import ExtensionVersion
def n_unreviewed_extensions(request):
if not request.user.has_perm("review.can-review-extensions"):
return dict()
return dict(n_unreviewed_extensions=ExtensionVersion.unreviewed().count())
|
from extensions.models import ExtensionVersion
def n_unreviewed_extensions(request):
if not request.user.has_perm("review.can-review-extensions"):
return dict()
return dict(n_unreviewed_extensions=ExtensionVersion.objects.unreviewed().count())
|
Fix site when logged in
|
Fix site when logged in
|
Python
|
agpl-3.0
|
GNOME/extensions-web,magcius/sweettooth,GNOME/extensions-web,magcius/sweettooth,GNOME/extensions-web,GNOME/extensions-web
|
---
+++
@@ -5,4 +5,4 @@
if not request.user.has_perm("review.can-review-extensions"):
return dict()
- return dict(n_unreviewed_extensions=ExtensionVersion.unreviewed().count())
+ return dict(n_unreviewed_extensions=ExtensionVersion.objects.unreviewed().count())
|
ec7b52b457e749b4b4a1e9110ede221f2f0d5fe9
|
data/propaganda2mongo.py
|
data/propaganda2mongo.py
|
import bson.json_util
from bson.objectid import ObjectId
import json
import sys
def main():
node_table = {}
while True:
line = sys.stdin.readline()
if not line:
break
record = json.loads(line)
ident = str(record["twitter_id"])
aoid = node_table.get(ident)
if aoid is None:
node_table[ident] = aoid = ObjectId()
print bson.json_util.dumps({"_id": aoid,
"type": "node",
"data": {"twitter_id": ident,
"type": "audience",
"propaganda_urls_exposed_to": record["propaganda_urls_exposed_to"],
"geos": record["geos"],
"timestamps_of_propaganda": record["timestamps_of_propaganda"]}})
for p in record["propagandists_followed"]:
oid = node_table.get(p)
if oid is None:
node_table[ident] = oid = ObjectId()
print bson.json_util.dumps({"_id": oid,
"type": "node",
"data": {"twitter_id": p,
"type": "propagandist"}})
print bson.json_util.dumps({"_id": ObjectId(),
"type": "link",
"source": aoid,
"target": oid,
"data": {}})
if __name__ == "__main__":
sys.exit(main())
|
import bson.json_util
from bson.objectid import ObjectId
import json
import sys
def main():
node_table = {}
while True:
line = sys.stdin.readline()
if not line:
break
record = json.loads(line)
ident = str(record["twitter_id"])
aoid = node_table.get(ident)
if aoid is None:
node_table[ident] = aoid = ObjectId()
print bson.json_util.dumps({"_id": aoid,
"type": "node",
"data": {"twitter_id": ident,
"type": "audience",
"propaganda_urls_exposed_to": record["propaganda_urls_exposed_to"],
"geos": record["geos"],
"timestamps_of_propaganda": record["timestamps_of_propaganda"]}})
for p in record["propagandists_followed"]:
oid = node_table.get(p)
if oid is None:
node_table[p] = oid = ObjectId()
print bson.json_util.dumps({"_id": oid,
"type": "node",
"data": {"twitter_id": p,
"type": "propagandist"}})
print bson.json_util.dumps({"_id": ObjectId(),
"type": "link",
"source": aoid,
"target": oid,
"data": {}})
if __name__ == "__main__":
sys.exit(main())
|
Fix fatal error in data processing.
|
Fix fatal error in data processing.
The wrong identifier was being used as the key to tell whether a propagandist
had been seen before in the dataset, leading to a completely, and incorrectly
disconnected graph.
|
Python
|
apache-2.0
|
XDATA-Year-3/clique-propaganda,XDATA-Year-3/clique-propaganda,XDATA-Year-3/clique-propaganda
|
---
+++
@@ -29,7 +29,7 @@
for p in record["propagandists_followed"]:
oid = node_table.get(p)
if oid is None:
- node_table[ident] = oid = ObjectId()
+ node_table[p] = oid = ObjectId()
print bson.json_util.dumps({"_id": oid,
"type": "node",
"data": {"twitter_id": p,
|
5bde6ca1fd62277463156875e874c4c6843923fd
|
pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.plugin_name}}.py
|
pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.plugin_name}}.py
|
# -*- coding: utf-8 -*-
def test_bar_fixture(testdir):
"""Make sure that pytest accepts our fixture."""
# create a temporary pytest test module
testdir.makepyfile("""
def test_sth(bar):
assert bar == "europython2015"
""")
# run pytest with the following cmd args
result = testdir.runpytest(
'--foo=something',
'-v'
)
# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines([
'*::test_a PASSED',
])
# make sure that that we get a '0' exit code for the testsuite
assert result.ret == 0
def test_help_message(testdir):
result = testdir.runpytest(
'--help',
)
# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines([
'cat:',
'*--foo=DEST_FOO*Set the value for the fixture "bar".',
])
|
# -*- coding: utf-8 -*-
def test_bar_fixture(testdir):
"""Make sure that pytest accepts our fixture."""
# create a temporary pytest test module
testdir.makepyfile("""
def test_sth(bar):
assert bar == "europython2015"
""")
# run pytest with the following cmd args
result = testdir.runpytest(
'--foo=something',
'-v'
)
# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines([
'*::test_a PASSED',
])
# make sure that that we get a '0' exit code for the testsuite
assert result.ret == 0
def test_help_message(testdir):
result = testdir.runpytest(
'--help',
)
# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines([
'{{cookiecutter.plugin_name}}:',
'*--foo=DEST_FOO*Set the value for the fixture "bar".',
])
|
Use the correct variable for the test
|
Use the correct variable for the test
|
Python
|
mit
|
luzfcb/cookiecutter-pytest-plugin,pytest-dev/cookiecutter-pytest-plugin,s0undt3ch/cookiecutter-pytest-plugin
|
---
+++
@@ -22,7 +22,7 @@
# make sure that that we get a '0' exit code for the testsuite
assert result.ret == 0
-
+
def test_help_message(testdir):
result = testdir.runpytest(
@@ -30,6 +30,6 @@
)
# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines([
- 'cat:',
+ '{{cookiecutter.plugin_name}}:',
'*--foo=DEST_FOO*Set the value for the fixture "bar".',
])
|
2549a66b6785d5a0ed0658a4f375a21c486792df
|
sifr/util.py
|
sifr/util.py
|
import datetime
from dateutil import parser
import six
def normalize_time(t):
try:
if isinstance(t, datetime.datetime):
return t
elif isinstance(t, datetime.date):
return datetime.datetime(t.year, t.month, t.day)
elif isinstance(t, (int, float)):
return datetime.datetime.fromtimestamp(t)
elif isinstance(t, six.string_types):
return parser.parse(t)
else:
raise
except: # noqa
raise TypeError(
"time must be represented as either a timestamp (int,float), "
"a datetime.datetime or datetime.date object, "
"or an iso-8601 formatted string"
)
|
import datetime
from dateutil import parser
import six
def normalize_time(t):
try:
if isinstance(t, datetime.datetime):
return t
elif isinstance(t, datetime.date):
return datetime.datetime(t.year, t.month, t.day)
elif isinstance(t, (int, float)):
return datetime.datetime.fromtimestamp(t)
elif isinstance(t, six.string_types):
return parser.parse(t)
else:
raise TypeError
except: # noqa
raise TypeError(
"time must be represented as either a timestamp (int,float), "
"a datetime.datetime or datetime.date object, "
"or an iso-8601 formatted string"
)
|
Raise explicit exception on no type match
|
Raise explicit exception on no type match
|
Python
|
mit
|
alisaifee/sifr,alisaifee/sifr
|
---
+++
@@ -14,7 +14,7 @@
elif isinstance(t, six.string_types):
return parser.parse(t)
else:
- raise
+ raise TypeError
except: # noqa
raise TypeError(
"time must be represented as either a timestamp (int,float), "
|
66d1bce2cb497954749b211a26fd00ae4db6f7e7
|
foodsaving/conversations/serializers.py
|
foodsaving/conversations/serializers.py
|
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from rest_framework.exceptions import PermissionDenied
from foodsaving.conversations.models import Conversation, ConversationMessage
class ConversationSerializer(serializers.ModelSerializer):
class Meta:
model = Conversation
fields = [
'id',
'participants',
'created_at'
]
def retrieve(self, validated_data):
user = self.context['request'].user
return ConversationMessage.objects.create(author=user, **validated_data)
class ConversationMessageSerializer(serializers.ModelSerializer):
class Meta:
model = ConversationMessage
fields = [
'id',
'author',
'content',
'conversation',
'created_at'
]
class CreateConversationMessageSerializer(serializers.ModelSerializer):
class Meta:
model = ConversationMessage
fields = [
'id',
'author',
'content',
'conversation'
]
extra_kwargs = {
'author': {
'read_only': True
}
}
def validate_conversation(self, conversation):
if self.context['request'].user not in conversation.participants.all():
raise PermissionDenied(_('You are not in this conversation'))
return conversation
def create(self, validated_data):
user = self.context['request'].user
return ConversationMessage.objects.create(author=user, **validated_data)
|
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from rest_framework.exceptions import PermissionDenied
from foodsaving.conversations.models import Conversation, ConversationMessage
class ConversationSerializer(serializers.ModelSerializer):
class Meta:
model = Conversation
fields = [
'id',
'participants',
'created_at'
]
class ConversationMessageSerializer(serializers.ModelSerializer):
class Meta:
model = ConversationMessage
fields = [
'id',
'author',
'content',
'conversation',
'created_at'
]
class CreateConversationMessageSerializer(serializers.ModelSerializer):
class Meta:
model = ConversationMessage
fields = [
'id',
'author',
'content',
'conversation'
]
extra_kwargs = {
'author': {
'read_only': True
}
}
def validate_conversation(self, conversation):
if self.context['request'].user not in conversation.participants.all():
raise PermissionDenied(_('You are not in this conversation'))
return conversation
def create(self, validated_data):
user = self.context['request'].user
return ConversationMessage.objects.create(author=user, **validated_data)
|
Remove random bit of code
|
Remove random bit of code
I have no idea what that is doing there. It is not called from
what I can tell, and the tests work without it. And it makes no
sense whatsoever, create a message each time you retrieve the
conversation info??!?!?!
|
Python
|
agpl-3.0
|
yunity/foodsaving-backend,yunity/foodsaving-backend,yunity/yunity-core,yunity/foodsaving-backend,yunity/yunity-core
|
---
+++
@@ -13,10 +13,6 @@
'participants',
'created_at'
]
-
- def retrieve(self, validated_data):
- user = self.context['request'].user
- return ConversationMessage.objects.create(author=user, **validated_data)
class ConversationMessageSerializer(serializers.ModelSerializer):
|
d3847357c446c4a1ac50735b983b20cf57f9c7c6
|
malcolm/controllers/countercontroller.py
|
malcolm/controllers/countercontroller.py
|
from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes
import numpy as np
class CounterController(Controller):
def create_attributes(self):
self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
self.counter.set_put_function(self.counter.set_value)
self.counter.set_value(0)
yield self.counter
@takes()
def reset(self):
self.counter.set_value(0)
@takes()
def increment(self):
self.counter.set_value(self.counter.value + 1)
|
from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes, returns
import numpy as np
class CounterController(Controller):
def create_attributes(self):
self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
self.counter.set_put_function(self.counter.set_value)
self.counter.set_value(0)
yield self.counter
@takes()
@returns()
def reset(self, args=None):
self.counter.set_value(0)
return {}
@takes()
@returns()
def increment(self, args=None):
self.counter.set_value(self.counter.value + 1)
return {}
|
Fix args and return of CounterController functions
|
Fix args and return of CounterController functions
Even though they're not used, functions to be wrapped by Methods have to
take arguments and return something (at least an empty dict).
|
Python
|
apache-2.0
|
dls-controls/pymalcolm,dls-controls/pymalcolm,dls-controls/pymalcolm
|
---
+++
@@ -1,7 +1,7 @@
from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
-from malcolm.core.method import takes
+from malcolm.core.method import takes, returns
import numpy as np
@@ -14,9 +14,13 @@
yield self.counter
@takes()
- def reset(self):
+ @returns()
+ def reset(self, args=None):
self.counter.set_value(0)
+ return {}
@takes()
- def increment(self):
+ @returns()
+ def increment(self, args=None):
self.counter.set_value(self.counter.value + 1)
+ return {}
|
270af43ffbe8974698d17ff6d5cae20fbf410f73
|
admin/urls.py
|
admin/urls.py
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .views import CubeHandler, ConnectionHandler
from .views import ElementHandler, DashboardHandler, APIElementCubeHandler
INCLUDE_URLS = [
(r"/admin/connection/?(?P<slug>[\w-]+)?", ConnectionHandler),
(r"/admin/cube/?(?P<slug>[\w-]+)?", CubeHandler),
(r"/admin/api/element/cube/?(?P<slug>[\w-]+)?", APIElementCubeHandler),
(r"/admin/element/?(?P<slug>[\w-]+)?", ElementHandler),
(r"/admin/dashboard/?(?P<slug>[\w-]+)?", DashboardHandler),
]
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .views import CubeHandler, ConnectionHandler, DeleteHandler
from .views import ElementHandler, DashboardHandler, APIElementCubeHandler
INCLUDE_URLS = [
(r"/admin/delete/(?P<bucket>[\w-]+)/(?P<slug>[\w-]+)", DeleteHandler),
(r"/admin/connection/?(?P<slug>[\w-]+)?", ConnectionHandler),
(r"/admin/cube/?(?P<slug>[\w-]+)?", CubeHandler),
(r"/admin/api/element/cube/?(?P<slug>[\w-]+)?", APIElementCubeHandler),
(r"/admin/element/?(?P<slug>[\w-]+)?", ElementHandler),
(r"/admin/dashboard/?(?P<slug>[\w-]+)?", DashboardHandler),
]
|
Add url enter delete element on riak
|
Add url enter delete element on riak
|
Python
|
mit
|
jgabriellima/mining,avelino/mining,chrisdamba/mining,seagoat/mining,avelino/mining,AndrzejR/mining,mlgruby/mining,mlgruby/mining,mining/mining,mlgruby/mining,mining/mining,chrisdamba/mining,AndrzejR/mining,seagoat/mining,jgabriellima/mining
|
---
+++
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from .views import CubeHandler, ConnectionHandler
+from .views import CubeHandler, ConnectionHandler, DeleteHandler
from .views import ElementHandler, DashboardHandler, APIElementCubeHandler
INCLUDE_URLS = [
+ (r"/admin/delete/(?P<bucket>[\w-]+)/(?P<slug>[\w-]+)", DeleteHandler),
(r"/admin/connection/?(?P<slug>[\w-]+)?", ConnectionHandler),
(r"/admin/cube/?(?P<slug>[\w-]+)?", CubeHandler),
(r"/admin/api/element/cube/?(?P<slug>[\w-]+)?", APIElementCubeHandler),
|
4e12aea0a5479bad8289cbf6c9f460931d51f701
|
database.py
|
database.py
|
import MySQLdb
class database(object):
def __init__(self):
config = {}
execfile("config.py",config)
self.db = MySQLdb.connect(config["host"],config["user"],config["password"],config["database"])
def insert(self,txt):
dbc = self.db.cursor()
try:
dbc.execute("insert into " + txt)
dbc.close()
self.db.commit()
except Exception as e:
print(e)
return False
return True
def update(self,txt):
dbc = self.db.cursor()
try:
dbc.execute("update from " + txt)
dbc.close()
self.db.commit()
except Exception as e:
print(e)
return False
return True
def select(self,txt):
dbc = self.db.cursor()
try:
dbc.execute("select " + txt)
result = dbc.fetchall()
except Exception as e:
print(e)
result = None
dbc.close()
return result
|
import MySQLdb
class database(object):
def __init__(self):
config = {}
execfile("config.py",config)
self.db = MySQLdb.connect(config["host"],config["user"],config["password"],config["database"])
self.db.autocommit(True)
def insert(self,txt):
dbc = self.db.cursor()
try:
dbc.execute("insert into " + txt)
dbc.close()
self.db.commit()
except Exception as e:
print(e)
return False
return True
def update(self,txt):
dbc = self.db.cursor()
try:
dbc.execute("update from " + txt)
dbc.close()
self.db.commit()
except Exception as e:
print(e)
return False
return True
def select(self,txt):
dbc = self.db.cursor()
try:
dbc.execute("select " + txt)
result = dbc.fetchall()
except Exception as e:
print(e)
result = None
dbc.close()
return result
|
Add autocommit to 1 to avoid select cache ¿WTF?
|
Add autocommit to 1 to avoid select cache ¿WTF?
|
Python
|
agpl-3.0
|
p4u/projecte_frigos,p4u/projecte_frigos,p4u/projecte_frigos,p4u/projecte_frigos
|
---
+++
@@ -5,6 +5,7 @@
config = {}
execfile("config.py",config)
self.db = MySQLdb.connect(config["host"],config["user"],config["password"],config["database"])
+ self.db.autocommit(True)
def insert(self,txt):
dbc = self.db.cursor()
|
f25e0fe435f334e19fc84a9c9458a1bea4a051f9
|
money/parser/__init__.py
|
money/parser/__init__.py
|
import csv
from money.models import Movement
def parse_csv(raw_csv, parser, header_lines=0):
reader = csv.reader(raw_csv, delimiter=',', quotechar='"')
rows = []
for row in reader:
if reader.line_num > header_lines and row:
rows.append(parser.parse_row(row))
return rows
def import_movements(data, bank_account):
rejected = []
accepted = 0
for row in data:
obj, created = Movement.objects.get_or_create(
bank_account=bank_account,
description=row["description"],
amount=row["amount"],
date=row["date"],
)
if created:
accepted += 1
else:
rejected.append(row)
return accepted, rejected
|
import csv
from money.models import Movement
def parse_csv(raw_csv, parser, header_lines=0, reverse_order=False):
reader = csv.reader(raw_csv, delimiter=',', quotechar='"')
rows = []
for row in reader:
if reader.line_num > header_lines and row:
rows.append(parser.parse_row(row))
if reverse_order:
rows.reverse()
return rows
def import_movements(data, bank_account):
rejected = []
accepted = 0
for row in data:
obj, created = Movement.objects.get_or_create(
bank_account=bank_account,
description=row["description"],
amount=row["amount"],
date=row["date"],
)
if created:
accepted += 1
else:
rejected.append(row)
return accepted, rejected
|
Allow to reverse the order of the CSV for a proper reading
|
Allow to reverse the order of the CSV for a proper reading
|
Python
|
bsd-3-clause
|
shakaran/casterly,shakaran/casterly
|
---
+++
@@ -3,28 +3,30 @@
from money.models import Movement
-def parse_csv(raw_csv, parser, header_lines=0):
- reader = csv.reader(raw_csv, delimiter=',', quotechar='"')
- rows = []
+def parse_csv(raw_csv, parser, header_lines=0, reverse_order=False):
+ reader = csv.reader(raw_csv, delimiter=',', quotechar='"')
+ rows = []
- for row in reader:
- if reader.line_num > header_lines and row:
- rows.append(parser.parse_row(row))
- return rows
+ for row in reader:
+ if reader.line_num > header_lines and row:
+ rows.append(parser.parse_row(row))
+ if reverse_order:
+ rows.reverse()
+ return rows
def import_movements(data, bank_account):
- rejected = []
- accepted = 0
- for row in data:
- obj, created = Movement.objects.get_or_create(
- bank_account=bank_account,
- description=row["description"],
- amount=row["amount"],
- date=row["date"],
- )
- if created:
- accepted += 1
- else:
- rejected.append(row)
- return accepted, rejected
+ rejected = []
+ accepted = 0
+ for row in data:
+ obj, created = Movement.objects.get_or_create(
+ bank_account=bank_account,
+ description=row["description"],
+ amount=row["amount"],
+ date=row["date"],
+ )
+ if created:
+ accepted += 1
+ else:
+ rejected.append(row)
+ return accepted, rejected
|
c4ef7fe24477d9160214c1cd2938aa8f5135d84b
|
utils/database_setup.py
|
utils/database_setup.py
|
import pandas
def load_excel(filepath):
"""
Returns a Pandas datafile that contains the contents of a Microsoft Excel
Spreadsheet
Params:
filepath - A string containing the path to the file
Returns:
A Pandas datafile
"""
return pandas.read_excel(filepath)
def get_column_names(datafile):
"""
Returns a list containing the column names of a Pandas datafile as Python
strings
Params:
datafile - A Pandas datafile
Returns:
A list of strings
"""
return [ str(s) for s in datafile.columns ]
def check_if_mysql_installed():
"""
Verifies if MySQL is installed on the current system. Will throw an
error if MySQL fails to run
"""
pass
def set_up_mysql_schema():
"""
Sets up MySQL with a table with a set schema
"""
pass
|
import pandas
import argparse
def get_excel(filepath):
"""
Returns a Pandas datafile that contains the contents of a Microsoft Excel
Spreadsheet
Params:
filepath - A string containing the path to the file
Returns:
A Pandas datafile
"""
return pandas.read_excel(filepath)
def get_column_names(datafile):
"""
Returns a list containing the column names of a Pandas datafile as Python
strings
Params:
datafile - A Pandas datafile
Returns:
A list of strings
"""
return [ str(s) for s in datafile.columns ]
def check_if_mysql_installed():
"""
Verifies if MySQL is installed on the current system. Will throw an
error if MySQL fails to run
"""
pass
def is_table_set_up():
"""
Returns True if this project's MySQL table is set up, False otherwise
"""
pass
def create_project_table(column_names):
"""
Sets up MySQL with a table with a set schema given a list of column_names.
Does nothing if the table is already set up.
Params:
column_names - A list of strings containing column names
Returns:
None
"""
pass
def delete_project_table():
"""
Deletes the table in MySQL that this project uses. Will do nothing if the
table does not yet exist.
"""
pass
def reset_project_table():
"""
Resets the table for this project by calling 'delete' and 'setup'
"""
delete_project_table()
create_project_table()
def load_excel_file(datafile):
"""
Takes a Pandas datafile and inserts the data into the project's MySQL table.
If the project's table is not yet created, this function will call 'create'.
"""
if not is_table_set_up():
create_project_table()
# TODO: Fill in this part
|
Add other needed method stubs
|
Add other needed method stubs
|
Python
|
mit
|
stuy-tetrabyte/graduation-req-tracker
|
---
+++
@@ -1,6 +1,7 @@
import pandas
+import argparse
-def load_excel(filepath):
+def get_excel(filepath):
"""
Returns a Pandas datafile that contains the contents of a Microsoft Excel
Spreadsheet
@@ -33,9 +34,45 @@
"""
pass
-def set_up_mysql_schema():
+def is_table_set_up():
"""
- Sets up MySQL with a table with a set schema
+ Returns True if this project's MySQL table is set up, False otherwise
"""
pass
+def create_project_table(column_names):
+ """
+ Sets up MySQL with a table with a set schema given a list of column_names.
+ Does nothing if the table is already set up.
+
+ Params:
+ column_names - A list of strings containing column names
+
+ Returns:
+ None
+ """
+ pass
+
+def delete_project_table():
+ """
+ Deletes the table in MySQL that this project uses. Will do nothing if the
+ table does not yet exist.
+ """
+ pass
+
+def reset_project_table():
+ """
+ Resets the table for this project by calling 'delete' and 'setup'
+ """
+ delete_project_table()
+ create_project_table()
+
+def load_excel_file(datafile):
+ """
+ Takes a Pandas datafile and inserts the data into the project's MySQL table.
+ If the project's table is not yet created, this function will call 'create'.
+ """
+ if not is_table_set_up():
+ create_project_table()
+ # TODO: Fill in this part
+
|
d52c4340a62802bcd0fcbd68516c5ac66fb10436
|
ftfy/streamtester/__init__.py
|
ftfy/streamtester/__init__.py
|
"""
This file defines a general method for evaluating ftfy using data that arrives
in a stream. A concrete implementation of it is found in `twitter_tester.py`.
"""
from __future__ import print_function, unicode_literals
from ftfy.fixes import fix_text_encoding
from ftfy.chardata import possible_encoding
class StreamTester:
"""
Take in a sequence of texts, and show the ones that will be changed by
ftfy. This will also periodically show updates, such as the proportion of
texts that changed.
"""
def __init__(self):
self.num_fixed = 0
self.count = 0
def check_ftfy(self, text):
"""
Given a single text input, check whether `ftfy.fix_text_encoding`
would change it. If so, display the change.
"""
self.count += 1
if not possible_encoding(text, 'ascii'):
fixed = fix_text_encoding(text)
if text != fixed:
# possibly filter common bots before printing
print(u'\nText:\t{text}\nFixed:\t{fixed}\n'.format(
text=text, fixed=fixed
))
self.num_fixed += 1
# Print status updates once in a while
if self.count % 100 == 0:
print('.', end='', flush=True)
if self.count % 10000 == 0:
print('\n%d/%d fixed' % (self.num_fixed, self.count))
|
"""
This file defines a general method for evaluating ftfy using data that arrives
in a stream. A concrete implementation of it is found in `twitter_tester.py`.
"""
from __future__ import print_function, unicode_literals
from ftfy.fixes import fix_encoding
from ftfy.chardata import possible_encoding
class StreamTester:
"""
Take in a sequence of texts, and show the ones that will be changed by
ftfy. This will also periodically show updates, such as the proportion of
texts that changed.
"""
def __init__(self):
self.num_fixed = 0
self.count = 0
def check_ftfy(self, text):
"""
Given a single text input, check whether `ftfy.fix_text_encoding`
would change it. If so, display the change.
"""
self.count += 1
if not possible_encoding(text, 'ascii'):
fixed = fix_encoding(text)
if text != fixed:
# possibly filter common bots before printing
print(u'\nText:\t{text}\nFixed:\t{fixed}\n'.format(
text=text, fixed=fixed
))
self.num_fixed += 1
# Print status updates once in a while
if self.count % 100 == 0:
print('.', end='', flush=True)
if self.count % 10000 == 0:
print('\n%d/%d fixed' % (self.num_fixed, self.count))
|
Update function name used in the streamtester
|
Update function name used in the streamtester
|
Python
|
mit
|
LuminosoInsight/python-ftfy
|
---
+++
@@ -3,7 +3,7 @@
in a stream. A concrete implementation of it is found in `twitter_tester.py`.
"""
from __future__ import print_function, unicode_literals
-from ftfy.fixes import fix_text_encoding
+from ftfy.fixes import fix_encoding
from ftfy.chardata import possible_encoding
@@ -24,7 +24,7 @@
"""
self.count += 1
if not possible_encoding(text, 'ascii'):
- fixed = fix_text_encoding(text)
+ fixed = fix_encoding(text)
if text != fixed:
# possibly filter common bots before printing
print(u'\nText:\t{text}\nFixed:\t{fixed}\n'.format(
|
7a786fd031c3faa057256abc5d9cb47618041696
|
checks.d/veneur.py
|
checks.d/veneur.py
|
import datetime
from urlparse import urljoin
import requests
# project
from checks import AgentCheck
class Veneur(AgentCheck):
VERSION_METRIC_NAME = 'veneur.deployed_version'
BUILDAGE_METRIC_NAME = 'veneur.build_age'
MAX_AGE_CHECK_NAME = 'veneur.build_age.fresh'
# Check that the build is no more than one week old
MAX_DEPLOYMENT_INTERVAL = 604800
def check(self, instance):
success = 0
host = instance['host']
try:
r = requests.get(urljoin(host, '/version'))
sha = r.text
success = 1
r = requests.get(urljoin(host, '/builddate'))
builddate = datetime.datetime.fromtimestamp(int(r.text))
tdelta = datetime.datetime.now() - builddate
if tdelta.seconds > self.MAX_DEPLOYMENT_INTERVAL:
self.service_check(self.MAX_AGE_CHECK_NAME, AgentCheck.CRITICAL,
message='Build date {0} is too old (build must be no more than {1} seconds old)'.format(builddate.strftime('%Y-%m-%d %H:%M:%S'), self.MAX_DEPLOYMENT_INTERVAL))
except:
success = 0
raise
finally:
self.gauge(self.VERSION_METRIC_NAME, success, tags = ['sha:{0}'.format(sha)])
self.histogram(self.BUILDAGE_METRIC_NAME, tdelta.seconds)
|
import datetime
from urlparse import urljoin
import requests
# project
from checks import AgentCheck
class Veneur(AgentCheck):
VERSION_METRIC_NAME = 'veneur.deployed_version'
BUILDAGE_METRIC_NAME = 'veneur.build_age'
def check(self, instance):
success = 0
host = instance['host']
try:
r = requests.get(urljoin(host, '/version'))
sha = r.text
success = 1
r = requests.get(urljoin(host, '/builddate'))
builddate = datetime.datetime.fromtimestamp(int(r.text))
tdelta = datetime.datetime.now() - builddate
except:
success = 0
raise
finally:
self.gauge(self.VERSION_METRIC_NAME, success, tags = ['sha:{0}'.format(sha)])
self.histogram(self.BUILDAGE_METRIC_NAME, tdelta.seconds)
|
Configure max build age on the monitoring side
|
Configure max build age on the monitoring side
|
Python
|
mit
|
stripe/stripe-datadog-checks,stripe/datadog-checks
|
---
+++
@@ -9,12 +9,6 @@
VERSION_METRIC_NAME = 'veneur.deployed_version'
BUILDAGE_METRIC_NAME = 'veneur.build_age'
-
- MAX_AGE_CHECK_NAME = 'veneur.build_age.fresh'
-
- # Check that the build is no more than one week old
- MAX_DEPLOYMENT_INTERVAL = 604800
-
def check(self, instance):
success = 0
@@ -31,10 +25,6 @@
tdelta = datetime.datetime.now() - builddate
- if tdelta.seconds > self.MAX_DEPLOYMENT_INTERVAL:
- self.service_check(self.MAX_AGE_CHECK_NAME, AgentCheck.CRITICAL,
- message='Build date {0} is too old (build must be no more than {1} seconds old)'.format(builddate.strftime('%Y-%m-%d %H:%M:%S'), self.MAX_DEPLOYMENT_INTERVAL))
-
except:
success = 0
raise
|
859d5ce6553b7651f05f27adec28e8c4330ca9bb
|
handler/supervisor_to_serf.py
|
handler/supervisor_to_serf.py
|
#!/usr/bin/env python
import json
import sys
from utils import serf_event
def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def main():
while True:
write_stdout('READY\n') # transition from ACKNOWLEDGED to READY
line = sys.stdin.readline() # read header line from stdin
headers = dict(x.split(':') for x in line.split())
data = sys.stdin.read(int(headers['len'])) # read the event payload
data_dict = dict(x.split(':') for x in data.split())
data_dict['eventname'] = headers['eventname']
serf_event('myevent', json.dumps(data_dict))
write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED
if __name__ == '__main__':
main()
|
#!/usr/bin/env python
import json
import sys
from utils import serf_event
def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def main():
while True:
write_stdout('READY\n') # transition from ACKNOWLEDGED to READY
line = sys.stdin.readline() # read header line from stdin
headers = dict(x.split(':') for x in line.split())
data = sys.stdin.read(int(headers['len'])) # read the event payload
data_dict = dict(x.split(':') for x in data.split())
data_dict['eventname'] = headers['eventname']
data_dict['node'] = serf('info')['agent']['name']
serf_event('supervisor', json.dumps(data_dict))
write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED
if __name__ == '__main__':
main()
|
Add id of node generating the supervisor event
|
Add id of node generating the supervisor event
|
Python
|
mit
|
waltermoreira/serfnode,waltermoreira/serfnode,waltermoreira/serfnode
|
---
+++
@@ -22,7 +22,8 @@
data = sys.stdin.read(int(headers['len'])) # read the event payload
data_dict = dict(x.split(':') for x in data.split())
data_dict['eventname'] = headers['eventname']
- serf_event('myevent', json.dumps(data_dict))
+ data_dict['node'] = serf('info')['agent']['name']
+ serf_event('supervisor', json.dumps(data_dict))
write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED
if __name__ == '__main__':
|
c136d416c2cb53449e1c175412eeaa46a2f78db1
|
zou/app/utils/emails.py
|
zou/app/utils/emails.py
|
from flask_mail import Message
from zou.app import mail, app
def send_email(subject, body, recipient_email, html=None):
"""
Send an email with given subject and body to given recipient.
"""
if html is None:
html = body
with app.app_context():
message = Message(
sender="Kitsu Bot <no-reply@cg-wire.com>"
body=body,
html=html,
subject=subject,
recipients=[recipient_email]
)
mail.send(message)
|
from flask_mail import Message
from zou.app import mail, app
def send_email(subject, body, recipient_email, html=None):
"""
Send an email with given subject and body to given recipient.
"""
if html is None:
html = body
with app.app_context():
message = Message(
sender="Kitsu Bot <no-reply@cg-wire.com>",
body=body,
html=html,
subject=subject,
recipients=[recipient_email]
)
mail.send(message)
|
Fix syntax error in email service
|
Fix syntax error in email service
|
Python
|
agpl-3.0
|
cgwire/zou
|
---
+++
@@ -11,7 +11,7 @@
html = body
with app.app_context():
message = Message(
- sender="Kitsu Bot <no-reply@cg-wire.com>"
+ sender="Kitsu Bot <no-reply@cg-wire.com>",
body=body,
html=html,
subject=subject,
|
020015cccceb3c2391c4764ee2ec29dfc5c461c6
|
__init__.py
|
__init__.py
|
from . import LayerView
def getMetaData():
return { "name": "LayerView", "type": "View" }
def register(app):
app.getController().addView("LayerView", LayerView.LayerView())
|
from . import LayerView
def getMetaData():
return { "name": "LayerView", "type": "View" }
def register(app):
return LayerView.LayerView()
|
Update plugin's register functions to return the object instance instead of performing the registration themselves
|
Update plugin's register functions to return the object instance instead of performing the registration themselves
|
Python
|
agpl-3.0
|
Curahelper/Cura,bq/Ultimaker-Cura,ad1217/Cura,bq/Ultimaker-Cura,senttech/Cura,lo0ol/Ultimaker-Cura,quillford/Cura,derekhe/Cura,ynotstartups/Wanhao,markwal/Cura,lo0ol/Ultimaker-Cura,senttech/Cura,DeskboxBrazil/Cura,ynotstartups/Wanhao,totalretribution/Cura,ad1217/Cura,fieldOfView/Cura,quillford/Cura,fxtentacle/Cura,derekhe/Cura,hmflash/Cura,DeskboxBrazil/Cura,fieldOfView/Cura,totalretribution/Cura,Curahelper/Cura,markwal/Cura,fxtentacle/Cura,hmflash/Cura
|
---
+++
@@ -4,4 +4,4 @@
return { "name": "LayerView", "type": "View" }
def register(app):
- app.getController().addView("LayerView", LayerView.LayerView())
+ return LayerView.LayerView()
|
b186ed26e3250d8b02c94f5bb3b394c35986bcf6
|
__init__.py
|
__init__.py
|
"""
Spyral, an awesome library for making games.
"""
__version__ = '0.1.1'
__license__ = 'MIT'
__author__ = 'Robert Deaton'
import compat
import memoize
import point
import camera
import sprite
import scene
import _lib
import event
import animator
import animation
import pygame
import image
import color
import rect
import signal
import font
import vector
Scene = scene.Scene
Image = image.Image
Sprite = sprite.Sprite
Group = sprite.Group
AnimationSprite = animation.AnimationSprite
AnimationGroup = animation.AnimationGroup
Rect = rect.Rect
Signal = signal.Signal
Vec2D = vector.Vec2D
keys = event.keys
director = scene.Director()
def init():
event.init()
pygame.init()
pygame.font.init()
def quit():
pygame.quit()
director._stack = []
|
"""
Spyral, an awesome library for making games.
"""
__version__ = '0.1.1'
__license__ = 'MIT'
__author__ = 'Robert Deaton'
import compat
import memoize
import point
import camera
import sprite
import scene
import _lib
import event
import animator
import animation
import pygame
import image
import color
import rect
import signal
import vector
Scene = scene.Scene
Image = image.Image
Sprite = sprite.Sprite
Group = sprite.Group
AnimationSprite = animation.AnimationSprite
AnimationGroup = animation.AnimationGroup
Rect = rect.Rect
Signal = signal.Signal
Vec2D = vector.Vec2D
keys = event.keys
director = scene.Director()
def init():
event.init()
pygame.init()
pygame.font.init()
def quit():
pygame.quit()
director._stack = []
|
Remove an import which snuck in but does not belong.
|
Remove an import which snuck in but does not belong.
Signed-off-by: Robert Deaton <eb00a885478926d5d594195591fb94a03acb1062@udel.edu>
|
Python
|
lgpl-2.1
|
platipy/spyral
|
---
+++
@@ -22,7 +22,6 @@
import color
import rect
import signal
-import font
import vector
Scene = scene.Scene
|
0ec01e1c5770c87faa5300b80c3b9d6bcb0df41b
|
tcxparser.py
|
tcxparser.py
|
"Simple parser for Garmin TCX files."
from lxml import objectify
__version__ = '0.3.0'
class TcxParser:
def __init__(self, tcx_file):
tree = objectify.parse(tcx_file)
self.root = tree.getroot()
self.activity = self.root.Activities.Activity
@property
def latitude(self):
return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees
@property
def longitude(self):
return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees
@property
def activity_type(self):
return self.activity.attrib['Sport'].lower()
@property
def completed_at(self):
return self.activity.Lap[-1].Track.Trackpoint[-1].Time
@property
def distance(self):
return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters
@property
def distance_units(self):
return 'meters'
@property
def duration(self):
"""Returns duration of workout in seconds."""
return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)
@property
def calories(self):
return sum(lap.Calories for lap in self.activity.Lap)
|
"Simple parser for Garmin TCX files."
from lxml import objectify
__version__ = '0.4.0'
class TcxParser:
def __init__(self, tcx_file):
tree = objectify.parse(tcx_file)
self.root = tree.getroot()
self.activity = self.root.Activities.Activity
@property
def latitude(self):
return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees.pyval
@property
def longitude(self):
return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees.pyval
@property
def activity_type(self):
return self.activity.attrib['Sport'].lower()
@property
def completed_at(self):
return self.activity.Lap[-1].Track.Trackpoint[-1].Time.pyval
@property
def distance(self):
return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters.pyval
@property
def distance_units(self):
return 'meters'
@property
def duration(self):
"""Returns duration of workout in seconds."""
return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)
@property
def calories(self):
return sum(lap.Calories for lap in self.activity.Lap)
|
Make sure to return python values, not lxml objects
|
Make sure to return python values, not lxml objects
Bump version to 0.4.0
|
Python
|
bsd-2-clause
|
vkurup/python-tcxparser,vkurup/python-tcxparser,SimonArnu/python-tcxparser
|
---
+++
@@ -2,7 +2,7 @@
from lxml import objectify
-__version__ = '0.3.0'
+__version__ = '0.4.0'
class TcxParser:
@@ -14,11 +14,11 @@
@property
def latitude(self):
- return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees
+ return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees.pyval
@property
def longitude(self):
- return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees
+ return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees.pyval
@property
def activity_type(self):
@@ -26,11 +26,11 @@
@property
def completed_at(self):
- return self.activity.Lap[-1].Track.Trackpoint[-1].Time
+ return self.activity.Lap[-1].Track.Trackpoint[-1].Time.pyval
@property
def distance(self):
- return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters
+ return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters.pyval
@property
def distance_units(self):
|
3f18e4891b64c45fbda9ae88e9b508b5bc2cb03a
|
temp2dash.py
|
temp2dash.py
|
import json
import requests
import sys
from temperusb import TemperHandler
URL="http://dashing:3030/widgets/inside"
SCALE=1.0
OFFSET=-3.0
th = TemperHandler()
devs = th.get_devices()
if len(devs) != 1:
print "Expected exactly one TEMPer device, found %d" % len(devs)
sys.exit(1)
dev = devs[0]
dev.set_calibration_data(scale=SCALE, offset=OFFSET)
temperature = dev.get_temperature(sensor=1)
payload = {
'auth_token': 'abcdefghijklmnopqrstuvwxyz',
'temperature': '%0.0f%s' % (
temperature,
u'\N{DEGREE SIGN}',
),
}
post = requests.post(URL, data=json.dumps(payload))
if post.status_code != 204:
sys.exit(255)
sys.exit(0)
|
import json
import os
import requests
import sys
import time
import traceback
from temperusb import TemperHandler
URL = os.environ['DASHING_URL']
SCALE = float(os.environ['TEMP_SCALE'])
OFFSET = float(os.environ['TEMP_OFFSET'])
SENSOR = int(os.environ['TEMP_SENSOR'])
SLEEP = int(os.environ['SLEEP_TIME'])
th = TemperHandler()
devs = th.get_devices()
if len(devs) != 1:
print "Expected exactly one TEMPer device, found %d" % len(devs)
sys.exit(1)
dev = devs[0]
dev.set_calibration_data(scale=SCALE, offset=OFFSET)
while True:
try:
temperature = dev.get_temperature(sensor=SENSOR)
except Exception, err:
print "\nException on getting temperature\n"
print traceback.format_exc()
payload = {
'auth_token': 'abcdefghijklmnopqrstuvwxyz',
'temperature': '%0.0f%s' % (
temperature,
u'\N{DEGREE SIGN}',
),
}
sys.stdout.write(u'%0.1f%s, ' % (
temperature,
u'\N{DEGREE SIGN}',
))
sys.stdout.flush()
try:
post = requests.post(URL, data=json.dumps(payload))
except Exception, err:
print "\nException on posting temperature to dashing\n"
print traceback.format_exc()
if post.status_code != 204:
print "\nHTTP status from POST was %s (expected 204)\n" % post.status_code
time.sleep(SLEEP)
|
Add infinite loop; Add env vars
|
Add infinite loop; Add env vars
|
Python
|
mit
|
ps-jay/temp2dash
|
---
+++
@@ -1,13 +1,16 @@
import json
+import os
import requests
import sys
+import time
+import traceback
from temperusb import TemperHandler
-
-URL="http://dashing:3030/widgets/inside"
-SCALE=1.0
-OFFSET=-3.0
-
+URL = os.environ['DASHING_URL']
+SCALE = float(os.environ['TEMP_SCALE'])
+OFFSET = float(os.environ['TEMP_OFFSET'])
+SENSOR = int(os.environ['TEMP_SENSOR'])
+SLEEP = int(os.environ['SLEEP_TIME'])
th = TemperHandler()
devs = th.get_devices()
@@ -17,19 +20,35 @@
dev = devs[0]
dev.set_calibration_data(scale=SCALE, offset=OFFSET)
-temperature = dev.get_temperature(sensor=1)
-payload = {
- 'auth_token': 'abcdefghijklmnopqrstuvwxyz',
- 'temperature': '%0.0f%s' % (
+while True:
+ try:
+ temperature = dev.get_temperature(sensor=SENSOR)
+ except Exception, err:
+ print "\nException on getting temperature\n"
+ print traceback.format_exc()
+
+ payload = {
+ 'auth_token': 'abcdefghijklmnopqrstuvwxyz',
+ 'temperature': '%0.0f%s' % (
+ temperature,
+ u'\N{DEGREE SIGN}',
+ ),
+ }
+
+ sys.stdout.write(u'%0.1f%s, ' % (
temperature,
u'\N{DEGREE SIGN}',
- ),
-}
+ ))
+ sys.stdout.flush()
-post = requests.post(URL, data=json.dumps(payload))
+ try:
+ post = requests.post(URL, data=json.dumps(payload))
+ except Exception, err:
+ print "\nException on posting temperature to dashing\n"
+ print traceback.format_exc()
-if post.status_code != 204:
- sys.exit(255)
+ if post.status_code != 204:
+ print "\nHTTP status from POST was %s (expected 204)\n" % post.status_code
-sys.exit(0)
+ time.sleep(SLEEP)
|
5768d1ebcfec46e564c8b420773d911c243327ff
|
dddp/msg.py
|
dddp/msg.py
|
"""Django DDP utils for DDP messaging."""
import collections
from django.core.serializers import get_serializer
_SERIALIZER = None
def obj_change_as_msg(obj, msg):
"""Generate a DDP msg for obj with specified msg type."""
global _SERIALIZER
if _SERIALIZER is None:
_SERIALIZER = get_serializer('ddp')()
data = _SERIALIZER.serialize([obj])[0]
name = data['model']
# cast ID as string
if not isinstance(data['pk'], basestring):
data['pk'] = '%d' % data['pk']
payload = {
'msg': msg,
'collection': name,
'id': data['pk'],
}
if msg != 'removed':
payload['fields'] = data['fields']
return (name, payload)
|
"""Django DDP utils for DDP messaging."""
from dddp import THREAD_LOCAL as this
from django.core.serializers import get_serializer
def serializer_factory():
"""Make a new DDP serializer."""
return get_serializer('ddp')()
def obj_change_as_msg(obj, msg):
"""Generate a DDP msg for obj with specified msg type."""
serializer = this.get('serializer', serializer_factory)
data = serializer.serialize([obj])[0]
name = data['model']
# cast ID as string
if not isinstance(data['pk'], basestring):
data['pk'] = '%d' % data['pk']
payload = {
'msg': msg,
'collection': name,
'id': data['pk'],
}
if msg != 'removed':
payload['fields'] = data['fields']
return (name, payload)
|
Fix non-threadsafe failure in serializer - now using thread local serializer instance.
|
Fix non-threadsafe failure in serializer - now using thread local serializer instance.
|
Python
|
mit
|
commoncode/django-ddp,commoncode/django-ddp,commoncode/django-ddp,django-ddp/django-ddp,django-ddp/django-ddp,django-ddp/django-ddp,commoncode/django-ddp,django-ddp/django-ddp
|
---
+++
@@ -1,15 +1,17 @@
"""Django DDP utils for DDP messaging."""
-import collections
+from dddp import THREAD_LOCAL as this
from django.core.serializers import get_serializer
-_SERIALIZER = None
+
+def serializer_factory():
+ """Make a new DDP serializer."""
+ return get_serializer('ddp')()
+
def obj_change_as_msg(obj, msg):
"""Generate a DDP msg for obj with specified msg type."""
- global _SERIALIZER
- if _SERIALIZER is None:
- _SERIALIZER = get_serializer('ddp')()
- data = _SERIALIZER.serialize([obj])[0]
+ serializer = this.get('serializer', serializer_factory)
+ data = serializer.serialize([obj])[0]
name = data['model']
# cast ID as string
|
338e2ba155df0759113c65ced6be6714092b9aaf
|
packages/gtk-quartz-engine.py
|
packages/gtk-quartz-engine.py
|
Package ('gtk-quartz-engine', 'master',
sources = [ 'git://github.com/jralls/gtk-quartz-engine.git' ],
override_properties = { 'configure':
'libtoolize --force --copy && '
'aclocal && '
'autoheader && '
'automake --add-missing && '
'autoconf && '
'./configure --prefix=%{prefix}'
}
)
|
Package ('gtk-quartz-engine', 'master',
sources = [ 'git://github.com/nirvanai/gtk-quartz-engine.git' ],
override_properties = { 'configure':
'libtoolize --force --copy && '
'aclocal && '
'autoheader && '
'automake --add-missing && '
'autoconf && '
'./configure --prefix=%{prefix}'
}
)
|
Use Alex's awesome new version of the GtkQuartz theme engine
|
Use Alex's awesome new version of the GtkQuartz theme engine
|
Python
|
mit
|
bl8/bockbuild,bl8/bockbuild,BansheeMediaPlayer/bockbuild,bl8/bockbuild,BansheeMediaPlayer/bockbuild,mono/bockbuild,BansheeMediaPlayer/bockbuild,mono/bockbuild
|
---
+++
@@ -1,5 +1,5 @@
Package ('gtk-quartz-engine', 'master',
- sources = [ 'git://github.com/jralls/gtk-quartz-engine.git' ],
+ sources = [ 'git://github.com/nirvanai/gtk-quartz-engine.git' ],
override_properties = { 'configure':
'libtoolize --force --copy && '
'aclocal && '
|
12130cef6c9b08e0928ed856972ace3c2000e6f8
|
mooc_aggregator_restful_api/udacity.py
|
mooc_aggregator_restful_api/udacity.py
|
'''
This module retrieves the course catalog and overviews of the Udacity API
Link to Documentation:
https://s3.amazonaws.com/content.udacity-data.com/techdocs/UdacityCourseCatalogAPIDocumentation-v0.pdf
'''
import json
import requests
class UdacityAPI(object):
'''
This class defines attributes and methods for Udaciy API
'''
UDACITY_API_ENDPOINT = 'https://udacity.com/public-api/v0/courses'
def __init__(self):
self.response = requests.get(UDACITY_API_ENDPOINT)
self.courses = self.response.json()['courses']
self.tracks = self.response.json()['tracks']
def status_code(self):
'''
Return status code of response object
'''
return self.response.status_code
def get_courses(self):
'''
Return list of course objects for all courses offered by Udacity
'''
return self.courses
def get_tracks(self):
'''
Return list of tracks offered by Udacity
'''
return self.tracks
if __name__ == '__main__':
udacity_object = UdacityAPI()
print len(udacity_object.get_courses())
print udacity_object.get_courses()[0].keys()
|
'''
This module retrieves the course catalog and overviews of the Udacity API
Link to Documentation:
https://s3.amazonaws.com/content.udacity-data.com/techdocs/UdacityCourseCatalogAPIDocumentation-v0.pdf
'''
import json
import requests
class UdacityAPI(object):
'''
This class defines attributes and methods for Udaciy API
'''
UDACITY_API_ENDPOINT = 'https://udacity.com/public-api/v0/courses'
def __init__(self):
self.response = requests.get(UdacityAPI.UDACITY_API_ENDPOINT)
self.courses = self.response.json()['courses']
self.tracks = self.response.json()['tracks']
def status_code(self):
'''
Return status code of response object
'''
return self.response.status_code
def get_courses(self):
'''
Return list of course objects for all courses offered by Udacity
'''
return self.courses
def get_tracks(self):
'''
Return list of tracks offered by Udacity
'''
return self.tracks
if __name__ == '__main__':
udacity_object = UdacityAPI()
print len(udacity_object.get_courses())
print udacity_object.get_courses()[0].keys()
|
Fix error accessing class variable
|
Fix error accessing class variable
|
Python
|
mit
|
ueg1990/mooc_aggregator_restful_api
|
---
+++
@@ -19,7 +19,7 @@
UDACITY_API_ENDPOINT = 'https://udacity.com/public-api/v0/courses'
def __init__(self):
- self.response = requests.get(UDACITY_API_ENDPOINT)
+ self.response = requests.get(UdacityAPI.UDACITY_API_ENDPOINT)
self.courses = self.response.json()['courses']
self.tracks = self.response.json()['tracks']
|
f5600008defcd5fe4c9c397c0b7170f6f5e9a5e4
|
__init__.py
|
__init__.py
|
__author__ = "Justin Kitzes, Mark Wilber, Chloe Lewis"
__copyright__ = "Copyright 2012, Regents of University of California"
__credits__ = []
__license__ = "BSD 2-clause"
__version__ = "0.1"
__maintainer__ = "Justin Kitzes"
__email__ = "jkitzes@berkeley.edu"
__status__ = "Development"
import compare
import data
import empirical
import output
import utils.workflow as workflow
|
Add header info and submodule imports to init
|
Add header info and submodule imports to init
|
Python
|
bsd-2-clause
|
jkitzes/macroeco
|
---
+++
@@ -1 +1,14 @@
+__author__ = "Justin Kitzes, Mark Wilber, Chloe Lewis"
+__copyright__ = "Copyright 2012, Regents of University of California"
+__credits__ = []
+__license__ = "BSD 2-clause"
+__version__ = "0.1"
+__maintainer__ = "Justin Kitzes"
+__email__ = "jkitzes@berkeley.edu"
+__status__ = "Development"
+import compare
+import data
+import empirical
+import output
+import utils.workflow as workflow
|
|
977cf58125a204010197c95827457843503e2c5b
|
ideascube/conf/kb_rca_alliancefrancaise.py
|
ideascube/conf/kb_rca_alliancefrancaise.py
|
# -*- coding: utf-8 -*-
"""KoomBook conf"""
from .kb import * # noqa
LANGUAGE_CODE = 'fr'
IDEASCUBE_NAME = 'Alliance française de Bangui'
|
# -*- coding: utf-8 -*-
"""KoomBook conf"""
from .kb import * # noqa
LANGUAGE_CODE = 'fr'
IDEASCUBE_NAME = 'Alliance française de Bangui'
# Disable BSF Campus for now
HOME_CARDS = [card for card in HOME_CARDS if card['id'] != 'bsfcampus']
|
Disable BSF Campus for RCA Alliance Française
|
Disable BSF Campus for RCA Alliance Française
@barbayellow said so.
|
Python
|
agpl-3.0
|
ideascube/ideascube,ideascube/ideascube,ideascube/ideascube,ideascube/ideascube
|
---
+++
@@ -4,3 +4,6 @@
LANGUAGE_CODE = 'fr'
IDEASCUBE_NAME = 'Alliance française de Bangui'
+
+# Disable BSF Campus for now
+HOME_CARDS = [card for card in HOME_CARDS if card['id'] != 'bsfcampus']
|
cc12728d7160a10f0c182c0cccfde0fd15cadb75
|
spicedham/basewrapper.py
|
spicedham/basewrapper.py
|
class BaseWrapper(object):
"""
A base class for backend plugins.
"""
def get_key(self, tag, key, default=None):
"""
Gets the value held by the tag, key composite key. If it doesn't exist,
return default.
"""
raise NotImplementedError()
def get_key_list(self, tag, keys, default=None):
"""
Given a list of key, tag tuples get all values.
If key, tag doesn't exist, return default.
Subclasses can override this to make more efficient queries for bulk
requests.
"""
return [self.get_key(tag, key, default) for tag, key in key_tag_pairs]
def set_key_list(self, tag, key_value_tuples):
"""
Given a list of tuples of tag, key, value set them all.
Subclasses can override this to make more efficient queries for bulk
requests.
"""
return [self.set_key(tag, key, value) for tag, key, value in tag_key_value_tuples]
def set_key(self, tag, key, value):
"""
Set the value held by the tag, key composite key.
"""
raise NotImplementedError()
|
class BaseWrapper(object):
"""
A base class for backend plugins.
"""
def reset(self, really):
"""
Resets the training data to a blank slate.
"""
if really:
raise NotImplementedError()
def get_key(self, tag, key, default=None):
"""
Gets the value held by the tag, key composite key. If it doesn't exist,
return default.
"""
raise NotImplementedError()
def get_key_list(self, tag, keys, default=None):
"""
Given a list of key, tag tuples get all values.
If key, tag doesn't exist, return default.
Subclasses can override this to make more efficient queries for bulk
requests.
"""
return [self.get_key(tag, key, default) for tag, key in key_tag_pairs]
def set_key_list(self, tag_key_value_tuples):
"""
Given a list of tuples of tag, key, value set them all.
Subclasses can override this to make more efficient queries for bulk
requests.
"""
return [self.set_key(tag, key, value) for tag, key, value in tag_key_value_tuples]
def set_key(self, tag, key, value):
"""
Set the value held by the tag, key composite key.
"""
raise NotImplementedError()
|
Add a reset function stub
|
Add a reset function stub
Also fix a typo.
|
Python
|
mpl-2.0
|
mozilla/spicedham,mozilla/spicedham
|
---
+++
@@ -3,6 +3,14 @@
"""
A base class for backend plugins.
"""
+
+ def reset(self, really):
+ """
+ Resets the training data to a blank slate.
+ """
+ if really:
+ raise NotImplementedError()
+
def get_key(self, tag, key, default=None):
"""
@@ -22,7 +30,7 @@
return [self.get_key(tag, key, default) for tag, key in key_tag_pairs]
- def set_key_list(self, tag, key_value_tuples):
+ def set_key_list(self, tag_key_value_tuples):
"""
Given a list of tuples of tag, key, value set them all.
Subclasses can override this to make more efficient queries for bulk
|
cf6ddfdac8a56194ad1297921a390be541d773cc
|
app_info.py
|
app_info.py
|
# coding=UTF8
import datetime
name = "Devo"
release_date = datetime.date(2012, 12, 13)
version = (1, 0, 0)
version_string = ".".join(str(x) for x in version)
identifier = "com.iogopro.devo"
copyright = u"Copyright © 2010-2012 Luke McCarthy"
developer = "Developer: Luke McCarthy <luke@iogopro.co.uk>"
company_name = "Iogopro Software"
url = "http://iogopro.com/devo"
|
# coding=UTF8
import datetime
name = "Devo"
release_date = datetime.date(2012, 12, 13)
version = (1, 0, 0)
version_string = ".".join(str(x) for x in (version if version[2] != 0 else version[:2]))
identifier = "com.iogopro.devo"
copyright = u"Copyright © 2010-2012 Luke McCarthy"
developer = "Developer: Luke McCarthy <luke@iogopro.co.uk>"
company_name = "Iogopro Software"
url = "http://iogopro.com/devo"
|
Remove last digit of version number if it's 0.
|
Remove last digit of version number if it's 0.
|
Python
|
mit
|
shaurz/devo
|
---
+++
@@ -8,7 +8,7 @@
version = (1, 0, 0)
-version_string = ".".join(str(x) for x in version)
+version_string = ".".join(str(x) for x in (version if version[2] != 0 else version[:2]))
identifier = "com.iogopro.devo"
|
0b11bf48989673245adbc89aa6f65c85debafd9f
|
armstrong/apps/donations/backends.py
|
armstrong/apps/donations/backends.py
|
from armstrong.utils.backends import GenericBackend
from billing import get_gateway
from . import forms
class AuthorizeNetBackend(object):
def get_form_class(self):
return forms.CreditCardDonationForm
def purchase(self, donation, form):
authorize = get_gateway("authorize_net")
authorize.purchase(donation.amount,
form.get_credit_card(donation.donor),
options=self.get_options(donation))
def get_options(self, donation):
donor = donation.donor
return {
"billing_address": {
"name": donor.name,
"address1": donor.address.address,
"city": donor.address.city,
"state": donor.address.state,
# TODO: Support other countries
"country": "US",
"zip": donor.address.zipcode,
},
"shipping_address": {
"name": donor.name,
"address1": donor.mailing_address.address,
"city": donor.mailing_address.city,
"state": donor.mailing_address.state,
# TODO: Support other countries
"country": "US",
"zip": donor.mailing_address.zipcode,
}
}
raw_backend = GenericBackend("ARMSTRONG_DONATIONS_BACKEND", defaults=[
"armstrong.apps.donations.backends.AuthorizeNetBackend",
])
get_backend = raw_backend.get_backend
|
from armstrong.utils.backends import GenericBackend
from billing import get_gateway
from . import forms
class AuthorizeNetBackend(object):
def get_form_class(self):
return forms.CreditCardDonationForm
def purchase(self, donation, form):
authorize = get_gateway("authorize_net")
authorize.purchase(donation.amount,
form.get_credit_card(donation.donor),
options=self.get_options(donation))
def get_options(self, donation):
donor = donation.donor
r = {}
if donor.address:
r["billing_address"] = {
"name": donor.name,
"address1": donor.address.address,
"city": donor.address.city,
"state": donor.address.state,
# TODO: Support other countries
"country": "US",
"zip": donor.address.zipcode,
}
if donor.mailing_address:
r["shipping_address"] = {
"name": donor.name,
"address1": donor.mailing_address.address,
"city": donor.mailing_address.city,
"state": donor.mailing_address.state,
# TODO: Support other countries
"country": "US",
"zip": donor.mailing_address.zipcode,
}
return r
raw_backend = GenericBackend("ARMSTRONG_DONATIONS_BACKEND", defaults=[
"armstrong.apps.donations.backends.AuthorizeNetBackend",
])
get_backend = raw_backend.get_backend
|
Make sure billing/shipping aren't populated if they aren't there
|
Make sure billing/shipping aren't populated if they aren't there
|
Python
|
apache-2.0
|
armstrong/armstrong.apps.donations,armstrong/armstrong.apps.donations
|
---
+++
@@ -16,8 +16,9 @@
def get_options(self, donation):
donor = donation.donor
- return {
- "billing_address": {
+ r = {}
+ if donor.address:
+ r["billing_address"] = {
"name": donor.name,
"address1": donor.address.address,
"city": donor.address.city,
@@ -25,8 +26,9 @@
# TODO: Support other countries
"country": "US",
"zip": donor.address.zipcode,
- },
- "shipping_address": {
+ }
+ if donor.mailing_address:
+ r["shipping_address"] = {
"name": donor.name,
"address1": donor.mailing_address.address,
"city": donor.mailing_address.city,
@@ -35,7 +37,8 @@
"country": "US",
"zip": donor.mailing_address.zipcode,
}
- }
+ return r
+
raw_backend = GenericBackend("ARMSTRONG_DONATIONS_BACKEND", defaults=[
"armstrong.apps.donations.backends.AuthorizeNetBackend",
|
5efddf26176ac778556a3568bf97c2e70daac866
|
anchorhub/settings/default_settings.py
|
anchorhub/settings/default_settings.py
|
"""
Defaults for all settings used by AnchorHub
"""
WRAPPER = "{ }"
INPUT = "."
OUTPUT = "out-anchorhub"
ARGPARSER = {
"description": "anchorhub parses through Markdown files and precompiles "
"links to specially formatted anchors."
}
ARGPARSE_INPUT = {
"help": "Path of directory tree to be parsed",
}
ARGPARSE_OUTPUT = {
"help": "Desired output location (default is \"" + OUTPUT + "\")",
"default": OUTPUT
}
ARGPARSE_OVERWRITE = {
"help": "Overwrite input files; ignore output location"
}
ARGPARSE_EXTENSION = {
"help": "Indicate which file extensions to search and run anchorhub on.",
"default": [".md"]
}
ARGPARSE_WRAPPER = {
"help": "Specify custom wrapper format (default is \"" + WRAPPER + "\")",
"default": WRAPPER
}
|
"""
Defaults for all settings used by AnchorHub
"""
WRAPPER = '{ }'
INPUT = '.'
OUTPUT = 'out-anchorhub'
ARGPARSER = {
'description': "anchorhub parses through Markdown files and precompiles "
"links to specially formatted anchors."
}
ARGPARSE_INPUT = {
'help': "Path of directory tree to be parsed",
}
ARGPARSE_OUTPUT = {
'help': "Desired output location (default is \"" + OUTPUT + "\")",
'default': OUTPUT
}
ARGPARSE_OVERWRITE = {
'help': "Overwrite input files; ignore output location"
}
ARGPARSE_EXTENSION = {
'help': "Indicate which file extensions to search and run anchorhub on.",
'default': [".md"]
}
ARGPARSE_WRAPPER = {
'help': "Specify custom wrapper format (default is \"" + WRAPPER + "\")",
'default': WRAPPER
}
|
Replace many double quotes with single quotes
|
Replace many double quotes with single quotes
|
Python
|
apache-2.0
|
samjabrahams/anchorhub
|
---
+++
@@ -2,30 +2,30 @@
Defaults for all settings used by AnchorHub
"""
-WRAPPER = "{ }"
+WRAPPER = '{ }'
-INPUT = "."
-OUTPUT = "out-anchorhub"
+INPUT = '.'
+OUTPUT = 'out-anchorhub'
ARGPARSER = {
- "description": "anchorhub parses through Markdown files and precompiles "
+ 'description': "anchorhub parses through Markdown files and precompiles "
"links to specially formatted anchors."
}
ARGPARSE_INPUT = {
- "help": "Path of directory tree to be parsed",
+ 'help': "Path of directory tree to be parsed",
}
ARGPARSE_OUTPUT = {
- "help": "Desired output location (default is \"" + OUTPUT + "\")",
- "default": OUTPUT
+ 'help': "Desired output location (default is \"" + OUTPUT + "\")",
+ 'default': OUTPUT
}
ARGPARSE_OVERWRITE = {
- "help": "Overwrite input files; ignore output location"
+ 'help': "Overwrite input files; ignore output location"
}
ARGPARSE_EXTENSION = {
- "help": "Indicate which file extensions to search and run anchorhub on.",
- "default": [".md"]
+ 'help': "Indicate which file extensions to search and run anchorhub on.",
+ 'default': [".md"]
}
ARGPARSE_WRAPPER = {
- "help": "Specify custom wrapper format (default is \"" + WRAPPER + "\")",
- "default": WRAPPER
+ 'help': "Specify custom wrapper format (default is \"" + WRAPPER + "\")",
+ 'default': WRAPPER
}
|
ff90958a0c79936d5056840ba03a5863bcdef099
|
formal/test/test_util.py
|
formal/test/test_util.py
|
from twisted.trial import unittest
from formal import util
class TestUtil(unittest.TestCase):
def test_validIdentifier(self):
self.assertEquals(util.validIdentifier('foo'), True)
self.assertEquals(util.validIdentifier('_foo'), True)
self.assertEquals(util.validIdentifier('_foo_'), True)
self.assertEquals(util.validIdentifier('foo2'), True)
self.assertEquals(util.validIdentifier('Foo'), True)
self.assertEquals(util.validIdentifier(' foo'), False)
self.assertEquals(util.validIdentifier('foo '), False)
self.assertEquals(util.validIdentifier('9'), False)
|
from twisted.trial import unittest
from formal import util
class TestUtil(unittest.TestCase):
def test_validIdentifier(self):
self.assertEquals(util.validIdentifier('foo'), True)
self.assertEquals(util.validIdentifier('_foo'), True)
self.assertEquals(util.validIdentifier('_foo_'), True)
self.assertEquals(util.validIdentifier('foo2'), True)
self.assertEquals(util.validIdentifier('Foo'), True)
self.assertEquals(util.validIdentifier(' foo'), False)
self.assertEquals(util.validIdentifier('foo '), False)
self.assertEquals(util.validIdentifier('9'), False)
test_validIdentifier.todo = "Fails due to weird import poblem"
|
Mark as test as "todo" for now.
|
Mark as test as "todo" for now.
|
Python
|
mit
|
emgee/formal,emgee/formal,emgee/formal
|
---
+++
@@ -13,3 +13,5 @@
self.assertEquals(util.validIdentifier(' foo'), False)
self.assertEquals(util.validIdentifier('foo '), False)
self.assertEquals(util.validIdentifier('9'), False)
+ test_validIdentifier.todo = "Fails due to weird import poblem"
+
|
2e7271a33e098d7cdef15207e8caa05e644c3223
|
changes/buildfailures/testfailure.py
|
changes/buildfailures/testfailure.py
|
from __future__ import absolute_import
from jinja2 import Markup
from changes.buildfailures.base import BuildFailure
class TestFailure(BuildFailure):
def get_html_label(self, build):
link = '/projects/{0}/builds/{1}/tests/?result=failed'.format(build.project.slug, build.id.hex)
try:
test_failures = (
s.value for s in build.stats if s.name == 'test_failures'
).next()
except StopIteration:
return Markup('There were an <a href="{link}">unknown number of test failures</a>.'.format(
link=link,
))
return Markup('There were <a href="{link}">{count} failing tests</a>.'.format(
link=link,
count=test_failures,
))
|
from __future__ import absolute_import
from jinja2 import Markup
from changes.buildfailures.base import BuildFailure
from changes.utils.http import build_uri
class TestFailure(BuildFailure):
def get_html_label(self, build):
link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(build.project.slug, build.id.hex))
try:
test_failures = (
s.value for s in build.stats if s.name == 'test_failures'
).next()
except StopIteration:
return Markup('There were an <a href="{link}">unknown number of test failures</a>.'.format(
link=link,
))
return Markup('There were <a href="{link}">{count} failing tests</a>.'.format(
link=link,
count=test_failures,
))
|
Use full URI for build failure reasons
|
Use full URI for build failure reasons
|
Python
|
apache-2.0
|
bowlofstew/changes,wfxiang08/changes,bowlofstew/changes,wfxiang08/changes,wfxiang08/changes,bowlofstew/changes,dropbox/changes,bowlofstew/changes,wfxiang08/changes,dropbox/changes,dropbox/changes,dropbox/changes
|
---
+++
@@ -3,11 +3,12 @@
from jinja2 import Markup
from changes.buildfailures.base import BuildFailure
+from changes.utils.http import build_uri
class TestFailure(BuildFailure):
def get_html_label(self, build):
- link = '/projects/{0}/builds/{1}/tests/?result=failed'.format(build.project.slug, build.id.hex)
+ link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(build.project.slug, build.id.hex))
try:
test_failures = (
|
4c303007d6418e2a2f1b2e1778d6b7d0c0573c74
|
gitfs/views/read_only.py
|
gitfs/views/read_only.py
|
import os
from errno import EROFS
from fuse import FuseOSError
from gitfs import FuseMethodNotImplemented
from .view import View
class ReadOnlyView(View):
def getxattr(self, path, fh):
raise FuseMethodNotImplemented
def open(self, path, flags):
return 0
def create(self, path, fh):
raise FuseOSError(EROFS)
def write(self, path, fh):
raise FuseOSError(EROFS)
def opendir(self, path):
return 0
def releasedir(self, path, fi):
return 0
def flush(self, path, fh):
return 0
def release(self, path, fh):
return 0
def access(self, path, amode):
return 0
def mkdir(self, path, mode):
raise FuseOSError(EROFS)
|
from errno import EROFS
from fuse import FuseOSError
from gitfs import FuseMethodNotImplemented
from .view import View
class ReadOnlyView(View):
def getxattr(self, path, fh):
raise FuseMethodNotImplemented
def open(self, path, flags):
return 0
def create(self, path, fh):
raise FuseOSError(EROFS)
def write(self, path, fh):
raise FuseOSError(EROFS)
def opendir(self, path):
return 0
def releasedir(self, path, fi):
return 0
def flush(self, path, fh):
return 0
def release(self, path, fh):
return 0
def access(self, path, amode):
return 0
def mkdir(self, path, mode):
raise FuseOSError(EROFS)
def utimens(self, path, times=None):
raise FuseOSError(EROFS)
|
Raise read-only fs on touch
|
Raise read-only fs on touch
|
Python
|
apache-2.0
|
bussiere/gitfs,PressLabs/gitfs,PressLabs/gitfs,ksmaheshkumar/gitfs,rowhit/gitfs
|
---
+++
@@ -1,4 +1,3 @@
-import os
from errno import EROFS
from fuse import FuseOSError
@@ -38,3 +37,6 @@
def mkdir(self, path, mode):
raise FuseOSError(EROFS)
+
+ def utimens(self, path, times=None):
+ raise FuseOSError(EROFS)
|
a307c5fc2555d282dfa6193cdbcfb2d15e185c0c
|
aq/parsers.py
|
aq/parsers.py
|
from collections import namedtuple
import collections
from six import string_types
from aq.errors import QueryParsingError
from aq.select_parser import select_stmt, ParseException
TableId = namedtuple('TableId', ('database', 'table', 'alias'))
QueryMetadata = namedtuple('QueryMetadata', ('tables',))
class SelectParser(object):
def __init__(self, options):
self.options = options
@staticmethod
def parse_query(query):
try:
parse_result = select_stmt.parseString(query, parseAll=True)
except ParseException as e:
raise QueryParsingError(e)
if not parse_result.table:
raise QueryParsingError('No table specified in query')
tables = [parse_table_id(tid) for tid in parse_result.table_ids]
parsed_query = concat(parse_result)
return parsed_query, QueryMetadata(tables=tables)
def parse_table_id(table_id):
database = table_id.database[0] if table_id.database else None
table = table_id.table[0] if table_id.table else None
alias = table_id.alias[0] if table_id.alias else None
return TableId(database, table, alias)
def flatten(nested_list):
for item in nested_list:
if isinstance(item, collections.Iterable) and not isinstance(item, string_types):
for nested_item in flatten(item):
yield nested_item
else:
yield item
def concat(tokens):
return ' '.join(flatten(tokens))
|
import collections
from collections import namedtuple
from six import string_types
from aq.errors import QueryParsingError
from aq.select_parser import select_stmt, ParseException
TableId = namedtuple('TableId', ('database', 'table', 'alias'))
QueryMetadata = namedtuple('QueryMetadata', ('tables',))
class SelectParser(object):
def __init__(self, options):
self.options = options
@staticmethod
def parse_query(query):
try:
parse_result = select_stmt.parseString(query, parseAll=True)
except ParseException as e:
raise QueryParsingError(e)
tables = [parse_table_id(tid) for tid in parse_result.table_ids]
parsed_query = concat(parse_result)
return parsed_query, QueryMetadata(tables=tables)
def parse_table_id(table_id):
database = table_id.database[0] if table_id.database else None
table = table_id.table[0] if table_id.table else None
alias = table_id.alias[0] if table_id.alias else None
return TableId(database, table, alias)
def flatten(nested_list):
for item in nested_list:
if isinstance(item, collections.Iterable) and not isinstance(item, string_types):
for nested_item in flatten(item):
yield nested_item
else:
yield item
def concat(tokens):
return ' '.join(flatten(tokens))
|
Allow query without table to run
|
Allow query without table to run
|
Python
|
mit
|
lebinh/aq
|
---
+++
@@ -1,6 +1,5 @@
+import collections
from collections import namedtuple
-
-import collections
from six import string_types
@@ -21,9 +20,6 @@
parse_result = select_stmt.parseString(query, parseAll=True)
except ParseException as e:
raise QueryParsingError(e)
-
- if not parse_result.table:
- raise QueryParsingError('No table specified in query')
tables = [parse_table_id(tid) for tid in parse_result.table_ids]
parsed_query = concat(parse_result)
|
583a6319230b89a5f19c26e5bab83e28a5a4792e
|
pywps/processes/dummyprocess.py
|
pywps/processes/dummyprocess.py
|
"""
DummyProcess to check the WPS structure
Author: Jorge de Jesus (jorge.de-jesus@jrc.it) as suggested by Kor de Jong
"""
from pywps.Process import WPSProcess
class Process(WPSProcess):
def __init__(self):
# init process
WPSProcess.__init__(self,
identifier = "dummyprocess", # must be same, as filename
title="Dummy Process",
version = "0.1",
storeSupported = "true",
statusSupported = "true",
abstract="The Dummy process is used for testing the WPS structure. The process will accept 2 input numbers and will return the XML result with an add one and subtract one operation",
grassLocation =False)
self.Input1 = self.addLiteralInput(identifier = "input1",
title = "Input1 number",
default="100")
self.Input2= self.addLiteralInput(identifier="input2",
title="Input2 number",
default="200")
self.Output1=self.addLiteralOutput(identifier="output1",
title="Output1 add 1 result")
self.Output2=self.addLiteralOutput(identifier="output2",title="Output2 subtract 1 result" )
def execute(self):
self.Output1.setValue(self.Input1.getValue()+1)
self.Output2.setValue(self.Input1.getValue()-1)
return
|
"""
DummyProcess to check the WPS structure
Author: Jorge de Jesus (jorge.jesus@gmail.com) as suggested by Kor de Jong
"""
from pywps.Process import WPSProcess
import types
class Process(WPSProcess):
def __init__(self):
# init process
WPSProcess.__init__(self,
identifier = "dummyprocess", # must be same, as filename
title="Dummy Process",
version = "0.1",
storeSupported = "true",
statusSupported = "true",
abstract="The Dummy process is used for testing the WPS structure. The process will accept 2 input numbers and will return the XML result with an add one and subtract one operation",
grassLocation =False)
self.Input1 = self.addLiteralInput(identifier = "input1",
title = "Input1 number",
type=types.IntType,
default="100")
self.Input2= self.addLiteralInput(identifier="input2",
title="Input2 number",
type=types.IntType,
default="200")
self.Output1=self.addLiteralOutput(identifier="output1",
title="Output1 add 1 result")
self.Output2=self.addLiteralOutput(identifier="output2",title="Output2 subtract 1 result" )
def execute(self):
self.Output1.setValue(int(self.Input1.getValue())+1)
self.Output2.setValue(int(self.Input1.getValue())-1)
return
|
Fix the but There is an error (cannot concatenate str and int objects) when the user does not specify the inputs.
|
Fix the but There is an error (cannot concatenate str and int objects)
when the user does not specify the inputs.
|
Python
|
mit
|
ricardogsilva/PyWPS,jonas-eberle/pywps,geopython/pywps,ldesousa/PyWPS,bird-house/PyWPS,jachym/PyWPS,tomkralidis/pywps
|
---
+++
@@ -1,9 +1,10 @@
"""
DummyProcess to check the WPS structure
-Author: Jorge de Jesus (jorge.de-jesus@jrc.it) as suggested by Kor de Jong
+Author: Jorge de Jesus (jorge.jesus@gmail.com) as suggested by Kor de Jong
"""
-from pywps.Process import WPSProcess
+from pywps.Process import WPSProcess
+import types
class Process(WPSProcess):
def __init__(self):
# init process
@@ -17,16 +18,18 @@
grassLocation =False)
self.Input1 = self.addLiteralInput(identifier = "input1",
- title = "Input1 number",
+ title = "Input1 number",
+ type=types.IntType,
default="100")
self.Input2= self.addLiteralInput(identifier="input2",
- title="Input2 number",
+ title="Input2 number",
+ type=types.IntType,
default="200")
self.Output1=self.addLiteralOutput(identifier="output1",
title="Output1 add 1 result")
self.Output2=self.addLiteralOutput(identifier="output2",title="Output2 subtract 1 result" )
def execute(self):
- self.Output1.setValue(self.Input1.getValue()+1)
- self.Output2.setValue(self.Input1.getValue()-1)
+ self.Output1.setValue(int(self.Input1.getValue())+1)
+ self.Output2.setValue(int(self.Input1.getValue())-1)
return
|
305e54c328cf212e01a3af7cec7b940894044e55
|
gen_test.py
|
gen_test.py
|
import math
import numpy
import random
from demodulate.cfg import *
def gen_test_data():
pattern = [1,0,1,1,1,0,0,0,0,0,0,0] # morse code 'A'
cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
radians_per_sample = cycles_per_sample * 2 * math.pi
WPM = random.randint(2,20)
elements_per_second = WPM * 50.0 / 60.0
samples_per_element = int(SAMPLE_FREQ/elements_per_second)
length = samples_per_element * len(pattern)
# Empty returns array containing random stuff, so we NEED to overwrite it
data = numpy.empty(length, dtype=numpy.float32)
for i in xrange(length):
keyed = pattern[int(i/samples_per_element)]
#keyed = 1
data[i] = 0 if not keyed else (radians_per_sample * i)
data = numpy.sin(data)
return data
|
import math
import numpy
import random
from demodulate.cfg import *
def gen_test_data():
pattern = [1,0,1,1,1,0,0,0,0,0,0,0] # morse code 'A'
cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
radians_per_sample = cycles_per_sample * 2 * math.pi
WPM = random.uniform(2,20)
elements_per_second = WPM * 50.0 / 60.0
samples_per_element = int(SAMPLE_FREQ/elements_per_second)
length = samples_per_element * len(pattern)
# Empty returns array containing random stuff, so we NEED to overwrite it
data = numpy.empty(length, dtype=numpy.float32)
for i in xrange(length):
keyed = pattern[int(i/samples_per_element)]
#keyed = 1
data[i] = 0 if not keyed else (radians_per_sample * i)
data = numpy.sin(data)
return data
|
Use float, not int for random WPM
|
Use float, not int for random WPM
|
Python
|
mit
|
nickodell/morse-code
|
---
+++
@@ -7,7 +7,7 @@
pattern = [1,0,1,1,1,0,0,0,0,0,0,0] # morse code 'A'
cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
radians_per_sample = cycles_per_sample * 2 * math.pi
- WPM = random.randint(2,20)
+ WPM = random.uniform(2,20)
elements_per_second = WPM * 50.0 / 60.0
samples_per_element = int(SAMPLE_FREQ/elements_per_second)
|
454c7d322af3328279582aef629736b92c87e869
|
backports/__init__.py
|
backports/__init__.py
|
# This file is part of a backport of 'lzma' included with Python 3.3,
# exposed under the namespace of backports.lzma following the conventions
# laid down here: http://pypi.python.org/pypi/backports/1.0
# Backports homepage: http://bitbucket.org/brandon/backports
# A Python "namespace package" http://www.python.org/dev/peps/pep-0382/
# This always goes inside of a namespace package's __init__.py
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
|
# This file is part of a backport of 'lzma' included with Python 3.3,
# exposed under the namespace of backports.lzma following the conventions
# laid down here: http://pypi.python.org/pypi/backports/1.0
# Backports homepage: http://bitbucket.org/brandon/backports
# A Python "namespace package" http://www.python.org/dev/peps/pep-0382/
# This always goes inside of a namespace package's __init__.py
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
|
Revert "It seems the mechanism to declare a namespace package changed."
|
Revert "It seems the mechanism to declare a namespace package changed."
This reverts commit 68658fe9a3fee91963944937b80fcdaf3af4c8a1.
Changing the backport to use setuptools namespaces broke all the other
packages using the backports namespace. Switch back to standard python
namespaces.
|
Python
|
bsd-3-clause
|
peterjc/backports.lzma,peterjc/backports.lzma
|
---
+++
@@ -6,9 +6,5 @@
# A Python "namespace package" http://www.python.org/dev/peps/pep-0382/
# This always goes inside of a namespace package's __init__.py
-try:
- import pkg_resources
- pkg_resources.declare_namespace(__name__)
-except ImportError:
- import pkgutil
- __path__ = pkgutil.extend_path(__path__, __name__)
+from pkgutil import extend_path
+__path__ = extend_path(__path__, __name__)
|
d1be7f345529594ba25ed5d0f22e544735a64404
|
qubs_data_centre/urls.py
|
qubs_data_centre/urls.py
|
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^api/', include('api.urls')),
url(r'^admin/', admin.site.urls),
]
|
from django.conf.urls import url, include
from django.contrib import admin
admin.site.site_header = 'QUBS Data Centre Admin'
urlpatterns = [
url(r'^api/', include('api.urls')),
url(r'^admin/', admin.site.urls),
]
|
Add a custom admin site header.
|
Add a custom admin site header.
|
Python
|
apache-2.0
|
qubs/climate-data-api,qubs/climate-data-api,qubs/data-centre,qubs/data-centre
|
---
+++
@@ -1,5 +1,8 @@
from django.conf.urls import url, include
from django.contrib import admin
+
+
+admin.site.site_header = 'QUBS Data Centre Admin'
urlpatterns = [
url(r'^api/', include('api.urls')),
|
2665aa46702175a0d33ae76cfccdbbbddf42d316
|
multi_schema/management/commands/syncdb.py
|
multi_schema/management/commands/syncdb.py
|
import os.path
from django.core.management.commands import syncdb
from django.db import models, connection, transaction
try:
from south.management.commands import syncdb
except ImportError:
pass
from ...models import Schema, template_schema
class Command(syncdb.Command):
def handle_noargs(self, **options):
# Ensure we have the clone_schema() function
clone_schema_file = os.path.join(os.path.abspath(__file__ + '/../../../'), 'sql', 'clone_schema.sql')
clone_schema_function = " ".join([x.strip() for x in open(clone_schema_file).readlines() if not x.startswith('--')])
clone_schema_function = clone_schema_function.replace("'%'", "'%%'")
cursor = connection.cursor()
cursor.execute(clone_schema_function)
# Ensure we have a __template__ schema.
template_schema.create_schema()
# Set the search path, so we find created models correctly
cursor = connection.cursor()
cursor.execute("SET search_path TO public,__template__;")
super(Command, self).handle_noargs(**options)
# Ensure all existing schemata exist (in case we imported them using loaddata or something)
for schema in Schema.objects.all():
schema.create_schema()
|
import os.path
from django.core.management.commands import syncdb
from django.db import models, connection, transaction
try:
from south.management.commands import syncdb
except ImportError:
pass
from ...models import Schema, template_schema
class Command(syncdb.Command):
def handle_noargs(self, **options):
# Ensure we have the clone_schema() function
clone_schema_file = os.path.join(os.path.abspath(__file__ + '/../../../'), 'sql', 'clone_schema.sql')
clone_schema_function = " ".join([x.strip() for x in open(clone_schema_file).readlines() if not x.strip().startswith('--')])
clone_schema_function = clone_schema_function.replace("'%'", "'%%'")
cursor = connection.cursor()
cursor.execute(clone_schema_function)
# Ensure we have a __template__ schema.
template_schema.create_schema()
# Set the search path, so we find created models correctly
cursor = connection.cursor()
cursor.execute("SET search_path TO public,__template__;")
super(Command, self).handle_noargs(**options)
# Ensure all existing schemata exist (in case we imported them using loaddata or something)
for schema in Schema.objects.all():
schema.create_schema()
|
Allow for comments in the sql file that do not start the line.
|
Allow for comments in the sql file that do not start the line.
|
Python
|
bsd-3-clause
|
luzfcb/django-boardinghouse,luzfcb/django-boardinghouse,luzfcb/django-boardinghouse
|
---
+++
@@ -14,7 +14,7 @@
def handle_noargs(self, **options):
# Ensure we have the clone_schema() function
clone_schema_file = os.path.join(os.path.abspath(__file__ + '/../../../'), 'sql', 'clone_schema.sql')
- clone_schema_function = " ".join([x.strip() for x in open(clone_schema_file).readlines() if not x.startswith('--')])
+ clone_schema_function = " ".join([x.strip() for x in open(clone_schema_file).readlines() if not x.strip().startswith('--')])
clone_schema_function = clone_schema_function.replace("'%'", "'%%'")
cursor = connection.cursor()
cursor.execute(clone_schema_function)
|
bf336d99484cc3804f469631b513a927940ada30
|
profile_collection/startup/50-scans.py
|
profile_collection/startup/50-scans.py
|
# vim: sw=4 ts=4 sts expandtab smarttab
# HXN step-scan configuration
import hxntools.scans
from bluesky.global_state import get_gs
gs = get_gs()
hxntools.scans.setup()
ct = hxntools.scans.count
ascan = hxntools.scans.absolute_scan
dscan = hxntools.scans.relative_scan
fermat = hxntools.scans.relative_fermat
spiral = hxntools.scans.relative_spiral
mesh = hxntools.scans.absolute_mesh
dmesh = hxntools.scans.relative_mesh
d2scan = hxntools.scans.d2scan
a2scan = hxntools.scans.a2scan
gs.DETS = [zebra, sclr1, merlin1, xspress3, lakeshore2]
gs.TABLE_COLS = ['sclr1_ch2','sclr1_ch3', 'sclr1_ch4', 'sclr1_ch5_calc', 'ssx', 'ssy', 'ssz',
't_base', 't_sample', 't_vlens', 't_hlens']
# Plot this by default versus motor position:
gs.PLOT_Y = 'Det2_Cr'
gs.OVERPLOT = False
gs.BASELINE_DEVICES = [smll,vmll, hmll, ssa2, zp]
|
# vim: sw=4 ts=4 sts expandtab smarttab
# HXN step-scan configuration
import hxntools.scans
from bluesky.global_state import get_gs
gs = get_gs()
hxntools.scans.setup()
ct = hxntools.scans.count
ascan = hxntools.scans.absolute_scan
dscan = hxntools.scans.relative_scan
fermat = hxntools.scans.relative_fermat
spiral = hxntools.scans.relative_spiral
mesh = hxntools.scans.absolute_mesh
dmesh = hxntools.scans.relative_mesh
d2scan = hxntools.scans.d2scan
a2scan = hxntools.scans.a2scan
scan_steps = hxntools.scans.scan_steps
gs.DETS = [zebra, sclr1, merlin1, xspress3, lakeshore2]
gs.TABLE_COLS = ['sclr1_ch2','sclr1_ch3', 'sclr1_ch4', 'sclr1_ch5_calc', 'ssx', 'ssy', 'ssz',
't_base', 't_sample', 't_vlens', 't_hlens']
# Plot this by default versus motor position:
gs.PLOT_Y = 'Det2_Cr'
gs.OVERPLOT = False
gs.BASELINE_DEVICES = [dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, zp]
|
Add scan_steps wrapper for scan_nd
|
Add scan_steps wrapper for scan_nd
|
Python
|
bsd-2-clause
|
NSLS-II-HXN/ipython_ophyd,NSLS-II-HXN/ipython_ophyd
|
---
+++
@@ -16,6 +16,7 @@
dmesh = hxntools.scans.relative_mesh
d2scan = hxntools.scans.d2scan
a2scan = hxntools.scans.a2scan
+scan_steps = hxntools.scans.scan_steps
gs.DETS = [zebra, sclr1, merlin1, xspress3, lakeshore2]
gs.TABLE_COLS = ['sclr1_ch2','sclr1_ch3', 'sclr1_ch4', 'sclr1_ch5_calc', 'ssx', 'ssy', 'ssz',
@@ -25,4 +26,4 @@
# Plot this by default versus motor position:
gs.PLOT_Y = 'Det2_Cr'
gs.OVERPLOT = False
-gs.BASELINE_DEVICES = [smll,vmll, hmll, ssa2, zp]
+gs.BASELINE_DEVICES = [dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, zp]
|
a619f703b2d259877e30d3e1ede11813c014f3ad
|
pysc2/env/available_actions_printer.py
|
pysc2/env/available_actions_printer.py
|
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""An env wrapper to print the available actions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from pysc2.env import base_env_wrapper
class AvailableActionsPrinter(base_env_wrapper.BaseEnvWrapper):
"""An env wrapper to print the available actions."""
def __init__(self, env):
super(AvailableActionsPrinter, self).__init__(env)
self._seen = set()
self._action_spec = self.action_spec()
def step(self, *args, **kwargs):
all_obs = super(AvailableActionsPrinter, self).step(*args, **kwargs)
for obs in all_obs:
for avail in obs.observation["available_actions"]:
if avail not in self._seen:
self._seen.add(avail)
self._print(self._action_spec.functions[avail].str(True))
return all_obs
def _print(self, s):
print(s)
|
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""An env wrapper to print the available actions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from pysc2.env import base_env_wrapper
class AvailableActionsPrinter(base_env_wrapper.BaseEnvWrapper):
"""An env wrapper to print the available actions."""
def __init__(self, env):
super(AvailableActionsPrinter, self).__init__(env)
self._seen = set()
self._action_spec = self.action_spec()[0]
def step(self, *args, **kwargs):
all_obs = super(AvailableActionsPrinter, self).step(*args, **kwargs)
for obs in all_obs:
for avail in obs.observation["available_actions"]:
if avail not in self._seen:
self._seen.add(avail)
self._print(self._action_spec.functions[avail].str(True))
return all_obs
def _print(self, s):
print(s)
|
Fix the AvailableActionsPrinter to support the new multiplayer action spec.
|
Fix the AvailableActionsPrinter to support the new multiplayer action spec.
PiperOrigin-RevId: 183247161
|
Python
|
apache-2.0
|
deepmind/pysc2
|
---
+++
@@ -26,7 +26,7 @@
def __init__(self, env):
super(AvailableActionsPrinter, self).__init__(env)
self._seen = set()
- self._action_spec = self.action_spec()
+ self._action_spec = self.action_spec()[0]
def step(self, *args, **kwargs):
all_obs = super(AvailableActionsPrinter, self).step(*args, **kwargs)
|
a537f049bfb61488a056333d362d9983e8e9f88d
|
2020/10/p1.py
|
2020/10/p1.py
|
# Python 3.8.3
def get_input():
with open('input.txt', 'r') as f:
return set(int(i) for i in f.read().split())
def main():
puzzle = get_input()
last_joltage = 0
one_jolt = 0
three_jolts = 1 # this is bad lmao
while len(puzzle) != 0:
if last_joltage + 1 in puzzle:
last_joltage = last_joltage + 1
one_jolt += 1
elif last_joltage + 2 in puzzle:
last_joltage = last_joltage + 2
elif last_joltage + 3 in puzzle:
last_joltage = last_joltage + 3
three_jolts += 1
puzzle.remove(last_joltage)
print(one_jolt, three_jolts)
return one_jolt * three_jolts
if __name__ == '__main__':
import time
start = time.perf_counter()
print(main())
print(time.perf_counter() - start)
|
# Python 3.8.3
def get_input():
with open('input.txt', 'r') as f:
return set(int(i) for i in f.read().split())
def main():
puzzle = get_input()
last_joltage = 0
one_jolt = 0
three_jolts = 1
while len(puzzle) != 0:
if last_joltage + 1 in puzzle:
last_joltage = last_joltage + 1
one_jolt += 1
elif last_joltage + 2 in puzzle:
last_joltage = last_joltage + 2
elif last_joltage + 3 in puzzle:
last_joltage = last_joltage + 3
three_jolts += 1
puzzle.remove(last_joltage)
print(one_jolt, three_jolts)
return one_jolt * three_jolts
if __name__ == '__main__':
import time
start = time.perf_counter()
print(main())
print(time.perf_counter() - start)
|
Fix minor issues in 2020.10.1 file
|
Fix minor issues in 2020.10.1 file
The comment about the 1 being bad was incorrect, in fact it was good. I
had forgotten about adding the extra three-jolt difference for the final
adapter in the device, and didn't make the connection between it and the
three-jolt count being one short lol.
|
Python
|
mit
|
foxscotch/advent-of-code,foxscotch/advent-of-code
|
---
+++
@@ -9,7 +9,7 @@
last_joltage = 0
one_jolt = 0
- three_jolts = 1 # this is bad lmao
+ three_jolts = 1
while len(puzzle) != 0:
if last_joltage + 1 in puzzle:
last_joltage = last_joltage + 1
@@ -25,7 +25,6 @@
return one_jolt * three_jolts
-
if __name__ == '__main__':
import time
|
77ddff664ad1e10037a43c3ffabd816387c35e42
|
rotational-cipher/rotational_cipher.py
|
rotational-cipher/rotational_cipher.py
|
import string
UPPER = string.ascii_uppercase
LOWER = string.ascii_lowercase
def rotate(s, n):
rules = shift_rules(n)
return "".join(map(lambda k: rules.get(k, k), s))
def shift_rules(n):
shifted = UPPER[n:] + UPPER[:n] + LOWER[n:] + LOWER[:n]
return {k:v for k,v in zip(UPPER+LOWER, shifted)}
|
import string
UPPER = string.ascii_uppercase
LOWER = string.ascii_lowercase
def rotate(s, n):
rules = shift_rules(n)
return "".join(rules.get(ch, ch) for ch in s)
def shift_rules(n):
shifted = UPPER[n:] + UPPER[:n] + LOWER[n:] + LOWER[:n]
return {k:v for k,v in zip(UPPER+LOWER, shifted)}
|
Use a comprehension instead of a lambda function
|
Use a comprehension instead of a lambda function
|
Python
|
agpl-3.0
|
CubicComet/exercism-python-solutions
|
---
+++
@@ -7,8 +7,7 @@
def rotate(s, n):
rules = shift_rules(n)
- return "".join(map(lambda k: rules.get(k, k), s))
-
+ return "".join(rules.get(ch, ch) for ch in s)
def shift_rules(n):
shifted = UPPER[n:] + UPPER[:n] + LOWER[n:] + LOWER[:n]
|
513c7a2f5c5fb5a8c47b3173a8d5854755f7928f
|
pylab/website/tests/test_about_page.py
|
pylab/website/tests/test_about_page.py
|
import datetime
from django_webtest import WebTest
from django.contrib.auth.models import User
from pylab.core.models import Event
class AboutPageTests(WebTest):
def setUp(self):
self.user = User.objects.create(username='u1')
def test_no_events_on_about_page(self):
resp = self.app.get('/about/')
self.assertEqual(resp.status_int, 200)
self.assertTrue(b'No events yet.' in resp.content)
def test_event_list_on_about_page(self):
Event.objects.create(
author=self.user,
starts=datetime.datetime(2015, 9, 3),
ends=datetime.datetime(2015, 9, 3),
title='Test title',
osm_map_link='http://openstreetmap.org/',
description='Test description',
)
resp = self.app.get('/about/')
self.assertEqual(resp.status_int, 200)
self.assertTrue(b'Test title' in resp.content)
|
import datetime
from django_webtest import WebTest
from pylab.core.models import Event
from pylab.core.factories import EventFactory
class AboutPageTests(WebTest):
def test_no_events_on_about_page(self):
resp = self.app.get('/about/')
self.assertEqual(resp.status_int, 200)
self.assertTrue(b'No events yet.' in resp.content)
def test_event_list_on_about_page(self):
EventFactory(
event_type=Event.WEEKLY_MEETING,
title='Summer Python workshop',
slug='python-workshop',
starts=datetime.datetime(2015, 7, 30, 18, 0),
ends=datetime.datetime(2015, 7, 30, 20, 0),
)
resp = self.app.get('/about/')
self.assertEqual(resp.status_int, 200)
self.assertTrue(b'Summer Python workshop' in resp.content)
|
Use factories instead of creating instance from model
|
Use factories instead of creating instance from model
|
Python
|
agpl-3.0
|
python-dirbtuves/website,python-dirbtuves/website,python-dirbtuves/website
|
---
+++
@@ -1,15 +1,12 @@
import datetime
from django_webtest import WebTest
-from django.contrib.auth.models import User
from pylab.core.models import Event
+from pylab.core.factories import EventFactory
class AboutPageTests(WebTest):
-
- def setUp(self):
- self.user = User.objects.create(username='u1')
def test_no_events_on_about_page(self):
resp = self.app.get('/about/')
@@ -17,14 +14,14 @@
self.assertTrue(b'No events yet.' in resp.content)
def test_event_list_on_about_page(self):
- Event.objects.create(
- author=self.user,
- starts=datetime.datetime(2015, 9, 3),
- ends=datetime.datetime(2015, 9, 3),
- title='Test title',
- osm_map_link='http://openstreetmap.org/',
- description='Test description',
+ EventFactory(
+ event_type=Event.WEEKLY_MEETING,
+ title='Summer Python workshop',
+ slug='python-workshop',
+ starts=datetime.datetime(2015, 7, 30, 18, 0),
+ ends=datetime.datetime(2015, 7, 30, 20, 0),
)
+
resp = self.app.get('/about/')
self.assertEqual(resp.status_int, 200)
- self.assertTrue(b'Test title' in resp.content)
+ self.assertTrue(b'Summer Python workshop' in resp.content)
|
1786702388abc4fe737ee73d64ef5864f42f0c3d
|
chat/query.py
|
chat/query.py
|
# Copyright 2017 Oursky Ltd.
#
# 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 .predicate import Predicate
class Query:
def __init__(self, record_type,
predicate=None, count=False,
limit=50, offset=None, include=[]):
self.record_type = record_type
if predicate is None:
predicate = Predicate()
self.predicate = predicate
self.count = count
self.sort = []
self.limit = limit
self.offset = None
self.include = include
def add_order(self, key, order):
self.sort.append([{'$type': 'keypath', '$val': key}, order])
return self
|
# Copyright 2017 Oursky Ltd.
#
# 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 .predicate import Predicate
class Query:
def __init__(self, record_type,
predicate=None, count=False,
limit=50, offset=None, include=[]):
self.record_type = record_type
if predicate is None:
predicate = Predicate()
self.predicate = predicate
self.count = count
self.sort = []
self.limit = limit
self.offset = offset
self.include = include
def add_order(self, key, order):
self.sort.append([{'$type': 'keypath', '$val': key}, order])
return self
|
Fix missing offset for Query
|
Fix missing offset for Query
|
Python
|
apache-2.0
|
SkygearIO/chat,SkygearIO/chat
|
---
+++
@@ -26,7 +26,7 @@
self.count = count
self.sort = []
self.limit = limit
- self.offset = None
+ self.offset = offset
self.include = include
def add_order(self, key, order):
|
270812e89e8e0870bfea01367cf645cf5194a806
|
openacademy/model/openacademy_course.py
|
openacademy/model/openacademy_course.py
|
# -*- coding: utf-8 -*-
from openerp import models, fields, api
'''
This module create model of Course
'''
class Course(models.Model):
'''This class create model of Course'''
_name = 'openacademy.course' # Model odoo name
name = fields.Char(string='Title', required=True) # field reserved to identified rec_name
description = fields.Text(string='Description')
responsible_id = fields.Many2one('res.users',
ondelete='set null',
string="Responsible",
index=True)
session_ids = fields.One2many('openacademy.session', 'course_id', string="Sessions")
@api.multi
def copy(self, default=None):
default = dict(default or {})
copied_count = self.search_count(
[('name', '=like', u"Copy of {}%".format(self.name))])
if not copied_count:
new_name = u"Copy of {}".format(self.name)
else:
new_name = u"Copy of {} ({})".format(self.name, copied_count)
default['name'] = new_name
return super(Course, self).copy(default)
_sql_constraints = [
('name_description_check',
'CHECK(name != description)',
"The title of the course should not be the description"),
('name_unique',
'UNIQUE(name)',
"The course title must be unique"),
]
|
# -*- coding: utf-8 -*-
from openerp import models, fields, api
'''
This module create model of Course
'''
class Course(models.Model):
'''This class create model of Course'''
_name = 'openacademy.course' # Model odoo name
name = fields.Char(string='Title', required=True) # field reserved to identified rec_name
description = fields.Text(string='Description')
responsible_id = fields.Many2one('res.users',
ondelete='set null',
string="Responsible",
index=True)
session_ids = fields.One2many('openacademy.session', 'course_id', string="Sessions")
@api.multi
def copy(self, default=None):
default = dict(default or {})
copied_count = self.search_count(
[('name', '=like', u"Copy of {}%".format(self.name))])
if not copied_count:
new_name = u"Copy of {}".format(self.name)
else:
new_name = u"Copy of {} ({})".format(self.name, copied_count)
default['name'] = new_name
return super(Course, self).copy(default)
_sql_constraints = [
('name_description_check',
'CHECK(name != description)',
"The title of the course should not be the description"),
('name_unique',
'UNIQUE(name)',
"The course title must be unique"),
]
|
Add sql constraint identation fixed
|
[REF] openacademy: Add sql constraint identation fixed
|
Python
|
apache-2.0
|
jorgescalona/openacademy-project
|
---
+++
@@ -34,10 +34,10 @@
_sql_constraints = [
('name_description_check',
- 'CHECK(name != description)',
- "The title of the course should not be the description"),
+ 'CHECK(name != description)',
+ "The title of the course should not be the description"),
('name_unique',
- 'UNIQUE(name)',
- "The course title must be unique"),
+ 'UNIQUE(name)',
+ "The course title must be unique"),
]
|
df6b13a70241b616f49d4dcc25073084c371f5b1
|
share/models/creative/base.py
|
share/models/creative/base.py
|
from django.db import models
from share.models.base import ShareObject
from share.models.people import Person
from share.models.base import TypedShareObjectMeta
from share.models.creative.meta import Venue, Institution, Funder, Award, Tag
from share.models.fields import ShareForeignKey, ShareManyToManyField
class AbstractCreativeWork(ShareObject, metaclass=TypedShareObjectMeta):
title = models.TextField()
description = models.TextField()
contributors = ShareManyToManyField(Person, through='Contributor')
institutions = ShareManyToManyField(Institution, through='ThroughInstitutions')
venues = ShareManyToManyField(Venue, through='ThroughVenues')
funders = ShareManyToManyField(Funder, through='ThroughFunders')
awards = ShareManyToManyField(Award, through='ThroughAwards')
subject = ShareForeignKey(Tag, related_name='subjected_%(class)s', null=True)
# Note: Null allows inserting of None but returns it as an empty string
tags = ShareManyToManyField(Tag, related_name='tagged_%(class)s', through='ThroughTags')
created = models.DateTimeField(null=True)
published = models.DateTimeField(null=True)
free_to_read_type = models.URLField(blank=True)
free_to_read_date = models.DateTimeField(null=True)
rights = models.TextField()
language = models.TextField()
class CreativeWork(AbstractCreativeWork):
pass
|
from django.db import models
from share.models.base import ShareObject
from share.models.people import Person
from share.models.base import TypedShareObjectMeta
from share.models.creative.meta import Venue, Institution, Funder, Award, Tag
from share.models.fields import ShareForeignKey, ShareManyToManyField
class AbstractCreativeWork(ShareObject, metaclass=TypedShareObjectMeta):
title = models.TextField()
description = models.TextField()
contributors = ShareManyToManyField(Person, through='Contributor')
institutions = ShareManyToManyField(Institution, through='ThroughInstitutions')
venues = ShareManyToManyField(Venue, through='ThroughVenues')
funders = ShareManyToManyField(Funder, through='ThroughFunders')
awards = ShareManyToManyField(Award, through='ThroughAwards')
subject = ShareForeignKey(Tag, related_name='subjected_%(class)s', null=True)
# Note: Null allows inserting of None but returns it as an empty string
tags = ShareManyToManyField(Tag, related_name='tagged_%(class)s', through='ThroughTags')
created = models.DateTimeField(null=True)
published = models.DateTimeField(null=True)
free_to_read_type = models.URLField(blank=True)
free_to_read_date = models.DateTimeField(null=True)
rights = models.TextField(blank=True, null=True)
language = models.TextField(blank=True, null=True)
class CreativeWork(AbstractCreativeWork):
pass
|
Swap out license with rights
|
Swap out license with rights
|
Python
|
apache-2.0
|
CenterForOpenScience/SHARE,aaxelb/SHARE,zamattiac/SHARE,zamattiac/SHARE,CenterForOpenScience/SHARE,CenterForOpenScience/SHARE,aaxelb/SHARE,zamattiac/SHARE,laurenbarker/SHARE,aaxelb/SHARE,laurenbarker/SHARE,laurenbarker/SHARE
|
---
+++
@@ -22,8 +22,9 @@
published = models.DateTimeField(null=True)
free_to_read_type = models.URLField(blank=True)
free_to_read_date = models.DateTimeField(null=True)
- rights = models.TextField()
- language = models.TextField()
+
+ rights = models.TextField(blank=True, null=True)
+ language = models.TextField(blank=True, null=True)
class CreativeWork(AbstractCreativeWork):
|
9f44888c00d29bd1d1a53eb09ab90b61f33c5e05
|
awx/main/migrations/0002_v300_changes.py
|
awx/main/migrations/0002_v300_changes.py
|
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Ansible, Inc.
# All Rights Reserved.
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('main', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='TowerSettings',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(default=None, editable=False)),
('modified', models.DateTimeField(default=None, editable=False)),
('key', models.CharField(unique=True, max_length=255)),
('description', models.TextField()),
('category', models.CharField(max_length=128)),
('value', models.TextField()),
('value_type', models.CharField(max_length=12, choices=[(b'string', 'String'), (b'int', 'Integer'), (b'float', 'Decimal'), (b'json', 'JSON'), (b'bool', 'Boolean'), (b'password', 'Password'), (b'list', 'List')])),
('user', models.ForeignKey(related_name='settings', default=None, editable=False, to=settings.AUTH_USER_MODEL, null=True)),
],
),
]
|
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Ansible, Inc.
# All Rights Reserved.
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('main', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='TowerSettings',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(default=None, editable=False)),
('modified', models.DateTimeField(default=None, editable=False)),
('key', models.CharField(unique=True, max_length=255)),
('description', models.TextField()),
('category', models.CharField(max_length=128)),
('value', models.TextField(blank=True)),
('value_type', models.CharField(max_length=12, choices=[(b'string', 'String'), (b'int', 'Integer'), (b'float', 'Decimal'), (b'json', 'JSON'), (b'bool', 'Boolean'), (b'password', 'Password'), (b'list', 'List')])),
('user', models.ForeignKey(related_name='settings', default=None, editable=False, to=settings.AUTH_USER_MODEL, null=True)),
],
),
]
|
Update existing settings migration with minor field change.
|
Update existing settings migration with minor field change.
|
Python
|
apache-2.0
|
snahelou/awx,wwitzel3/awx,snahelou/awx,wwitzel3/awx,snahelou/awx,wwitzel3/awx,snahelou/awx,wwitzel3/awx
|
---
+++
@@ -26,7 +26,7 @@
('key', models.CharField(unique=True, max_length=255)),
('description', models.TextField()),
('category', models.CharField(max_length=128)),
- ('value', models.TextField()),
+ ('value', models.TextField(blank=True)),
('value_type', models.CharField(max_length=12, choices=[(b'string', 'String'), (b'int', 'Integer'), (b'float', 'Decimal'), (b'json', 'JSON'), (b'bool', 'Boolean'), (b'password', 'Password'), (b'list', 'List')])),
('user', models.ForeignKey(related_name='settings', default=None, editable=False, to=settings.AUTH_USER_MODEL, null=True)),
],
|
18618a56ce674c479a0737dcabd4a47913ae2dde
|
scripts/compare_dir.py
|
scripts/compare_dir.py
|
import os
dropboxFiles = []
localFiles = []
for dirpath, dirnames, filenames in os.walk(
'/media/itto/TOSHIBA EXT/Photos/Dropbox/ITTO/Southeast Asia 2017'):
dropboxFiles += filenames
for dirpath, dirnames, filenames in os.walk(
'/media/itto/TOSHIBA EXT/Photos/Southeast Asia'):
if ('Process' not in dirpath):
localFiles += filenames
localNotInDropbox = []
for file in localFiles:
if file not in dropboxFiles:
localNotInDropbox.append(file)
print('************')
for file in dropboxFiles:
if file not in localFiles:
print(file)
print(len(localNotInDropbox))
|
import os
from shutil import copyfile
FOLDER_A = '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'
FOLDER_B = '/media/itto/disk/PRIVATE/AVCHD/BDMV/STREAM'
files_a = []
files_b = []
for dirpath, dirnames, filenames in os.walk(FOLDER_A):
files_a += filenames
for dirpath, dirnames, filenames in os.walk(FOLDER_B):
files_b += filenames
inA_notB = []
inB_notA = []
for file in files_b:
if file not in files_a:
inB_notA.append(file)
for file in files_a:
if file not in files_b:
inA_notB.append(file)
print('{} in Folder A. {} in Folder B.'.format(len(files_a), len(files_b)))
print('In A but not B: {}'.format(len(inA_notB)))
print('In B but not A: {}'.format(len(inB_notA)))
def EnsureFolder(path):
if os.path.isdir(path):
pass
else:
# Make folder
os.mkdir(path)
def CopyLeftoverFromBToA():
for file in inB_notA:
EnsureFolder(os.path.join(FOLDER_A, 'transfer'))
src = os.path.join(FOLDER_B, file)
dst = os.path.join(FOLDER_A, 'transfer', file)
if not os.path.exists(dst):
print('Copying {}'.format(file))
copyfile(src, dst)
else:
print('{} previously copied'.format(file))
|
Add functionality to copy any missing files to the other folder
|
Add functionality to copy any missing files to the other folder
|
Python
|
mit
|
itko/itko.github.io,itko/itko.github.io,itko/itko.github.io,itko/itko.github.io
|
---
+++
@@ -1,23 +1,45 @@
import os
+from shutil import copyfile
-dropboxFiles = []
-localFiles = []
-for dirpath, dirnames, filenames in os.walk(
- '/media/itto/TOSHIBA EXT/Photos/Dropbox/ITTO/Southeast Asia 2017'):
- dropboxFiles += filenames
+FOLDER_A = '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'
+FOLDER_B = '/media/itto/disk/PRIVATE/AVCHD/BDMV/STREAM'
+files_a = []
+files_b = []
+for dirpath, dirnames, filenames in os.walk(FOLDER_A):
+ files_a += filenames
-for dirpath, dirnames, filenames in os.walk(
- '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'):
- if ('Process' not in dirpath):
- localFiles += filenames
+for dirpath, dirnames, filenames in os.walk(FOLDER_B):
+ files_b += filenames
-localNotInDropbox = []
-for file in localFiles:
- if file not in dropboxFiles:
- localNotInDropbox.append(file)
-print('************')
-for file in dropboxFiles:
- if file not in localFiles:
- print(file)
+inA_notB = []
+inB_notA = []
+for file in files_b:
+ if file not in files_a:
+ inB_notA.append(file)
+for file in files_a:
+ if file not in files_b:
+ inA_notB.append(file)
-print(len(localNotInDropbox))
+print('{} in Folder A. {} in Folder B.'.format(len(files_a), len(files_b)))
+print('In A but not B: {}'.format(len(inA_notB)))
+print('In B but not A: {}'.format(len(inB_notA)))
+
+
+def EnsureFolder(path):
+ if os.path.isdir(path):
+ pass
+ else:
+ # Make folder
+ os.mkdir(path)
+
+
+def CopyLeftoverFromBToA():
+ for file in inB_notA:
+ EnsureFolder(os.path.join(FOLDER_A, 'transfer'))
+ src = os.path.join(FOLDER_B, file)
+ dst = os.path.join(FOLDER_A, 'transfer', file)
+ if not os.path.exists(dst):
+ print('Copying {}'.format(file))
+ copyfile(src, dst)
+ else:
+ print('{} previously copied'.format(file))
|
31231afea71b3fd9213b39cf1bb32e10b2a9e843
|
djangovirtualpos/admin.py
|
djangovirtualpos/admin.py
|
# coding=utf-8
from django.contrib import admin
from djangovirtualpos.models import VirtualPointOfSale, VPOSRefundOperation, VPOSCeca, VPOSRedsys, VPOSSantanderElavon, VPOSPaypal
admin.site.register(VirtualPointOfSale)
admin.site.register(VPOSRefundOperation)
admin.site.register(VPOSCeca)
admin.site.register(VPOSRedsys)
admin.site.register(VPOSPaypal)
admin.site.register(VPOSSantanderElavon)
|
# coding=utf-8
from django.contrib import admin
from djangovirtualpos.models import VirtualPointOfSale, VPOSRefundOperation, VPOSCeca, VPOSRedsys, VPOSSantanderElavon, VPOSPaypal, VPOSBitpay
admin.site.register(VirtualPointOfSale)
admin.site.register(VPOSRefundOperation)
admin.site.register(VPOSCeca)
admin.site.register(VPOSRedsys)
admin.site.register(VPOSPaypal)
admin.site.register(VPOSSantanderElavon)
admin.site.register(VPOSBitpay)
|
Add Bitpay config model to Django Admin panel
|
Add Bitpay config model to Django Admin panel
|
Python
|
mit
|
intelligenia/django-virtual-pos,intelligenia/django-virtual-pos,intelligenia/django-virtual-pos
|
---
+++
@@ -1,7 +1,7 @@
# coding=utf-8
from django.contrib import admin
-from djangovirtualpos.models import VirtualPointOfSale, VPOSRefundOperation, VPOSCeca, VPOSRedsys, VPOSSantanderElavon, VPOSPaypal
+from djangovirtualpos.models import VirtualPointOfSale, VPOSRefundOperation, VPOSCeca, VPOSRedsys, VPOSSantanderElavon, VPOSPaypal, VPOSBitpay
admin.site.register(VirtualPointOfSale)
admin.site.register(VPOSRefundOperation)
@@ -9,5 +9,6 @@
admin.site.register(VPOSRedsys)
admin.site.register(VPOSPaypal)
admin.site.register(VPOSSantanderElavon)
+admin.site.register(VPOSBitpay)
|
ef15a8ba699e10b9f2d059669b63af6f4c768d39
|
casspy/admin_commands.py
|
casspy/admin_commands.py
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Cassoundra: admin-commands
~~~~~~~~~~
Module to handle special commands to control the bot once it is already running.
Created by Joshua Prince, 2017
"""
import discord
from casspy import cassoundra
async def process_input(loop):
while True:
command = await loop.run_in_executor(None, input, "> ")
if str(command).split(" ")[0].lower() == "shutdown":
return
print(await handle(command))
async def handle(cmd: str) -> str:
tok = cmd.split(' ')
try:
if tok[0].lower() == 'shutdown':
return await cmd_shutdown()
elif tok[0].lower() == 'say':
return await cmd_say(tok[1], ' '.join(tok[2:]))
else:
return "Unknown command " + tok[0] + "."
except IndexError:
pass
async def cmd_shutdown() -> str:
raise KeyboardInterrupt
async def cmd_say(channel: str, content: str) -> str:
ch = cassoundra.client.get_channel(channel)
if ch is None:
return '<#{}>: I couldn\'t find that channel!'.format(channel)
if ch.type == discord.ChannelType.voice:
return '<#{}>: Is a voice channel.'.format(channel)
await cassoundra.client.send_message(ch, content)
return '<#{}>: "{}"'.format(channel, content)
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Cassoundra: admin-commands
~~~~~~~~~~
Module to handle special commands to control the bot once it is already running.
Created by Joshua Prince, 2017
"""
import discord
from casspy import cassoundra
async def process_input(loop):
while True:
command = await loop.run_in_executor(None, input)
if str(command).split(" ")[0].lower() == "shutdown":
return
print(await handle(command))
async def handle(cmd: str) -> str:
tok = cmd.split(' ')
try:
if tok[0].lower() == 'shutdown':
return await cmd_shutdown()
elif tok[0].lower() == 'say':
return await cmd_say(tok[1], ' '.join(tok[2:]))
else:
return "Unknown command " + tok[0] + "."
except IndexError:
pass
async def cmd_shutdown() -> str:
raise KeyboardInterrupt
async def cmd_say(channel: str, content: str) -> str:
ch = cassoundra.client.get_channel(channel)
if ch is None:
return '<#{}>: I couldn\'t find that channel!'.format(channel)
if ch.type == discord.ChannelType.voice:
return '<#{}>: Is a voice channel.'.format(channel)
await cassoundra.client.send_message(ch, content)
return '<#{}>: "{}"'.format(channel, content)
|
Change to console command prompt
|
[casspy] Change to console command prompt
|
Python
|
mit
|
joshuaprince/Cassoundra,joshuaprince/Cassoundra,joshuaprince/Cassoundra
|
---
+++
@@ -17,7 +17,7 @@
async def process_input(loop):
while True:
- command = await loop.run_in_executor(None, input, "> ")
+ command = await loop.run_in_executor(None, input)
if str(command).split(" ")[0].lower() == "shutdown":
return
print(await handle(command))
|
75c0861608871de2a2b1a6b4f2ea89c800dd8c07
|
pava/implementation/__init__.py
|
pava/implementation/__init__.py
|
import sys
method_count = 0
def method(argcount, nlocals, stacksize, flags, codestring, constants, names,
varnames, filename, name, firstlineno, lnotab, modules, static):
global method_count
print 'define', name, method_count
method_count += 1
globals_dict = {}
for module_name in modules:
if not '[' in module_name and not '.' in module_name:
globals_dict[module_name] = __import__(module_name, {})
code = new.code(argcount, nlocals, stacksize, flags, codestring, constants, names,
varnames, filename, name, firstlineno, lnotab)
method = new.function(code, globals_dict, name)
return staticmethod(method) if static else method
nan = None
inf = sys.maxint
|
import new
import sys
DEBUG = False
method_count = 0
def method(argcount, nlocals, stacksize, flags, codestring, constants, names,
varnames, filename, name, firstlineno, lnotab, modules, static):
global method_count
if DEBUG:
print 'define', name, method_count
method_count += 1
globals_dict = {}
for module_name in modules:
if not '[' in module_name and not '.' in module_name:
globals_dict[module_name] = __import__(module_name, {})
code = new.code(argcount, nlocals, stacksize, flags, codestring, constants, names,
varnames, filename, name, firstlineno, lnotab)
method = new.function(code, globals_dict, name)
return staticmethod(method) if static else method
nan = None
inf = sys.maxint
|
Make verbose loading messages optional
|
Make verbose loading messages optional
|
Python
|
mit
|
laffra/pava,laffra/pava
|
---
+++
@@ -1,11 +1,15 @@
+import new
import sys
+
+DEBUG = False
method_count = 0
def method(argcount, nlocals, stacksize, flags, codestring, constants, names,
varnames, filename, name, firstlineno, lnotab, modules, static):
global method_count
- print 'define', name, method_count
+ if DEBUG:
+ print 'define', name, method_count
method_count += 1
globals_dict = {}
for module_name in modules:
|
7e6dc283dbecf4bf9674559198b4a2c06e9f4c2e
|
spacy/tests/regression/test_issue1799.py
|
spacy/tests/regression/test_issue1799.py
|
'''Test sentence boundaries are deserialized correctly,
even for non-projective sentences.'''
import pytest
import numpy
from ... tokens import Doc
from ... vocab import Vocab
from ... attrs import HEAD, DEP
def test_issue1799():
problem_sentence = 'Just what I was looking for.'
heads_deps = numpy.asarray([[1, 397], [4, 436], [2, 426], [1, 402],
[0, 8206900633647566924], [18446744073709551615, 440],
[18446744073709551614, 442]], dtype='uint64')
doc = Doc(Vocab(), words='Just what I was looking for .'.split())
doc.vocab.strings.add('ROOT')
doc = doc.from_array([HEAD, DEP], heads_deps)
assert len(list(doc.sents)) == 1
|
'''Test sentence boundaries are deserialized correctly,
even for non-projective sentences.'''
from __future__ import unicode_literals
import pytest
import numpy
from ... tokens import Doc
from ... vocab import Vocab
from ... attrs import HEAD, DEP
def test_issue1799():
problem_sentence = 'Just what I was looking for.'
heads_deps = numpy.asarray([[1, 397], [4, 436], [2, 426], [1, 402],
[0, 8206900633647566924], [18446744073709551615, 440],
[18446744073709551614, 442]], dtype='uint64')
doc = Doc(Vocab(), words='Just what I was looking for .'.split())
doc.vocab.strings.add('ROOT')
doc = doc.from_array([HEAD, DEP], heads_deps)
assert len(list(doc.sents)) == 1
|
Fix unicode import in test
|
Fix unicode import in test
|
Python
|
mit
|
aikramer2/spaCy,aikramer2/spaCy,explosion/spaCy,spacy-io/spaCy,explosion/spaCy,honnibal/spaCy,explosion/spaCy,explosion/spaCy,spacy-io/spaCy,recognai/spaCy,honnibal/spaCy,spacy-io/spaCy,honnibal/spaCy,explosion/spaCy,aikramer2/spaCy,aikramer2/spaCy,spacy-io/spaCy,aikramer2/spaCy,recognai/spaCy,spacy-io/spaCy,aikramer2/spaCy,recognai/spaCy,recognai/spaCy,recognai/spaCy,explosion/spaCy,recognai/spaCy,honnibal/spaCy,spacy-io/spaCy
|
---
+++
@@ -1,5 +1,6 @@
'''Test sentence boundaries are deserialized correctly,
even for non-projective sentences.'''
+from __future__ import unicode_literals
import pytest
import numpy
|
2cd19b395f4320330b66dff1ef98d149f3a40a31
|
ckanext/syndicate/tests/test_plugin.py
|
ckanext/syndicate/tests/test_plugin.py
|
from mock import patch
import unittest
import ckan.model as model
from ckan.model.domain_object import DomainObjectOperation
from ckanext.syndicate.plugin import SyndicatePlugin
class TestPlugin(unittest.TestCase):
def test_notify_syndicates_task(self):
entity = model.Package()
entity.extras = {'syndicate': 'true'}
with patch('ckanext.syndicate.plugin.syndicate_task') as mock_syndicate:
plugin = SyndicatePlugin()
plugin.notify(entity, DomainObjectOperation.new)
mock_syndicate.assert_called_with(entity.id, 'dataset/create')
|
from mock import patch
import unittest
import ckan.model as model
from ckan.model.domain_object import DomainObjectOperation
from ckanext.syndicate.plugin import SyndicatePlugin
class TestNotify(unittest.TestCase):
def setUp(self):
super(TestNotify, self).setUp()
self.entity = model.Package()
self.entity.extras = {'syndicate': 'true'}
self.syndicate_patch = patch('ckanext.syndicate.plugin.syndicate_task')
self.plugin = SyndicatePlugin()
def test_syndicates_task_for_dataset_create(self):
with self.syndicate_patch as mock_syndicate:
self.plugin.notify(self.entity, DomainObjectOperation.new)
mock_syndicate.assert_called_with(self.entity.id,
'dataset/create')
def test_syndicates_task_for_dataset_update(self):
with self.syndicate_patch as mock_syndicate:
self.plugin.notify(self.entity, DomainObjectOperation.changed)
mock_syndicate.assert_called_with(self.entity.id,
'dataset/update')
|
Add test for notify dataset/update
|
Add test for notify dataset/update
|
Python
|
agpl-3.0
|
aptivate/ckanext-syndicate,sorki/ckanext-redmine-autoissues,aptivate/ckanext-syndicate,sorki/ckanext-redmine-autoissues
|
---
+++
@@ -8,13 +8,22 @@
from ckanext.syndicate.plugin import SyndicatePlugin
-class TestPlugin(unittest.TestCase):
- def test_notify_syndicates_task(self):
- entity = model.Package()
- entity.extras = {'syndicate': 'true'}
+class TestNotify(unittest.TestCase):
+ def setUp(self):
+ super(TestNotify, self).setUp()
+ self.entity = model.Package()
+ self.entity.extras = {'syndicate': 'true'}
+ self.syndicate_patch = patch('ckanext.syndicate.plugin.syndicate_task')
+ self.plugin = SyndicatePlugin()
- with patch('ckanext.syndicate.plugin.syndicate_task') as mock_syndicate:
- plugin = SyndicatePlugin()
+ def test_syndicates_task_for_dataset_create(self):
+ with self.syndicate_patch as mock_syndicate:
+ self.plugin.notify(self.entity, DomainObjectOperation.new)
+ mock_syndicate.assert_called_with(self.entity.id,
+ 'dataset/create')
- plugin.notify(entity, DomainObjectOperation.new)
- mock_syndicate.assert_called_with(entity.id, 'dataset/create')
+ def test_syndicates_task_for_dataset_update(self):
+ with self.syndicate_patch as mock_syndicate:
+ self.plugin.notify(self.entity, DomainObjectOperation.changed)
+ mock_syndicate.assert_called_with(self.entity.id,
+ 'dataset/update')
|
80a1912ce69fd356d6c54bb00f946fbc7874a9ce
|
bluecanary/set_cloudwatch_alarm.py
|
bluecanary/set_cloudwatch_alarm.py
|
import boto3
from bluecanary.exceptions import NamespaceError
from bluecanary.utilities import throttle
@throttle()
def set_cloudwatch_alarm(identifier, **kwargs):
if not kwargs.get('Dimensions'):
kwargs['Dimensions'] = _get_dimensions(identifier, **kwargs)
if not kwargs.get('AlarmName'):
kwargs['AlarmName'] = '{}_{}'.format(identifier, kwargs.get('MetricName'))
cloudwatch_client = boto3.client('cloudwatch')
return cloudwatch_client.put_metric_alarm(**kwargs)
def _get_dimensions(identifier, **kwargs):
base_dimensions = {
'AWS/ELB': [{u'Name': 'LoadBalancerName', u'Value': identifier}],
'AWS/EC2': [{u'Name': 'InstanceId', u'Value': identifier}],
}
try:
return base_dimensions[kwargs.get('Namespace')]
except KeyError:
message = ('Namespace "{}" is not supported by Blue Canary. '
'If you are using a plugin that supports this Namespace '
'please ensure that the plugin alarm class does not return '
'None when calling the "get_dimensions" method.'
.format(kwargs.get('Namespace')))
raise NamespaceError(message)
|
import boto3
from bluecanary.exceptions import NamespaceError
from bluecanary.utilities import throttle
@throttle()
def set_cloudwatch_alarm(identifier, **kwargs):
if not kwargs.get('Dimensions'):
kwargs['Dimensions'] = _get_dimensions(identifier, **kwargs)
if not kwargs.get('AlarmName'):
kwargs['AlarmName'] = '{}_{}'.format(identifier,
kwargs.get('MetricName'))
if kwargs.get('AlarmNameModifier'):
kwargs['AlarmName'] = '{}_{}'.format(kwargs.get('AlarmName'),
kwargs.get('AlarmNameModifier'))
del(kwargs['AlarmNameModifier'])
cloudwatch_client = boto3.client('cloudwatch')
return cloudwatch_client.put_metric_alarm(**kwargs)
def _get_dimensions(identifier, **kwargs):
base_dimensions = {
'AWS/ELB': [{u'Name': 'LoadBalancerName', u'Value': identifier}],
'AWS/EC2': [{u'Name': 'InstanceId', u'Value': identifier}],
}
try:
return base_dimensions[kwargs.get('Namespace')]
except KeyError:
message = ('Namespace "{}" is not supported by Blue Canary. '
'If you are using a plugin that supports this Namespace '
'please ensure that the plugin alarm class does not return '
'None when calling the "get_dimensions" method.'
.format(kwargs.get('Namespace')))
raise NamespaceError(message)
|
Allow multiple alarms for same metric type
|
Allow multiple alarms for same metric type
|
Python
|
mit
|
voxy/bluecanary
|
---
+++
@@ -10,7 +10,13 @@
kwargs['Dimensions'] = _get_dimensions(identifier, **kwargs)
if not kwargs.get('AlarmName'):
- kwargs['AlarmName'] = '{}_{}'.format(identifier, kwargs.get('MetricName'))
+ kwargs['AlarmName'] = '{}_{}'.format(identifier,
+ kwargs.get('MetricName'))
+
+ if kwargs.get('AlarmNameModifier'):
+ kwargs['AlarmName'] = '{}_{}'.format(kwargs.get('AlarmName'),
+ kwargs.get('AlarmNameModifier'))
+ del(kwargs['AlarmNameModifier'])
cloudwatch_client = boto3.client('cloudwatch')
|
7611a4b3e064868c37b9f52778c8fe9f721e86c5
|
polyaxon/events/management/commands/monitor_namespace.py
|
polyaxon/events/management/commands/monitor_namespace.py
|
import time
from kubernetes.client.rest import ApiException
from django.conf import settings
from clusters.models import Cluster
from events.management.commands._base_monitor import BaseMonitorCommand
from events.monitors import namespace
from polyaxon_k8s.manager import K8SManager
class Command(BaseMonitorCommand):
help = 'Watch namespace warning and errors events.'
def handle(self, *args, **options):
log_sleep_interval = options['log_sleep_interval']
self.stdout.write(
"Started a new namespace monitor with, "
"log sleep interval: `{}`.".format(log_sleep_interval),
ending='\n')
k8s_manager = K8SManager(namespace=settings.K8S_NAMESPACE, in_cluster=True)
cluster = Cluster.load()
while True:
try:
namespace.run(k8s_manager, cluster)
except ApiException as e:
namespace.logger.error(
"Exception when calling CoreV1Api->list_event_for_all_namespaces: %s\n", e)
time.sleep(log_sleep_interval)
except Exception as e:
namespace.logger.exception("Unhandled exception occurred: %s\n", e)
|
import time
from kubernetes.client.rest import ApiException
from django.conf import settings
from django.db import InterfaceError, ProgrammingError, OperationalError
from clusters.models import Cluster
from events.management.commands._base_monitor import BaseMonitorCommand
from events.monitors import namespace
from polyaxon_k8s.manager import K8SManager
class Command(BaseMonitorCommand):
help = 'Watch namespace warning and errors events.'
def get_cluster_or_wait(self, log_sleep_interval):
max_trials = 10
trials = 0
while trials < max_trials:
try:
return Cluster.load()
except (InterfaceError, ProgrammingError, OperationalError) as e:
namespace.logger.exception("Database is not synced yet %s\n", e)
trials += 1
time.sleep(log_sleep_interval * 2)
return None
def handle(self, *args, **options):
log_sleep_interval = options['log_sleep_interval']
self.stdout.write(
"Started a new namespace monitor with, "
"log sleep interval: `{}`.".format(log_sleep_interval),
ending='\n')
k8s_manager = K8SManager(namespace=settings.K8S_NAMESPACE, in_cluster=True)
cluster = self.get_cluster_or_wait(log_sleep_interval)
if not cluster:
# End process
return
while True:
try:
namespace.run(k8s_manager, cluster)
except ApiException as e:
namespace.logger.error(
"Exception when calling CoreV1Api->list_event_for_all_namespaces: %s\n", e)
time.sleep(log_sleep_interval)
except Exception as e:
namespace.logger.exception("Unhandled exception occurred: %s\n", e)
|
Update namespace monitor with exception handling
|
Update namespace monitor with exception handling
|
Python
|
apache-2.0
|
polyaxon/polyaxon,polyaxon/polyaxon,polyaxon/polyaxon
|
---
+++
@@ -3,6 +3,7 @@
from kubernetes.client.rest import ApiException
from django.conf import settings
+from django.db import InterfaceError, ProgrammingError, OperationalError
from clusters.models import Cluster
from events.management.commands._base_monitor import BaseMonitorCommand
@@ -13,6 +14,18 @@
class Command(BaseMonitorCommand):
help = 'Watch namespace warning and errors events.'
+ def get_cluster_or_wait(self, log_sleep_interval):
+ max_trials = 10
+ trials = 0
+ while trials < max_trials:
+ try:
+ return Cluster.load()
+ except (InterfaceError, ProgrammingError, OperationalError) as e:
+ namespace.logger.exception("Database is not synced yet %s\n", e)
+ trials += 1
+ time.sleep(log_sleep_interval * 2)
+ return None
+
def handle(self, *args, **options):
log_sleep_interval = options['log_sleep_interval']
self.stdout.write(
@@ -20,7 +33,11 @@
"log sleep interval: `{}`.".format(log_sleep_interval),
ending='\n')
k8s_manager = K8SManager(namespace=settings.K8S_NAMESPACE, in_cluster=True)
- cluster = Cluster.load()
+ cluster = self.get_cluster_or_wait(log_sleep_interval)
+ if not cluster:
+ # End process
+ return
+
while True:
try:
namespace.run(k8s_manager, cluster)
|
2a852c3ca1ff30cb02740f7934d97c1fe2da3bbe
|
compress.py
|
compress.py
|
"""
compression
"""
class Compress():
"""Compress"""
def encode(self, string):
"""Encodes string to byte representation"""
return b'0'
def decode(self, byteString):
"""Decodes bytes into a text string"""
return ""
|
"""
compression
"""
import Queue as queue
class HuffmanNode:
"""Node in the Huffman coding tree"""
def __init__(self, symbol, freq):
self.parent = None
self.children = []
self.symbol = symbol
self.freq = freq
def set_parent(self, node):
node.add_child(self)
self.parent = node
def add_child(self, node):
self.children.append(node)
def is_leaf(self):
return len(self.children) == 0
class Compress:
"""Compress"""
def __init__(self):
self.word_list = []
self.huffman_tree = None
self.codeWordlist()
self.build_huffman_tree()
def codeWordlist(self):
wordfile = open('words256.txt', 'r')
for line in wordfile.readlines():
self.word_list.append(line.strip())
wordfile.close()
def build_huffman_tree(self):
fake_freq = 0.5
nodes = []
for word in self.word_list:
node = HuffmanNode(word, fake_freq)
fake_freq *= fake_freq
nodes.append(node)
priorityq = queue.PriorityQueue()
for node in nodes:
priorityq.put((node.freq, node))
while(priorityq.qsize() > 1):
n1 = priorityq.get()[1]
n2 = priorityq.get()[1]
parent = HuffmanNode("", n1.freq + n2.freq)
n1.set_parent(parent)
n2.set_parent(parent)
priorityq.put((parent.freq, parent))
self.huffman_tree = priorityq.get()[1]
def encode(self, string):
"""Encodes string to byte representation"""
return b'0'
def decode(self, byteString):
"""Decodes bytes into a text string"""
return ""
if __name__ == '__main__':
c = Compress()
|
Build tree for huffman coding
|
Build tree for huffman coding
|
Python
|
apache-2.0
|
rylans/text-compression-english
|
---
+++
@@ -2,8 +2,64 @@
compression
"""
-class Compress():
+import Queue as queue
+
+class HuffmanNode:
+ """Node in the Huffman coding tree"""
+ def __init__(self, symbol, freq):
+ self.parent = None
+ self.children = []
+
+ self.symbol = symbol
+ self.freq = freq
+
+ def set_parent(self, node):
+ node.add_child(self)
+ self.parent = node
+
+ def add_child(self, node):
+ self.children.append(node)
+
+ def is_leaf(self):
+ return len(self.children) == 0
+
+class Compress:
"""Compress"""
+ def __init__(self):
+ self.word_list = []
+ self.huffman_tree = None
+
+ self.codeWordlist()
+ self.build_huffman_tree()
+
+ def codeWordlist(self):
+ wordfile = open('words256.txt', 'r')
+ for line in wordfile.readlines():
+ self.word_list.append(line.strip())
+ wordfile.close()
+
+ def build_huffman_tree(self):
+ fake_freq = 0.5
+ nodes = []
+ for word in self.word_list:
+ node = HuffmanNode(word, fake_freq)
+ fake_freq *= fake_freq
+ nodes.append(node)
+
+ priorityq = queue.PriorityQueue()
+ for node in nodes:
+ priorityq.put((node.freq, node))
+
+ while(priorityq.qsize() > 1):
+ n1 = priorityq.get()[1]
+ n2 = priorityq.get()[1]
+ parent = HuffmanNode("", n1.freq + n2.freq)
+ n1.set_parent(parent)
+ n2.set_parent(parent)
+ priorityq.put((parent.freq, parent))
+
+ self.huffman_tree = priorityq.get()[1]
+
def encode(self, string):
"""Encodes string to byte representation"""
return b'0'
@@ -11,3 +67,6 @@
def decode(self, byteString):
"""Decodes bytes into a text string"""
return ""
+
+if __name__ == '__main__':
+ c = Compress()
|
3b412830710018abadacd148be544b4bfb1ec2f0
|
compare_mt/formatting.py
|
compare_mt/formatting.py
|
import re
class Formatter(object):
pat_square_open = re.compile("\[")
pat_square_closed = re.compile("\]")
pat_lt = re.compile("<")
pat_gt = re.compile(">")
latex_substitutions = {
pat_square_open: "{[}",
pat_square_closed: "{]}",
pat_lt: r"\\textless",
pat_gt: r"\\textgreater"
}
def __init__(self, decimals=4):
self.set_decimals(decimals)
def set_decimals(self, decimals):
self.decimals = decimals
def escape_latex(self, x):
"""Adds escape sequences wherever needed to make the output
LateX compatible"""
for pat, replace_with in self.latex_substitutions.items():
x = pat.sub(replace_with, x)
return x
def __call__(self, x):
"""Convert object to string with controlled decimals"""
if isinstance(x, str):
return self.escape_latex(x)
elif isinstance(x, int):
return f"{x:d}"
elif isinstance(x, float):
return f"{x:.{self.decimals}f}"
else:
str(x)
fmt = Formatter(decimals=4)
|
import re
class Formatter(object):
latex_substitutions = {
re.compile("\["): "{[}",
re.compile("\]"): "{]}",
re.compile("<"): r"\\textless",
re.compile(">"): r"\\textgreater"
}
def __init__(self, decimals=4):
self.set_decimals(decimals)
def set_decimals(self, decimals):
self.decimals = decimals
def escape_latex(self, x):
"""Adds escape sequences wherever needed to make the output
LateX compatible"""
for pat, replace_with in self.latex_substitutions.items():
x = pat.sub(replace_with, x)
return x
def __call__(self, x):
"""Convert object to string with controlled decimals"""
if isinstance(x, str):
return self.escape_latex(x)
elif isinstance(x, int):
return f"{x:d}"
elif isinstance(x, float):
return f"{x:.{self.decimals}f}"
else:
str(x)
fmt = Formatter(decimals=4)
|
Move definition of substitution patterns inside the latex_substitutions dictionary
|
Move definition of substitution patterns inside the latex_substitutions dictionary
|
Python
|
bsd-3-clause
|
neulab/compare-mt,neulab/compare-mt
|
---
+++
@@ -1,15 +1,12 @@
import re
class Formatter(object):
- pat_square_open = re.compile("\[")
- pat_square_closed = re.compile("\]")
- pat_lt = re.compile("<")
- pat_gt = re.compile(">")
+
latex_substitutions = {
- pat_square_open: "{[}",
- pat_square_closed: "{]}",
- pat_lt: r"\\textless",
- pat_gt: r"\\textgreater"
+ re.compile("\["): "{[}",
+ re.compile("\]"): "{]}",
+ re.compile("<"): r"\\textless",
+ re.compile(">"): r"\\textgreater"
}
def __init__(self, decimals=4):
|
8b598333c06698185762cc98e414853e03c427f2
|
src/reviews/resources.py
|
src/reviews/resources.py
|
from import_export import fields, resources
from .models import Review
class ReviewResource(resources.ModelResource):
reviewer = fields.Field(
attribute='reviewer__email',
readonly=True,
)
proposal = fields.Field(
attribute='proposal__title',
readonly=True,
)
class Meta:
model = Review
fields = [
'id', 'reviewer', 'proposal', 'stage', 'vote', 'comment',
'discloses_comment', 'appropriateness',
]
export_order = fields
def dehydrate_discloses_comment(self, instance):
return int(instance.discloses_comment)
def dehydrate_appropriateness(self, instance):
return int(instance.appropriateness)
|
from import_export import fields, resources
from .models import Review
class ReviewResource(resources.ModelResource):
reviewer = fields.Field(
attribute='reviewer__email',
readonly=True,
)
proposal = fields.Field(
attribute='proposal__title',
readonly=True,
)
stage = fields.Field(
attribute='stage',
readonly=True,
)
vote = fields.Field(
attribute='vote',
readonly=True,
)
comment = fields.Field(
attribute='comment',
readonly=True,
)
discloses_comment = fields.Field(
attribute='discloses_comment',
readonly=True,
)
class Meta:
model = Review
fields = [
'id', 'reviewer', 'proposal', 'stage', 'vote', 'comment',
'discloses_comment', 'appropriateness',
]
export_order = fields
def dehydrate_discloses_comment(self, instance):
return int(instance.discloses_comment)
def dehydrate_appropriateness(self, instance):
return int(instance.appropriateness)
|
Mark fields except appropriateness as readonly
|
Mark fields except appropriateness as readonly
|
Python
|
mit
|
pycontw/pycontw2016,pycontw/pycontw2016,pycontw/pycontw2016,pycontw/pycontw2016
|
---
+++
@@ -11,6 +11,22 @@
)
proposal = fields.Field(
attribute='proposal__title',
+ readonly=True,
+ )
+ stage = fields.Field(
+ attribute='stage',
+ readonly=True,
+ )
+ vote = fields.Field(
+ attribute='vote',
+ readonly=True,
+ )
+ comment = fields.Field(
+ attribute='comment',
+ readonly=True,
+ )
+ discloses_comment = fields.Field(
+ attribute='discloses_comment',
readonly=True,
)
|
b355d61edc413f8fd60c7ce3ac37d9c1da7caa67
|
tests/nimoy/runner/test_spec_finder.py
|
tests/nimoy/runner/test_spec_finder.py
|
import tempfile
import unittest
import os
from nimoy.runner.spec_finder import SpecFinder
class TestSpecFinder(unittest.TestCase):
def setUp(self):
self.temp_spec = tempfile.NamedTemporaryFile(suffix='_spec.py')
def tearDown(self):
os.remove(self.temp_spec.name)
def test_implicit_location(self):
spec_locations = SpecFinder(os.path.dirname(self.temp_spec.name)).find([])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], self.temp_spec.name)
def test_explicit_spec_path(self):
spec_locations = SpecFinder('/some/working/dir').find([self.temp_spec.name])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], self.temp_spec.name)
def test_explicit_spec_directory(self):
spec_locations = SpecFinder('/some/working/dir').find([os.path.dirname(self.temp_spec.name)])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], self.temp_spec.name)
def test_relative_spec_path(self):
spec_locations = SpecFinder('/some/working/dir').find(['jim_spec.py'])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], '/some/working/dir/jim_spec.py')
|
import os
import tempfile
import unittest
from nimoy.runner.spec_finder import SpecFinder
class TestSpecFinder(unittest.TestCase):
def setUp(self):
self.temp_spec = tempfile.NamedTemporaryFile(suffix='_spec.py')
def test_implicit_location(self):
spec_locations = SpecFinder(os.path.dirname(self.temp_spec.name)).find([])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], self.temp_spec.name)
def test_explicit_spec_path(self):
spec_locations = SpecFinder('/some/working/dir').find([self.temp_spec.name])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], self.temp_spec.name)
def test_explicit_spec_directory(self):
spec_locations = SpecFinder('/some/working/dir').find([os.path.dirname(self.temp_spec.name)])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], self.temp_spec.name)
def test_relative_spec_path(self):
spec_locations = SpecFinder('/some/working/dir').find(['jim_spec.py'])
self.assertEquals(len(spec_locations), 1)
self.assertRegex(spec_locations[0], '/some/working/dir/jim_spec.py')
|
Remove the code cleans up the temp file as temp files are already automatically cleaned
|
Remove the code cleans up the temp file as temp files are already automatically cleaned
|
Python
|
apache-2.0
|
Luftzig/nimoy,browncoat-ninjas/nimoy
|
---
+++
@@ -1,15 +1,13 @@
+import os
import tempfile
import unittest
-import os
+
from nimoy.runner.spec_finder import SpecFinder
class TestSpecFinder(unittest.TestCase):
def setUp(self):
self.temp_spec = tempfile.NamedTemporaryFile(suffix='_spec.py')
-
- def tearDown(self):
- os.remove(self.temp_spec.name)
def test_implicit_location(self):
spec_locations = SpecFinder(os.path.dirname(self.temp_spec.name)).find([])
|
ddce385c22284ec68797b512fade8599c76ce3d1
|
datawire/manage.py
|
datawire/manage.py
|
from flask.ext.script import Manager
from datawire.core import app, db
from datawire.model import Service
from datawire.views import index
manager = Manager(app)
@manager.command
def create_db():
""" Create the database entities. """
db.create_all()
if __name__ == "__main__":
manager.run()
|
from flask.ext.script import Manager
from datawire.core import app, db
from datawire.model import User
from datawire.views import index
manager = Manager(app)
@manager.command
def createdb():
""" Create the database entities. """
db.create_all()
admin_data = {'screen_name': 'admin', 'display_name': 'Systems Admin'}
if User.by_screen_name(admin_data.get('screen_name')) is None:
admin = User.create(admin_data)
db.session.commit()
if __name__ == "__main__":
manager.run()
|
Create an admin user on db initialisation.
|
Create an admin user on db initialisation.
|
Python
|
mit
|
arc64/datawi.re,arc64/datawi.re,arc64/datawi.re
|
---
+++
@@ -1,16 +1,20 @@
from flask.ext.script import Manager
from datawire.core import app, db
-from datawire.model import Service
+from datawire.model import User
from datawire.views import index
manager = Manager(app)
@manager.command
-def create_db():
+def createdb():
""" Create the database entities. """
db.create_all()
+ admin_data = {'screen_name': 'admin', 'display_name': 'Systems Admin'}
+ if User.by_screen_name(admin_data.get('screen_name')) is None:
+ admin = User.create(admin_data)
+ db.session.commit()
if __name__ == "__main__":
|
b2ca081fbc10cc4c5d6b02ef2a4f5ce7bcab35e5
|
doc/conf.py
|
doc/conf.py
|
# -*- coding: utf-8 -*-
# Copyright (c) 2010-2016, MIT Probabilistic Computing Project
#
# 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.
"""Sphinx configuration file."""
extensions = [
'sphinx.ext.autodoc',
]
copyright = '2010-2016, MIT Probabilistic Computing Project'
master_doc = 'index'
project = 'bayeslite'
release = '0.1.3rc1'
version = '0.1.3'
nitpicky = True
|
# -*- coding: utf-8 -*-
# Copyright (c) 2010-2016, MIT Probabilistic Computing Project
#
# 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.
"""Sphinx configuration file."""
extensions = [
'sphinx.ext.autodoc',
]
copyright = '2010-2016, MIT Probabilistic Computing Project'
master_doc = 'index'
project = 'bayeslite'
release = '0.1.3rc1'
version = '0.1.3'
nitpicky = True
html_theme = 'sphinxdoc'
|
Use sphinxdoc html theme, cleaner than alabast.
|
Use sphinxdoc html theme, cleaner than alabast.
|
Python
|
apache-2.0
|
probcomp/bayeslite,probcomp/bayeslite
|
---
+++
@@ -27,3 +27,4 @@
version = '0.1.3'
nitpicky = True
+html_theme = 'sphinxdoc'
|
bdcdeee5c913f65dc2ea7f611a0ca0882b4e910f
|
tests/views/test_view.py
|
tests/views/test_view.py
|
# Copyright 2014 PressLabs SRL
#
# 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 gitfs.views.view import View
class SimpleView(View):
pass
class TestView(object):
def test_get_attr(self):
simple_view = SimpleView(**{
'uid': 1,
'gid': 1,
'mount_time': "now",
})
asserted_getattr = {
'st_uid': 1,
'st_gid': 1,
'st_ctime': "now",
'st_mtime': "now",
}
assert simple_view.getattr() == asserted_getattr
|
# Copyright 2014 PressLabs SRL
#
# 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 gitfs.views.view import View
class SimpleView(View):
pass
class TestView(object):
def test_get_attr(self):
simple_view = SimpleView(**{
'uid': 1,
'gid': 1,
'mount_time': "now",
})
asserted_getattr = {
'st_uid': 1,
'st_gid': 1,
'st_ctime': "now",
'st_mtime': "now",
}
assert simple_view.getattr("/fake/test/path") == asserted_getattr
|
Update test for the getattr method.
|
Update test for the getattr method.
|
Python
|
apache-2.0
|
rowhit/gitfs,PressLabs/gitfs,ksmaheshkumar/gitfs,PressLabs/gitfs,bussiere/gitfs
|
---
+++
@@ -34,4 +34,4 @@
'st_ctime': "now",
'st_mtime': "now",
}
- assert simple_view.getattr() == asserted_getattr
+ assert simple_view.getattr("/fake/test/path") == asserted_getattr
|
c37af8399decdbe3e1303f236891d694985b9040
|
consulrest/keyvalue.py
|
consulrest/keyvalue.py
|
import json
import re
import requests
class KeyValue(object):
def __init__(self, url):
self._url = "%s/kv" % url
def _get(self, key, recurse=None, keys=None):
url = self._url + '/' + key
params = dict()
if recurse is not None:
params['recurse'] = True
if keys is not None:
params['keys'] = True
r = requests.get(url, params=params)
if r.status_code == 200:
return json.loads(r.text)
else:
return None
def get(self, key, recurse=None):
return self._get(key, recurse=recurse)
def list(self, key=''):
return self._get(key, keys=True)
def set(self, key, value):
r = requests.put(self._url + '/' + key, data=value)
if r.status_code == 200 and re.match(r"true", r.text) is not None:
return True
else:
return False
def delete(self, key, recurse=None):
url = self._url + '/' + key
params = dict()
if recurse is not None:
params['recurse'] = True
requests.delete(url, params=params)
|
import json
import re
import requests
class KeyValue(object):
def __init__(self, url):
self._url = "%s/kv" % url
def _get(self, key, recurse=None, keys=None):
url = self._url + '/' + key
params = dict()
if recurse is not None:
params['recurse'] = True
if keys is not None:
params['keys'] = True
r = requests.get(url, params=params)
if r.status_code == 200:
return json.loads(r.text)
else:
r.raise_for_status()
def get(self, key, recurse=None):
return self._get(key, recurse=recurse)
def list(self, key=''):
return self._get(key, keys=True)
def set(self, key, value, cas=None):
params = dict()
if cas is not None:
params['cas'] = cas
r = requests.put(self._url + '/' + key, data=value, params=params)
if r.status_code == 200:
if re.match(r"true", r.text) is not None:
return True
elif re.match(r"false", r.text) is not None:
return False
else:
r.raise_for_status()
def delete(self, key, recurse=None):
url = self._url + '/' + key
params = dict()
if recurse is not None:
params['recurse'] = True
r = requests.delete(url, params=params)
r.raise_for_status()
|
Allow use of Check-And-Set option and raise exception if status is 4xx or 5xx
|
Allow use of Check-And-Set option and raise exception if status is 4xx or 5xx
|
Python
|
mit
|
vcoque/consul-ri
|
---
+++
@@ -21,7 +21,7 @@
if r.status_code == 200:
return json.loads(r.text)
else:
- return None
+ r.raise_for_status()
def get(self, key, recurse=None):
return self._get(key, recurse=recurse)
@@ -29,12 +29,20 @@
def list(self, key=''):
return self._get(key, keys=True)
- def set(self, key, value):
- r = requests.put(self._url + '/' + key, data=value)
- if r.status_code == 200 and re.match(r"true", r.text) is not None:
- return True
+ def set(self, key, value, cas=None):
+ params = dict()
+ if cas is not None:
+ params['cas'] = cas
+
+ r = requests.put(self._url + '/' + key, data=value, params=params)
+
+ if r.status_code == 200:
+ if re.match(r"true", r.text) is not None:
+ return True
+ elif re.match(r"false", r.text) is not None:
+ return False
else:
- return False
+ r.raise_for_status()
def delete(self, key, recurse=None):
url = self._url + '/' + key
@@ -42,4 +50,5 @@
params = dict()
if recurse is not None:
params['recurse'] = True
- requests.delete(url, params=params)
+ r = requests.delete(url, params=params)
+ r.raise_for_status()
|
244f9ad92683a1b3a3bc8409724fea9c671f38b6
|
src/mcedit2/widgets/layout.py
|
src/mcedit2/widgets/layout.py
|
from __future__ import absolute_import, division, print_function, unicode_literals
from PySide import QtGui
def _Box(box, *a):
for arg in a:
if isinstance(arg, tuple):
item = arg[0]
else:
item = arg
arg = (item,)
if isinstance(item, QtGui.QLayout):
box.addLayout(*arg)
if isinstance(item, QtGui.QWidget):
box.addWidget(*arg)
if item is None:
box.addStretch()
return box
def Row(*a, **kw):
"""
:rtype: QHBoxLayout
"""
margin = kw.pop('margin', None)
box = QtGui.QHBoxLayout(**kw)
if margin:
box.setContentsMargins((margin,) * 4)
_Box(box, *a)
return box
def Column(*a, **kw):
"""
:rtype: QtGui.QVBoxLayout
"""
margin = kw.pop('margin', None)
box = QtGui.QVBoxLayout(**kw)
if margin:
box.setContentsMargins((margin,) * 4)
_Box(box, *a)
return box
def setWidgetError(widget, exc):
"""
Add a subwidget to `widget` that displays the error message for the exception `exc`
:param widget:
:param exc:
:return:
"""
layout = QtGui.QVBoxLayout()
layout.addWidget(QtGui.QLabel(exc.message))
layout.addStretch()
widget.setLayout(layout)
|
from __future__ import absolute_import, division, print_function, unicode_literals
from PySide import QtGui
def _Box(box, *a):
for arg in a:
if isinstance(arg, tuple):
item = arg[0]
else:
item = arg
arg = (item,)
if isinstance(item, QtGui.QLayout):
box.addLayout(*arg)
if isinstance(item, QtGui.QWidget):
box.addWidget(*arg)
if item is None:
box.addStretch()
return box
def Row(*a, **kw):
"""
:rtype: QtGui.QHBoxLayout
"""
margin = kw.pop('margin', None)
box = QtGui.QHBoxLayout(**kw)
_Box(box, *a)
if margin is not None:
box.setContentsMargins(margin, margin, margin, margin)
return box
def Column(*a, **kw):
"""
:rtype: QtGui.QVBoxLayout
"""
margin = kw.pop('margin', None)
box = QtGui.QVBoxLayout(**kw)
_Box(box, *a)
if margin is not None:
box.setContentsMargins(margin, margin, margin, margin)
return box
def setWidgetError(widget, exc):
"""
Add a subwidget to `widget` that displays the error message for the exception `exc`
:param widget:
:param exc:
:return:
"""
layout = QtGui.QVBoxLayout()
layout.addWidget(QtGui.QLabel(exc.message))
layout.addStretch()
widget.setLayout(layout)
|
Check margin keyword to Row/Column is not None
|
Check margin keyword to Row/Column is not None
|
Python
|
bsd-3-clause
|
Rubisk/mcedit2,Rubisk/mcedit2,vorburger/mcedit2,vorburger/mcedit2
|
---
+++
@@ -21,13 +21,13 @@
def Row(*a, **kw):
"""
- :rtype: QHBoxLayout
+ :rtype: QtGui.QHBoxLayout
"""
margin = kw.pop('margin', None)
box = QtGui.QHBoxLayout(**kw)
- if margin:
- box.setContentsMargins((margin,) * 4)
_Box(box, *a)
+ if margin is not None:
+ box.setContentsMargins(margin, margin, margin, margin)
return box
@@ -37,9 +37,9 @@
"""
margin = kw.pop('margin', None)
box = QtGui.QVBoxLayout(**kw)
- if margin:
- box.setContentsMargins((margin,) * 4)
_Box(box, *a)
+ if margin is not None:
+ box.setContentsMargins(margin, margin, margin, margin)
return box
def setWidgetError(widget, exc):
|
bd6bb741db3b5403ec8ee590a919b0f9ff29bf14
|
plugins/logging.py
|
plugins/logging.py
|
import logging
import sublime
PACKAGE_NAME = __package__.split(".", 1)[0]
logging.basicConfig(
level=logging.ERROR,
format="%(name)s [%(levelname)s]: %(message)s"
)
logger = logging.getLogger(PACKAGE_NAME)
def load_logger():
"""
Subscribe to Markdown changes in to get log level from user settings.
Must be called in plugin_loaded().
"""
settings = sublime.load_settings("Markdown.sublime-settings")
settings.clear_on_change(__name__)
settings.add_on_change(__name__, on_preferences_changed)
on_preferences_changed()
def unload_logger():
"""
Unsubscribe to Markdown changes.
Must be called in plugin_unloaded().
"""
settings = sublime.load_settings("Markdown.sublime-settings")
settings.clear_on_change(__name__)
def on_preferences_changed():
"""
Update log level according to user settings
"""
settings = sublime.load_settings("Markdown.sublime-settings")
try:
logger.setLevel(settings.get("mde.logging.level", "ERROR"))
except (TypeError, ValueError):
logger.setLevel(logging.ERROR)
|
import logging
import sublime
PACKAGE_NAME = __package__.split(".", 1)[0]
logging.basicConfig(
level=logging.ERROR,
format="%(name)s [%(levelname)s]: %(message)s"
)
logger = logging.getLogger(PACKAGE_NAME)
def load_logger():
"""
Subscribe to Preferences changes in to get log level from user settings.
Must be called in plugin_loaded().
"""
settings = sublime.load_settings("Preferences.sublime-settings")
settings.clear_on_change(__name__)
settings.add_on_change(__name__, on_preferences_changed)
on_preferences_changed()
def unload_logger():
"""
Unsubscribe to Preferences changes.
Must be called in plugin_unloaded().
"""
settings = sublime.load_settings("Preferences.sublime-settings")
settings.clear_on_change(__name__)
def on_preferences_changed():
"""
Update log level according to user settings
"""
settings = sublime.load_settings("Preferences.sublime-settings")
try:
logger.setLevel(settings.get("mde.logging.level", "ERROR"))
except (TypeError, ValueError):
logger.setLevel(logging.ERROR)
|
Read logger config from Preferences
|
Plugins: Read logger config from Preferences
required due to 9b30d85d1b60fef4f4d7c35868dd406f0c5d94f3
|
Python
|
mit
|
SublimeText-Markdown/MarkdownEditing
|
---
+++
@@ -12,11 +12,11 @@
def load_logger():
"""
- Subscribe to Markdown changes in to get log level from user settings.
+ Subscribe to Preferences changes in to get log level from user settings.
Must be called in plugin_loaded().
"""
- settings = sublime.load_settings("Markdown.sublime-settings")
+ settings = sublime.load_settings("Preferences.sublime-settings")
settings.clear_on_change(__name__)
settings.add_on_change(__name__, on_preferences_changed)
on_preferences_changed()
@@ -24,11 +24,11 @@
def unload_logger():
"""
- Unsubscribe to Markdown changes.
+ Unsubscribe to Preferences changes.
Must be called in plugin_unloaded().
"""
- settings = sublime.load_settings("Markdown.sublime-settings")
+ settings = sublime.load_settings("Preferences.sublime-settings")
settings.clear_on_change(__name__)
@@ -36,7 +36,7 @@
"""
Update log level according to user settings
"""
- settings = sublime.load_settings("Markdown.sublime-settings")
+ settings = sublime.load_settings("Preferences.sublime-settings")
try:
logger.setLevel(settings.get("mde.logging.level", "ERROR"))
|
c6298a573dc3188b8c57954287d78e7da253483a
|
lot/urls.py
|
lot/urls.py
|
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns("",
url(r"^login/(?P<uuid>[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12})/$", views.LOTLogin.as_view(), name="login"),
)
|
# -*- coding: utf-8 -*-
from django.conf.urls import url
from . import views
urlpatterns = [
url(r"^login/(?P<uuid>[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12})/$", views.LOTLogin.as_view(), name="login"),
]
|
Update to new-style urlpatterns format
|
Update to new-style urlpatterns format
|
Python
|
bsd-3-clause
|
ABASystems/django-lot
|
---
+++
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import patterns, url
+from django.conf.urls import url
from . import views
-urlpatterns = patterns("",
+urlpatterns = [
url(r"^login/(?P<uuid>[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12})/$", views.LOTLogin.as_view(), name="login"),
-)
+]
|
d55920576d288e9cb703337c6183cfe071d274ce
|
cryptography/primitives/block/ciphers.py
|
cryptography/primitives/block/ciphers.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
class AES(object):
name = "AES"
block_size = 128
key_sizes = set([128, 192, 256])
def __init__(self, key):
super(AES, self).__init__()
self.key = key
# Verify that the key size matches the expected key size
if self.key_size not in self.key_sizes:
raise ValueError("Invalid key size (%s) for %s".format(
self.key_size, self.name
))
@property
def key_size(self):
return len(self.key) * 8
|
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function
class AES(object):
name = "AES"
block_size = 128
key_sizes = set([128, 192, 256])
def __init__(self, key):
super(AES, self).__init__()
self.key = key
# Verify that the key size matches the expected key size
if self.key_size not in self.key_sizes:
raise ValueError("Invalid key size ({0}) for {1}".format(
self.key_size, self.name
))
@property
def key_size(self):
return len(self.key) * 8
|
Fix issue mixing %s and format for ValueError in AES
|
Fix issue mixing %s and format for ValueError in AES
|
Python
|
bsd-3-clause
|
skeuomorf/cryptography,dstufft/cryptography,dstufft/cryptography,bwhmather/cryptography,kimvais/cryptography,skeuomorf/cryptography,Ayrx/cryptography,sholsapp/cryptography,dstufft/cryptography,kimvais/cryptography,sholsapp/cryptography,dstufft/cryptography,Hasimir/cryptography,sholsapp/cryptography,Ayrx/cryptography,bwhmather/cryptography,kimvais/cryptography,bwhmather/cryptography,kimvais/cryptography,dstufft/cryptography,bwhmather/cryptography,Lukasa/cryptography,Ayrx/cryptography,Hasimir/cryptography,Lukasa/cryptography,sholsapp/cryptography,Ayrx/cryptography,skeuomorf/cryptography,skeuomorf/cryptography,Hasimir/cryptography,Hasimir/cryptography,glyph/cryptography,Lukasa/cryptography,glyph/cryptography
|
---
+++
@@ -25,7 +25,7 @@
# Verify that the key size matches the expected key size
if self.key_size not in self.key_sizes:
- raise ValueError("Invalid key size (%s) for %s".format(
+ raise ValueError("Invalid key size ({0}) for {1}".format(
self.key_size, self.name
))
|
7beecc71b53a14f5515763f551613e381978dd3f
|
xbob/learn/linear/__init__.py
|
xbob/learn/linear/__init__.py
|
from ._library import *
from ._library import __version__, __api_version__
def get_include():
"""Returns the directory containing the C/C++ API include directives"""
return __import__('pkg_resources').resource_filename(__name__, 'include')
def get_config():
"""Returns a string containing the configuration information.
"""
import pkg_resources
from .version import externals
packages = pkg_resources.require(__name__)
this = packages[0]
deps = packages[1:]
retval = "%s: %s [api=0x%04x] (%s)\n" % (this.key, this.version,
version.api, this.location)
retval += " - c/c++ dependencies:\n"
for k in sorted(externals): retval += " - %s: %s\n" % (k, externals[k])
retval += " - python dependencies:\n"
for d in deps: retval += " - %s: %s (%s)\n" % (d.key, d.version, d.location)
return retval.strip()
# gets sphinx autodoc done right - don't remove it
__all__ = [_ for _ in dir() if not _.startswith('_')]
|
from ._library import *
from . import version
from .version import module as __version__
from .version import api as __api_version__
def get_include():
"""Returns the directory containing the C/C++ API include directives"""
return __import__('pkg_resources').resource_filename(__name__, 'include')
def get_config():
"""Returns a string containing the configuration information.
"""
import pkg_resources
from .version import externals
packages = pkg_resources.require(__name__)
this = packages[0]
deps = packages[1:]
retval = "%s: %s [api=0x%04x] (%s)\n" % (this.key, this.version,
version.api, this.location)
retval += " - c/c++ dependencies:\n"
for k in sorted(externals): retval += " - %s: %s\n" % (k, externals[k])
retval += " - python dependencies:\n"
for d in deps: retval += " - %s: %s (%s)\n" % (d.key, d.version, d.location)
return retval.strip()
# gets sphinx autodoc done right - don't remove it
__all__ = [_ for _ in dir() if not _.startswith('_')]
|
Make use of the version module
|
Make use of the version module
|
Python
|
bsd-3-clause
|
tiagofrepereira2012/bob.learn.linear,tiagofrepereira2012/bob.learn.linear,tiagofrepereira2012/bob.learn.linear
|
---
+++
@@ -1,5 +1,7 @@
from ._library import *
-from ._library import __version__, __api_version__
+from . import version
+from .version import module as __version__
+from .version import api as __api_version__
def get_include():
"""Returns the directory containing the C/C++ API include directives"""
|
d86144aa09ea0d6a679a661b0b2f887d6a2a725d
|
examples/python/values.py
|
examples/python/values.py
|
#! /usr/bin/env python
#
# values.py
#
"""
An example of using values via Python API
"""
from opencog.atomspace import AtomSpace, TruthValue
from opencog.type_constructors import *
a = AtomSpace()
set_type_ctor_atomspace(a)
a = FloatValue([1.0, 2.0, 3.0])
b = FloatValue([1.0, 2.0, 3.0])
c = FloatValue(1.0)
print('{} == {}: {}'.format(a, b, a == b))
print('{} == {}: {}'.format(a, c, a == c))
featureValue = FloatValue([1.0, 2])
print('new value created: {}'.format(featureValue))
boundingBox = ConceptNode('boundingBox')
featureKey = PredicateNode('features')
boundingBox.set_value(featureKey, featureValue)
print('set value to atom: {}'.format(boundingBox))
print('get value from atom: {}'.format(boundingBox.get_value(featureKey)))
|
#! /usr/bin/env python
#
# values.py
#
"""
An example of using values via Python API
"""
from opencog.atomspace import AtomSpace, TruthValue
from opencog.type_constructors import *
a = AtomSpace()
set_type_ctor_atomspace(a)
a = FloatValue([1.0, 2.0, 3.0])
b = FloatValue([1.0, 2.0, 3.0])
c = FloatValue(1.0)
print('{} == {}: {}'.format(a, b, a == b))
print('{} == {}: {}'.format(a, c, a == c))
featureValue = FloatValue([1.0, 2])
print('new value created: {}'.format(featureValue))
boundingBox = ConceptNode('boundingBox')
featureKey = PredicateNode('features')
boundingBox.set_value(featureKey, featureValue)
print('set value to atom: {}'.format(boundingBox))
value = boundingBox.get_value(featureKey)
print('get value from atom: {}'.format(value))
list = value.to_list()
print('get python list from value: {}'.format(list))
|
Add example of Value to Python list conversion
|
Add example of Value to Python list conversion
|
Python
|
agpl-3.0
|
rTreutlein/atomspace,AmeBel/atomspace,AmeBel/atomspace,rTreutlein/atomspace,AmeBel/atomspace,rTreutlein/atomspace,rTreutlein/atomspace,AmeBel/atomspace,AmeBel/atomspace,rTreutlein/atomspace
|
---
+++
@@ -27,4 +27,8 @@
boundingBox.set_value(featureKey, featureValue)
print('set value to atom: {}'.format(boundingBox))
-print('get value from atom: {}'.format(boundingBox.get_value(featureKey)))
+value = boundingBox.get_value(featureKey)
+print('get value from atom: {}'.format(value))
+
+list = value.to_list()
+print('get python list from value: {}'.format(list))
|
c1fdbcf724ac7cc713cf3f5f3ca3cfca50007e34
|
application.py
|
application.py
|
#!/usr/bin/env python
import os
from app import create_app
from flask.ext.script import Manager
application = create_app(os.getenv('FLASH_CONFIG') or 'default')
manager = Manager(application)
if __name__ == '__main__':
manager.run()
|
#!/usr/bin/env python
import os
from app import create_app
from flask.ext.script import Manager, Server
application = create_app(os.getenv('FLASH_CONFIG') or 'default')
manager = Manager(application)
manager.add_command("runserver", Server(port=5002))
if __name__ == '__main__':
manager.run()
|
Update to run on port 5002
|
Update to run on port 5002
For development we will want to run multiple apps, so they should each bind to a different port number.
|
Python
|
mit
|
mtekel/digitalmarketplace-buyer-frontend,mtekel/digitalmarketplace-buyer-frontend,AusDTO/dto-digitalmarketplace-buyer-frontend,alphagov/digitalmarketplace-buyer-frontend,alphagov/digitalmarketplace-buyer-frontend,mtekel/digitalmarketplace-buyer-frontend,AusDTO/dto-digitalmarketplace-buyer-frontend,AusDTO/dto-digitalmarketplace-buyer-frontend,alphagov/digitalmarketplace-buyer-frontend,alphagov/digitalmarketplace-buyer-frontend,mtekel/digitalmarketplace-buyer-frontend,AusDTO/dto-digitalmarketplace-buyer-frontend
|
---
+++
@@ -2,10 +2,11 @@
import os
from app import create_app
-from flask.ext.script import Manager
+from flask.ext.script import Manager, Server
application = create_app(os.getenv('FLASH_CONFIG') or 'default')
manager = Manager(application)
+manager.add_command("runserver", Server(port=5002))
if __name__ == '__main__':
manager.run()
|
864f5be90fb31529f8ae9b0cf765fcf77504c0c5
|
comics/comics/mortenm.py
|
comics/comics/mortenm.py
|
# encoding: utf-8
from comics.aggregator.crawler import BaseComicCrawler
from comics.meta.base import BaseComicMeta
class ComicMeta(BaseComicMeta):
name = 'Morten M (vg.no)'
language = 'no'
url = 'http://www.vg.no/spesial/mortenm/'
start_date = '1978-01-01'
history_capable_days = 120
schedule = 'Mo,Tu,We,Th,Fr,Sa,Su'
time_zone = 1
rights = 'Morten M. Kristiansen'
class ComicCrawler(BaseComicCrawler):
def crawl(self):
self.url = 'http://static.vg.no/gfx/mortenm/output/%(year)s/%(month)s/%(year)-%(month)s-%(day).jpg' % {
'year': self.pub_date.strftime("%Y"),
'month': self.pub_date.strftime("%m"),
'day': self.pub_date.strftime("%d"),
}
|
# encoding: utf-8
from comics.aggregator.crawler import BaseComicCrawler
from comics.meta.base import BaseComicMeta
class ComicMeta(BaseComicMeta):
name = 'Morten M (vg.no)'
language = 'no'
url = 'http://www.vg.no/spesial/mortenm/'
start_date = '1978-01-01'
history_capable_days = 120
schedule = 'Mo,Tu,We,Th,Fr,Sa,Su'
time_zone = 1
rights = 'Morten M. Kristiansen'
class ComicCrawler(BaseComicCrawler):
def crawl(self):
self.url = 'http://static.vg.no/gfx/mortenm/output/%(year)s/%(month)s/%(year)s-%(month)s-%(day)s.jpg' % {
'year': self.pub_date.strftime("%Y"),
'month': self.pub_date.strftime("%m"),
'day': self.pub_date.strftime("%d"),
}
|
Add missing chars in URL for 'Morten M' crawler
|
Add missing chars in URL for 'Morten M' crawler
|
Python
|
agpl-3.0
|
klette/comics,jodal/comics,datagutten/comics,datagutten/comics,klette/comics,datagutten/comics,jodal/comics,jodal/comics,klette/comics,datagutten/comics,jodal/comics
|
---
+++
@@ -15,7 +15,7 @@
class ComicCrawler(BaseComicCrawler):
def crawl(self):
- self.url = 'http://static.vg.no/gfx/mortenm/output/%(year)s/%(month)s/%(year)-%(month)s-%(day).jpg' % {
+ self.url = 'http://static.vg.no/gfx/mortenm/output/%(year)s/%(month)s/%(year)s-%(month)s-%(day)s.jpg' % {
'year': self.pub_date.strftime("%Y"),
'month': self.pub_date.strftime("%m"),
'day': self.pub_date.strftime("%d"),
|
07fd8bf23917e18ba419859d788d9f51735f3b39
|
conda_gitenv/__init__.py
|
conda_gitenv/__init__.py
|
from __future__ import absolute_import, division, print_function, unicode_literals
from distutils.version import StrictVersion
from conda import __version__ as CONDA_VERSION
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
_conda_base = StrictVersion('4.3.0')
_conda_support = StrictVersion(CONDA_VERSION) >= _conda_base
assert _conda_support, 'Minimum supported conda version is {}.'.format(_conda_base)
manifest_branch_prefix = 'manifest/'
|
from __future__ import absolute_import, division, print_function, unicode_literals
from distutils.version import StrictVersion
from conda import __version__ as CONDA_VERSION
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
_conda_base = StrictVersion('4.3.0')
_conda_version = StrictVersion(CONDA_VERSION)
_conda_supported = _conda_version >= _conda_base
assert _conda_support, 'Minimum supported conda version is {}, got {}.'.format(_conda_base, _conda_version)
manifest_branch_prefix = 'manifest/'
|
Update minimum conda version diagnostic
|
Update minimum conda version diagnostic
|
Python
|
bsd-3-clause
|
SciTools/conda-gitenv
|
---
+++
@@ -11,7 +11,8 @@
del get_versions
_conda_base = StrictVersion('4.3.0')
-_conda_support = StrictVersion(CONDA_VERSION) >= _conda_base
-assert _conda_support, 'Minimum supported conda version is {}.'.format(_conda_base)
+_conda_version = StrictVersion(CONDA_VERSION)
+_conda_supported = _conda_version >= _conda_base
+assert _conda_support, 'Minimum supported conda version is {}, got {}.'.format(_conda_base, _conda_version)
manifest_branch_prefix = 'manifest/'
|
82c1b2c14977040f9e6251ed9616fc0f64a52779
|
system/slackhandler.py
|
system/slackhandler.py
|
import logging
from slacker import Slacker
import os
class SlackHandler(logging.Handler):
def __init__(self, slack_token):
logging.Handler.__init__(self)
self.slack = Slacker(slack_token)
def emit(self, record):
self.slack.chat.post_message('#leonard', text='ERROR ON {}\n{}'.format(
'DEBUG' if os.environ.get('BOT_DEBUG', '0') == '1' else 'PRODUCTION @channel',
record
), parse='full')
|
import logging
from slacker import Slacker
import os
class SlackHandler(logging.Handler):
def __init__(self, slack_token):
logging.Handler.__init__(self)
self.slack = Slacker(slack_token)
def emit(self, record):
if record.name != 'Unauthorized':
self.slack.chat.post_message('#leonard', text='ERROR ON {}\n{}'.format(
'DEBUG' if os.environ.get('BOT_DEBUG', '0') == '1' else 'PRODUCTION @channel',
record
), parse='full')
|
Remove Unauthorized exception logging to slack
|
Remove Unauthorized exception logging to slack
|
Python
|
mit
|
sevazhidkov/leonard
|
---
+++
@@ -9,7 +9,8 @@
self.slack = Slacker(slack_token)
def emit(self, record):
- self.slack.chat.post_message('#leonard', text='ERROR ON {}\n{}'.format(
- 'DEBUG' if os.environ.get('BOT_DEBUG', '0') == '1' else 'PRODUCTION @channel',
- record
- ), parse='full')
+ if record.name != 'Unauthorized':
+ self.slack.chat.post_message('#leonard', text='ERROR ON {}\n{}'.format(
+ 'DEBUG' if os.environ.get('BOT_DEBUG', '0') == '1' else 'PRODUCTION @channel',
+ record
+ ), parse='full')
|
845aee2341b3beeb6c96c0a2b830e2729f5f30d2
|
tests/GrammarCopyTest.py
|
tests/GrammarCopyTest.py
|
#!/usr/bin/env python
"""
:Author Patrik Valkovic
:Created 16.08.2017 19:16
:Licence GNUv3
Part of grammpy
"""
from unittest import main, TestCase
from grammpy import *
class GrammarCopyTest(TestCase):
pass
if __name__ == '__main__':
main()
|
#!/usr/bin/env python
"""
:Author Patrik Valkovic
:Created 16.08.2017 19:16
:Licence GNUv3
Part of grammpy
"""
from copy import deepcopy, copy
from unittest import main, TestCase
from grammpy import *
class A(Nonterminal):
pass
class B(Nonterminal):
pass
class RuleAtoB(Rule):
rule = ([A], [B])
class GrammarCopyTest(TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)
self.g = Grammar()
def setUp(self):
self.g = Grammar(terminals=[0, 1],
nonterminals=[A, B],
rules=[RuleAtoB],
start_symbol=A)
def test_shouldNotDeleteTerminals(self):
g = copy(self.g)
g.remove_term()
self.assertTrue(self.g.have_term([0, 1]))
self.assertFalse(g.have_term(0))
self.assertFalse(g.have_term(1))
def test_shouldNotDeleteNonterminals(self):
g = copy(self.g)
g.remove_nonterm()
self.assertTrue(self.g.have_nonterm([A, B]))
self.assertFalse(g.have_term(A))
self.assertFalse(g.have_term(B))
def test_shouldNotDeleteRules(self):
g = copy(self.g)
g.remove_rule()
self.assertTrue(self.g.have_rule(RuleAtoB))
self.assertFalse(g.have_rule(RuleAtoB))
def test_shouldNotChangeStartSymbol(self):
g = copy(self.g)
g.start_set(None)
self.assertTrue(self.g.start_is(A))
self.assertFalse(g.start_is(A))
if __name__ == '__main__':
main()
|
Add tests for grammar's __clone__ method
|
Add tests for grammar's __clone__ method
|
Python
|
mit
|
PatrikValkovic/grammpy
|
---
+++
@@ -7,12 +7,61 @@
"""
+from copy import deepcopy, copy
from unittest import main, TestCase
from grammpy import *
+class A(Nonterminal):
+ pass
+
+
+class B(Nonterminal):
+ pass
+
+
+class RuleAtoB(Rule):
+ rule = ([A], [B])
+
+
class GrammarCopyTest(TestCase):
- pass
+ def __init__(self, methodName='runTest'):
+ super().__init__(methodName)
+ self.g = Grammar()
+
+ def setUp(self):
+ self.g = Grammar(terminals=[0, 1],
+ nonterminals=[A, B],
+ rules=[RuleAtoB],
+ start_symbol=A)
+
+ def test_shouldNotDeleteTerminals(self):
+ g = copy(self.g)
+ g.remove_term()
+ self.assertTrue(self.g.have_term([0, 1]))
+ self.assertFalse(g.have_term(0))
+ self.assertFalse(g.have_term(1))
+
+
+ def test_shouldNotDeleteNonterminals(self):
+ g = copy(self.g)
+ g.remove_nonterm()
+ self.assertTrue(self.g.have_nonterm([A, B]))
+ self.assertFalse(g.have_term(A))
+ self.assertFalse(g.have_term(B))
+
+ def test_shouldNotDeleteRules(self):
+ g = copy(self.g)
+ g.remove_rule()
+ self.assertTrue(self.g.have_rule(RuleAtoB))
+ self.assertFalse(g.have_rule(RuleAtoB))
+
+ def test_shouldNotChangeStartSymbol(self):
+ g = copy(self.g)
+ g.start_set(None)
+ self.assertTrue(self.g.start_is(A))
+ self.assertFalse(g.start_is(A))
+
if __name__ == '__main__':
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.