![](https://cdn-avatars.huggingface.co/v1/production/uploads/642c4c84b09c70b36ddff5f3/WGRnoLaxxP8XzvII9cido.jpeg)
CNXT/CHaTx
Updated
•
7
code
stringlengths 9
256k
|
---|
<s> """<STR_LIT>""" <EOL> from bootstrap import Bootstrap <EOL> from fund import InstantPaymentNotificationHandler <EOL> from fund import ThankYouHandler <EOL> from view import * <EOL> mapping = [ ( <EOL> r'<STR_LIT:/>' , <EOL> Index <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> InstantPaymentNotificationHandler <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> ThankYouHandler <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> About <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Guide <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Download <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Standards <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Community <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> News <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Support <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Contact <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Press <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Terms <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Library <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Library <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Library <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Users <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> User <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Design <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Design <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Design <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Design <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Design <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> RedirectSuccess <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> RedirectError <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> RedirectAfterDelete <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Moderate <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Bootstrap <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> ActivityScreen <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> TxnList <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Base64Blob <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> Base64Blob <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> MessageStrings <EOL> ) , ( <EOL> r'<STR_LIT>' , <EOL> NotFound <EOL> ) <EOL> ] </s>
|
<s> import msgpack <EOL> import gevent . pool <EOL> import gevent . queue <EOL> import gevent . event <EOL> import gevent . local <EOL> import gevent . lock <EOL> import logging <EOL> import sys <EOL> import gevent_zmq as zmq <EOL> from . exceptions import TimeoutExpired <EOL> from . context import Context <EOL> from . channel_base import ChannelBase <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> def get_pyzmq_frame_buffer ( frame ) : <EOL> return frame . buffer [ : ] <EOL> else : <EOL> def get_pyzmq_frame_buffer ( frame ) : <EOL> return frame . buffer <EOL> logger = logging . getLogger ( __name__ ) <EOL> class SequentialSender ( object ) : <EOL> def __init__ ( self , socket ) : <EOL> self . _socket = socket <EOL> def _send ( self , parts ) : <EOL> e = None <EOL> for i in xrange ( len ( parts ) - <NUM_LIT:1> ) : <EOL> try : <EOL> self . _socket . send ( parts [ i ] , copy = False , flags = zmq . SNDMORE ) <EOL> except ( gevent . GreenletExit , gevent . Timeout ) as e : <EOL> if i == <NUM_LIT:0> : <EOL> raise <EOL> self . _socket . send ( parts [ i ] , copy = False , flags = zmq . SNDMORE ) <EOL> try : <EOL> self . _socket . send ( parts [ - <NUM_LIT:1> ] , copy = False ) <EOL> except ( gevent . GreenletExit , gevent . Timeout ) as e : <EOL> self . _socket . send ( parts [ - <NUM_LIT:1> ] , copy = False ) <EOL> if e : <EOL> raise e <EOL> def __call__ ( self , parts , timeout = None ) : <EOL> if timeout : <EOL> with gevent . Timeout ( timeout ) : <EOL> self . _send ( parts ) <EOL> else : <EOL> self . _send ( parts ) <EOL> class SequentialReceiver ( object ) : <EOL> def __init__ ( self , socket ) : <EOL> self . _socket = socket <EOL> def _recv ( self ) : <EOL> e = None <EOL> parts = [ ] <EOL> while True : <EOL> try : <EOL> part = self . _socket . recv ( copy = False ) <EOL> except ( gevent . GreenletExit , gevent . Timeout ) as e : <EOL> if len ( parts ) == <NUM_LIT:0> : <EOL> raise <EOL> part = self . _socket . recv ( copy = False ) <EOL> parts . append ( part ) <EOL> if not part . more : <EOL> break <EOL> if e : <EOL> raise e <EOL> return parts <EOL> def __call__ ( self , timeout = None ) : <EOL> if timeout : <EOL> with gevent . Timeout ( timeout ) : <EOL> return self . _recv ( ) <EOL> else : <EOL> return self . _recv ( ) <EOL> class Sender ( SequentialSender ) : <EOL> def __init__ ( self , socket ) : <EOL> self . _socket = socket <EOL> self . _send_queue = gevent . queue . Channel ( ) <EOL> self . _send_task = gevent . spawn ( self . _sender ) <EOL> def close ( self ) : <EOL> if self . _send_task : <EOL> self . _send_task . kill ( ) <EOL> def _sender ( self ) : <EOL> for parts in self . _send_queue : <EOL> super ( Sender , self ) . _send ( parts ) <EOL> def __call__ ( self , parts , timeout = None ) : <EOL> try : <EOL> self . _send_queue . put ( parts , timeout = timeout ) <EOL> except gevent . queue . Full : <EOL> raise TimeoutExpired ( timeout ) <EOL> class Receiver ( SequentialReceiver ) : <EOL> def __init__ ( self , socket ) : <EOL> self . _socket = socket <EOL> self . _recv_queue = gevent . queue . Channel ( ) <EOL> self . _recv_task = gevent . spawn ( self . _recver ) <EOL> def close ( self ) : <EOL> if self . _recv_task : <EOL> self . _recv_task . kill ( ) <EOL> self . _recv_queue = None <EOL> def _recver ( self ) : <EOL> while True : <EOL> parts = super ( Receiver , self ) . _recv ( ) <EOL> self . _recv_queue . put ( parts ) <EOL> def __call__ ( self , timeout = None ) : <EOL> try : <EOL> return self . _recv_queue . get ( timeout = timeout ) <EOL> except gevent . queue . Empty : <EOL> raise TimeoutExpired ( timeout ) <EOL> class Event ( object ) : <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , name , args , context , header = None ) : <EOL> self . _name = name <EOL> self . _args = args <EOL> if header is None : <EOL> self . _header = { '<STR_LIT>' : context . new_msgid ( ) , '<STR_LIT:v>' : <NUM_LIT:3> } <EOL> else : <EOL> self . _header = header <EOL> self . _identity = None <EOL> @ property <EOL> def header ( self ) : <EOL> return self . _header <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ name . setter <EOL> def name ( self , v ) : <EOL> self . _name = v <EOL> @ property <EOL> def args ( self ) : <EOL> return self . _args <EOL> @ property <EOL> def identity ( self ) : <EOL> return self . _identity <EOL> @ identity . setter <EOL> def identity ( self , v ) : <EOL> self . _identity = v <EOL> def pack ( self ) : <EOL> return msgpack . Packer ( use_bin_type = True ) . pack ( ( self . _header , self . _name , self . _args ) ) <EOL> @ staticmethod <EOL> def unpack ( blob ) : <EOL> unpacker = msgpack . Unpacker ( encoding = '<STR_LIT:utf-8>' ) <EOL> unpacker . feed ( blob ) <EOL> unpacked_msg = unpacker . unpack ( ) <EOL> try : <EOL> ( header , name , args ) = unpacked_msg <EOL> except Exception as e : <EOL> raise Exception ( '<STR_LIT>' . format ( <EOL> unpacked_msg , e ) ) <EOL> if not isinstance ( header , dict ) : <EOL> header = { } <EOL> return Event ( name , args , None , header ) <EOL> def __str__ ( self , ignore_args = False ) : <EOL> if ignore_args : <EOL> args = '<STR_LIT>' <EOL> else : <EOL> args = self . _args <EOL> try : <EOL> args = '<STR_LIT>' . format ( str ( self . unpack ( self . _args ) ) ) <EOL> except Exception : <EOL> pass <EOL> if self . _identity : <EOL> identity = '<STR_LIT:U+002CU+0020>' . join ( repr ( x . bytes ) for x in self . _identity ) <EOL> return '<STR_LIT>' . format ( identity , self . _name , <EOL> self . _header , args ) <EOL> return '<STR_LIT>' . format ( self . _name , self . _header , args ) <EOL> class Events ( ChannelBase ) : <EOL> def __init__ ( self , zmq_socket_type , context = None ) : <EOL> self . _debug = False <EOL> self . _zmq_socket_type = zmq_socket_type <EOL> self . _context = context or Context . get_instance ( ) <EOL> self . _socket = self . _context . socket ( zmq_socket_type ) <EOL> if zmq_socket_type in ( zmq . PUSH , zmq . PUB , zmq . DEALER , zmq . ROUTER ) : <EOL> self . _send = Sender ( self . _socket ) <EOL> elif zmq_socket_type in ( zmq . REQ , zmq . REP ) : <EOL> self . _send = SequentialSender ( self . _socket ) <EOL> else : <EOL> self . _send = None <EOL> if zmq_socket_type in ( zmq . PULL , zmq . SUB , zmq . DEALER , zmq . ROUTER ) : <EOL> self . _recv = Receiver ( self . _socket ) <EOL> elif zmq_socket_type in ( zmq . REQ , zmq . REP ) : <EOL> self . _recv = SequentialReceiver ( self . _socket ) <EOL> else : <EOL> self . _recv = None <EOL> @ property <EOL> def recv_is_supported ( self ) : <EOL> return self . _recv is not None <EOL> @ property <EOL> def emit_is_supported ( self ) : <EOL> return self . _send is not None <EOL> def __del__ ( self ) : <EOL> try : <EOL> if not self . _socket . closed : <EOL> self . close ( ) <EOL> except ( AttributeError , TypeError ) : <EOL> pass <EOL> def close ( self ) : <EOL> try : <EOL> self . _send . close ( ) <EOL> except AttributeError : <EOL> pass <EOL> try : <EOL> self . _recv . close ( ) <EOL> except AttributeError : <EOL> pass <EOL> self . _socket . close ( ) <EOL> @ property <EOL> def debug ( self ) : <EOL> return self . _debug <EOL> @ debug . setter <EOL> def debug ( self , v ) : <EOL> if v != self . _debug : <EOL> self . _debug = v <EOL> if self . _debug : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> else : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> def _resolve_endpoint ( self , endpoint , resolve = True ) : <EOL> if resolve : <EOL> endpoint = self . _context . hook_resolve_endpoint ( endpoint ) <EOL> if isinstance ( endpoint , ( tuple , list ) ) : <EOL> r = [ ] <EOL> for sub_endpoint in endpoint : <EOL> r . extend ( self . _resolve_endpoint ( sub_endpoint , resolve ) ) <EOL> return r <EOL> return [ endpoint ] <EOL> def connect ( self , endpoint , resolve = True ) : <EOL> r = [ ] <EOL> for endpoint_ in self . _resolve_endpoint ( endpoint , resolve ) : <EOL> r . append ( self . _socket . connect ( endpoint_ ) ) <EOL> logger . debug ( '<STR_LIT>' , endpoint_ , r [ - <NUM_LIT:1> ] ) <EOL> return r <EOL> def bind ( self , endpoint , resolve = True ) : <EOL> r = [ ] <EOL> for endpoint_ in self . _resolve_endpoint ( endpoint , resolve ) : <EOL> r . append ( self . _socket . bind ( endpoint_ ) ) <EOL> logger . debug ( '<STR_LIT>' , endpoint_ , r [ - <NUM_LIT:1> ] ) <EOL> return r <EOL> def disconnect ( self , endpoint , resolve = True ) : <EOL> r = [ ] <EOL> for endpoint_ in self . _resolve_endpoint ( endpoint , resolve ) : <EOL> r . append ( self . _socket . disconnect ( endpoint_ ) ) <EOL> logging . debug ( '<STR_LIT>' , endpoint_ , r [ - <NUM_LIT:1> ] ) <EOL> return r <EOL> def new_event ( self , name , args , xheader = None ) : <EOL> event = Event ( name , args , context = self . _context ) <EOL> if xheader : <EOL> event . header . update ( xheader ) <EOL> return event <EOL> def emit_event ( self , event , timeout = None ) : <EOL> if self . _debug : <EOL> logger . debug ( '<STR_LIT>' , event ) <EOL> if event . identity : <EOL> parts = list ( event . identity or list ( ) ) <EOL> parts . extend ( [ '<STR_LIT>' , event . pack ( ) ] ) <EOL> elif self . _zmq_socket_type in ( zmq . DEALER , zmq . ROUTER ) : <EOL> parts = ( '<STR_LIT>' , event . pack ( ) ) <EOL> else : <EOL> parts = ( event . pack ( ) , ) <EOL> self . _send ( parts , timeout ) <EOL> def recv ( self , timeout = None ) : <EOL> parts = self . _recv ( timeout = timeout ) <EOL> if len ( parts ) > <NUM_LIT:2> : <EOL> identity = parts [ <NUM_LIT:0> : - <NUM_LIT:2> ] <EOL> blob = parts [ - <NUM_LIT:1> ] <EOL> elif len ( parts ) == <NUM_LIT:2> : <EOL> identity = parts [ <NUM_LIT:0> : - <NUM_LIT:1> ] <EOL> blob = parts [ - <NUM_LIT:1> ] <EOL> else : <EOL> identity = None <EOL> blob = parts [ <NUM_LIT:0> ] <EOL> event = Event . unpack ( get_pyzmq_frame_buffer ( blob ) ) <EOL> event . identity = identity <EOL> if self . _debug : <EOL> logger . debug ( '<STR_LIT>' , event ) <EOL> return event <EOL> def setsockopt ( self , * args ) : <EOL> return self . _socket . setsockopt ( * args ) <EOL> @ property <EOL> def context ( self ) : <EOL> return self . _context </s>
|
<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> os . environ . setdefault ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> from django . core . management import execute_from_command_line <EOL> execute_from_command_line ( sys . argv ) </s>
|
<s> """<STR_LIT>""" <EOL> import os <EOL> cwd = os . path . dirname ( __file__ ) <EOL> __version__ = open ( os . path . join ( cwd , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:r>' ) . read ( ) . strip ( ) <EOL> try : <EOL> from setuptools import setup , find_packages <EOL> except ImportError : <EOL> from ez_setup import use_setuptools <EOL> use_setuptools ( ) <EOL> from setuptools import setup , find_packages <EOL> setup ( <EOL> name = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> long_description = open ( '<STR_LIT>' ) . read ( ) , <EOL> version = __version__ , <EOL> author = '<STR_LIT>' , <EOL> author_email = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> packages = find_packages ( exclude = [ '<STR_LIT>' ] ) , <EOL> install_requires = open ( '<STR_LIT>' ) . readlines ( ) , <EOL> package_data = { '<STR_LIT>' : [ '<STR_LIT>' ] } , <EOL> include_package_data = True , <EOL> extras_require = { <EOL> '<STR_LIT>' : open ( '<STR_LIT>' ) . readlines ( ) , <EOL> } , <EOL> entry_points = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> } , <EOL> license = '<STR_LIT>' <EOL> ) </s>
|
<s> import os <EOL> import sys <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> os . environ . setdefault ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> from django . core . management import execute_from_command_line <EOL> execute_from_command_line ( sys . argv ) </s>
|
<s> from __future__ import unicode_literals <EOL> from django . db import models , migrations <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ] <EOL> operations = [ <EOL> migrations . CreateModel ( <EOL> name = '<STR_LIT>' , <EOL> fields = [ <EOL> ( '<STR_LIT:id>' , models . AutoField ( verbose_name = '<STR_LIT>' , serialize = False , auto_created = True , primary_key = True ) ) , <EOL> ( '<STR_LIT:name>' , models . CharField ( help_text = b'<STR_LIT>' , max_length = <NUM_LIT> ) ) , <EOL> ( '<STR_LIT:image>' , models . ImageField ( help_text = b'<STR_LIT>' , null = True , upload_to = b'<STR_LIT>' , blank = True ) ) , <EOL> ] , <EOL> options = { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> bases = ( models . Model , ) , <EOL> ) , <EOL> ] </s>
|
<s> import twitter <EOL> from django . contrib import messages <EOL> from django . contrib . auth . decorators import user_passes_test <EOL> from django . db import transaction <EOL> from django . shortcuts import redirect , render <EOL> from twobuntu . news . forms import AddItemForm <EOL> @ user_passes_test ( lambda u : u . is_staff ) <EOL> def add ( request ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = AddItemForm ( data = request . POST ) <EOL> if form . is_valid ( ) : <EOL> item = form . save ( commit = False ) <EOL> item . reporter = request . user <EOL> try : <EOL> with transaction . atomic ( ) : <EOL> item . save ( ) <EOL> except twitter . TwitterError as e : <EOL> messages . error ( request , "<STR_LIT>" % e . message [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] ) <EOL> else : <EOL> messages . info ( request , "<STR_LIT>" ) <EOL> return redirect ( '<STR_LIT>' ) <EOL> else : <EOL> form = AddItemForm ( ) <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT:description>' : "<STR_LIT>" , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> } ) </s>
|
<s> """<STR_LIT>""" <EOL> __all__ = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class DjangoWSGIException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ApplicationCallError ( DjangoWSGIException ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
|
<s> import boto <EOL> import boto . s3 . connection <EOL> from django . conf import settings <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> def get_s3_connection ( ) : <EOL> if settings . S3_ACCESS_KEY and settings . S3_SECRET_KEY and settings . S3_HOST : <EOL> log . debug ( '<STR_LIT>' . <EOL> format ( settings . S3_HOST , settings . S3_SECURE_CONNECTION ) ) <EOL> return boto . connect_s3 ( <EOL> aws_access_key_id = settings . S3_ACCESS_KEY , <EOL> aws_secret_access_key = settings . S3_SECRET_KEY , <EOL> host = settings . S3_HOST , <EOL> is_secure = settings . S3_SECURE_CONNECTION , <EOL> calling_format = boto . s3 . connection . OrdinaryCallingFormat ( ) ) <EOL> return None <EOL> def get_or_create_bucket ( s3_connection ) : <EOL> bucket = s3_connection . get_bucket ( settings . S3_BUCKET_NAME ) <EOL> if bucket is None : <EOL> bucket = s3_connection . create_bucket ( settings . S3_BUCKET_NAME ) <EOL> return bucket </s>
|
<s> from django . db import models <EOL> import datetime <EOL> from common . models import Project <EOL> class Stage ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT> ) <EOL> project = models . ForeignKey ( Project ) <EOL> text = models . TextField ( default = '<STR_LIT>' , blank = True ) <EOL> link = models . URLField ( default = None , blank = True , null = True ) <EOL> state = models . CharField ( max_length = <NUM_LIT> , default = '<STR_LIT:info>' , blank = True ) <EOL> weight = models . IntegerField ( default = <NUM_LIT:0> ) <EOL> updated = models . DateTimeField ( default = datetime . datetime . now ( ) ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . updated = datetime . datetime . now ( ) <EOL> return super ( Stage , self ) . save ( * args , ** kwargs ) <EOL> def __str__ ( self ) : <EOL> return self . name </s>
|
<s> from __future__ import unicode_literals <EOL> from django . db import models , migrations <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> operations = [ <EOL> migrations . AddField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> field = models . TextField ( default = b'<STR_LIT>' , max_length = <NUM_LIT> , verbose_name = '<STR_LIT>' , blank = True ) , <EOL> preserve_default = True , <EOL> ) , <EOL> migrations . AddField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> field = models . BooleanField ( default = False , verbose_name = '<STR_LIT>' ) , <EOL> preserve_default = True , <EOL> ) , <EOL> ] </s>
|
<s> import gevent <EOL> from gevent import monkey <EOL> monkey . patch_all ( ) <EOL> import time <EOL> import smtplib <EOL> TEST_MAIL = """<STR_LIT>""" <EOL> def timeit ( func ) : <EOL> def wrap ( num , port , * args , ** kwargs ) : <EOL> max_rqs = <NUM_LIT:0> <EOL> for _ in xrange ( <NUM_LIT:3> ) : <EOL> conns = [ smtplib . SMTP ( port = port ) for x in xrange ( num ) ] <EOL> map ( lambda x : x . connect ( '<STR_LIT:127.0.0.1>' , port ) , conns ) <EOL> start_at = time . time ( ) <EOL> func ( num , conns , ** kwargs ) <EOL> interval = time . time ( ) - start_at <EOL> for con in conns : <EOL> try : <EOL> con . quit ( ) <EOL> con . close ( ) <EOL> except Exception : <EOL> pass <EOL> gevent . sleep ( <NUM_LIT:3> ) <EOL> rqs = num / interval <EOL> max_rqs = max ( rqs , max_rqs ) <EOL> return max_rqs <EOL> return wrap <EOL> @ timeit <EOL> def helo ( num , conns ) : <EOL> tasks = [ gevent . spawn ( x . helo ) for x in conns ] <EOL> gevent . joinall ( tasks ) <EOL> @ timeit <EOL> def send ( num , conns ) : <EOL> tasks = [ gevent . spawn ( x . sendmail , '<STR_LIT>' , [ '<STR_LIT>' ] , TEST_MAIL ) for x in conns ] <EOL> gevent . joinall ( tasks ) <EOL> def main ( port , num ) : <EOL> print "<STR_LIT>" % ( num , helo ( num , port ) , send ( num , port ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> try : <EOL> main ( int ( sys . argv [ <NUM_LIT:1> ] ) , int ( sys . argv [ <NUM_LIT:2> ] ) ) <EOL> except IndexError : <EOL> print '<STR_LIT>' </s>
|
<s> import sys <EOL> import json <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> def b ( x ) : <EOL> return x <EOL> def s ( x ) : <EOL> return x <EOL> else : <EOL> def b ( x ) : <EOL> return bytes ( x , '<STR_LIT:utf-8>' ) <EOL> def s ( x ) : <EOL> return x . decode ( '<STR_LIT:utf-8>' ) <EOL> def parse_payload ( payload ) : <EOL> if not isinstance ( payload , str ) : <EOL> payload = '<STR_LIT:U+0020>' . join ( payload ) <EOL> try : <EOL> json . loads ( payload ) <EOL> except ValueError : <EOL> kv = payload . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) <EOL> if len ( kv ) > <NUM_LIT:1> : <EOL> payload = '<STR_LIT>' % ( kv [ <NUM_LIT:0> ] , kv [ <NUM_LIT:1> ] ) <EOL> else : <EOL> payload = '<STR_LIT:%s>' % kv [ <NUM_LIT:0> ] <EOL> return payload <EOL> def requires_elements ( xs , dictionary ) : <EOL> missing_values = [ ] <EOL> for x in xs : <EOL> if x not in dictionary : <EOL> missing_values . append ( x ) <EOL> if missing_values : <EOL> err_msg = '<STR_LIT:U+002CU+0020>' . join ( missing_values ) <EOL> raise KeyError ( '<STR_LIT>' % ( err_msg ) ) </s>
|
<s> from flask_resty import Api , GenericModelView <EOL> from marshmallow import fields , Schema <EOL> import pytest <EOL> from sqlalchemy import Column , Integer , String <EOL> import helpers <EOL> @ pytest . yield_fixture <EOL> def models ( db ) : <EOL> class Widget ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id_1 = Column ( Integer , primary_key = True ) <EOL> id_2 = Column ( Integer , primary_key = True ) <EOL> name = Column ( String , nullable = False ) <EOL> db . create_all ( ) <EOL> yield { <EOL> '<STR_LIT>' : Widget , <EOL> } <EOL> db . drop_all ( ) <EOL> @ pytest . fixture <EOL> def schemas ( ) : <EOL> class WidgetSchema ( Schema ) : <EOL> id_1 = fields . Integer ( as_string = True ) <EOL> id_2 = fields . Integer ( as_string = True ) <EOL> name = fields . String ( required = True ) <EOL> return { <EOL> '<STR_LIT>' : WidgetSchema ( ) , <EOL> } <EOL> @ pytest . fixture ( autouse = True ) <EOL> def routes ( app , models , schemas ) : <EOL> class WidgetViewBase ( GenericModelView ) : <EOL> model = models [ '<STR_LIT>' ] <EOL> schema = schemas [ '<STR_LIT>' ] <EOL> id_fields = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class WidgetListView ( WidgetViewBase ) : <EOL> def get ( self ) : <EOL> return self . list ( ) <EOL> def post ( self ) : <EOL> return self . create ( allow_client_id = True ) <EOL> class WidgetView ( WidgetViewBase ) : <EOL> def get ( self , id_1 , id_2 ) : <EOL> return self . retrieve ( ( id_1 , id_2 ) ) <EOL> def patch ( self , id_1 , id_2 ) : <EOL> return self . update ( ( id_1 , id_2 ) , partial = True ) <EOL> def delete ( self , id_1 , id_2 ) : <EOL> return self . destroy ( ( id_1 , id_2 ) ) <EOL> api = Api ( app ) <EOL> api . add_resource ( <EOL> '<STR_LIT>' , WidgetListView , WidgetView , <EOL> id_rule = '<STR_LIT>' , <EOL> ) <EOL> @ pytest . fixture ( autouse = True ) <EOL> def data ( db , models ) : <EOL> db . session . add_all ( ( <EOL> models [ '<STR_LIT>' ] ( id_1 = <NUM_LIT:1> , id_2 = <NUM_LIT:2> , name = "<STR_LIT>" ) , <EOL> models [ '<STR_LIT>' ] ( id_1 = <NUM_LIT:1> , id_2 = <NUM_LIT:3> , name = "<STR_LIT>" ) , <EOL> models [ '<STR_LIT>' ] ( id_1 = <NUM_LIT:4> , id_2 = <NUM_LIT:5> , name = "<STR_LIT>" ) , <EOL> ) ) <EOL> db . session . commit ( ) <EOL> def test_list ( client ) : <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . status_code == <NUM_LIT:200> <EOL> assert helpers . get_data ( response ) == [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } , <EOL> ] <EOL> def test_retrieve ( client ) : <EOL> response = client . get ( '<STR_LIT>' ) <EOL> assert response . status_code == <NUM_LIT:200> <EOL> assert helpers . get_data ( response ) == { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } <EOL> def test_create ( client ) : <EOL> response = helpers . request ( <EOL> client , <EOL> '<STR_LIT:POST>' , '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } , <EOL> ) <EOL> assert response . status_code == <NUM_LIT> <EOL> assert response . headers [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert helpers . get_data ( response ) == { <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } <EOL> def test_update ( client ) : <EOL> update_response = helpers . request ( <EOL> client , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } , <EOL> ) <EOL> assert update_response . status_code == <NUM_LIT> <EOL> retrieve_response = client . get ( '<STR_LIT>' ) <EOL> assert retrieve_response . status_code == <NUM_LIT:200> <EOL> assert helpers . get_data ( retrieve_response ) == { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> } <EOL> def test_destroy ( client ) : <EOL> destroy_response = client . delete ( '<STR_LIT>' ) <EOL> assert destroy_response . status_code == <NUM_LIT> <EOL> retrieve_response = client . get ( '<STR_LIT>' ) <EOL> assert retrieve_response . status_code == <NUM_LIT> </s>
|
<s> from . dogpile import Dogpile </s>
|
<s> """<STR_LIT>""" <EOL> import pygame <EOL> from pygame . locals import * <EOL> import time <EOL> import datetime <EOL> import sys <EOL> import os <EOL> import glob <EOL> import subprocess <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> white = ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) <EOL> red = ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> green = ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) <EOL> blue = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> black = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> cyan = ( <NUM_LIT:50> , <NUM_LIT:255> , <NUM_LIT:255> ) <EOL> magenta = ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> yellow = ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:0> ) <EOL> orange = ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:0> ) <EOL> width = <NUM_LIT> <EOL> height = <NUM_LIT> <EOL> size = ( width , height ) <EOL> screen = pygame . display . set_mode ( size ) <EOL> pygame . init ( ) <EOL> pygame . mouse . set_visible ( False ) <EOL> font = pygame . font . Font ( None , <NUM_LIT> ) <EOL> screensaver_timer = <NUM_LIT:5> <EOL> screensaver = False <EOL> menu = <NUM_LIT:1> <EOL> skin_number = <NUM_LIT:1> <EOL> max_skins = <NUM_LIT:8> <EOL> font_color = cyan <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin = skin1 <EOL> screen . blit ( skin , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> reboot_label = font . render ( "<STR_LIT>" , <NUM_LIT:1> , ( font_color ) ) <EOL> poweroff_label = font . render ( "<STR_LIT>" , <NUM_LIT:1> , ( font_color ) ) <EOL> song_title = "<STR_LIT:U+0020>" <EOL> playlist = "<STR_LIT:U+0020>" <EOL> def reboot ( ) : <EOL> screen . fill ( black ) <EOL> screen . blit ( reboot_label , ( <NUM_LIT:10> , <NUM_LIT:100> ) ) <EOL> pygame . display . flip ( ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> def poweroff ( ) : <EOL> screen . fill ( black ) <EOL> screen . blit ( poweroff_label , ( <NUM_LIT:10> , <NUM_LIT:100> ) ) <EOL> pygame . display . flip ( ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> def favorite ( ) : <EOL> print song_title <EOL> f = open ( '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> f . write ( '<STR_LIT:->' + song_title + '<STR_LIT:\n>' ) <EOL> f . close ( ) <EOL> def on_touch ( ) : <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:1> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:2> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:3> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:4> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:5> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:6> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:7> ) <EOL> if <NUM_LIT> <= pos [ <NUM_LIT:0> ] <= <NUM_LIT> and <NUM_LIT> <= pos [ <NUM_LIT:1> ] <= <NUM_LIT> : <EOL> button ( <NUM_LIT:8> ) <EOL> def button ( number ) : <EOL> global menu <EOL> if menu == <NUM_LIT:1> : <EOL> if number == <NUM_LIT:1> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:2> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:3> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:4> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:5> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:6> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:7> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> if number == <NUM_LIT:8> : <EOL> menu = <NUM_LIT:2> <EOL> update_screen ( ) <EOL> return <EOL> if menu == <NUM_LIT:2> : <EOL> if number == <NUM_LIT:1> : <EOL> favorite ( ) <EOL> if number == <NUM_LIT:2> : <EOL> global skin_number <EOL> skin_number = skin_number + <NUM_LIT:1> <EOL> update_screen ( ) <EOL> if number == <NUM_LIT:3> : <EOL> pygame . quit ( ) <EOL> sys . exit ( ) <EOL> if number == <NUM_LIT:4> : <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> pygame . quit ( ) <EOL> sys . exit ( ) <EOL> if number == <NUM_LIT:5> : <EOL> print "<STR_LIT>" <EOL> poweroff ( ) <EOL> if number == <NUM_LIT:6> : <EOL> print "<STR_LIT>" <EOL> reboot ( ) <EOL> if number == <NUM_LIT:7> : <EOL> update_screen ( ) <EOL> if number == <NUM_LIT:8> : <EOL> menu = <NUM_LIT:1> <EOL> update_screen ( ) <EOL> return <EOL> def update_screen ( ) : <EOL> global skin_number <EOL> if skin_number == <NUM_LIT:9> : <EOL> skin_number = <NUM_LIT:1> <EOL> if skin_number == <NUM_LIT:1> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = cyan <EOL> if skin_number == <NUM_LIT:2> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = blue <EOL> if skin_number == <NUM_LIT:3> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = green <EOL> if skin_number == <NUM_LIT:4> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = magenta <EOL> if skin_number == <NUM_LIT:5> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = orange <EOL> if skin_number == <NUM_LIT:6> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = red <EOL> if skin_number == <NUM_LIT:7> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = white <EOL> if skin_number == <NUM_LIT:8> : <EOL> skin1 = pygame . image . load ( "<STR_LIT>" ) <EOL> skin2 = pygame . image . load ( "<STR_LIT>" ) <EOL> font_color = yellow <EOL> global menu <EOL> if screensaver == False : <EOL> current_time = datetime . datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> time_label = font . render ( current_time , <NUM_LIT:1> , ( font_color ) ) <EOL> if menu == <NUM_LIT:1> : <EOL> skin = skin1 <EOL> screen . blit ( skin , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> lines = subprocess . check_output ( '<STR_LIT>' , shell = True ) . split ( "<STR_LIT::>" ) <EOL> if len ( lines ) == <NUM_LIT:1> : <EOL> line1 = lines [ <NUM_LIT:0> ] <EOL> line1 = line1 [ : - <NUM_LIT:1> ] <EOL> station_label = font . render ( "<STR_LIT>" , <NUM_LIT:1> , ( font_color ) ) <EOL> else : <EOL> line1 = lines [ <NUM_LIT:0> ] <EOL> line2 = lines [ <NUM_LIT:1> ] <EOL> line1 = line1 [ : <NUM_LIT:30> ] <EOL> station_label = font . render ( '<STR_LIT>' + line1 + '<STR_LIT:.>' , <NUM_LIT:1> , ( font_color ) ) <EOL> lines = subprocess . check_output ( '<STR_LIT>' , shell = True ) . split ( "<STR_LIT:\n>" ) <EOL> line1 = lines [ <NUM_LIT:0> ] <EOL> if line1 . startswith ( "<STR_LIT>" ) : <EOL> title_label = font . render ( "<STR_LIT>" , <NUM_LIT:1> , ( font_color ) ) <EOL> else : <EOL> line1 = lines [ <NUM_LIT:0> ] <EOL> line2 = lines [ <NUM_LIT:1> ] <EOL> global song_title <EOL> song_title = line1 <EOL> line1 = line1 [ : <NUM_LIT:30> ] <EOL> title_label = font . render ( line1 + '<STR_LIT:.>' , <NUM_LIT:1> , ( font_color ) ) <EOL> title = font . render ( "<STR_LIT>" , <NUM_LIT:1> , ( font_color ) ) <EOL> screen . blit ( skin , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> screen . blit ( station_label , ( <NUM_LIT> , <NUM_LIT:15> ) ) <EOL> screen . blit ( title , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> screen . blit ( title_label , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> screen . blit ( time_label , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> lines = subprocess . check_output ( '<STR_LIT>' , shell = True ) . split ( "<STR_LIT:\n>" ) <EOL> line1 = lines [ <NUM_LIT:0> ] <EOL> volume_label = font . render ( line1 , <NUM_LIT:1> , ( font_color ) ) <EOL> screen . blit ( volume_label , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> pygame . display . flip ( ) <EOL> if menu == <NUM_LIT:2> : <EOL> skin = skin2 <EOL> screen . blit ( skin , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ip = subprocess . check_output ( '<STR_LIT>' , shell = True ) . strip ( ) <EOL> ip_label = font . render ( '<STR_LIT>' + ip , <NUM_LIT:1> , ( font_color ) ) <EOL> screen . blit ( ip_label , ( <NUM_LIT> , <NUM_LIT:15> ) ) <EOL> cpu_temp = subprocess . check_output ( '<STR_LIT>' , shell = True ) . strip ( ) <EOL> temp = font . render ( '<STR_LIT>' + cpu_temp , <NUM_LIT:1> , ( font_color ) ) <EOL> screen . blit ( temp , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> screen . blit ( time_label , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> pygame . display . flip ( ) <EOL> if screensaver == True : <EOL> screen . fill ( white ) <EOL> pygame . display . flip ( ) <EOL> minutes = <NUM_LIT:0> <EOL> pygame . time . set_timer ( USEREVENT + <NUM_LIT:1> , <NUM_LIT> ) <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> update_screen ( ) <EOL> running = True <EOL> while running : <EOL> for event in pygame . event . get ( ) : <EOL> if event . type == USEREVENT + <NUM_LIT:1> : <EOL> minutes += <NUM_LIT:1> <EOL> if event . type == pygame . QUIT : <EOL> print "<STR_LIT>" <EOL> pygame . quit ( ) <EOL> sys . exit ( ) <EOL> if event . type == pygame . KEYDOWN : <EOL> if event . key == K_ESCAPE : <EOL> print "<STR_LIT>" <EOL> pygame . quit ( ) <EOL> sys . exit ( ) <EOL> if event . type == pygame . MOUSEBUTTONDOWN and screensaver == True : <EOL> minutes = <NUM_LIT:0> <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> screensaver = False <EOL> update_screen ( ) <EOL> break <EOL> if event . type == pygame . MOUSEBUTTONDOWN and screensaver == False : <EOL> pos = ( pygame . mouse . get_pos ( ) [ <NUM_LIT:0> ] , pygame . mouse . get_pos ( ) [ <NUM_LIT:1> ] ) <EOL> minutes = <NUM_LIT:0> <EOL> on_touch ( ) <EOL> update_screen ( ) <EOL> if minutes > screensaver_timer : <EOL> screensaver = True <EOL> subprocess . call ( '<STR_LIT>' , shell = True ) <EOL> update_screen ( ) <EOL> update_screen ( ) <EOL> time . sleep ( <NUM_LIT:0.1> ) </s>
|
<s> '''<STR_LIT>''' <EOL> import memcache <EOL> class MemConnError ( Exception ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class MemClient : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , timeout = <NUM_LIT:0> ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> self . _hostname = "<STR_LIT>" <EOL> self . _urls = [ ] <EOL> self . connection = None <EOL> def connect ( self , urls , hostname ) : <EOL> '''<STR_LIT>''' <EOL> self . _hostname = hostname <EOL> self . _urls = urls <EOL> self . connection = memcache . Client ( self . _urls , debug = <NUM_LIT:0> ) <EOL> if not self . connection . set ( "<STR_LIT>" , <NUM_LIT:1> ) : <EOL> raise MemConnError ( ) <EOL> def produceKey ( self , keyname ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> if isinstance ( keyname , basestring ) : <EOL> return '<STR_LIT>' . join ( [ self . _hostname , '<STR_LIT::>' , keyname ] ) <EOL> else : <EOL> raise "<STR_LIT>" <EOL> def get ( self , key ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> key = self . produceKey ( key ) <EOL> return self . connection . get ( key ) <EOL> def get_multi ( self , keys ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> keynamelist = [ self . produceKey ( keyname ) for keyname in keys ] <EOL> olddict = self . connection . get_multi ( keynamelist ) <EOL> newdict = dict ( zip ( [ keyname . split ( '<STR_LIT::>' ) [ - <NUM_LIT:1> ] for keyname in olddict . keys ( ) ] , <EOL> olddict . values ( ) ) ) <EOL> return newdict <EOL> def set ( self , keyname , value ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> key = self . produceKey ( keyname ) <EOL> result = self . connection . set ( key , value ) <EOL> if not result : <EOL> self . connect ( self . _urls , self . _hostname ) <EOL> return self . connection . set ( key , value ) <EOL> return result <EOL> def set_multi ( self , mapping ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> newmapping = dict ( zip ( [ self . produceKey ( keyname ) for keyname in mapping . keys ( ) ] , <EOL> mapping . values ( ) ) ) <EOL> result = self . connection . set_multi ( newmapping ) <EOL> if result : <EOL> self . connect ( self . _urls , self . _hostname ) <EOL> return self . connection . set_multi ( newmapping ) <EOL> return result <EOL> def incr ( self , key , delta ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> key = self . produceKey ( key ) <EOL> return self . connection . incr ( key , delta ) <EOL> def delete ( self , key ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> key = self . produceKey ( key ) <EOL> return self . connection . delete ( key ) <EOL> def delete_multi ( self , keys ) : <EOL> """<STR_LIT:U+0020>""" <EOL> keys = [ self . produceKey ( key ) for key in keys ] <EOL> return self . connection . delete_multi ( keys ) <EOL> def flush_all ( self ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> self . connection . flush_all ( ) <EOL> mclient = MemClient ( ) </s>
|
<s> '''<STR_LIT>''' <EOL> from firefly . dbentrust . dbpool import dbpool <EOL> from firefly . dbentrust . madminanager import MAdminManager <EOL> from firefly . dbentrust import mmode <EOL> from firefly . dbentrust . memclient import mclient <EOL> import time <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> hostname = "<STR_LIT:localhost>" <EOL> username = '<STR_LIT:root>' <EOL> password = '<STR_LIT>' <EOL> dbname = '<STR_LIT:test>' <EOL> charset = '<STR_LIT:utf8>' <EOL> tablename = "<STR_LIT>" <EOL> aa = { '<STR_LIT:host>' : "<STR_LIT:localhost>" , <EOL> '<STR_LIT:user>' : '<STR_LIT:root>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' } <EOL> dbpool . initPool ( ** aa ) <EOL> mclient . connect ( [ '<STR_LIT>' ] , "<STR_LIT:test>" ) <EOL> mmanager = MAdminManager ( ) <EOL> m1 = mmode . MAdmin ( '<STR_LIT>' , '<STR_LIT:id>' , incrkey = '<STR_LIT:id>' ) <EOL> m1 . insert ( ) <EOL> print m1 . get ( '<STR_LIT>' ) <EOL> m2 = mmode . MAdmin ( '<STR_LIT>' , '<STR_LIT:id>' , incrkey = '<STR_LIT:id>' ) <EOL> print m2 . get ( '<STR_LIT>' ) </s>
|
<s> """<STR_LIT>""" <EOL> import pexpect <EOL> class connect ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , address ) : <EOL> self . address = "<STR_LIT>" <EOL> self . conn = None <EOL> self . connect ( address ) <EOL> def connect ( self , address , adapter = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if self . conn is None : <EOL> self . address = address <EOL> cmd = '<STR_LIT:U+0020>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , address , '<STR_LIT>' , adapter , '<STR_LIT>' ] ) <EOL> self . conn = pexpect . spawn ( cmd ) <EOL> self . conn . expect ( r'<STR_LIT>' , timeout = <NUM_LIT:1> ) <EOL> self . conn . sendline ( '<STR_LIT>' ) <EOL> try : <EOL> self . conn . expect ( r'<STR_LIT>' , timeout = <NUM_LIT:10> ) <EOL> print ( "<STR_LIT>" + address ) <EOL> except pexpect . TIMEOUT : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def reconnect ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . conn . expect ( r'<STR_LIT>' , timeout = <NUM_LIT:0.1> ) <EOL> self . conn . sendline ( '<STR_LIT>' ) <EOL> try : <EOL> self . conn . expect ( r'<STR_LIT>' , timeout = <NUM_LIT:10> ) <EOL> print ( "<STR_LIT>" + self . address ) <EOL> except pexpect . TIMEOUT : <EOL> print ( "<STR_LIT>" + self . address ) <EOL> return True <EOL> except pexpect . TIMEOUT : <EOL> return False <EOL> def disconnect ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . conn is not None : <EOL> self . conn . sendline ( '<STR_LIT>' ) <EOL> self . conn = None <EOL> print ( "<STR_LIT>" + self . address ) <EOL> def write ( self , handle , value ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT:U+0020>' . join ( [ '<STR_LIT>' , '<STR_LIT>' + handle , value ] ) ) <EOL> def read ( self , handle ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' + handle , r'<STR_LIT>' , timeout = <NUM_LIT:5> ) <EOL> val = '<STR_LIT:U+0020>' . join ( self . conn . after . decode ( "<STR_LIT:utf-8>" ) . split ( ) [ <NUM_LIT:1> : ] ) <EOL> return val <EOL> def send ( self , cmd , expect = None , timeout = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> self . conn . sendline ( cmd ) <EOL> if expect is not None : <EOL> try : <EOL> self . conn . expect ( expect , timeout ) <EOL> except pexpect . TIMEOUT : <EOL> if self . reconnect ( ) : <EOL> self . conn . sendline ( cmd ) <EOL> else : <EOL> if self . reconnect ( ) : <EOL> self . conn . sendline ( cmd ) </s>
|
<s> from __future__ import unicode_literals <EOL> from django . db import models , migrations <EOL> import wagtail . wagtailcore . fields <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> operations = [ <EOL> migrations . AlterField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT:description>' , <EOL> field = models . CharField ( max_length = <NUM_LIT:255> , help_text = '<STR_LIT>' , verbose_name = '<STR_LIT>' , blank = True ) , <EOL> ) , <EOL> migrations . AlterField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT:description>' , <EOL> field = models . CharField ( max_length = <NUM_LIT> , verbose_name = '<STR_LIT>' , blank = True ) , <EOL> ) , <EOL> migrations . AlterField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT:name>' , <EOL> field = models . CharField ( max_length = <NUM_LIT> , unique = True , verbose_name = '<STR_LIT>' ) , <EOL> ) , <EOL> migrations . AlterField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> field = models . ForeignKey ( to = '<STR_LIT>' , related_name = '<STR_LIT>' , null = True , verbose_name = '<STR_LIT>' , blank = True ) , <EOL> ) , <EOL> migrations . AlterField ( <EOL> model_name = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> field = wagtail . wagtailcore . fields . RichTextField ( help_text = '<STR_LIT>' , verbose_name = '<STR_LIT>' , blank = True ) , <EOL> ) , <EOL> ] </s>
|
<s> """<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import matplotlib . pyplot as plt <EOL> import pyart <EOL> XSAPR_SW_FILE = '<STR_LIT>' <EOL> XSAPR_SE_FILE = '<STR_LIT>' <EOL> radar_sw = pyart . io . read_cfradial ( XSAPR_SW_FILE ) <EOL> radar_se = pyart . io . read_cfradial ( XSAPR_SE_FILE ) <EOL> gatefilter_se = pyart . filters . GateFilter ( radar_se ) <EOL> gatefilter_se . exclude_above ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> gatefilter_sw = pyart . filters . GateFilter ( radar_sw ) <EOL> gatefilter_sw . exclude_above ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> grid = pyart . map . grid_from_radars ( <EOL> ( radar_se , radar_sw ) , gatefilters = ( gatefilter_se , gatefilter_sw ) , <EOL> grid_shape = ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , <EOL> grid_limits = ( ( <NUM_LIT:1000> , <NUM_LIT:1000> ) , ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) ) , <EOL> grid_origin = ( <NUM_LIT> , - <NUM_LIT> ) , <EOL> fields = [ '<STR_LIT>' ] ) <EOL> fig = plt . figure ( ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> ax . imshow ( grid . fields [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] , <EOL> origin = '<STR_LIT>' , extent = ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:50> , <NUM_LIT> ) , vmin = <NUM_LIT:0> , vmax = <NUM_LIT> ) <EOL> plt . show ( ) </s>
|
<s> """<STR_LIT>""" <EOL> import os <EOL> import tempfile <EOL> import subprocess <EOL> from . . io . cfradial import read_cfradial <EOL> from . . io . common import _test_arguments <EOL> def read_radx ( filename , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _test_arguments ( kwargs ) <EOL> tmpfile = tempfile . mkstemp ( suffix = '<STR_LIT>' , dir = '<STR_LIT:.>' ) [ <NUM_LIT:1> ] <EOL> head , tail = os . path . split ( tmpfile ) <EOL> try : <EOL> subprocess . check_call ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , head , '<STR_LIT>' , tail , '<STR_LIT>' , filename ] ) <EOL> if not os . path . isfile ( tmpfile ) : <EOL> raise IOError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> radar = read_cfradial ( tmpfile ) <EOL> finally : <EOL> os . remove ( tmpfile ) <EOL> return radar </s>
|
<s> """<STR_LIT>""" <EOL> import warnings <EOL> class MissingOptionalDependency ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DeprecatedAttribute ( DeprecationWarning ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DeprecatedFunctionName ( DeprecationWarning ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _deprecated_alias ( func , old_name , new_name ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( * args , ** kwargs ) : <EOL> warnings . warn ( <EOL> ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) . format ( <EOL> old_name , new_name ) , category = DeprecatedFunctionName ) <EOL> return func ( * args , ** kwargs ) <EOL> return wrapper </s>
|
<s> """<STR_LIT>""" <EOL> import warnings <EOL> import numpy as np <EOL> from . . config import FileMetadata , get_fillvalue <EOL> from . . core . radar import Radar <EOL> from . common import make_time_unit_str , _test_arguments , prepare_for_read <EOL> from . nexrad_level2 import NEXRADLevel2File <EOL> from . . lazydict import LazyLoadDict <EOL> from . nexrad_common import get_nexrad_location <EOL> def read_nexrad_archive ( filename , field_names = None , additional_metadata = None , <EOL> file_field_names = False , exclude_fields = None , <EOL> delay_field_loading = False , station = None , scans = None , <EOL> linear_interp = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _test_arguments ( kwargs ) <EOL> filemetadata = FileMetadata ( '<STR_LIT>' , field_names , <EOL> additional_metadata , file_field_names , <EOL> exclude_fields ) <EOL> nfile = NEXRADLevel2File ( prepare_for_read ( filename ) ) <EOL> scan_info = nfile . scan_info ( scans ) <EOL> time = filemetadata ( '<STR_LIT:time>' ) <EOL> time_start , _time = nfile . get_times ( scans ) <EOL> time [ '<STR_LIT:data>' ] = _time <EOL> time [ '<STR_LIT>' ] = make_time_unit_str ( time_start ) <EOL> _range = filemetadata ( '<STR_LIT>' ) <EOL> first_gate , gate_spacing , last_gate = _find_range_params ( <EOL> scan_info , filemetadata ) <EOL> _range [ '<STR_LIT:data>' ] = np . arange ( first_gate , last_gate , gate_spacing , '<STR_LIT>' ) <EOL> _range [ '<STR_LIT>' ] = float ( first_gate ) <EOL> _range [ '<STR_LIT>' ] = float ( gate_spacing ) <EOL> metadata = filemetadata ( '<STR_LIT>' ) <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> scan_type = '<STR_LIT>' <EOL> latitude = filemetadata ( '<STR_LIT>' ) <EOL> longitude = filemetadata ( '<STR_LIT>' ) <EOL> altitude = filemetadata ( '<STR_LIT>' ) <EOL> if nfile . _msg_type == '<STR_LIT:1>' and station is not None : <EOL> lat , lon , alt = get_nexrad_location ( station ) <EOL> else : <EOL> lat , lon , alt = nfile . location ( ) <EOL> latitude [ '<STR_LIT:data>' ] = np . array ( [ lat ] , dtype = '<STR_LIT>' ) <EOL> longitude [ '<STR_LIT:data>' ] = np . array ( [ lon ] , dtype = '<STR_LIT>' ) <EOL> altitude [ '<STR_LIT:data>' ] = np . array ( [ alt ] , dtype = '<STR_LIT>' ) <EOL> sweep_number = filemetadata ( '<STR_LIT>' ) <EOL> sweep_mode = filemetadata ( '<STR_LIT>' ) <EOL> sweep_start_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> sweep_end_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> if scans is None : <EOL> nsweeps = int ( nfile . nscans ) <EOL> else : <EOL> nsweeps = len ( scans ) <EOL> sweep_number [ '<STR_LIT:data>' ] = np . arange ( nsweeps , dtype = '<STR_LIT>' ) <EOL> sweep_mode [ '<STR_LIT:data>' ] = np . array ( <EOL> nsweeps * [ '<STR_LIT>' ] , dtype = '<STR_LIT:S>' ) <EOL> rays_per_scan = [ s [ '<STR_LIT>' ] for s in scan_info ] <EOL> sweep_end_ray_index [ '<STR_LIT:data>' ] = np . cumsum ( rays_per_scan , dtype = '<STR_LIT>' ) - <NUM_LIT:1> <EOL> rays_per_scan . insert ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> sweep_start_ray_index [ '<STR_LIT:data>' ] = np . cumsum ( <EOL> rays_per_scan [ : - <NUM_LIT:1> ] , dtype = '<STR_LIT>' ) <EOL> azimuth = filemetadata ( '<STR_LIT>' ) <EOL> elevation = filemetadata ( '<STR_LIT>' ) <EOL> fixed_angle = filemetadata ( '<STR_LIT>' ) <EOL> azimuth [ '<STR_LIT:data>' ] = nfile . get_azimuth_angles ( scans ) <EOL> elevation [ '<STR_LIT:data>' ] = nfile . get_elevation_angles ( scans ) . astype ( '<STR_LIT>' ) <EOL> fixed_angle [ '<STR_LIT:data>' ] = nfile . get_target_angles ( scans ) <EOL> max_ngates = len ( _range [ '<STR_LIT:data>' ] ) <EOL> available_moments = set ( [ m for scan in scan_info for m in scan [ '<STR_LIT>' ] ] ) <EOL> interpolate = _find_scans_to_interp ( <EOL> scan_info , first_gate , gate_spacing , filemetadata ) <EOL> fields = { } <EOL> for moment in available_moments : <EOL> field_name = filemetadata . get_field_name ( moment ) <EOL> if field_name is None : <EOL> continue <EOL> dic = filemetadata ( field_name ) <EOL> dic [ '<STR_LIT>' ] = get_fillvalue ( ) <EOL> if delay_field_loading and moment not in interpolate : <EOL> dic = LazyLoadDict ( dic ) <EOL> data_call = _NEXRADLevel2StagedField ( <EOL> nfile , moment , max_ngates , scans ) <EOL> dic . set_lazy ( '<STR_LIT:data>' , data_call ) <EOL> else : <EOL> mdata = nfile . get_data ( moment , max_ngates , scans = scans ) <EOL> if moment in interpolate : <EOL> interp_scans = interpolate [ moment ] <EOL> warnings . warn ( <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" % ( interp_scans , moment ) , <EOL> UserWarning ) <EOL> for scan in interp_scans : <EOL> idx = scan_info [ scan ] [ '<STR_LIT>' ] . index ( moment ) <EOL> moment_ngates = scan_info [ scan ] [ '<STR_LIT>' ] [ idx ] <EOL> start = sweep_start_ray_index [ '<STR_LIT:data>' ] [ scan ] <EOL> end = sweep_end_ray_index [ '<STR_LIT:data>' ] [ scan ] <EOL> _interpolate_scan ( mdata , start , end , moment_ngates , <EOL> linear_interp ) <EOL> dic [ '<STR_LIT:data>' ] = mdata <EOL> fields [ field_name ] = dic <EOL> nyquist_velocity = filemetadata ( '<STR_LIT>' ) <EOL> unambiguous_range = filemetadata ( '<STR_LIT>' ) <EOL> nyquist_velocity [ '<STR_LIT:data>' ] = nfile . get_nyquist_vel ( scans ) . astype ( '<STR_LIT>' ) <EOL> unambiguous_range [ '<STR_LIT:data>' ] = ( <EOL> nfile . get_unambigous_range ( scans ) . astype ( '<STR_LIT>' ) ) <EOL> instrument_parameters = { '<STR_LIT>' : unambiguous_range , <EOL> '<STR_LIT>' : nyquist_velocity , } <EOL> nfile . close ( ) <EOL> return Radar ( <EOL> time , _range , fields , metadata , scan_type , <EOL> latitude , longitude , altitude , <EOL> sweep_number , sweep_mode , fixed_angle , sweep_start_ray_index , <EOL> sweep_end_ray_index , <EOL> azimuth , elevation , <EOL> instrument_parameters = instrument_parameters ) <EOL> def _find_range_params ( scan_info , filemetadata ) : <EOL> """<STR_LIT>""" <EOL> min_first_gate = <NUM_LIT> <EOL> min_gate_spacing = <NUM_LIT> <EOL> max_last_gate = <NUM_LIT:0> <EOL> for scan_params in scan_info : <EOL> ngates = scan_params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> for i , moment in enumerate ( scan_params [ '<STR_LIT>' ] ) : <EOL> if filemetadata . get_field_name ( moment ) is None : <EOL> continue <EOL> first_gate = scan_params [ '<STR_LIT>' ] [ i ] <EOL> gate_spacing = scan_params [ '<STR_LIT>' ] [ i ] <EOL> last_gate = first_gate + gate_spacing * ( ngates - <NUM_LIT:0.5> ) <EOL> min_first_gate = min ( min_first_gate , first_gate ) <EOL> min_gate_spacing = min ( min_gate_spacing , gate_spacing ) <EOL> max_last_gate = max ( max_last_gate , last_gate ) <EOL> return min_first_gate , min_gate_spacing , max_last_gate <EOL> def _find_scans_to_interp ( scan_info , first_gate , gate_spacing , filemetadata ) : <EOL> """<STR_LIT>""" <EOL> moments = set ( [ m for scan in scan_info for m in scan [ '<STR_LIT>' ] ] ) <EOL> interpolate = dict ( [ ( moment , [ ] ) for moment in moments ] ) <EOL> for scan_num , scan in enumerate ( scan_info ) : <EOL> for moment in moments : <EOL> if moment not in scan [ '<STR_LIT>' ] : <EOL> continue <EOL> if filemetadata . get_field_name ( moment ) is None : <EOL> continue <EOL> index = scan [ '<STR_LIT>' ] . index ( moment ) <EOL> first = scan [ '<STR_LIT>' ] [ index ] <EOL> spacing = scan [ '<STR_LIT>' ] [ index ] <EOL> if first != first_gate or spacing != gate_spacing : <EOL> interpolate [ moment ] . append ( scan_num ) <EOL> assert spacing == gate_spacing * <NUM_LIT:4> <EOL> assert first_gate + <NUM_LIT> * gate_spacing == first <EOL> interpolate = dict ( [ ( k , v ) for k , v in interpolate . items ( ) if len ( v ) != <NUM_LIT:0> ] ) <EOL> return interpolate <EOL> def _interpolate_scan ( mdata , start , end , moment_ngates , linear_interp = True ) : <EOL> """<STR_LIT>""" <EOL> for ray_num in range ( start , end + <NUM_LIT:1> ) : <EOL> ray = mdata [ ray_num ] . copy ( ) <EOL> interp_ngates = <NUM_LIT:4> * moment_ngates <EOL> ray [ : interp_ngates ] = np . repeat ( ray [ : moment_ngates ] , <NUM_LIT:4> ) <EOL> if linear_interp : <EOL> for i in range ( <NUM_LIT:2> , interp_ngates - <NUM_LIT:4> , <NUM_LIT:4> ) : <EOL> gate_val = ray [ i ] <EOL> next_val = ray [ i + <NUM_LIT:4> ] <EOL> if np . ma . is_masked ( gate_val ) or np . ma . is_masked ( next_val ) : <EOL> continue <EOL> delta = ( next_val - gate_val ) / <NUM_LIT> <EOL> ray [ i + <NUM_LIT:0> ] = gate_val + delta * <NUM_LIT:0.5> <EOL> ray [ i + <NUM_LIT:1> ] = gate_val + delta * <NUM_LIT> <EOL> ray [ i + <NUM_LIT:2> ] = gate_val + delta * <NUM_LIT> <EOL> ray [ i + <NUM_LIT:3> ] = gate_val + delta * <NUM_LIT> <EOL> mdata [ ray_num ] = ray [ : ] <EOL> class _NEXRADLevel2StagedField ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , nfile , moment , max_ngates , scans ) : <EOL> """<STR_LIT>""" <EOL> self . nfile = nfile <EOL> self . moment = moment <EOL> self . max_ngates = max_ngates <EOL> self . scans = scans <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . nfile . get_data ( <EOL> self . moment , self . max_ngates , scans = self . scans ) </s>
|
<s> """<STR_LIT>""" <EOL> import warnings <EOL> import numpy as np <EOL> from netCDF4 import date2num <EOL> from . . config import FileMetadata , get_fillvalue <EOL> from . . core . radar import Radar <EOL> from . common import make_time_unit_str , _test_arguments , prepare_for_read <EOL> from . uffile import UFFile <EOL> _LIGHT_SPEED = <NUM_LIT> <EOL> _UF_SWEEP_MODES = { <EOL> <NUM_LIT:0> : '<STR_LIT>' , <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' , <EOL> <NUM_LIT:3> : '<STR_LIT>' , <EOL> <NUM_LIT:4> : '<STR_LIT>' , <EOL> <NUM_LIT:5> : '<STR_LIT:target>' , <EOL> <NUM_LIT:6> : '<STR_LIT>' , <EOL> <NUM_LIT:7> : '<STR_LIT>' , <EOL> } <EOL> _SWEEP_MODE_STR = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:target>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def read_uf ( filename , field_names = None , additional_metadata = None , <EOL> file_field_names = False , exclude_fields = None , <EOL> delay_field_loading = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _test_arguments ( kwargs ) <EOL> filemetadata = FileMetadata ( '<STR_LIT>' , field_names , additional_metadata , <EOL> file_field_names , exclude_fields ) <EOL> ufile = UFFile ( prepare_for_read ( filename ) ) <EOL> first_ray = ufile . rays [ <NUM_LIT:0> ] <EOL> dts = ufile . get_datetimes ( ) <EOL> units = make_time_unit_str ( min ( dts ) ) <EOL> time = filemetadata ( '<STR_LIT:time>' ) <EOL> time [ '<STR_LIT>' ] = units <EOL> time [ '<STR_LIT:data>' ] = date2num ( dts , units ) . astype ( '<STR_LIT>' ) <EOL> _range = filemetadata ( '<STR_LIT>' ) <EOL> field_header = first_ray . field_headers [ <NUM_LIT:0> ] <EOL> ngates = field_header [ '<STR_LIT>' ] <EOL> step = field_header [ '<STR_LIT>' ] <EOL> start = ( field_header [ '<STR_LIT>' ] * <NUM_LIT> + <EOL> field_header [ '<STR_LIT>' ] + step / <NUM_LIT> ) <EOL> _range [ '<STR_LIT:data>' ] = np . arange ( ngates , dtype = '<STR_LIT>' ) * step + start <EOL> _range [ '<STR_LIT>' ] = start <EOL> _range [ '<STR_LIT>' ] = step <EOL> latitude = filemetadata ( '<STR_LIT>' ) <EOL> longitude = filemetadata ( '<STR_LIT>' ) <EOL> altitude = filemetadata ( '<STR_LIT>' ) <EOL> lat , lon , height = first_ray . get_location ( ) <EOL> latitude [ '<STR_LIT:data>' ] = np . array ( [ lat ] , dtype = '<STR_LIT>' ) <EOL> longitude [ '<STR_LIT:data>' ] = np . array ( [ lon ] , dtype = '<STR_LIT>' ) <EOL> altitude [ '<STR_LIT:data>' ] = np . array ( [ height ] , dtype = '<STR_LIT>' ) <EOL> metadata = filemetadata ( '<STR_LIT>' ) <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> metadata [ '<STR_LIT>' ] = first_ray . mandatory_header [ '<STR_LIT>' ] <EOL> metadata [ '<STR_LIT>' ] = first_ray . mandatory_header [ '<STR_LIT>' ] <EOL> sweep_start_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> sweep_end_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> sweep_start_ray_index [ '<STR_LIT:data>' ] = ufile . first_ray_in_sweep <EOL> sweep_end_ray_index [ '<STR_LIT:data>' ] = ufile . last_ray_in_sweep <EOL> sweep_number = filemetadata ( '<STR_LIT>' ) <EOL> sweep_number [ '<STR_LIT:data>' ] = np . arange ( ufile . nsweeps , dtype = '<STR_LIT>' ) <EOL> scan_type = _UF_SWEEP_MODES [ first_ray . mandatory_header [ '<STR_LIT>' ] ] <EOL> sweep_mode = filemetadata ( '<STR_LIT>' ) <EOL> sweep_mode [ '<STR_LIT:data>' ] = np . array ( <EOL> ufile . nsweeps * [ _SWEEP_MODE_STR [ scan_type ] ] , dtype = '<STR_LIT:S>' ) <EOL> elevation = filemetadata ( '<STR_LIT>' ) <EOL> elevation [ '<STR_LIT:data>' ] = ufile . get_elevations ( ) <EOL> azimuth = filemetadata ( '<STR_LIT>' ) <EOL> azimuth [ '<STR_LIT:data>' ] = ufile . get_azimuths ( ) <EOL> fixed_angle = filemetadata ( '<STR_LIT>' ) <EOL> fixed_angle [ '<STR_LIT:data>' ] = ufile . get_sweep_fixed_angles ( ) <EOL> fields = { } <EOL> for uf_field_number , uf_field_dic in enumerate ( first_ray . field_positions ) : <EOL> uf_field_name = uf_field_dic [ '<STR_LIT>' ] . decode ( '<STR_LIT:ascii>' ) <EOL> field_name = filemetadata . get_field_name ( uf_field_name ) <EOL> if field_name is None : <EOL> continue <EOL> field_dic = filemetadata ( field_name ) <EOL> field_dic [ '<STR_LIT:data>' ] = ufile . get_field_data ( uf_field_number ) <EOL> field_dic [ '<STR_LIT>' ] = get_fillvalue ( ) <EOL> fields [ field_name ] = field_dic <EOL> instrument_parameters = _get_instrument_parameters ( ufile , filemetadata ) <EOL> scan_rate = filemetadata ( '<STR_LIT>' ) <EOL> scan_rate [ '<STR_LIT:data>' ] = ufile . get_sweep_rates ( ) <EOL> ufile . close ( ) <EOL> return Radar ( <EOL> time , _range , fields , metadata , scan_type , <EOL> latitude , longitude , altitude , <EOL> sweep_number , sweep_mode , fixed_angle , sweep_start_ray_index , <EOL> sweep_end_ray_index , <EOL> azimuth , elevation , <EOL> scan_rate = scan_rate , <EOL> instrument_parameters = instrument_parameters ) <EOL> def _get_instrument_parameters ( ufile , filemetadata ) : <EOL> """<STR_LIT>""" <EOL> pulse_width = filemetadata ( '<STR_LIT>' ) <EOL> pulse_width [ '<STR_LIT:data>' ] = ufile . get_pulse_widths ( ) / _LIGHT_SPEED <EOL> first_ray = ufile . rays [ <NUM_LIT:0> ] <EOL> field_header = first_ray . field_headers [ <NUM_LIT:0> ] <EOL> beam_width_h = field_header [ '<STR_LIT>' ] / <NUM_LIT> <EOL> beam_width_v = field_header [ '<STR_LIT>' ] / <NUM_LIT> <EOL> bandwidth = field_header [ '<STR_LIT>' ] / <NUM_LIT> * <NUM_LIT> <EOL> wavelength_cm = field_header [ '<STR_LIT>' ] / <NUM_LIT> <EOL> if wavelength_cm == <NUM_LIT:0> : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> wavelength_hz = <NUM_LIT> <EOL> else : <EOL> wavelength_hz = _LIGHT_SPEED / ( wavelength_cm / <NUM_LIT> ) <EOL> radar_beam_width_h = filemetadata ( '<STR_LIT>' ) <EOL> radar_beam_width_h [ '<STR_LIT:data>' ] = np . array ( [ beam_width_h ] , dtype = '<STR_LIT>' ) <EOL> radar_beam_width_v = filemetadata ( '<STR_LIT>' ) <EOL> radar_beam_width_v [ '<STR_LIT:data>' ] = np . array ( [ beam_width_v ] , dtype = '<STR_LIT>' ) <EOL> radar_receiver_bandwidth = filemetadata ( '<STR_LIT>' ) <EOL> radar_receiver_bandwidth [ '<STR_LIT:data>' ] = np . array ( [ bandwidth ] , dtype = '<STR_LIT>' ) <EOL> polarization_mode = filemetadata ( '<STR_LIT>' ) <EOL> polarization_mode [ '<STR_LIT:data>' ] = ufile . get_sweep_polarizations ( ) <EOL> frequency = filemetadata ( '<STR_LIT>' ) <EOL> frequency [ '<STR_LIT:data>' ] = np . array ( [ wavelength_hz ] , dtype = '<STR_LIT>' ) <EOL> prt = filemetadata ( '<STR_LIT>' ) <EOL> prt [ '<STR_LIT:data>' ] = ufile . get_prts ( ) / <NUM_LIT> <EOL> instrument_parameters = { <EOL> '<STR_LIT>' : pulse_width , <EOL> '<STR_LIT>' : radar_beam_width_h , <EOL> '<STR_LIT>' : radar_beam_width_v , <EOL> '<STR_LIT>' : radar_receiver_bandwidth , <EOL> '<STR_LIT>' : polarization_mode , <EOL> '<STR_LIT>' : frequency , <EOL> '<STR_LIT>' : prt , <EOL> } <EOL> nyquist_velocity = filemetadata ( '<STR_LIT>' ) <EOL> nyquist_velocity [ '<STR_LIT:data>' ] = ufile . get_nyquists ( ) <EOL> if nyquist_velocity [ '<STR_LIT:data>' ] is not None : <EOL> instrument_parameters [ '<STR_LIT>' ] = nyquist_velocity <EOL> return instrument_parameters </s>
|
<s> """<STR_LIT>""" <EOL> import pyart <EOL> radar = pyart . io . read_rsl ( '<STR_LIT>' ) <EOL> time_slice = slice ( None , <NUM_LIT> , <NUM_LIT> ) <EOL> range_slice = slice ( None , None , <NUM_LIT:12> ) <EOL> sweep_slice = slice ( None , <NUM_LIT:1> ) <EOL> rf_field = radar . fields [ '<STR_LIT>' ] <EOL> rf_data = rf_field [ '<STR_LIT:data>' ] <EOL> rf_field [ '<STR_LIT:data>' ] = rf_data [ time_slice , range_slice ] <EOL> radar . fields = { '<STR_LIT>' : rf_field } <EOL> radar . nsweeps = <NUM_LIT:1> <EOL> radar . nray = <NUM_LIT> <EOL> radar . ngates = <NUM_LIT> <EOL> radar . range [ '<STR_LIT:data>' ] = radar . range [ '<STR_LIT:data>' ] [ range_slice ] <EOL> radar . time [ '<STR_LIT:data>' ] = radar . time [ '<STR_LIT:data>' ] [ time_slice ] <EOL> radar . azimuth [ '<STR_LIT:data>' ] = radar . azimuth [ '<STR_LIT:data>' ] [ time_slice ] <EOL> radar . elevation [ '<STR_LIT:data>' ] = radar . elevation [ '<STR_LIT:data>' ] [ time_slice ] <EOL> radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] = radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] [ time_slice ] <EOL> radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] = radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] [ time_slice ] <EOL> radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] = radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] [ time_slice ] <EOL> radar . sweep_number [ '<STR_LIT:data>' ] = radar . sweep_number [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . fixed_angle [ '<STR_LIT:data>' ] = radar . fixed_angle [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . sweep_start_ray_index [ '<STR_LIT:data>' ] = radar . sweep_start_ray_index [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . sweep_end_ray_index [ '<STR_LIT:data>' ] = radar . sweep_end_ray_index [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . sweep_end_ray_index [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> radar . sweep_mode [ '<STR_LIT:data>' ] = radar . sweep_mode [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . sweep_number [ '<STR_LIT:data>' ] = radar . sweep_number [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] = radar . instrument_parameters [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] [ sweep_slice ] <EOL> radar . metadata = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT:none>' , <EOL> '<STR_LIT:source>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:none>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> pyart . io . write_cfradial ( '<STR_LIT>' , radar ) </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import copy <EOL> import numpy as np <EOL> from netCDF4 import num2date , date2num <EOL> from . import datetime_utils <EOL> def is_vpt ( radar , offset = <NUM_LIT:0.5> ) : <EOL> """<STR_LIT>""" <EOL> elev = radar . elevation [ '<STR_LIT:data>' ] <EOL> return np . all ( ( elev < <NUM_LIT> + offset ) & ( elev > <NUM_LIT> - offset ) ) <EOL> def to_vpt ( radar , single_scan = True ) : <EOL> """<STR_LIT>""" <EOL> if single_scan : <EOL> nsweeps = <NUM_LIT:1> <EOL> radar . azimuth [ '<STR_LIT:data>' ] [ : ] = <NUM_LIT:0.0> <EOL> seri = np . array ( [ radar . nrays - <NUM_LIT:1> ] , dtype = '<STR_LIT>' ) <EOL> radar . sweep_end_ray_index [ '<STR_LIT:data>' ] = seri <EOL> else : <EOL> nsweeps = radar . nrays <EOL> radar . sweep_end_ray_index [ '<STR_LIT:data>' ] = np . arange ( nsweeps , dtype = '<STR_LIT>' ) <EOL> radar . scan_type = '<STR_LIT>' <EOL> radar . nsweeps = nsweeps <EOL> radar . target_scan_rate = None <EOL> radar . elevation [ '<STR_LIT:data>' ] [ : ] = <NUM_LIT> <EOL> radar . sweep_number [ '<STR_LIT:data>' ] = np . arange ( nsweeps , dtype = '<STR_LIT>' ) <EOL> radar . sweep_mode [ '<STR_LIT:data>' ] = np . array ( [ '<STR_LIT>' ] * nsweeps ) <EOL> radar . fixed_angle [ '<STR_LIT:data>' ] = np . ones ( nsweeps , dtype = '<STR_LIT>' ) * <NUM_LIT> <EOL> radar . sweep_start_ray_index [ '<STR_LIT:data>' ] = np . arange ( nsweeps , dtype = '<STR_LIT>' ) <EOL> if radar . instrument_parameters is not None : <EOL> for key in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if key in radar . instrument_parameters : <EOL> ip_dic = radar . instrument_parameters [ key ] <EOL> ip_dic [ '<STR_LIT:data>' ] = np . array ( [ ip_dic [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] ] * nsweeps ) <EOL> return <EOL> def join_radar ( radar1 , radar2 ) : <EOL> """<STR_LIT>""" <EOL> new_radar = copy . deepcopy ( radar1 ) <EOL> new_radar . azimuth [ '<STR_LIT:data>' ] = np . append ( radar1 . azimuth [ '<STR_LIT:data>' ] , <EOL> radar2 . azimuth [ '<STR_LIT:data>' ] ) <EOL> new_radar . elevation [ '<STR_LIT:data>' ] = np . append ( radar1 . elevation [ '<STR_LIT:data>' ] , <EOL> radar2 . elevation [ '<STR_LIT:data>' ] ) <EOL> if len ( radar1 . range [ '<STR_LIT:data>' ] ) >= len ( radar2 . range [ '<STR_LIT:data>' ] ) : <EOL> new_radar . range [ '<STR_LIT:data>' ] = radar1 . range [ '<STR_LIT:data>' ] <EOL> else : <EOL> new_radar . range [ '<STR_LIT:data>' ] = radar2 . range [ '<STR_LIT:data>' ] <EOL> estring = "<STR_LIT>" <EOL> r1dt = num2date ( radar1 . time [ '<STR_LIT:data>' ] , radar1 . time [ '<STR_LIT>' ] ) <EOL> r2dt = num2date ( radar2 . time [ '<STR_LIT:data>' ] , radar2 . time [ '<STR_LIT>' ] ) <EOL> r1num = datetime_utils . datetimes_from_radar ( radar1 , epoch = True ) <EOL> r2num = datetime_utils . datetimes_from_radar ( radar2 , epoch = True ) <EOL> new_radar . time [ '<STR_LIT:data>' ] = np . append ( r1num , r2num ) <EOL> new_radar . time [ '<STR_LIT>' ] = datetime_utils . EPOCH_UNITS <EOL> for var in new_radar . fields . keys ( ) : <EOL> sh1 = radar1 . fields [ var ] [ '<STR_LIT:data>' ] . shape <EOL> sh2 = radar2 . fields [ var ] [ '<STR_LIT:data>' ] . shape <EOL> new_field = np . ma . zeros ( [ sh1 [ <NUM_LIT:0> ] + sh2 [ <NUM_LIT:0> ] , <EOL> max ( [ sh1 [ <NUM_LIT:1> ] , sh2 [ <NUM_LIT:1> ] ] ) ] ) - <NUM_LIT> <EOL> new_field [ <NUM_LIT:0> : sh1 [ <NUM_LIT:0> ] , <NUM_LIT:0> : sh1 [ <NUM_LIT:1> ] ] = radar1 . fields [ var ] [ '<STR_LIT:data>' ] <EOL> new_field [ sh1 [ <NUM_LIT:0> ] : , <NUM_LIT:0> : sh2 [ <NUM_LIT:1> ] ] = radar2 . fields [ var ] [ '<STR_LIT:data>' ] <EOL> new_radar . fields [ var ] [ '<STR_LIT:data>' ] = new_field <EOL> if ( len ( radar1 . latitude [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> & <EOL> len ( radar2 . latitude [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> & <EOL> len ( radar1 . longitude [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> & <EOL> len ( radar2 . longitude [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> & <EOL> len ( radar1 . altitude [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> & <EOL> len ( radar2 . altitude [ '<STR_LIT:data>' ] ) == <NUM_LIT:1> ) : <EOL> lat1 = float ( radar1 . latitude [ '<STR_LIT:data>' ] ) <EOL> lon1 = float ( radar1 . longitude [ '<STR_LIT:data>' ] ) <EOL> alt1 = float ( radar1 . altitude [ '<STR_LIT:data>' ] ) <EOL> lat2 = float ( radar2 . latitude [ '<STR_LIT:data>' ] ) <EOL> lon2 = float ( radar2 . longitude [ '<STR_LIT:data>' ] ) <EOL> alt2 = float ( radar2 . altitude [ '<STR_LIT:data>' ] ) <EOL> if ( lat1 != lat2 ) or ( lon1 != lon2 ) or ( alt1 != alt2 ) : <EOL> ones1 = np . ones ( len ( radar1 . time [ '<STR_LIT:data>' ] ) , dtype = '<STR_LIT>' ) <EOL> ones2 = np . ones ( len ( radar2 . time [ '<STR_LIT:data>' ] ) , dtype = '<STR_LIT>' ) <EOL> new_radar . latitude [ '<STR_LIT:data>' ] = np . append ( ones1 * lat1 , ones2 * lat2 ) <EOL> new_radar . longitude [ '<STR_LIT:data>' ] = np . append ( ones1 * lon1 , ones2 * lon2 ) <EOL> new_radar . latitude [ '<STR_LIT:data>' ] = np . append ( ones1 * alt1 , ones2 * alt2 ) <EOL> else : <EOL> new_radar . latitude [ '<STR_LIT:data>' ] = radar1 . latitude [ '<STR_LIT:data>' ] <EOL> new_radar . longitude [ '<STR_LIT:data>' ] = radar1 . longitude [ '<STR_LIT:data>' ] <EOL> new_radar . altitude [ '<STR_LIT:data>' ] = radar1 . altitude [ '<STR_LIT:data>' ] <EOL> else : <EOL> new_radar . latitude [ '<STR_LIT:data>' ] = np . append ( radar1 . latitude [ '<STR_LIT:data>' ] , <EOL> radar2 . latitude [ '<STR_LIT:data>' ] ) <EOL> new_radar . longitude [ '<STR_LIT:data>' ] = np . append ( radar1 . longitude [ '<STR_LIT:data>' ] , <EOL> radar2 . longitude [ '<STR_LIT:data>' ] ) <EOL> new_radar . altitude [ '<STR_LIT:data>' ] = np . append ( radar1 . altitude [ '<STR_LIT:data>' ] , <EOL> radar2 . altitude [ '<STR_LIT:data>' ] ) <EOL> return new_radar </s>
|
<s> """<STR_LIT>""" <EOL> reboot_policy = '<STR_LIT>' <EOL> execution_order = '<STR_LIT>' <EOL> retry_on_status = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> max_retries = <NUM_LIT:3> <EOL> device = '<STR_LIT>' <EOL> device_config = dict ( <EOL> ) <EOL> instrumentation = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> result_processors = [ <EOL> '<STR_LIT:status>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> logging = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } </s>
|
<s> import logging <EOL> from wlauto import LinuxDevice , Parameter <EOL> from wlauto . common . gem5 . device import BaseGem5Device <EOL> from wlauto . utils import types <EOL> class Gem5LinuxDevice ( BaseGem5Device , LinuxDevice ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> platform = '<STR_LIT>' <EOL> parameters = [ <EOL> Parameter ( '<STR_LIT>' , default = [ ] , override = True ) , <EOL> Parameter ( '<STR_LIT>' , default = [ ] , override = True ) , <EOL> Parameter ( '<STR_LIT:host>' , default = '<STR_LIT:localhost>' , override = True , <EOL> description = '<STR_LIT>' ) , <EOL> Parameter ( '<STR_LIT>' , kind = types . list_of_strs , <EOL> default = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> mandatory = False ) , <EOL> Parameter ( '<STR_LIT>' , kind = types . list_of_strs , <EOL> default = [ '<STR_LIT>' ] , mandatory = False ) , <EOL> ] <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . logger = logging . getLogger ( '<STR_LIT>' ) <EOL> LinuxDevice . __init__ ( self , ** kwargs ) <EOL> BaseGem5Device . __init__ ( self ) <EOL> def login_to_device ( self ) : <EOL> prompt = self . login_prompt + [ self . sckt . UNIQUE_PROMPT ] <EOL> i = self . sckt . expect ( prompt , timeout = <NUM_LIT:10> ) <EOL> if i < len ( prompt ) - <NUM_LIT:1> : <EOL> self . sckt . sendline ( "<STR_LIT:{}>" . format ( self . username ) ) <EOL> password_prompt = self . login_password_prompt + [ r'<STR_LIT>' , self . sckt . UNIQUE_PROMPT ] <EOL> j = self . sckt . expect ( password_prompt , timeout = self . delay ) <EOL> if j < len ( password_prompt ) - <NUM_LIT:2> : <EOL> self . sckt . sendline ( "<STR_LIT:{}>" . format ( self . password ) ) <EOL> self . sckt . expect ( [ r'<STR_LIT>' , self . sckt . UNIQUE_PROMPT ] , timeout = self . delay ) <EOL> def capture_screen ( self , filepath ) : <EOL> if BaseGem5Device . capture_screen ( self , filepath ) : <EOL> return <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> LinuxDevice . capture_screen ( self , filepath ) <EOL> def initialize ( self , context ) : <EOL> self . resize_shell ( ) <EOL> self . deploy_m5 ( context , force = False ) </s>
|
<s> """<STR_LIT>""" <EOL> NAME = '<STR_LIT>' <EOL> DESCRIPTION = '<STR_LIT>' <EOL> VERSION = '<STR_LIT>' </s>
|
<s> import os <EOL> import sqlite3 <EOL> import json <EOL> import uuid <EOL> from datetime import datetime , timedelta <EOL> from contextlib import contextmanager <EOL> from wlauto import ResultProcessor , settings , Parameter <EOL> from wlauto . exceptions import ResultProcessorError <EOL> from wlauto . utils . types import boolean <EOL> SCHEMA_VERSION = '<STR_LIT>' <EOL> SCHEMA = [ <EOL> '''<STR_LIT>''' , <EOL> '''<STR_LIT>''' , <EOL> '''<STR_LIT>''' , <EOL> '''<STR_LIT>''' , <EOL> '''<STR_LIT>''' , <EOL> '''<STR_LIT>''' . format ( SCHEMA_VERSION ) , <EOL> ] <EOL> sqlite3 . register_adapter ( datetime , lambda x : x . isoformat ( ) ) <EOL> sqlite3 . register_adapter ( timedelta , lambda x : x . total_seconds ( ) ) <EOL> sqlite3 . register_adapter ( uuid . UUID , str ) <EOL> class SqliteResultProcessor ( ResultProcessor ) : <EOL> name = '<STR_LIT>' <EOL> description = """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> parameters = [ <EOL> Parameter ( '<STR_LIT>' , default = None , <EOL> global_alias = '<STR_LIT>' , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( '<STR_LIT>' , kind = boolean , default = False , <EOL> global_alias = '<STR_LIT>' , <EOL> description = """<STR_LIT>""" ) , <EOL> ] <EOL> def initialize ( self , context ) : <EOL> self . _last_spec = None <EOL> self . _run_oid = None <EOL> self . _spec_oid = None <EOL> if not os . path . exists ( self . database ) : <EOL> self . _initdb ( ) <EOL> elif self . overwrite : <EOL> os . remove ( self . database ) <EOL> self . _initdb ( ) <EOL> else : <EOL> self . _validate_schema_version ( ) <EOL> self . _update_run ( context . run_info . uuid ) <EOL> def process_iteration_result ( self , result , context ) : <EOL> if self . _last_spec != context . spec : <EOL> self . _update_spec ( context . spec ) <EOL> metrics = [ ( self . _spec_oid , context . current_iteration , m . name , str ( m . value ) , m . units , int ( m . lower_is_better ) ) <EOL> for m in result . metrics ] <EOL> with self . _open_connecton ( ) as conn : <EOL> conn . executemany ( '<STR_LIT>' , metrics ) <EOL> def process_run_result ( self , result , context ) : <EOL> info = context . run_info <EOL> with self . _open_connecton ( ) as conn : <EOL> conn . execute ( '''<STR_LIT>''' , ( info . start_time , info . end_time , info . duration , self . _run_oid ) ) <EOL> def validate ( self ) : <EOL> if not self . database : <EOL> self . database = os . path . join ( settings . output_directory , '<STR_LIT>' ) <EOL> self . database = os . path . expandvars ( os . path . expanduser ( self . database ) ) <EOL> def _initdb ( self ) : <EOL> with self . _open_connecton ( ) as conn : <EOL> for command in SCHEMA : <EOL> conn . execute ( command ) <EOL> def _validate_schema_version ( self ) : <EOL> with self . _open_connecton ( ) as conn : <EOL> try : <EOL> c = conn . execute ( '<STR_LIT>' ) <EOL> found_version = c . fetchone ( ) [ <NUM_LIT:0> ] <EOL> except sqlite3 . OperationalError : <EOL> message = '<STR_LIT>' . format ( self . database ) <EOL> raise ResultProcessorError ( message ) <EOL> if found_version != SCHEMA_VERSION : <EOL> message = '<STR_LIT>' <EOL> raise ResultProcessorError ( message . format ( self . database , found_version , SCHEMA_VERSION ) ) <EOL> def _update_run ( self , run_uuid ) : <EOL> with self . _open_connecton ( ) as conn : <EOL> conn . execute ( '<STR_LIT>' , ( run_uuid , ) ) <EOL> conn . commit ( ) <EOL> c = conn . execute ( '<STR_LIT>' , ( run_uuid , ) ) <EOL> self . _run_oid = c . fetchone ( ) [ <NUM_LIT:0> ] <EOL> def _update_spec ( self , spec ) : <EOL> self . _last_spec = spec <EOL> spec_tuple = ( spec . id , self . _run_oid , spec . number_of_iterations , spec . label , spec . workload_name , <EOL> json . dumps ( spec . boot_parameters ) , json . dumps ( spec . runtime_parameters ) , <EOL> json . dumps ( spec . workload_parameters ) ) <EOL> with self . _open_connecton ( ) as conn : <EOL> conn . execute ( '<STR_LIT>' , spec_tuple ) <EOL> conn . commit ( ) <EOL> c = conn . execute ( '<STR_LIT>' , ( self . _run_oid , spec . id ) ) <EOL> self . _spec_oid = c . fetchone ( ) [ <NUM_LIT:0> ] <EOL> @ contextmanager <EOL> def _open_connecton ( self ) : <EOL> conn = sqlite3 . connect ( self . database ) <EOL> try : <EOL> yield conn <EOL> finally : <EOL> conn . commit ( ) </s>
|
<s> """<STR_LIT>""" <EOL> import telnetlib <EOL> import socket <EOL> import re <EOL> import time <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class NetioError ( Exception ) : <EOL> pass <EOL> class KshellConnection ( object ) : <EOL> response_regex = re . compile ( r'<STR_LIT>' ) <EOL> delay = <NUM_LIT:0.5> <EOL> def __init__ ( self , host = '<STR_LIT>' , port = <NUM_LIT> , timeout = None ) : <EOL> """<STR_LIT>""" <EOL> self . host = host <EOL> self . port = port <EOL> self . conn = telnetlib . Telnet ( host , port , timeout ) <EOL> time . sleep ( self . delay ) <EOL> output = self . conn . read_very_eager ( ) <EOL> if '<STR_LIT>' not in output : <EOL> raise NetioError ( '<STR_LIT>' . format ( output ) ) <EOL> def login ( self , user , password ) : <EOL> code , out = self . send_command ( '<STR_LIT>' . format ( user , password ) ) <EOL> if code != <NUM_LIT> : <EOL> raise NetioError ( '<STR_LIT>' . format ( code , out ) ) <EOL> def enable_port ( self , port ) : <EOL> """<STR_LIT>""" <EOL> self . set_port ( port , <NUM_LIT:1> ) <EOL> def disable_port ( self , port ) : <EOL> """<STR_LIT>""" <EOL> self . set_port ( port , <NUM_LIT:0> ) <EOL> def set_port ( self , port , value ) : <EOL> code , out = self . send_command ( '<STR_LIT>' . format ( port , value ) ) <EOL> if code != <NUM_LIT> : <EOL> raise NetioError ( '<STR_LIT>' . format ( value , port , code , out ) ) <EOL> def send_command ( self , command ) : <EOL> try : <EOL> if command . startswith ( '<STR_LIT>' ) : <EOL> parts = command . split ( ) <EOL> parts [ <NUM_LIT:2> ] = '<STR_LIT:*>' * len ( parts [ <NUM_LIT:2> ] ) <EOL> logger . debug ( '<STR_LIT:U+0020>' . join ( parts ) ) <EOL> else : <EOL> logger . debug ( command ) <EOL> self . conn . write ( '<STR_LIT>' . format ( command ) ) <EOL> time . sleep ( self . delay ) <EOL> out = self . conn . read_very_eager ( ) <EOL> match = self . response_regex . search ( out ) <EOL> if not match : <EOL> raise NetioError ( '<STR_LIT>' . format ( out . strip ( ) ) ) <EOL> logger . debug ( '<STR_LIT>' . format ( match . group ( <NUM_LIT:1> ) , match . group ( <NUM_LIT:2> ) ) ) <EOL> return int ( match . group ( <NUM_LIT:1> ) ) , match . group ( <NUM_LIT:2> ) <EOL> except socket . error as err : <EOL> try : <EOL> time . sleep ( self . delay ) <EOL> out = self . conn . read_very_eager ( ) <EOL> if out . startswith ( '<STR_LIT>' ) : <EOL> raise NetioError ( '<STR_LIT>' ) <EOL> except EOFError : <EOL> pass <EOL> raise err <EOL> def close ( self ) : <EOL> self . conn . close ( ) </s>
|
<s> import os <EOL> import time <EOL> from wlauto import settings , Workload , Executable , Parameter <EOL> from wlauto . exceptions import ConfigError , WorkloadError <EOL> from wlauto . utils . types import boolean <EOL> TXT_RESULT_NAME = '<STR_LIT>' <EOL> RESULT_INTERPRETATION = { <EOL> '<STR_LIT:T>' : '<STR_LIT>' , <EOL> '<STR_LIT:P>' : '<STR_LIT>' , <EOL> '<STR_LIT:C>' : '<STR_LIT>' , <EOL> } <EOL> class Cyclictest ( Workload ) : <EOL> name = '<STR_LIT>' <EOL> description = """<STR_LIT>""" <EOL> parameters = [ <EOL> Parameter ( '<STR_LIT>' , allowed_values = [ '<STR_LIT>' , '<STR_LIT>' ] , default = '<STR_LIT>' , <EOL> description = ( '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = int , default = <NUM_LIT:30> , <EOL> description = ( '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = boolean , default = True , <EOL> description = ( '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = int , default = <NUM_LIT:8> , <EOL> description = ( '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = int , default = <NUM_LIT> , <EOL> description = ( '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = str , default = "<STR_LIT>" , <EOL> description = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = boolean , default = True , <EOL> description = ( '<STR_LIT>' ) ) , <EOL> Parameter ( '<STR_LIT>' , kind = boolean , default = True , <EOL> description = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) , <EOL> ] <EOL> def setup ( self , context ) : <EOL> self . cyclictest_on_device = '<STR_LIT>' <EOL> self . cyclictest_result = os . path . join ( self . device . working_directory , TXT_RESULT_NAME ) <EOL> self . cyclictest_command = '<STR_LIT>' <EOL> self . device_binary = None <EOL> if not self . device . is_rooted : <EOL> raise WorkloadError ( "<STR_LIT>" ) <EOL> host_binary = context . resolver . get ( Executable ( self , self . device . abi , '<STR_LIT>' ) ) <EOL> self . device_binary = self . device . install ( host_binary ) <EOL> self . cyclictest_command = self . cyclictest_command . format ( self . device_binary , <EOL> <NUM_LIT:0> if self . clock == '<STR_LIT>' else <NUM_LIT:1> , <EOL> self . duration , <EOL> self . thread , <EOL> self . latency , <EOL> "<STR_LIT>" if self . quiet else "<STR_LIT>" , <EOL> self . extra_parameters , <EOL> self . cyclictest_result ) <EOL> if self . clear_file_cache : <EOL> self . device . execute ( '<STR_LIT>' ) <EOL> self . device . set_sysfile_value ( '<STR_LIT>' , <NUM_LIT:3> ) <EOL> if self . device . platform == '<STR_LIT>' : <EOL> if self . screen_off and self . device . is_screen_on : <EOL> self . device . execute ( '<STR_LIT>' ) <EOL> def run ( self , context ) : <EOL> self . device . execute ( self . cyclictest_command , self . duration * <NUM_LIT:2> , as_root = True ) <EOL> def update_result ( self , context ) : <EOL> self . device . pull_file ( self . cyclictest_result , context . output_directory ) <EOL> with open ( os . path . join ( context . output_directory , TXT_RESULT_NAME ) ) as f : <EOL> for line in f : <EOL> if line . find ( '<STR_LIT>' ) is not - <NUM_LIT:1> : <EOL> ( key , sperator , remaing ) = line . partition ( '<STR_LIT>' ) <EOL> index = key . find ( '<STR_LIT:T>' ) <EOL> key = key . replace ( key [ index ] , RESULT_INTERPRETATION [ '<STR_LIT:T>' ] ) <EOL> index = key . find ( '<STR_LIT:P>' ) <EOL> key = key . replace ( key [ index ] , RESULT_INTERPRETATION [ '<STR_LIT:P>' ] ) <EOL> index = sperator . find ( '<STR_LIT:C>' ) <EOL> sperator = sperator . replace ( sperator [ index ] , RESULT_INTERPRETATION [ '<STR_LIT:C>' ] ) <EOL> metrics = ( sperator + remaing ) . split ( ) <EOL> for i in range ( <NUM_LIT:0> , len ( metrics ) , <NUM_LIT:2> ) : <EOL> full_key = key + '<STR_LIT:U+0020>' + metrics [ i ] [ : - <NUM_LIT:1> ] <EOL> value = int ( metrics [ i + <NUM_LIT:1> ] ) <EOL> context . result . add_metric ( full_key , value , '<STR_LIT>' ) <EOL> def teardown ( self , context ) : <EOL> if self . device . platform == '<STR_LIT>' : <EOL> if self . screen_off : <EOL> self . device . ensure_screen_is_on ( ) <EOL> self . device . execute ( '<STR_LIT>' . format ( self . cyclictest_result ) ) </s>
|
<s> import os <EOL> import re <EOL> from collections import defaultdict <EOL> from wlauto import Workload , Parameter , File <EOL> from wlauto . utils . types import caseless_string <EOL> from wlauto . exceptions import WorkloadError <EOL> class Recentfling ( Workload ) : <EOL> name = '<STR_LIT>' <EOL> description = """<STR_LIT>""" <EOL> supported_platforms = [ '<STR_LIT>' ] <EOL> parameters = [ <EOL> Parameter ( '<STR_LIT>' , kind = int , default = <NUM_LIT:3> , <EOL> description = "<STR_LIT>" ) , <EOL> ] <EOL> def initialise ( self , context ) : <EOL> if context . device . get_sdk_version ( ) < <NUM_LIT> : <EOL> raise WorkloadError ( "<STR_LIT>" ) <EOL> def setup ( self , context ) : <EOL> self . defs_host = context . resolver . get ( File ( self , "<STR_LIT>" ) ) <EOL> self . recentfling_host = context . resolver . get ( File ( self , "<STR_LIT>" ) ) <EOL> self . device . push_file ( self . recentfling_host , self . device . working_directory ) <EOL> self . device . push_file ( self . defs_host , self . device . working_directory ) <EOL> self . _kill_recentfling ( ) <EOL> self . device . ensure_screen_is_on ( ) <EOL> def run ( self , context ) : <EOL> cmd = "<STR_LIT>" <EOL> cmd = cmd . format ( self . loops , dir = self . device . working_directory ) <EOL> try : <EOL> self . output = self . device . execute ( cmd , timeout = <NUM_LIT> ) <EOL> except KeyboardInterrupt : <EOL> self . _kill_recentfling ( ) <EOL> raise <EOL> def update_result ( self , context ) : <EOL> group_names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> count = <NUM_LIT:0> <EOL> for line in self . output . strip ( ) . splitlines ( ) : <EOL> p = re . compile ( "<STR_LIT>" ) <EOL> match = p . search ( line ) <EOL> if match : <EOL> count += <NUM_LIT:1> <EOL> if line . startswith ( "<STR_LIT>" ) : <EOL> group_names = [ "<STR_LIT>" + g for g in group_names ] <EOL> count = <NUM_LIT:0> <EOL> for metric in zip ( group_names , match . groups ( ) ) : <EOL> context . result . add_metric ( metric [ <NUM_LIT:0> ] , <EOL> metric [ <NUM_LIT:1> ] , <EOL> None , <EOL> classifiers = { "<STR_LIT>" : count or "<STR_LIT>" } ) <EOL> def teardown ( self , context ) : <EOL> self . device . delete_file ( self . device . path . join ( self . device . working_directory , <EOL> "<STR_LIT>" ) ) <EOL> self . device . delete_file ( self . device . path . join ( self . device . working_directory , <EOL> "<STR_LIT>" ) ) <EOL> def _kill_recentfling ( self ) : <EOL> pid = self . device . execute ( '<STR_LIT>' . format ( self . device . working_directory ) ) <EOL> if pid : <EOL> self . device . kill ( pid . strip ( ) , signal = '<STR_LIT>' ) </s>
|
<s> """<STR_LIT>""" <EOL> import sys <EOL> from time import time <EOL> class HtrunLogger ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , prn_lock , name ) : <EOL> self . __prn_lock = prn_lock <EOL> self . __name = name <EOL> def __prn_func ( self , text , nl = True ) : <EOL> """<STR_LIT>""" <EOL> with self . __prn_lock : <EOL> if nl and not text . endswith ( '<STR_LIT:\n>' ) : <EOL> text += '<STR_LIT:\n>' <EOL> sys . stdout . write ( text ) <EOL> sys . stdout . flush ( ) <EOL> def __prn_log_human ( self , level , text , timestamp = None ) : <EOL> if not timestamp : <EOL> timestamp = time ( ) <EOL> timestamp_str = strftime ( "<STR_LIT>" , gmtime ( timestamp ) ) <EOL> frac , whole = modf ( timestamp ) <EOL> s = "<STR_LIT>" % ( timestamp_str , frac , self . __name , level , text ) <EOL> self . __prn_func ( s , nl = True ) <EOL> def __prn_log ( self , level , text , timestamp = None ) : <EOL> if not timestamp : <EOL> timestamp = time ( ) <EOL> s = "<STR_LIT>" % ( timestamp , self . __name , level , text ) <EOL> self . __prn_func ( s , nl = True ) <EOL> def prn_dbg ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) <EOL> def prn_wrn ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) <EOL> def prn_err ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) <EOL> def prn_inf ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) <EOL> def prn_txt ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) <EOL> def prn_txd ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) <EOL> def prn_rxd ( self , text , timestamp = None ) : <EOL> self . __prn_log ( '<STR_LIT>' , text , timestamp ) </s>
|
<s> """<STR_LIT>""" <EOL> import unittest <EOL> from mbed_host_tests import is_host_test <EOL> from mbed_host_tests import get_host_test <EOL> from mbed_host_tests import get_plugin_caps <EOL> from mbed_host_tests import get_host_test_list <EOL> class BasicHostTestsTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_basic_get_host_test ( self ) : <EOL> self . assertNotEqual ( None , get_host_test ( '<STR_LIT:default>' ) ) <EOL> self . assertNotEqual ( None , get_host_test ( '<STR_LIT>' ) ) <EOL> def test_basic_is_host_test ( self ) : <EOL> self . assertFalse ( is_host_test ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( is_host_test ( None ) ) <EOL> self . assertTrue ( is_host_test ( '<STR_LIT:default>' ) ) <EOL> self . assertTrue ( is_host_test ( '<STR_LIT>' ) ) <EOL> def test_get_host_test_list ( self ) : <EOL> d = get_host_test_list ( ) <EOL> self . assertIs ( type ( d ) , dict ) <EOL> self . assertIn ( '<STR_LIT:default>' , d ) <EOL> self . assertIn ( '<STR_LIT>' , d ) <EOL> def test_get_plugin_caps ( self ) : <EOL> d = get_plugin_caps ( ) <EOL> self . assertIs ( type ( d ) , dict ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
|
<s> import sys <EOL> import os <EOL> import subprocess <EOL> import tempfile <EOL> import shutil <EOL> import argparse <EOL> def Parser ( ) : <EOL> the_parser = argparse . ArgumentParser ( <EOL> description = "<STR_LIT>" ) <EOL> the_parser . add_argument ( <EOL> '<STR_LIT>' , action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( <EOL> '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = str , <EOL> help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT:store>" , <EOL> type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( <EOL> '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( <EOL> '<STR_LIT>' , action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( <EOL> '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( '<STR_LIT>' , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( <EOL> '<STR_LIT>' , action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , <EOL> type = str , help = "<STR_LIT>" ) <EOL> the_parser . add_argument ( '<STR_LIT>' , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = str , help = "<STR_LIT>" ) <EOL> args = the_parser . parse_args ( ) <EOL> return args <EOL> def stop_err ( msg ) : <EOL> sys . stderr . write ( '<STR_LIT>' % msg ) <EOL> sys . exit ( ) <EOL> def bowtieCommandLiner ( alignment_method = "<STR_LIT>" , v_mis = "<STR_LIT:1>" , out_type = "<STR_LIT>" , <EOL> aligned = "<STR_LIT:None>" , unaligned = "<STR_LIT:None>" , input_format = "<STR_LIT>" , input = "<STR_LIT:path>" , <EOL> index = "<STR_LIT:path>" , output = "<STR_LIT:path>" , pslots = "<STR_LIT:4>" ) : <EOL> if input_format == "<STR_LIT>" : <EOL> input_format = "<STR_LIT>" <EOL> elif ( input_format == "<STR_LIT>" ) or ( input_format == "<STR_LIT>" ) : <EOL> input_format = "<STR_LIT>" <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if alignment_method == "<STR_LIT>" : <EOL> x = "<STR_LIT>" % ( <EOL> v_mis , pslots ) <EOL> elif alignment_method == "<STR_LIT>" : <EOL> x = "<STR_LIT>" % ( v_mis , pslots ) <EOL> elif alignment_method == "<STR_LIT>" : <EOL> x = "<STR_LIT>" % ( <EOL> v_mis , pslots ) <EOL> elif alignment_method == "<STR_LIT>" : <EOL> x = "<STR_LIT>" % ( v_mis , pslots ) <EOL> elif alignment_method == "<STR_LIT>" : <EOL> x = "<STR_LIT>" % ( v_mis , pslots ) <EOL> elif alignment_method == "<STR_LIT>" : <EOL> x = "<STR_LIT>" % ( v_mis , pslots ) <EOL> if aligned == "<STR_LIT:None>" and unaligned == "<STR_LIT:None>" : <EOL> fasta_command = "<STR_LIT>" <EOL> elif aligned != "<STR_LIT:None>" and unaligned == "<STR_LIT:None>" : <EOL> fasta_command = "<STR_LIT>" % aligned <EOL> elif aligned == "<STR_LIT:None>" and unaligned != "<STR_LIT:None>" : <EOL> fasta_command = "<STR_LIT>" % unaligned <EOL> else : <EOL> fasta_command = "<STR_LIT>" % ( aligned , unaligned ) <EOL> x = x + fasta_command <EOL> if out_type == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( x , index , input_format , input , output ) <EOL> elif out_type == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( x , index , input_format , input , output ) <EOL> elif out_type == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( <EOL> x , index , input_format , input , output ) <EOL> def bowtie_squash ( fasta ) : <EOL> tmp_index_dir = tempfile . mkdtemp ( ) <EOL> ref_file = tempfile . NamedTemporaryFile ( dir = tmp_index_dir ) <EOL> ref_file_name = ref_file . name <EOL> ref_file . close ( ) <EOL> os . symlink ( fasta , ref_file_name ) <EOL> cmd1 = '<STR_LIT>' % ( ref_file_name , ref_file_name ) <EOL> try : <EOL> FNULL = open ( os . devnull , '<STR_LIT:w>' ) <EOL> tmp = tempfile . NamedTemporaryFile ( dir = tmp_index_dir ) . name <EOL> tmp_stderr = open ( tmp , '<STR_LIT:wb>' ) <EOL> proc = subprocess . Popen ( <EOL> args = cmd1 , shell = True , cwd = tmp_index_dir , stderr = FNULL , stdout = FNULL ) <EOL> returncode = proc . wait ( ) <EOL> tmp_stderr . close ( ) <EOL> FNULL . close ( ) <EOL> sys . stdout . write ( cmd1 + "<STR_LIT:\n>" ) <EOL> except Exception as e : <EOL> if os . path . exists ( tmp_index_dir ) : <EOL> shutil . rmtree ( tmp_index_dir ) <EOL> stop_err ( '<STR_LIT>' + str ( e ) ) <EOL> index_full_path = os . path . join ( tmp_index_dir , ref_file_name ) <EOL> return tmp_index_dir , index_full_path <EOL> def bowtie_alignment ( command_line , flyPreIndexed = '<STR_LIT>' ) : <EOL> tmp_index_dir = tempfile . mkdtemp ( ) <EOL> tmp = tempfile . NamedTemporaryFile ( dir = tmp_index_dir ) . name <EOL> tmp_stderr = open ( tmp , '<STR_LIT:wb>' ) <EOL> if "<STR_LIT>" in command_line : <EOL> target_file = command_line . split ( ) [ - <NUM_LIT:1> ] <EOL> path_to_unsortedBam = os . path . join ( tmp_index_dir , "<STR_LIT>" ) <EOL> path_to_sortedBam = os . path . join ( tmp_index_dir , "<STR_LIT>" ) <EOL> first_command_line = "<STR_LIT:U+0020>" . join ( <EOL> command_line . split ( ) [ : - <NUM_LIT:3> ] ) + "<STR_LIT>" + path_to_unsortedBam + "<STR_LIT>" <EOL> second_command_line = "<STR_LIT>" % ( <EOL> path_to_unsortedBam , path_to_sortedBam ) <EOL> p = subprocess . Popen ( <EOL> args = first_command_line , cwd = tmp_index_dir , shell = True , stderr = tmp_stderr . fileno ( ) ) <EOL> returncode = p . wait ( ) <EOL> sys . stdout . write ( "<STR_LIT>" % first_command_line + str ( returncode ) ) <EOL> p = subprocess . Popen ( <EOL> args = second_command_line , cwd = tmp_index_dir , shell = True , stderr = tmp_stderr . fileno ( ) ) <EOL> returncode = p . wait ( ) <EOL> sys . stdout . write ( "<STR_LIT>" % second_command_line + str ( returncode ) ) <EOL> if os . path . isfile ( path_to_sortedBam + "<STR_LIT>" ) : <EOL> shutil . copy2 ( path_to_sortedBam + "<STR_LIT>" , target_file ) <EOL> else : <EOL> p = subprocess . Popen ( <EOL> args = command_line , shell = True , stderr = tmp_stderr . fileno ( ) ) <EOL> returncode = p . wait ( ) <EOL> sys . stdout . write ( command_line + "<STR_LIT:\n>" ) <EOL> tmp_stderr . close ( ) <EOL> if os . path . exists ( flyPreIndexed ) : <EOL> shutil . rmtree ( flyPreIndexed ) <EOL> if os . path . exists ( tmp_index_dir ) : <EOL> shutil . rmtree ( tmp_index_dir ) <EOL> return <EOL> def __main__ ( ) : <EOL> args = Parser ( ) <EOL> F = open ( args . output , "<STR_LIT:w>" ) <EOL> if args . index_from == "<STR_LIT>" : <EOL> tmp_dir , index_path = bowtie_squash ( args . index_source ) <EOL> else : <EOL> tmp_dir , index_path = "<STR_LIT>" , args . index_source <EOL> command_line = bowtieCommandLiner ( args . method , args . v_mismatches , args . output_format , <EOL> args . aligned , args . unaligned , args . input_format , args . input , <EOL> index_path , args . output , args . num_threads ) <EOL> bowtie_alignment ( command_line , flyPreIndexed = tmp_dir ) <EOL> F . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> __main__ ( ) </s>
|
<s> import sys <EOL> input = open ( sys . argv [ <NUM_LIT:1> ] , "<STR_LIT:r>" ) <EOL> output = open ( sys . argv [ <NUM_LIT:2> ] , "<STR_LIT:w>" ) <EOL> for line in input : <EOL> if line [ <NUM_LIT:0> ] == "<STR_LIT:>>" : <EOL> print >> output , "<STR_LIT>" + line [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> continue <EOL> else : <EOL> print >> output , line [ : - <NUM_LIT:1> ] <EOL> print >> output , "<STR_LIT:+>" <EOL> print >> output , "<STR_LIT:H>" * len ( line [ : - <NUM_LIT:1> ] ) <EOL> input . close ( ) <EOL> output . close ( ) </s>
|
<s> """<STR_LIT>""" <EOL> import sys <EOL> import subprocess <EOL> from pelita . simplesetup import SimpleServer , SimplePublisher , SimpleController <EOL> import logging <EOL> from pelita . ui . tk_viewer import TkViewer <EOL> try : <EOL> import colorama <EOL> MAGENTA = colorama . Fore . MAGENTA <EOL> RESET = colorama . Fore . RESET <EOL> except ImportError : <EOL> MAGENTA = "<STR_LIT>" <EOL> RESET = "<STR_LIT>" <EOL> def get_python_process ( ) : <EOL> py_proc = sys . executable <EOL> if not py_proc : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> return py_proc <EOL> FORMAT = '<STR_LIT>' + MAGENTA + '<STR_LIT>' + RESET <EOL> logging . basicConfig ( format = FORMAT , datefmt = "<STR_LIT>" , level = logging . INFO ) <EOL> layout = ( <EOL> """<STR_LIT>""" ) <EOL> server = SimpleServer ( layout_string = layout , rounds = <NUM_LIT:200> , bind_addrs = ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> publisher = SimplePublisher ( "<STR_LIT>" ) <EOL> server . game_master . register_viewer ( publisher ) <EOL> subscribe_sock = server <EOL> tk_open = "<STR_LIT>" % ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> tkprocess = subprocess . Popen ( [ get_python_process ( ) , <EOL> "<STR_LIT:-c>" , <EOL> "<STR_LIT>" + tk_open ] ) <EOL> try : <EOL> print ( server . bind_addresses ) <EOL> server . register_teams ( ) <EOL> controller = SimpleController ( server . game_master , "<STR_LIT>" ) <EOL> controller . run ( ) <EOL> server . exit_teams ( ) <EOL> except KeyboardInterrupt : <EOL> tkprocess . kill ( ) </s>
|
<s> import sublime , sublime_plugin <EOL> import os <EOL> import threading <EOL> import queue <EOL> import asyncore <EOL> import socket <EOL> from itertools import chain <EOL> import re <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> TCP_IP = '<STR_LIT:127.0.0.1>' <EOL> TCP_PORT = <NUM_LIT> <EOL> BUFFER_SIZE = <NUM_LIT> <EOL> BASEDIR = settings . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> STEP_ON_CONNECT = settings . get ( "<STR_LIT>" , False ) <EOL> class SubDebugHandler ( asyncore . dispatcher ) : <EOL> def __init__ ( self , socket , handler_id ) : <EOL> asyncore . dispatcher . __init__ ( self , socket ) <EOL> self . handler_id = handler_id <EOL> msg_queue . put ( b"<STR_LIT>" if STEP_ON_CONNECT else b"<STR_LIT>" ) <EOL> for view_name , row in state_handler . breakpoints ( ) : <EOL> msg_queue . put ( "<STR_LIT>" . format ( view_name , row ) . encode ( '<STR_LIT>' ) ) <EOL> def handle_read ( self ) : <EOL> data = self . recv ( BUFFER_SIZE ) <EOL> if data : <EOL> print ( self . handler_id , "<STR_LIT>" , data ) <EOL> split = data . split ( ) <EOL> if split [ <NUM_LIT:0> ] in message_parsers : <EOL> message_parsers [ split [ <NUM_LIT:0> ] ] ( split ) <EOL> def handle_write ( self ) : <EOL> if not msg_queue . empty ( ) : <EOL> msg = msg_queue . get ( ) <EOL> print ( "<STR_LIT>" , msg ) <EOL> self . send ( msg ) <EOL> def handle_error ( self ) : <EOL> raise <EOL> class SubDebugServer ( asyncore . dispatcher ) : <EOL> def __init__ ( self , host , port ) : <EOL> asyncore . dispatcher . __init__ ( self ) <EOL> self . handler_id = <NUM_LIT:0> <EOL> self . create_socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> self . set_reuse_addr ( ) <EOL> self . bind ( ( host , port ) ) <EOL> self . listen ( <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" , host , "<STR_LIT::>" , port ) <EOL> def handle_accept ( self ) : <EOL> pair = self . accept ( ) <EOL> if pair is not None : <EOL> ( conn_sock , client_address ) = pair <EOL> print ( "<STR_LIT>" , client_address ) <EOL> SubDebugHandler ( conn_sock , + + self . handler_id ) <EOL> def handle_close ( self ) : <EOL> print ( "<STR_LIT>" ) <EOL> self . close ( ) <EOL> def handle_error ( self ) : <EOL> self . close ( ) <EOL> class RunCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> print ( "<STR_LIT>" ) <EOL> msg_queue . put ( b"<STR_LIT>" ) <EOL> state_handler . remove_line_marker ( ) <EOL> class StepCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> print ( "<STR_LIT>" ) <EOL> msg_queue . put ( b"<STR_LIT>" ) <EOL> class ToggleBreakpointCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> view_name = simplify_path ( self . view . file_name ( ) ) <EOL> row , _ = self . view . rowcol ( self . view . sel ( ) [ <NUM_LIT:0> ] . begin ( ) ) <EOL> print ( "<STR_LIT>" , view_name , row ) <EOL> state_handler . toggle_breakpoint ( view_name , row + <NUM_LIT:1> ) <EOL> class SetBasedirCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> def choose_other ( path ) : <EOL> global BASEDIR <EOL> BASEDIR = path . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> if ( BASEDIR [ - <NUM_LIT:1> ] != "<STR_LIT:/>" ) : <EOL> BASEDIR += "<STR_LIT:/>" <EOL> print ( "<STR_LIT>" , BASEDIR ) <EOL> def selected_folder ( index ) : <EOL> global BASEDIR <EOL> if index != - <NUM_LIT:1> : <EOL> if ( index == len ( folders ) - <NUM_LIT:1> ) : <EOL> sublime . active_window ( ) . show_input_panel ( "<STR_LIT>" , BASEDIR , choose_other , None , None ) <EOL> else : <EOL> BASEDIR = folders [ index ] + "<STR_LIT:/>" <EOL> state_handler . clear_state ( ) <EOL> print ( "<STR_LIT>" , BASEDIR ) <EOL> folders = list ( chain . from_iterable ( [ w . folders ( ) for w in sublime . windows ( ) ] ) ) <EOL> folders = [ f . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) for f in folders ] <EOL> folders . insert ( len ( folders ) , "<STR_LIT>" ) <EOL> sublime . active_window ( ) . show_quick_panel ( folders , selected_folder ) <EOL> class ToggleStepOnConnectCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> global STEP_ON_CONNECT <EOL> STEP_ON_CONNECT = not STEP_ON_CONNECT <EOL> print ( "<STR_LIT>" , STEP_ON_CONNECT ) <EOL> def is_checked ( self ) : <EOL> return STEP_ON_CONNECT or False <EOL> def paused_command ( args ) : <EOL> state_handler . set_line_marker ( args [ <NUM_LIT:2> ] . decode ( "<STR_LIT:utf-8>" ) , int ( args [ <NUM_LIT:3> ] ) ) <EOL> message_parsers = { <EOL> b"<STR_LIT>" : paused_command , <EOL> } <EOL> class StateHandler ( ) : <EOL> def __init__ ( self ) : <EOL> self . clear_state ( ) <EOL> self . update_regions ( ) <EOL> def clear_state ( self ) : <EOL> self . state = { } <EOL> self . update_regions ( ) <EOL> def add_missing_views ( self ) : <EOL> views = [ v for v in sum ( [ w . views ( ) for w in sublime . windows ( ) ] , [ ] ) ] <EOL> self . views = { simplify_path ( v . file_name ( ) ) : v for v in views if v . file_name ( ) != None } <EOL> print ( self . views ) <EOL> for view_name , view in self . views . items ( ) : <EOL> if view_name not in self . state : <EOL> self . state [ view_name ] = [ ] <EOL> def update_regions ( self ) : <EOL> self . add_missing_views ( ) <EOL> for view_name , regions in self . state . items ( ) : <EOL> for reg_type_name in self . region_types : <EOL> self . views [ view_name ] . erase_regions ( reg_type_name ) <EOL> region_sets = { } <EOL> for ( reg_type , line ) in regions : <EOL> if reg_type == "<STR_LIT>" or ( "<STR_LIT>" , line ) not in regions : <EOL> if reg_type not in region_sets : <EOL> region_sets [ reg_type ] = [ ] <EOL> region_sets [ reg_type ] . append ( sublime . Region ( self . views [ view_name ] . text_point ( line - <NUM_LIT:1> , <NUM_LIT:0> ) ) ) <EOL> for reg_name , v in region_sets . items ( ) : <EOL> print ( "<STR_LIT>" , view_name , reg_name , v ) <EOL> self . views [ view_name ] . add_regions ( reg_name , v , * self . region_types [ reg_name ] ) <EOL> def set_line_marker ( self , view_name , line_number ) : <EOL> view_name = simplify_path ( view_name ) <EOL> print ( "<STR_LIT>" , view_name , line_number ) <EOL> self . add_missing_views ( ) <EOL> if view_name in self . views : <EOL> self . state . setdefault ( view_name , [ ] ) <EOL> self . state [ view_name ] = [ ( k , v ) for k , v in self . state [ view_name ] if k != "<STR_LIT>" ] <EOL> self . state [ view_name ] . append ( ( "<STR_LIT>" , line_number ) ) <EOL> self . update_regions ( ) <EOL> def remove_line_marker ( self ) : <EOL> for name , view in self . state . items ( ) : <EOL> self . state [ name ] = [ ( t , n ) for t , n in view if t != "<STR_LIT>" ] <EOL> self . update_regions ( ) <EOL> def toggle_breakpoint ( self , view_name , line_number ) : <EOL> self . add_missing_views ( ) <EOL> if view_name in self . views and ( "<STR_LIT>" , line_number ) in self . state [ view_name ] : <EOL> self . remove_breakpoint ( view_name , line_number ) <EOL> else : <EOL> self . set_breakpoint ( view_name , line_number ) <EOL> self . update_regions ( ) <EOL> def set_breakpoint ( self , view_name , line_number ) : <EOL> self . state . setdefault ( view_name , [ ] ) <EOL> self . state [ view_name ] . append ( ( "<STR_LIT>" , line_number ) ) <EOL> msg_queue . put ( "<STR_LIT>" . format ( view_name , line_number ) . encode ( '<STR_LIT>' ) ) <EOL> def remove_breakpoint ( self , view_name , line_number ) : <EOL> self . state [ view_name ] . remove ( ( "<STR_LIT>" , line_number ) ) <EOL> msg_queue . put ( "<STR_LIT>" . format ( view_name , line_number ) . encode ( '<STR_LIT>' ) ) <EOL> def breakpoints ( self ) : <EOL> ret = [ ] <EOL> for k , v in self . state . items ( ) : <EOL> for t in v : <EOL> if t [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> ret . append ( ( k , t [ <NUM_LIT:1> ] ) ) <EOL> return ret <EOL> views = { } <EOL> state = { } <EOL> region_types = { <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> } <EOL> def plugin_unloaded ( ) : <EOL> settings . set ( "<STR_LIT>" , BASEDIR ) <EOL> settings . set ( "<STR_LIT>" , STEP_ON_CONNECT ) <EOL> print ( "<STR_LIT>" ) <EOL> server . close ( ) <EOL> def simplify_path ( path ) : <EOL> path = path . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) . replace ( BASEDIR , "<STR_LIT>" ) <EOL> path = re . sub ( '<STR_LIT>' , '<STR_LIT>' , path ) <EOL> return path <EOL> msg_queue = queue . Queue ( ) <EOL> state_handler = StateHandler ( ) <EOL> server = SubDebugServer ( TCP_IP , TCP_PORT ) <EOL> if os . name == "<STR_LIT>" : <EOL> thread = threading . Thread ( target = asyncore . loop , kwargs = { "<STR_LIT>" : True } ) <EOL> else : <EOL> thread = threading . Thread ( target = asyncore . loop ) <EOL> thread . start ( ) </s>
|
<s> from django . contrib import sitemaps <EOL> from django . core . urlresolvers import reverse <EOL> class StaticViewSitemap ( sitemaps . Sitemap ) : <EOL> priority = <NUM_LIT:0.5> <EOL> changefreq = '<STR_LIT>' <EOL> def items ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] <EOL> def location ( self , item ) : <EOL> return reverse ( item ) </s>
|
<s> from django . conf . urls import patterns , include , url <EOL> from publisher . views import catalog <EOL> from publisher . views import my_publication <EOL> from publisher . views import publication <EOL> urlpatterns = patterns ( '<STR_LIT>' , <EOL> url ( r'<STR_LIT>' , catalog . catalog_page ) , <EOL> url ( r'<STR_LIT>' , publication . publication_page ) , <EOL> url ( r'<STR_LIT>' , publication . peer_review_modal ) , <EOL> url ( r'<STR_LIT>' , publication . save_peer_review ) , <EOL> url ( r'<STR_LIT>' , publication . delete_peer_review ) , <EOL> url ( r'<STR_LIT>' , my_publication . my_publications_page ) , <EOL> url ( r'<STR_LIT>' , my_publication . refresh_publications_table ) , <EOL> url ( r'<STR_LIT>' , my_publication . my_publication_modal ) , <EOL> url ( r'<STR_LIT>' , my_publication . save_publication ) , <EOL> url ( r'<STR_LIT>' , my_publication . delete_publication ) , <EOL> ) </s>
|
<s> from django . core . urlresolvers import resolve <EOL> from django . http import HttpRequest <EOL> from django . http import QueryDict <EOL> from django . test import TestCase <EOL> from django . test import Client <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth import authenticate , login , logout <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . conf . urls . static import static , settings <EOL> import json <EOL> from registrar . models import Course <EOL> from registrar . models import Teacher <EOL> from registrar . models import Student <EOL> from registrar . models import Assignment <EOL> from registrar . models import AssignmentSubmission <EOL> from registrar . models import Quiz <EOL> from registrar . models import QuizSubmission <EOL> from registrar . models import Exam <EOL> from registrar . models import ExamSubmission <EOL> from registrar . models import EssayQuestion <EOL> from registrar . models import EssaySubmission <EOL> from registrar . models import MultipleChoiceQuestion <EOL> from registrar . models import MultipleChoiceSubmission <EOL> from registrar . models import ResponseQuestion <EOL> from registrar . models import ResponseSubmission <EOL> from registrar . models import TrueFalseQuestion <EOL> from registrar . models import TrueFalseSubmission <EOL> from registrar . models import PeerReview <EOL> from student . views import assignment <EOL> from student . views import quiz <EOL> from student . views import exam <EOL> from student . views import credit <EOL> TEST_USER_EMAIL = "<STR_LIT>" <EOL> TEST_USER_USERNAME = "<STR_LIT>" <EOL> TEST_USER_PASSWORD = "<STR_LIT:password>" <EOL> class CreditTestCase ( TestCase ) : <EOL> def tearDown ( self ) : <EOL> courses = Course . objects . all ( ) <EOL> for course in courses : <EOL> course . delete ( ) <EOL> User . objects . get ( email = TEST_USER_EMAIL ) . delete ( ) <EOL> def setUp ( self ) : <EOL> User . objects . create_user ( <EOL> email = TEST_USER_EMAIL , <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> user = User . objects . get ( email = TEST_USER_EMAIL ) <EOL> teacher = Teacher . objects . create ( user = user ) <EOL> student = Student . objects . create ( user = user ) <EOL> course = Course . objects . create ( <EOL> id = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> sub_title = "<STR_LIT>" , <EOL> category = "<STR_LIT>" , <EOL> teacher = teacher , <EOL> ) <EOL> assignment = Assignment . objects . create ( <EOL> assignment_id = <NUM_LIT:1> , <EOL> assignment_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT> , <EOL> course = course , <EOL> ) <EOL> EssayQuestion . objects . create ( <EOL> question_id = <NUM_LIT:1> , <EOL> assignment = assignment , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> ) <EOL> MultipleChoiceQuestion . objects . create ( <EOL> question_id = <NUM_LIT:2> , <EOL> assignment = assignment , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> a = "<STR_LIT>" , <EOL> a_is_correct = True , <EOL> b = "<STR_LIT>" , <EOL> b_is_correct = False , <EOL> c = "<STR_LIT>" , <EOL> c_is_correct = False , <EOL> d = "<STR_LIT>" , <EOL> d_is_correct = False , <EOL> e = "<STR_LIT>" , <EOL> e_is_correct = False , <EOL> ) <EOL> TrueFalseQuestion . objects . create ( <EOL> question_id = <NUM_LIT:3> , <EOL> assignment = assignment , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> true_choice = "<STR_LIT>" , <EOL> false_choice = "<STR_LIT>" , <EOL> answer = True , <EOL> ) <EOL> ResponseQuestion . objects . create ( <EOL> question_id = <NUM_LIT:4> , <EOL> assignment = assignment , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> answer = "<STR_LIT>" , <EOL> ) <EOL> Quiz . objects . create ( <EOL> quiz_id = <NUM_LIT:1> , <EOL> quiz_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT> , <EOL> course = course , <EOL> ) <EOL> quiz = Quiz . objects . get ( quiz_id = <NUM_LIT:1> ) <EOL> TrueFalseQuestion . objects . create ( <EOL> question_id = <NUM_LIT:5> , <EOL> quiz = quiz , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> true_choice = "<STR_LIT>" , <EOL> false_choice = "<STR_LIT>" , <EOL> answer = True , <EOL> ) <EOL> Exam . objects . create ( <EOL> exam_id = <NUM_LIT:1> , <EOL> exam_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT:50> , <EOL> course = course , <EOL> is_final = True , <EOL> ) <EOL> exam = Exam . objects . get ( exam_id = <NUM_LIT:1> ) <EOL> MultipleChoiceQuestion . objects . create ( <EOL> question_id = <NUM_LIT:6> , <EOL> exam = exam , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> a = "<STR_LIT>" , <EOL> a_is_correct = True , <EOL> b = "<STR_LIT>" , <EOL> b_is_correct = False , <EOL> c = "<STR_LIT>" , <EOL> c_is_correct = False , <EOL> d = "<STR_LIT>" , <EOL> d_is_correct = False , <EOL> e = "<STR_LIT>" , <EOL> e_is_correct = False , <EOL> ) <EOL> def get_logged_in_client ( self ) : <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> return client <EOL> def test_url_resolves_to_credit_page_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , credit . credit_page ) <EOL> def test_credit_page_with_no_submissions ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> response = client . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_url_resolves_to_submit_json ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , credit . submit_credit_application ) <EOL> def test_submit_credit_application_on_no_failing_criteria ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client = self . get_logged_in_client ( ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_submit_credit_application_on_passing_criteria_without_peer_reviews ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client = self . get_logged_in_client ( ) <EOL> file_path = settings . MEDIA_ROOT + '<STR_LIT>' <EOL> with open ( file_path , '<STR_LIT:rb>' ) as fp : <EOL> self . assertTrue ( fp is not None ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:file>' : fp <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> try : <EOL> EssaySubmission . objects . get ( submission_id = <NUM_LIT:1> ) . delete ( ) <EOL> except EssaySubmission . DoesNotExist : <EOL> pass <EOL> try : <EOL> EssaySubmission . objects . get ( submission_id = <NUM_LIT:2> ) . delete ( ) <EOL> except EssaySubmission . DoesNotExist : <EOL> pass <EOL> def test_submit_credit_application_on_passing_criteria_with_peer_reviews ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client = self . get_logged_in_client ( ) <EOL> file_path = settings . MEDIA_ROOT + '<STR_LIT>' <EOL> with open ( file_path , '<STR_LIT:rb>' ) as fp : <EOL> self . assertTrue ( fp is not None ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:file>' : fp <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> try : <EOL> EssaySubmission . objects . get ( submission_id = <NUM_LIT:1> ) . delete ( ) <EOL> except EssaySubmission . DoesNotExist : <EOL> pass <EOL> try : <EOL> EssaySubmission . objects . get ( submission_id = <NUM_LIT:2> ) . delete ( ) <EOL> except EssaySubmission . DoesNotExist : <EOL> pass </s>
|
<s> from django . core . urlresolvers import resolve <EOL> from django . http import HttpRequest <EOL> from django . http import QueryDict <EOL> from django . test import TestCase <EOL> from django . test import Client <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth import authenticate , login , logout <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . conf . urls . static import static , settings <EOL> import json <EOL> from registrar . models import Teacher <EOL> from registrar . models import Course <EOL> from registrar . models import Announcement <EOL> from registrar . models import Syllabus <EOL> from registrar . models import Policy <EOL> from registrar . models import Lecture <EOL> from registrar . models import Assignment <EOL> from registrar . models import Quiz <EOL> from registrar . models import Exam <EOL> from registrar . models import CourseSubmission <EOL> from teacher . views import overview <EOL> TEST_USER_EMAIL = "<STR_LIT>" <EOL> TEST_USER_USERNAME = "<STR_LIT>" <EOL> TEST_USER_PASSWORD = "<STR_LIT>" <EOL> TEST_USER_EMAIL2 = "<STR_LIT>" <EOL> TEST_USER_USERNAME2 = "<STR_LIT>" <EOL> TEST_USER_PASSWORD2 = "<STR_LIT>" <EOL> class OverviewTestCase ( TestCase ) : <EOL> def tearDown ( self ) : <EOL> syllabuses = Syllabus . objects . all ( ) <EOL> for syllabus in syllabuses : <EOL> syllabus . delete ( ) <EOL> policies = Policy . objects . all ( ) <EOL> for policy in policies : <EOL> policy . delete ( ) <EOL> courses = Course . objects . all ( ) <EOL> for course in courses : <EOL> course . delete ( ) <EOL> User . objects . all ( ) . delete ( ) <EOL> def setUp ( self ) : <EOL> User . objects . create_user ( <EOL> email = TEST_USER_EMAIL2 , <EOL> username = TEST_USER_USERNAME2 , <EOL> password = TEST_USER_PASSWORD2 <EOL> ) <EOL> user = User . objects . get ( email = TEST_USER_EMAIL2 ) <EOL> teacher = Teacher . objects . create ( user = user ) <EOL> user = User . objects . create_user ( <EOL> email = TEST_USER_EMAIL , <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> teacher = Teacher . objects . create ( user = user ) <EOL> course = Course . objects . create ( <EOL> id = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> sub_title = "<STR_LIT>" , <EOL> category = "<STR_LIT>" , <EOL> teacher = teacher , <EOL> ) <EOL> def populate_course_content ( self , client , kwargs ) : <EOL> course = Course . objects . get ( id = <NUM_LIT:1> ) <EOL> Announcement . objects . create ( <EOL> announcement_id = <NUM_LIT:1> , <EOL> course = course , <EOL> title = '<STR_LIT>' , <EOL> body = '<STR_LIT>' , <EOL> ) <EOL> course = Course . objects . get ( id = <NUM_LIT:1> ) <EOL> file_path = settings . MEDIA_ROOT + '<STR_LIT>' <EOL> with open ( file_path , '<STR_LIT:rb>' ) as fp : <EOL> self . assertTrue ( fp is not None ) <EOL> Syllabus . objects . create ( <EOL> syllabus_id = <NUM_LIT:1> , <EOL> file = '<STR_LIT>' , <EOL> course = course , <EOL> ) <EOL> with open ( file_path , '<STR_LIT:rb>' ) as fp : <EOL> self . assertTrue ( fp is not None ) <EOL> Policy . objects . create ( <EOL> policy_id = <NUM_LIT:1> , <EOL> file = '<STR_LIT>' , <EOL> course = course , <EOL> ) <EOL> Lecture . objects . create ( <EOL> lecture_id = <NUM_LIT:1> , <EOL> lecture_num = <NUM_LIT:1> , <EOL> week_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> course = course , <EOL> ) <EOL> Lecture . objects . create ( <EOL> lecture_id = <NUM_LIT:2> , <EOL> lecture_num = <NUM_LIT:2> , <EOL> week_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> course = course , <EOL> ) <EOL> Assignment . objects . create ( <EOL> assignment_id = <NUM_LIT:1> , <EOL> assignment_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT> , <EOL> course = course , <EOL> ) <EOL> Quiz . objects . create ( <EOL> quiz_id = <NUM_LIT:1> , <EOL> quiz_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT> , <EOL> course = course , <EOL> ) <EOL> Exam . objects . create ( <EOL> exam_id = <NUM_LIT:1> , <EOL> exam_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT:50> , <EOL> course = course , <EOL> is_final = True , <EOL> ) <EOL> def delete_course_content ( self ) : <EOL> for id in range ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> try : <EOL> Syllabus . objects . get ( syllabus_id = id ) . delete ( ) <EOL> except Syllabus . DoesNotExist : <EOL> pass <EOL> try : <EOL> Policy . objects . get ( policy_id = id ) . delete ( ) <EOL> except Policy . DoesNotExist : <EOL> pass <EOL> try : <EOL> Announcement . objects . get ( announcement_id = <NUM_LIT:1> ) . delete ( ) <EOL> except Announcement . DoesNotExist : <EOL> pass <EOL> def get_logged_in_client ( self ) : <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> return client <EOL> def test_url_resolves_to_overview_page_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , overview . overview_page ) <EOL> def test_overview_page ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> response = client . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_submit_course_for_review ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . populate_course_content ( client , kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { } , ** kwargs ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . delete_course_content ( ) </s>
|
<s> """<STR_LIT>""" <EOL> revision = '<STR_LIT>' <EOL> down_revision = '<STR_LIT>' <EOL> branch_labels = None <EOL> depends_on = None <EOL> from alembic import op <EOL> import sqlalchemy as sa <EOL> def upgrade ( ) : <EOL> op . create_table ( '<STR_LIT>' , <EOL> sa . Column ( '<STR_LIT:id>' , sa . Integer ( ) , nullable = False ) , <EOL> sa . Column ( '<STR_LIT:name>' , sa . String ( length = <NUM_LIT:255> ) , nullable = False ) , <EOL> sa . Column ( '<STR_LIT>' , sa . Boolean ( ) , nullable = False ) , <EOL> sa . PrimaryKeyConstraint ( '<STR_LIT:id>' ) <EOL> ) <EOL> op . create_table ( '<STR_LIT>' , <EOL> sa . Column ( '<STR_LIT>' , sa . Integer ( ) , nullable = False ) , <EOL> sa . Column ( '<STR_LIT>' , sa . Integer ( ) , nullable = False ) , <EOL> sa . Column ( '<STR_LIT:value>' , sa . String ( length = <NUM_LIT:255> ) , nullable = True ) , <EOL> sa . Column ( '<STR_LIT>' , sa . Integer ( ) , nullable = True ) , <EOL> sa . Column ( '<STR_LIT>' , sa . Integer ( ) , nullable = False ) , <EOL> sa . ForeignKeyConstraint ( [ '<STR_LIT>' ] , [ '<STR_LIT>' ] , ondelete = '<STR_LIT>' ) , <EOL> sa . ForeignKeyConstraint ( [ '<STR_LIT>' ] , [ '<STR_LIT>' ] , ondelete = '<STR_LIT>' ) , <EOL> sa . ForeignKeyConstraint ( [ '<STR_LIT>' ] , [ '<STR_LIT>' ] , ondelete = '<STR_LIT>' ) , <EOL> sa . PrimaryKeyConstraint ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> op . add_column ( u'<STR_LIT>' , sa . Column ( '<STR_LIT:name>' , sa . String ( length = <NUM_LIT:255> ) , nullable = False , server_default = "<STR_LIT>" ) ) <EOL> def downgrade ( ) : <EOL> op . drop_column ( u'<STR_LIT>' , '<STR_LIT:name>' ) <EOL> op . drop_table ( '<STR_LIT>' ) <EOL> op . drop_table ( '<STR_LIT>' ) </s>
|
<s> import logging <EOL> from applib . base import Cmdln , Application <EOL> from applib . misc import require_option <EOL> from applib import textui , sh , _cmdln as cmdln <EOL> LOG = logging . getLogger ( __name__ ) <EOL> application = Application ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ cmdln . option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> class Commands ( Cmdln ) : <EOL> name = "<STR_LIT>" <EOL> def initialize ( self ) : <EOL> require_option ( self . options , '<STR_LIT:foo>' ) <EOL> @ cmdln . alias ( '<STR_LIT>' ) <EOL> @ cmdln . option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> def do_currentdate ( self , subcmd , opts ) : <EOL> """<STR_LIT>""" <EOL> with self . bootstrapped ( ) : <EOL> from datetime import datetime <EOL> now = datetime . now ( ) <EOL> LOG . debug ( '<STR_LIT>' , now ) <EOL> if opts . show_time : <EOL> print ( now ) <EOL> else : <EOL> print ( now . date ( ) ) <EOL> def do_ls ( self , subcmd , opts ) : <EOL> """<STR_LIT>""" <EOL> with self . bootstrapped ( ) : <EOL> print ( sh . run ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . decode ( '<STR_LIT:utf-8>' ) ) <EOL> def do_makeerror ( self , subcmd , opts , what ) : <EOL> """<STR_LIT>""" <EOL> with self . bootstrapped ( ) : <EOL> LOG . debug ( '<STR_LIT>' , what ) <EOL> textui . askyesno ( '<STR_LIT>' , default = True ) <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> @ cmdln . option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> def do_think ( self , subcmd , opts , length = <NUM_LIT:200> ) : <EOL> """<STR_LIT>""" <EOL> with self . bootstrapped ( ) : <EOL> import time <EOL> length = int ( length ) <EOL> for x in textui . ProgressBar . iterate ( range ( length ) , <EOL> post = '<STR_LIT>' ) : <EOL> if x == length - <NUM_LIT:1> and not opts . no_break : <EOL> break <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> def do_multable ( self , subcmd , opts , number = <NUM_LIT:10> , times = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> with self . bootstrapped ( ) : <EOL> textui . colprint ( [ <EOL> [ str ( x * y ) for y in range ( <NUM_LIT:1> , <NUM_LIT:1> + int ( times ) ) ] <EOL> for x in range ( <NUM_LIT:1> , <NUM_LIT:1> + int ( number ) ) <EOL> ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> application . run ( Commands ) </s>
|
<s> from assertpy import assert_that , fail <EOL> class TestType ( object ) : <EOL> def test_is_type_of ( self ) : <EOL> assert_that ( '<STR_LIT:foo>' ) . is_type_of ( str ) <EOL> assert_that ( <NUM_LIT> ) . is_type_of ( int ) <EOL> assert_that ( <NUM_LIT> ) . is_type_of ( float ) <EOL> assert_that ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) . is_type_of ( list ) <EOL> assert_that ( ( '<STR_LIT:a>' , '<STR_LIT:b>' ) ) . is_type_of ( tuple ) <EOL> assert_that ( { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } ) . is_type_of ( dict ) <EOL> assert_that ( set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) ) . is_type_of ( set ) <EOL> assert_that ( None ) . is_type_of ( type ( None ) ) <EOL> assert_that ( Foo ( ) ) . is_type_of ( Foo ) <EOL> assert_that ( Bar ( ) ) . is_type_of ( Bar ) <EOL> def test_is_type_of_failure ( self ) : <EOL> try : <EOL> assert_that ( '<STR_LIT:foo>' ) . is_type_of ( int ) <EOL> fail ( '<STR_LIT>' ) <EOL> except AssertionError as ex : <EOL> assert_that ( str ( ex ) ) . is_equal_to ( '<STR_LIT>' ) <EOL> def test_is_type_of_bad_arg_failure ( self ) : <EOL> try : <EOL> assert_that ( '<STR_LIT:foo>' ) . is_type_of ( '<STR_LIT>' ) <EOL> fail ( '<STR_LIT>' ) <EOL> except TypeError as ex : <EOL> assert_that ( str ( ex ) ) . is_equal_to ( '<STR_LIT>' ) <EOL> def test_is_type_of_subclass_failure ( self ) : <EOL> try : <EOL> assert_that ( Bar ( ) ) . is_type_of ( Foo ) <EOL> fail ( '<STR_LIT>' ) <EOL> except AssertionError as ex : <EOL> assert_that ( str ( ex ) ) . starts_with ( '<STR_LIT>' ) <EOL> assert_that ( str ( ex ) ) . ends_with ( '<STR_LIT>' ) <EOL> def test_is_instance_of ( self ) : <EOL> assert_that ( '<STR_LIT:foo>' ) . is_instance_of ( str ) <EOL> assert_that ( <NUM_LIT> ) . is_instance_of ( int ) <EOL> assert_that ( <NUM_LIT> ) . is_instance_of ( float ) <EOL> assert_that ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) . is_instance_of ( list ) <EOL> assert_that ( ( '<STR_LIT:a>' , '<STR_LIT:b>' ) ) . is_instance_of ( tuple ) <EOL> assert_that ( { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } ) . is_instance_of ( dict ) <EOL> assert_that ( set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) ) . is_instance_of ( set ) <EOL> assert_that ( None ) . is_instance_of ( type ( None ) ) <EOL> assert_that ( Foo ( ) ) . is_instance_of ( Foo ) <EOL> assert_that ( Bar ( ) ) . is_instance_of ( Bar ) <EOL> assert_that ( Bar ( ) ) . is_instance_of ( Foo ) <EOL> def test_is_instance_of_failure ( self ) : <EOL> try : <EOL> assert_that ( '<STR_LIT:foo>' ) . is_instance_of ( int ) <EOL> fail ( '<STR_LIT>' ) <EOL> except AssertionError as ex : <EOL> assert_that ( str ( ex ) ) . is_equal_to ( '<STR_LIT>' ) <EOL> def test_is_instance_of_bad_arg_failure ( self ) : <EOL> try : <EOL> assert_that ( '<STR_LIT:foo>' ) . is_instance_of ( '<STR_LIT>' ) <EOL> fail ( '<STR_LIT>' ) <EOL> except TypeError as ex : <EOL> assert_that ( str ( ex ) ) . is_equal_to ( '<STR_LIT>' ) <EOL> class Foo ( object ) : <EOL> pass <EOL> class Bar ( Foo ) : <EOL> pass </s>
|
<s> import sys <EOL> import math <EOL> import scipy <EOL> import pylab <EOL> import scipy . io . wavfile as wav <EOL> import wave <EOL> from scipy import signal <EOL> from itertools import product <EOL> import numpy <EOL> def readWav ( ) : <EOL> """<STR_LIT>""" <EOL> sound_wave = wave . open ( sys . argv [ <NUM_LIT:1> ] , "<STR_LIT:r>" ) <EOL> nframes = sound_wave . getnframes ( ) <EOL> framerate = sound_wave . getframerate ( ) <EOL> params = sound_wave . getparams ( ) <EOL> duration = nframes / float ( framerate ) <EOL> print "<STR_LIT>" % ( framerate , ) <EOL> print "<STR_LIT>" % ( nframes , ) <EOL> print "<STR_LIT>" % ( duration , ) <EOL> print scipy . array ( sound_wave ) <EOL> return ( sound_wave , nframes , framerate , duration , params ) <EOL> def getDuration ( sound_file ) : <EOL> """<STR_LIT>""" <EOL> wr = wave . open ( sound_file , '<STR_LIT:r>' ) <EOL> nchannels , sampwidth , framerate , nframes , comptype , compname = wr . getparams ( ) <EOL> return nframes / float ( framerate ) <EOL> def getFrameRate ( sound_file ) : <EOL> """<STR_LIT>""" <EOL> wr = wave . open ( sound_file , '<STR_LIT:r>' ) <EOL> nchannels , sampwidth , framerate , nframes , comptype , compname = wr . getparams ( ) <EOL> return framerate <EOL> def get_channels_no ( sound_file ) : <EOL> """<STR_LIT>""" <EOL> wr = wave . open ( sound_file , '<STR_LIT:r>' ) <EOL> nchannels , sampwidth , framerate , nframes , comptype , compname = wr . getparams ( ) <EOL> return nchannels <EOL> def plotSoundWave ( rate , sample ) : <EOL> """<STR_LIT>""" <EOL> t = scipy . linspace ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:2> * rate , endpoint = False ) <EOL> pylab . figure ( '<STR_LIT>' ) <EOL> T = int ( <NUM_LIT> * rate ) <EOL> pylab . plot ( t [ : T ] , sample [ : T ] , ) <EOL> pylab . show ( ) <EOL> def plotPartials ( binFrequencies , maxFreq , magnitudes ) : <EOL> """<STR_LIT>""" <EOL> T = int ( maxFreq ) <EOL> pylab . figure ( '<STR_LIT>' ) <EOL> pylab . plot ( binFrequencies [ : T ] , magnitudes [ : T ] , ) <EOL> pylab . xlabel ( '<STR_LIT>' ) <EOL> pylab . ylabel ( '<STR_LIT>' ) <EOL> pylab . show ( ) <EOL> def plotPowerSpectrum ( FFT , binFrequencies , maxFreq ) : <EOL> """<STR_LIT>""" <EOL> T = int ( maxFreq ) <EOL> pylab . figure ( '<STR_LIT>' ) <EOL> pylab . plot ( binFrequencies [ : T ] , scipy . absolute ( FFT [ : T ] ) * scipy . absolute ( FFT [ : T ] ) , ) <EOL> pylab . xlabel ( '<STR_LIT>' ) <EOL> pylab . ylabel ( '<STR_LIT>' ) <EOL> pylab . show ( ) <EOL> def get_frequencies_axis ( framerate , fft_length ) : <EOL> binResolution = float ( framerate ) / float ( fft_length ) <EOL> binFreqs = [ ] <EOL> for k in range ( fft_length ) : <EOL> binFreq = k * binResolution <EOL> binFreqs . append ( binFreq ) <EOL> return binFreqs <EOL> def get_next_power_2 ( n ) : <EOL> """<STR_LIT>""" <EOL> power = <NUM_LIT:1> <EOL> while ( power < n ) : <EOL> power *= <NUM_LIT:2> <EOL> if power > <NUM_LIT:1> : <EOL> return power / <NUM_LIT:2> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> class MIDI_Detector ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wav_file ) : <EOL> self . wav_file = wav_file <EOL> self . minFreqConsidered = <NUM_LIT:20> <EOL> self . maxFreqConsidered = <NUM_LIT> <EOL> self . low_f0s = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> def detect_MIDI_notes ( self ) : <EOL> """<STR_LIT>""" <EOL> ( framerate , sample ) = wav . read ( self . wav_file ) <EOL> if get_channels_no ( self . wav_file ) > <NUM_LIT:1> : <EOL> sample = sample . mean ( axis = <NUM_LIT:1> ) <EOL> duration = getDuration ( self . wav_file ) <EOL> midi_notes = [ ] <EOL> if duration > <NUM_LIT> : <EOL> FFT , filteredFreqs , maxFreq , magnitudes , significant_freq = self . calculateFFT ( duration , framerate , sample ) <EOL> clusters = self . clusterFrequencies ( filteredFreqs ) <EOL> averagedClusters = self . getClustersMeans ( clusters ) <EOL> f0_candidates = self . getF0Candidates ( averagedClusters ) <EOL> midi_notes = self . matchWithMIDINotes ( f0_candidates ) <EOL> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' <EOL> return midi_notes <EOL> def remove_lower_octave ( self , upper_octave , midi_notes ) : <EOL> lower_octave = upper_octave - <NUM_LIT:12> <EOL> if lower_octave in midi_notes : <EOL> midi_notes . remove ( lower_octave ) <EOL> return midi_notes <EOL> def get_candidates_with_partials ( self , frequencies , magnitudes ) : <EOL> print frequencies <EOL> partial_margin = <NUM_LIT> <EOL> candidates_freq = [ ] <EOL> candidates_magnitude = [ ] <EOL> for i in range ( len ( frequencies ) ) : <EOL> partials , partial_magnitudes = self . find_partials ( <EOL> frequencies [ i : ] , frequencies [ i ] , magnitudes [ i : ] ) <EOL> candidates_freq . append ( partials ) <EOL> candidates_magnitude . append ( partial_magnitudes ) <EOL> return ( candidates_freq , candidates_magnitude ) <EOL> def calculateFFT ( self , duration , framerate , sample ) : <EOL> """<STR_LIT>""" <EOL> fft_length = int ( duration * framerate ) <EOL> fft_length = get_next_power_2 ( fft_length ) <EOL> FFT = numpy . fft . fft ( sample , n = fft_length ) <EOL> '''<STR_LIT>''' <EOL> threshold = <NUM_LIT:0> <EOL> power_spectra = [ ] <EOL> frequency_bin_with_max_spectrum = <NUM_LIT:0> <EOL> for i in range ( len ( FFT ) / <NUM_LIT:2> ) : <EOL> power_spectrum = scipy . absolute ( FFT [ i ] ) * scipy . absolute ( FFT [ i ] ) <EOL> if power_spectrum > threshold : <EOL> threshold = power_spectrum <EOL> frequency_bin_with_max_spectrum = i <EOL> power_spectra . append ( power_spectrum ) <EOL> max_power_spectrum = threshold <EOL> threshold *= <NUM_LIT:0.1> <EOL> binFrequencies = [ ] <EOL> magnitudes = [ ] <EOL> binResolution = float ( framerate ) / float ( fft_length ) <EOL> sum_of_significant_spectra = <NUM_LIT:0> <EOL> for k in range ( len ( FFT ) ) : <EOL> binFreq = k * binResolution <EOL> if binFreq > self . maxFreqConsidered : <EOL> FFT = FFT [ : k ] <EOL> break <EOL> elif binFreq > self . minFreqConsidered : <EOL> power_spectrum = power_spectra [ k ] <EOL> if power_spectrum > threshold : <EOL> magnitudes . append ( power_spectrum ) <EOL> binFrequencies . append ( binFreq ) <EOL> if power_spectrum != max_power_spectrum : <EOL> sum_of_significant_spectra += power_spectrum <EOL> significant_freq = <NUM_LIT:0.0> <EOL> if max_power_spectrum > sum_of_significant_spectra : <EOL> significant_freq = frequency_bin_with_max_spectrum * binResolution <EOL> maxFreq = len ( FFT ) / duration <EOL> return ( FFT , binFrequencies , maxFreq , magnitudes , significant_freq ) <EOL> def STFT ( self , x , samplingFreq , framesz , hop ) : <EOL> """<STR_LIT>""" <EOL> framesamp = int ( framesz * samplingFreq ) <EOL> print '<STR_LIT>' + str ( framesamp ) <EOL> hopsamp = int ( hop * samplingFreq ) <EOL> print '<STR_LIT>' + str ( hopsamp ) <EOL> w = signal . hann ( framesamp ) <EOL> X = numpy . array ( [ numpy . fft . fft ( w * x [ i : i + framesamp ] ) <EOL> for i in range ( <NUM_LIT:0> , len ( x ) - framesamp , hopsamp ) ] ) <EOL> return X <EOL> def plotMagnitudeSpectrogram ( self , rate , sample , framesz , hop ) : <EOL> """<STR_LIT>""" <EOL> X = self . STFT ( sample , rate , framesz , hop ) <EOL> pylab . figure ( '<STR_LIT>' ) <EOL> pylab . imshow ( scipy . absolute ( X . T ) , origin = '<STR_LIT>' , aspect = '<STR_LIT>' , <EOL> interpolation = '<STR_LIT>' ) <EOL> pylab . xlabel ( '<STR_LIT>' ) <EOL> pylab . ylabel ( '<STR_LIT>' ) <EOL> pylab . show ( ) <EOL> def getFilteredFFT ( self , FFT , duration , threshold ) : <EOL> """<STR_LIT>""" <EOL> significantFreqs = [ ] <EOL> for i in range ( len ( FFT ) ) : <EOL> power_spectrum = scipy . absolute ( FFT [ i ] ) * scipy . absolute ( FFT [ i ] ) <EOL> if power_spectrum > threshold : <EOL> significantFreqs . append ( i / duration ) <EOL> return significantFreqs <EOL> def clusterFrequencies ( self , freqs ) : <EOL> """<STR_LIT>""" <EOL> if len ( freqs ) == <NUM_LIT:0> : <EOL> return { } <EOL> clusteredFreqs = { } <EOL> bin = <NUM_LIT:0> <EOL> clusteredFreqs [ <NUM_LIT:0> ] = [ freqs [ <NUM_LIT:0> ] ] <EOL> for i in range ( len ( freqs ) - <NUM_LIT:1> ) : <EOL> dist = self . calcDistance ( freqs [ i ] , freqs [ i + <NUM_LIT:1> ] ) <EOL> if dist < <NUM_LIT> : <EOL> clusteredFreqs [ bin ] . append ( freqs [ i + <NUM_LIT:1> ] ) <EOL> else : <EOL> bin += <NUM_LIT:1> <EOL> clusteredFreqs [ bin ] = [ freqs [ i + <NUM_LIT:1> ] ] <EOL> return clusteredFreqs <EOL> def getClustersMeans ( self , clusters ) : <EOL> """<STR_LIT>""" <EOL> means = [ ] <EOL> for bin , freqs in clusters . iteritems ( ) : <EOL> means . append ( sum ( freqs ) / len ( freqs ) ) <EOL> return means <EOL> def getDistances ( self , freqs ) : <EOL> """<STR_LIT>""" <EOL> distances = { ( freqs [ i ] , freqs [ j ] ) : self . calcDistance ( freqs [ i ] , freqs [ j ] ) <EOL> for ( i , j ) in product ( range ( len ( freqs ) ) , repeat = <NUM_LIT:2> ) } <EOL> distances = { freq_pair : dist for freq_pair , dist in distances . iteritems ( ) if dist < <NUM_LIT> } <EOL> return distances <EOL> def calcDistance ( self , freq1 , freq2 ) : <EOL> """<STR_LIT>""" <EOL> difference = abs ( freq1 - freq2 ) <EOL> log = math . log ( ( freq1 + freq2 ) / <NUM_LIT:2> ) <EOL> return difference / log <EOL> def getF0Candidates ( self , frequencies ) : <EOL> """<STR_LIT>""" <EOL> f0_candidates = [ ] <EOL> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' <EOL> while len ( frequencies ) > <NUM_LIT:0> : <EOL> f0_candidate = frequencies [ <NUM_LIT:0> ] <EOL> f0_candidates . append ( f0_candidate ) <EOL> frequencies . remove ( f0_candidate ) <EOL> frequencies = self . filterOutHarmonics ( frequencies , f0_candidate ) <EOL> return f0_candidates <EOL> def filterOutHarmonics ( self , frequencies , f0_candidate ) : <EOL> """<STR_LIT>""" <EOL> REMAINDER_THRESHOLD = <NUM_LIT> <EOL> def is_multiple ( f , f0 ) : <EOL> return abs ( round ( f / f0 ) - f / f0 ) < REMAINDER_THRESHOLD <EOL> return [ f for f in frequencies if not is_multiple ( f , f0_candidate ) ] <EOL> def find_low_freq_candidate ( self , frequencies ) : <EOL> REMAINDER_THRESHOLD = <NUM_LIT> <EOL> f0_candidates = [ ] <EOL> def is_multiple ( f , f0 ) : <EOL> return abs ( round ( f / f0 ) - f / f0 ) < REMAINDER_THRESHOLD <EOL> best_candidate = - <NUM_LIT:1> <EOL> max_no_partials = <NUM_LIT:0> <EOL> for low_f0 in self . low_f0s : <EOL> num_of_partials = <NUM_LIT:0> <EOL> for f in frequencies : <EOL> if is_multiple ( f , low_f0 ) : <EOL> num_of_partials += <NUM_LIT:1> <EOL> if num_of_partials > max_no_partials : <EOL> max_no_partials = num_of_partials <EOL> best_candidate = low_f0 <EOL> return best_candidate <EOL> def find_partials ( self , frequencies , f0_candidate , magnitudes ) : <EOL> """<STR_LIT>""" <EOL> REMAINDER_THRESHOLD = <NUM_LIT> <EOL> def is_multiple ( f , f0 ) : <EOL> return abs ( round ( f / f0 ) - f / f0 ) < REMAINDER_THRESHOLD <EOL> partials = [ ] <EOL> partial_magnitudes = [ ] <EOL> for i in range ( len ( frequencies ) ) : <EOL> if is_multiple ( frequencies [ i ] , f0_candidate ) : <EOL> partials . append ( frequencies [ i ] ) <EOL> partial_magnitudes . append ( magnitudes [ i ] ) <EOL> return ( partials , partial_magnitudes ) <EOL> def matchWithMIDINotes ( self , f0_candidates ) : <EOL> midi_notes = [ ] <EOL> for freq in f0_candidates : <EOL> midi_notes . append ( int ( <EOL> round ( <NUM_LIT> + <NUM_LIT:12> * math . log ( freq / <NUM_LIT> ) / math . log ( <NUM_LIT:2> ) ) ) ) <EOL> return midi_notes <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> MIDI_detector = MIDI_Detector ( sys . argv [ <NUM_LIT:1> ] ) <EOL> midi_notes = MIDI_detector . detect_MIDI_notes ( ) <EOL> print midi_notes </s>
|
<s> __author__ = '<STR_LIT>' <EOL> class Action ( object ) : <EOL> def GetActionName ( self ) : <EOL> return self . __name <EOL> def SetActionName ( self , name ) : <EOL> self . __name = name <EOL> def __init__ ( self , name ) : <EOL> self . __name = name </s>
|
<s> import _cffi_backend <EOL> ffi = _cffi_backend . FFI ( '<STR_LIT>' , <EOL> _version = <NUM_LIT> , <EOL> _types = b'<STR_LIT>' , <EOL> _globals = ( b'<STR_LIT>' , <NUM_LIT:0> , ) , <EOL> ) </s>
|
<s> from dnslib import * <EOL> packet = binascii . unhexlify ( b'<STR_LIT>' ) <EOL> d = DNSRecord . parse ( packet ) <EOL> print d </s>
|
<s> from app import app <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> app . run ( ) </s>
|
<s> from flask import render_template , Blueprint , redirect , request , url_for <EOL> from . . forms import SigninForm , SignupForm <EOL> from . . utils . account import signin_user , signout_user <EOL> from . . utils . permissions import VisitorPermission , UserPermission <EOL> from . . models import db , User <EOL> bp = Blueprint ( '<STR_LIT>' , __name__ ) <EOL> @ bp . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ VisitorPermission ( ) <EOL> def signin ( ) : <EOL> """<STR_LIT>""" <EOL> form = SigninForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> signin_user ( form . user ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ bp . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ VisitorPermission ( ) <EOL> def signup ( ) : <EOL> """<STR_LIT>""" <EOL> form = SignupForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> params = form . data . copy ( ) <EOL> params . pop ( '<STR_LIT>' ) <EOL> user = User ( ** params ) <EOL> db . session . add ( user ) <EOL> db . session . commit ( ) <EOL> signin_user ( user ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ bp . route ( '<STR_LIT>' ) <EOL> def signout ( ) : <EOL> """<STR_LIT>""" <EOL> signout_user ( ) <EOL> return redirect ( request . referrer or url_for ( '<STR_LIT>' ) ) </s>
|
<s> from app import app , db <EOL> import unittest <EOL> import os <EOL> import tempfile <EOL> from flask import json <EOL> TEST_DB = '<STR_LIT>' <EOL> class BasicTestCase ( unittest . TestCase ) : <EOL> def test_index ( self ) : <EOL> """<STR_LIT>""" <EOL> tester = app . test_client ( self ) <EOL> response = tester . get ( '<STR_LIT:/>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_database ( self ) : <EOL> """<STR_LIT>""" <EOL> tester = os . path . exists ( "<STR_LIT>" ) <EOL> self . assertTrue ( tester ) <EOL> class FlaskrTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> basedir = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> app . config [ '<STR_LIT>' ] = True <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' + os . path . join ( basedir , TEST_DB ) <EOL> self . app = app . test_client ( ) <EOL> db . create_all ( ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> db . drop_all ( ) <EOL> def login ( self , username , password ) : <EOL> """<STR_LIT>""" <EOL> return self . app . post ( '<STR_LIT>' , data = dict ( <EOL> username = username , <EOL> password = password <EOL> ) , follow_redirects = True ) <EOL> def logout ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . app . get ( '<STR_LIT>' , follow_redirects = True ) <EOL> def test_empty_db ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . app . get ( '<STR_LIT:/>' ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> def test_login_logout ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . login ( app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> rv = self . logout ( ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> rv = self . login ( app . config [ '<STR_LIT>' ] + '<STR_LIT:x>' , app . config [ '<STR_LIT>' ] ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> rv = self . login ( app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] + '<STR_LIT:x>' ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> def test_messages ( self ) : <EOL> """<STR_LIT>""" <EOL> self . login ( app . config [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] ) <EOL> rv = self . app . post ( '<STR_LIT>' , data = dict ( <EOL> title = '<STR_LIT>' , <EOL> text = '<STR_LIT>' <EOL> ) , follow_redirects = True ) <EOL> self . assertNotIn ( b'<STR_LIT>' , rv . data ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> self . assertIn ( b'<STR_LIT>' , rv . data ) <EOL> def test_delete_message ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . app . get ( '<STR_LIT>' ) <EOL> data = json . loads ( rv . data ) <EOL> self . assertEqual ( data [ '<STR_LIT:status>' ] , <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
|
<s> import json <EOL> data = [ { '<STR_LIT:a>' : '<STR_LIT:A>' , '<STR_LIT:b>' : ( <NUM_LIT:2> , <NUM_LIT:4> ) , '<STR_LIT:c>' : <NUM_LIT> } ] <EOL> print '<STR_LIT>' , repr ( data ) <EOL> unsorted = json . dumps ( data ) <EOL> print '<STR_LIT>' , json . dumps ( data ) <EOL> print '<STR_LIT>' , json . dumps ( data , sort_keys = True ) <EOL> first = json . dumps ( data , sort_keys = True ) <EOL> second = json . dumps ( data , sort_keys = True ) <EOL> print '<STR_LIT>' , unsorted == first <EOL> print '<STR_LIT>' , first == second </s>
|
<s> people = <NUM_LIT:30> <EOL> cars = <NUM_LIT> <EOL> trucks = <NUM_LIT:15> <EOL> if cars > people : <EOL> print "<STR_LIT>" <EOL> elif cars < people : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> if trucks > cars : <EOL> print "<STR_LIT>" <EOL> elif trucks < cars : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> if people > trucks : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" </s>
|
<s> import thread <EOL> import time <EOL> mylock = thread . allocate_lock ( ) <EOL> num = <NUM_LIT:0> <EOL> def add_num ( name ) : <EOL> global num <EOL> while True : <EOL> mylock . acquire ( ) <EOL> print ( '<STR_LIT>' % ( name , str ( num ) ) ) <EOL> if num >= <NUM_LIT:5> : <EOL> print ( '<STR_LIT>' % ( name , str ( num ) ) ) <EOL> mylock . release ( ) <EOL> thread . exit ( ) <EOL> num += <NUM_LIT:1> <EOL> print ( '<STR_LIT>' % ( name , str ( num ) ) ) <EOL> mylock . release ( ) <EOL> def test ( ) : <EOL> thread . start_new_thread ( add_num , ( '<STR_LIT:A>' , ) ) <EOL> thread . start_new_thread ( add_num , ( '<STR_LIT:B>' , ) ) <EOL> time . sleep ( <NUM_LIT:30> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test ( ) </s>
|
<s> """<STR_LIT>""" <EOL> import os . path <EOL> import os <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> print os . path . expandvars ( '<STR_LIT>' ) </s>
|
<s> from __future__ import print_function <EOL> import pyglet <EOL> from pyglet . window import key <EOL> from pyglet . window import mouse <EOL> window = pyglet . window . Window ( ) <EOL> @ window . event <EOL> def on_key_press ( symbol , modifiers ) : <EOL> print ( "<STR_LIT>" % symbol ) <EOL> if symbol == key . A : <EOL> print ( '<STR_LIT>' ) <EOL> elif symbol == key . LEFT : <EOL> print ( '<STR_LIT>' ) <EOL> elif symbol == key . ENTER : <EOL> print ( '<STR_LIT>' ) <EOL> @ window . event <EOL> def on_mouse_press ( x , y , button , modifiers ) : <EOL> print ( "<STR_LIT>" % ( x , y , button ) ) <EOL> if button == mouse . LEFT : <EOL> print ( '<STR_LIT>' ) <EOL> @ window . event <EOL> def on_draw ( ) : <EOL> window . clear ( ) <EOL> pyglet . app . run ( ) </s>
|
<s> number = <NUM_LIT> <EOL> go = True <EOL> while go : <EOL> guess = int ( raw_input ( '<STR_LIT>' ) ) <EOL> if guess == number : <EOL> print '<STR_LIT>' <EOL> go = False <EOL> elif guess < number : <EOL> print '<STR_LIT>' <EOL> else : <EOL> print '<STR_LIT>' <EOL> else : <EOL> print '<STR_LIT>' </s>
|
<s> import os <EOL> from setuptools import setup , find_packages <EOL> here = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> with open ( os . path . join ( here , '<STR_LIT>' ) ) as f : <EOL> README = f . read ( ) <EOL> with open ( os . path . join ( here , '<STR_LIT>' ) ) as f : <EOL> CHANGES = f . read ( ) <EOL> requires = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> setup ( name = '<STR_LIT>' , <EOL> version = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> long_description = README + '<STR_LIT>' + CHANGES , <EOL> classifiers = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> author = '<STR_LIT>' , <EOL> author_email = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> keywords = '<STR_LIT>' , <EOL> packages = find_packages ( ) , <EOL> include_package_data = True , <EOL> zip_safe = False , <EOL> test_suite = '<STR_LIT>' , <EOL> install_requires = requires , <EOL> entry_points = """<STR_LIT>""" , <EOL> ) </s>
|
<s> from mako . template import Template <EOL> from mako . runtime import Context <EOL> from StringIO import StringIO <EOL> mytemplate = Template ( "<STR_LIT>" ) <EOL> buf = StringIO ( ) <EOL> ctx = Context ( buf , name = "<STR_LIT>" ) <EOL> mytemplate . render_context ( ctx ) <EOL> print ( buf . getvalue ( ) ) </s>
|
<s> """<STR_LIT>""" <EOL> import unittest <EOL> class InequalityTest ( unittest . TestCase ) : <EOL> def testEqual ( self ) : <EOL> self . failIfEqual ( <NUM_LIT:1> , <NUM_LIT:3> - <NUM_LIT:2> ) <EOL> def testNotEqual ( self ) : <EOL> self . failUnlessEqual ( <NUM_LIT:2> , <NUM_LIT:3> - <NUM_LIT:2> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
|
<s> from flask import Flask <EOL> from flask . ext . fragment import Fragment <EOL> from flask . ext . login import LoginManager <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> app = Flask ( __name__ ) <EOL> db = SQLAlchemy ( app ) <EOL> fragment = Fragment ( app ) <EOL> login = LoginManager ( app ) <EOL> from models import User , Post , Comment , LoginForm , RegisterForm , PostForm , CommentForm <EOL> from flask . ext . login import current_user , login_required , login_user , logout_user <EOL> from flask import render_template , redirect , url_for , request , flash <EOL> from models import User , Post , Comment , LoginForm , RegisterForm , PostForm , CommentForm <EOL> from flask . ext . login import current_user , login_required , login_user , logout_user <EOL> from flask import render_template , redirect , url_for , request , flash <EOL> POSTS_ON_PAGE = <NUM_LIT:20> <EOL> COMMENTS_ON_PAGE = <NUM_LIT:20> <EOL> @ login . user_loader <EOL> def load_user ( userid ) : <EOL> return User . get ( userid ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def page_not_found ( e ) : <EOL> return render_template ( '<STR_LIT>' ) , <NUM_LIT> <EOL> @ login . unauthorized_handler <EOL> def unauthorized ( ) : <EOL> flash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> @ fragment ( app ) <EOL> def login_form ( ) : <EOL> return render_template ( '<STR_LIT>' , form = LoginForm ( ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def login ( ) : <EOL> form = LoginForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> login_user ( form . user ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:info>' ) <EOL> return redirect ( request . args . get ( '<STR_LIT>' ) or url_for ( '<STR_LIT:index>' ) ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> @ login_required <EOL> def logout ( ) : <EOL> logout_user ( ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def register ( ) : <EOL> form = RegisterForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> db . session . add ( form . user ) <EOL> db . session . commit ( ) <EOL> login_user ( form . user ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:info>' ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ fragment ( app , cache = <NUM_LIT> ) <EOL> def user_info ( userid ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ fragment ( app , cache = <NUM_LIT> ) <EOL> def posts_list ( page ) : <EOL> page = int ( page ) <EOL> page_size = POSTS_ON_PAGE <EOL> pagination = Post . query . filter_by ( ) . paginate ( page , page_size ) <EOL> posts = Post . query . filter_by ( ) . offset ( ( page - <NUM_LIT:1> ) * page_size ) . limit ( page_size ) . all ( ) <EOL> return render_template ( '<STR_LIT>' , pagination = pagination , posts = posts ) <EOL> @ fragment . resethandler ( posts_list ) <EOL> def reset_posts_list ( ) : <EOL> page_size = POSTS_ON_PAGE <EOL> pagination = Post . query . filter_by ( ) . paginate ( <NUM_LIT:1> , page_size ) <EOL> for N in range ( pagination . pages ) : <EOL> fragment . reset_url ( url_for ( '<STR_LIT>' , page = N + <NUM_LIT:1> ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT:/>' , endpoint = '<STR_LIT:index>' , defaults = { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> def posts ( page ) : <EOL> return render_template ( '<STR_LIT>' , page = page ) <EOL> @ fragment ( app , cache = <NUM_LIT> ) <EOL> def post_show ( post_id ) : <EOL> post = Post . query . filter_by ( id = post_id ) . first ( ) <EOL> return render_template ( '<STR_LIT>' , post = post ) <EOL> @ fragment ( app , cache = <NUM_LIT> ) <EOL> def comments_list ( post_id , page ) : <EOL> page = int ( page ) <EOL> page_size = COMMENTS_ON_PAGE <EOL> pagination = Comment . query . filter_by ( post_id = post_id ) . paginate ( page , page_size ) <EOL> comments = Comment . query . filter_by ( post_id = post_id ) . offset ( ( page - <NUM_LIT:1> ) * page_size ) . limit ( page_size ) . all ( ) <EOL> return render_template ( '<STR_LIT>' , post_id = post_id , page = page , <EOL> pagination = pagination , comments = comments ) <EOL> @ fragment . resethandler ( comments_list ) <EOL> def reset_comments_list ( post_id ) : <EOL> page_size = COMMENTS_ON_PAGE <EOL> pagination = Comment . query . filter_by ( post_id = post_id ) . paginate ( <NUM_LIT:1> , page_size ) <EOL> for N in range ( pagination . pages ) : <EOL> fragment . reset_url ( url_for ( '<STR_LIT>' , post_id = post_id , page = N + <NUM_LIT:1> ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def post ( post_id , page ) : <EOL> form = CommentForm ( ) <EOL> if ( current_user . is_authenticated ( ) and form . validate_on_submit ( ) ) : <EOL> form . comment . author_id = current_user . id <EOL> form . comment . post_id = post_id <EOL> db . session . add ( form . comment ) <EOL> db . session . commit ( ) <EOL> fragment . reset ( posts_list ) <EOL> fragment . reset ( comments_list , post_id ) <EOL> fragment . reset ( user_info , current_user . id ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:info>' ) <EOL> return render_template ( '<STR_LIT>' , form = form , post_id = post_id , page = page ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ login_required <EOL> def new_post ( ) : <EOL> form = PostForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> form . post . author_id = current_user . id <EOL> db . session . add ( form . post ) <EOL> db . session . commit ( ) <EOL> fragment . reset ( posts_list ) <EOL> fragment . reset ( user_info , current_user . id ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:info>' ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> class DefaultConfig ( object ) : <EOL> FRAGMENT_CACHING = True <EOL> SQLALCHEMY_DATABASE_URI = '<STR_LIT>' <EOL> SECRET_KEY = '<STR_LIT>' <EOL> import sys <EOL> import os . path <EOL> PY2 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> from flask . ext . script import Manager <EOL> manager = Manager ( app , with_default_commands = False ) <EOL> @ manager . command <EOL> def debug ( ) : <EOL> """<STR_LIT>""" <EOL> app . config [ '<STR_LIT>' ] = True <EOL> if PY2 : <EOL> from flask_debugtoolbar import DebugToolbarExtension <EOL> DebugToolbarExtension ( app ) <EOL> app . run ( debug = True ) <EOL> @ manager . command <EOL> def nginx_conf ( ) : <EOL> """<STR_LIT>""" <EOL> file_name = os . path . join ( os . path . dirname ( os . path . dirname ( __file__ ) ) , '<STR_LIT>' ) <EOL> fragment . _create_nginx_config ( file_name ) <EOL> @ manager . command <EOL> def create_db ( ) : <EOL> """<STR_LIT>""" <EOL> from models import DB <EOL> url = app . config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> path = url [ <NUM_LIT:10> : ] <EOL> if not os . path . exists ( path ) : <EOL> os . makedirs ( path ) <EOL> DB . create_all ( ) <EOL> DB . session . commit ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . config . from_object ( DefaultConfig ) <EOL> manager . run ( ) </s>
|
<s> from tests . common import parent_id , parent_name , child_id , child_parent_id , relation , child , parent <EOL> from eralchemy . main import _intermediary_to_markdown <EOL> import re <EOL> import pytest <EOL> column_re = re . compile ( '<STR_LIT>' ) <EOL> def test_all_to_er ( ) : <EOL> tables = [ child , parent ] <EOL> relations = [ relation ] <EOL> output = _intermediary_to_markdown ( tables , relations ) <EOL> for element in relations + tables : <EOL> assert element . to_markdown ( ) in output <EOL> def assert_column_well_rendered_to_er ( col ) : <EOL> col_er = col . to_markdown ( ) . strip ( ) <EOL> col_parsed = column_re . match ( col_er ) <EOL> assert col_parsed . group ( '<STR_LIT:key>' ) == ( '<STR_LIT:*>' if col . is_key else '<STR_LIT>' ) <EOL> assert col_parsed . group ( '<STR_LIT:name>' ) == col . name <EOL> assert col_parsed . group ( '<STR_LIT:type>' ) == col . type <EOL> def test_column_to_er ( ) : <EOL> assert_column_well_rendered_to_er ( parent_id ) <EOL> assert_column_well_rendered_to_er ( parent_name ) <EOL> assert_column_well_rendered_to_er ( child_id ) <EOL> assert_column_well_rendered_to_er ( child_parent_id ) <EOL> def test_relation ( ) : <EOL> assert relation . to_markdown ( ) in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def assert_table_well_rendered_to_er ( table ) : <EOL> assert table . header_markdown == '<STR_LIT:[>' + table . name + '<STR_LIT:]>' <EOL> table_er = table . to_markdown ( ) <EOL> for col in table . columns : <EOL> assert col . to_markdown ( ) in table_er <EOL> def test_table ( ) : <EOL> assert_table_well_rendered_to_er ( child ) <EOL> assert_table_well_rendered_to_er ( parent ) </s>
|
<s> from django . http import Http404 <EOL> from django . shortcuts import render_to_response <EOL> from django . core . paginator import Paginator , EmptyPage , PageNotAnInteger <EOL> def choice_list ( request , app_label , module_name , field_name , models ) : <EOL> m , f = lookup_field ( app_label , module_name , field_name , models ) <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : m , '<STR_LIT>' : f } <EOL> ) <EOL> def choice_detail ( request , app_label , module_name , field_name , <EOL> field_val , models ) : <EOL> m , f = lookup_field ( app_label , module_name , field_name , models ) <EOL> try : <EOL> label = dict ( f . field . choices ) [ field_val ] <EOL> except KeyError : <EOL> raise Http404 ( '<STR_LIT>' ) <EOL> obj_list = m . objects ( ** { f . field . name : field_val } ) <EOL> numitems = request . GET . get ( '<STR_LIT>' ) <EOL> items_per_page = [ <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT:100> ] <EOL> if numitems and numitems . isdigit ( ) and int ( numitems ) > <NUM_LIT:0> : <EOL> paginator = Paginator ( obj_list , numitems ) <EOL> else : <EOL> paginator = Paginator ( obj_list , items_per_page [ <NUM_LIT:0> ] ) <EOL> page = request . GET . get ( '<STR_LIT>' ) <EOL> try : <EOL> obj_list_page = paginator . page ( page ) <EOL> except PageNotAnInteger : <EOL> obj_list_page = paginator . page ( <NUM_LIT:1> ) <EOL> except EmptyPage : <EOL> obj_list_page = paginator . page ( paginator . num_pages ) <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : m , <EOL> '<STR_LIT>' : f , <EOL> '<STR_LIT:value>' : label , <EOL> '<STR_LIT>' : obj_list_page , <EOL> '<STR_LIT>' : items_per_page , <EOL> } <EOL> ) </s>
|
<s> """<STR_LIT>""" </s>
|
<s> """<STR_LIT>""" </s>
|
<s> from __future__ import unicode_literals <EOL> from django . db import migrations , models <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> operations = [ <EOL> migrations . AddField ( <EOL> model_name = '<STR_LIT:user>' , <EOL> name = '<STR_LIT>' , <EOL> field = models . TextField ( null = True , blank = True ) , <EOL> preserve_default = True , <EOL> ) , <EOL> migrations . AddField ( <EOL> model_name = '<STR_LIT:user>' , <EOL> name = '<STR_LIT>' , <EOL> field = models . ForeignKey ( blank = True , to = '<STR_LIT>' , null = True ) , <EOL> preserve_default = True , <EOL> ) , <EOL> ] </s>
|
<s> """<STR_LIT>""" <EOL> class User ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def current_user ( self ) : <EOL> """<STR_LIT>""" <EOL> url = self . root_collection [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return url <EOL> def current_user_person ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> url = self . collections [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ <EOL> "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> self . update_collection ( "<STR_LIT>" ) <EOL> url = self . collections [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ <EOL> "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> return url <EOL> def agent ( self , uid ) : <EOL> """<STR_LIT>""" <EOL> return self . user_base + "<STR_LIT>" + uid <EOL> def current_user_history ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> url = self . collections [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ <EOL> "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> self . update_collection ( "<STR_LIT>" ) <EOL> url = self . collections [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ <EOL> "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> return url </s>
|
<s> '''<STR_LIT>''' <EOL> from __future__ import unicode_literals , print_function <EOL> from argparse import FileType <EOL> import logging <EOL> import sys <EOL> import yaml <EOL> from chalmers . utils . cli import add_selection_group , select_programs <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> def main ( args ) : <EOL> export_data = [ ] <EOL> programs = select_programs ( args , filter_paused = False ) <EOL> for prog in programs : <EOL> export_data . append ( { '<STR_LIT>' : dict ( prog . raw_data ) } ) <EOL> yaml . safe_dump ( export_data , args . output , default_flow_style = False ) <EOL> def add_parser ( subparsers ) : <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> description = __doc__ ) <EOL> add_selection_group ( parser ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = FileType ( '<STR_LIT:w>' ) , default = sys . stdout ) <EOL> parser . set_defaults ( main = main ) </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals , print_function <EOL> import logging <EOL> import platform <EOL> import sys <EOL> from . import cron_service , sysv_service , upstart_service , systemd_service <EOL> from chalmers import errors <EOL> if sys . version_info . major == <NUM_LIT:3> : <EOL> system_dist = ( '<STR_LIT>' , ) <EOL> else : <EOL> system_dist = ( b'<STR_LIT>' , ) <EOL> platform . _supported_dists += system_dist <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> class NoPosixSystemService ( object ) : <EOL> def __init__ ( self , target_user = None ) : <EOL> supported_dists = platform . _supported_dists + system_dist <EOL> linux = platform . linux_distribution ( supported_dists = supported_dists ) <EOL> raise errors . ChalmersError ( "<STR_LIT>" % linux [ <NUM_LIT:0> ] ) <EOL> if systemd_service . check ( ) : <EOL> PosixSystemService = systemd_service . SystemdService <EOL> elif sysv_service . check ( ) : <EOL> PosixSystemService = sysv_service . SysVService <EOL> elif upstart_service . check ( ) : <EOL> PosixSystemService = upstart_service . UpstartService <EOL> else : <EOL> PosixSystemService = NoPosixSystemService <EOL> PosixLocalService = cron_service . CronService </s>
|
<s> import abc <EOL> import logging <EOL> import traceback <EOL> import servicemanager <EOL> import win32event , win32service , win32api <EOL> from win32serviceutil import ServiceFramework <EOL> log = logging . getLogger ( __name__ ) <EOL> class WindowsService ( object , ServiceFramework ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = abc . ABCMeta <EOL> def __init__ ( self , args ) : <EOL> try : <EOL> self . _svc_name_ = args [ <NUM_LIT:0> ] <EOL> self . _svc_display_name_ = args [ <NUM_LIT:0> ] <EOL> ServiceFramework . __init__ ( self , args ) <EOL> self . stop_event = win32event . CreateEvent ( None , <NUM_LIT:0> , <NUM_LIT:0> , None ) <EOL> except Exception : <EOL> self . log ( "<STR_LIT>" ) <EOL> self . log ( traceback . format_exc ( ) ) <EOL> raise <EOL> def log ( self , msg ) : <EOL> '<STR_LIT>' <EOL> servicemanager . LogInfoMsg ( str ( msg ) ) <EOL> def sleep ( self , sec ) : <EOL> win32api . Sleep ( sec * <NUM_LIT:1000> , True ) <EOL> def SvcDoRun ( self ) : <EOL> self . log ( '<STR_LIT:start>' ) <EOL> self . ReportServiceStatus ( win32service . SERVICE_START_PENDING ) <EOL> try : <EOL> self . ReportServiceStatus ( win32service . SERVICE_RUNNING ) <EOL> self . log ( '<STR_LIT:start>' ) <EOL> self . start ( ) <EOL> self . ReportServiceStatus ( win32service . SERVICE_STOPPED ) <EOL> self . log ( '<STR_LIT>' ) <EOL> except Exception : <EOL> self . log ( "<STR_LIT>" ) <EOL> self . log ( traceback . format_exc ( ) ) <EOL> self . SvcStop ( ) <EOL> def SvcStop ( self ) : <EOL> pass <EOL> self . ReportServiceStatus ( win32service . SERVICE_STOP_PENDING ) <EOL> self . log ( '<STR_LIT>' ) <EOL> self . stop ( ) <EOL> self . log ( '<STR_LIT>' ) <EOL> win32event . SetEvent ( self . stop_event ) <EOL> self . ReportServiceStatus ( win32service . SERVICE_STOPPED ) </s>
|
<s> from . . pyelliptic . ecc import * <EOL> from . . threads . threadutils import * <EOL> from . . constants import * <EOL> from . key import * <EOL> import hashlib <EOL> from struct import * <EOL> import sys <EOL> def encodeInt ( val , alphabet = ALPHABET ) : <EOL> base = len ( alphabet ) <EOL> result = "<STR_LIT>" <EOL> while val > <NUM_LIT:0> : <EOL> rem = val % base <EOL> result = str ( alphabet [ rem ] ) + result <EOL> val = val // base <EOL> return result <EOL> class Address : <EOL> def __init__ ( self , hashValue , version = VERSION ) : <EOL> self . version = version <EOL> self . hashValue = hashValue <EOL> self . encodedValue = "<STR_LIT>" <EOL> def encodeVersion ( self ) : <EOL> return pack ( '<STR_LIT>' , self . version ) <EOL> def encode ( self ) : <EOL> a = self . encodeVersion ( ) + self . hashValue <EOL> sha = hashlib . new ( '<STR_LIT>' ) <EOL> sha . update ( a ) <EOL> sha . update ( sha . digest ( ) ) <EOL> checksum = sha . digest ( ) [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> intValue = int . from_bytes ( a + checksum , '<STR_LIT>' ) <EOL> self . encodedValue = encodeInt ( intValue ) <EOL> def genKey ( ) : <EOL> curve = ECC ( ) <EOL> pubKey = curve . get_pubkey ( ) <EOL> sha = hashlib . new ( '<STR_LIT>' ) <EOL> sha . update ( pubKey ) <EOL> ripemd = hashlib . new ( '<STR_LIT>' ) <EOL> ripemd . update ( sha . digest ( ) ) <EOL> sha . update ( ripemd . digest ( ) ) <EOL> ripemd . update ( sha . digest ( ) ) <EOL> a = Address ( ripemd . digest ( ) ) <EOL> a . encode ( ) <EOL> key = Key ( pubKey , curve . get_privkey ( ) , a . encodedValue ) <EOL> return key </s>
|
<s> from anymesh import AnyMesh , AnyMeshDelegateProtocol <EOL> class LeftDelegate ( AnyMeshDelegateProtocol ) : <EOL> def connected_to ( self , device_info ) : <EOL> print ( '<STR_LIT>' + device_info . name ) <EOL> def disconnected_from ( self , name ) : <EOL> pass <EOL> def received_msg ( self , message ) : <EOL> print ( '<STR_LIT>' + message . sender ) <EOL> print ( '<STR_LIT>' + message . data [ '<STR_LIT>' ] ) <EOL> leftMesh . request ( '<STR_LIT:right>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class RightDelegate ( AnyMeshDelegateProtocol ) : <EOL> def connected_to ( self , device_info ) : <EOL> print ( '<STR_LIT>' + device_info . name ) <EOL> rightMesh . request ( '<STR_LIT:left>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def disconnected_from ( self , name ) : <EOL> pass <EOL> def received_msg ( self , message ) : <EOL> print ( '<STR_LIT>' + message . sender ) <EOL> print ( '<STR_LIT>' + message . data [ '<STR_LIT>' ] ) <EOL> leftMesh = AnyMesh ( '<STR_LIT:left>' , '<STR_LIT>' , LeftDelegate ( ) ) <EOL> rightMesh = AnyMesh ( '<STR_LIT:right>' , '<STR_LIT>' , RightDelegate ( ) ) <EOL> AnyMesh . run ( ) </s>
|
<s> import unittest <EOL> import doctest <EOL> import urwid <EOL> def load_tests ( loader , tests , ignore ) : <EOL> module_doctests = [ <EOL> urwid . widget , <EOL> urwid . wimp , <EOL> urwid . decoration , <EOL> urwid . display_common , <EOL> urwid . main_loop , <EOL> urwid . monitored_list , <EOL> urwid . raw_display , <EOL> '<STR_LIT>' , <EOL> urwid . util , <EOL> urwid . signals , <EOL> ] <EOL> for m in module_doctests : <EOL> tests . addTests ( doctest . DocTestSuite ( m , <EOL> optionflags = doctest . ELLIPSIS | doctest . IGNORE_EXCEPTION_DETAIL ) ) <EOL> return tests </s>
|
<s> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> EXCLUDED_LOG_VARS = [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:args>' , '<STR_LIT>' , '<STR_LIT:filename>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:message>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def register_logging ( logger , client_config , cls ) : <EOL> found = False <EOL> for handler in logger . handlers : <EOL> if isinstance ( handler , cls ) : <EOL> found = True <EOL> reg_handler = handler <EOL> if not found : <EOL> reg_handler = cls ( client_config = client_config ) <EOL> logger . addHandler ( reg_handler ) <EOL> return reg_handler <EOL> def unregister_logger ( logger , handler ) : <EOL> logger . removeHandler ( handler ) </s>
|
<s> import uuid <EOL> import datetime <EOL> from appenlight_client . timing import get_local_storage <EOL> from appenlight_client . timing import default_timer <EOL> from appenlight_client . client import PY3 <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> class AppenlightWSGIWrapper ( object ) : <EOL> __version__ = '<STR_LIT>' <EOL> def __init__ ( self , app , appenlight_client ) : <EOL> self . app = app <EOL> self . appenlight_client = appenlight_client <EOL> def __call__ ( self , environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> environ [ '<STR_LIT>' ] = str ( uuid . uuid4 ( ) ) <EOL> appenlight_storage = get_local_storage ( ) <EOL> appenlight_storage . clear ( ) <EOL> app_iter = None <EOL> detected_data = [ ] <EOL> create_report = False <EOL> traceback = None <EOL> http_status = <NUM_LIT:200> <EOL> start_time = default_timer ( ) <EOL> def detect_headers ( status , headers , * k , ** kw ) : <EOL> detected_data [ : ] = status [ : <NUM_LIT:3> ] , headers <EOL> return start_response ( status , headers , * k , ** kw ) <EOL> if '<STR_LIT>' not in environ : <EOL> environ [ '<STR_LIT>' ] = self . appenlight_client <EOL> def local_report ( message , include_traceback = True , http_status = <NUM_LIT:200> ) : <EOL> environ [ '<STR_LIT>' ] = True <EOL> def local_log ( level , message ) : <EOL> environ [ '<STR_LIT>' ] = True <EOL> environ [ '<STR_LIT>' ] = local_report <EOL> environ [ '<STR_LIT>' ] = local_log <EOL> if '<STR_LIT>' not in environ : <EOL> environ [ '<STR_LIT>' ] = { } <EOL> if '<STR_LIT>' not in environ : <EOL> environ [ '<STR_LIT>' ] = { } <EOL> try : <EOL> app_iter = self . app ( environ , detect_headers ) <EOL> return app_iter <EOL> except Exception : <EOL> if hasattr ( app_iter , '<STR_LIT>' ) : <EOL> app_iter . close ( ) <EOL> traceback = self . appenlight_client . get_current_traceback ( ) <EOL> if self . appenlight_client . config [ '<STR_LIT>' ] : <EOL> raise <EOL> try : <EOL> start_response ( '<STR_LIT>' , <EOL> [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> except Exception : <EOL> environ [ '<STR_LIT>' ] . write ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> finally : <EOL> end_time = default_timer ( ) <EOL> appenlight_storage . thread_stats [ '<STR_LIT>' ] = end_time - start_time <EOL> delta = datetime . timedelta ( seconds = ( end_time - start_time ) ) <EOL> stats , slow_calls = appenlight_storage . get_thread_stats ( ) <EOL> if '<STR_LIT>' not in environ : <EOL> environ [ '<STR_LIT>' ] = getattr ( appenlight_storage , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if detected_data and detected_data [ <NUM_LIT:0> ] : <EOL> http_status = int ( detected_data [ <NUM_LIT:0> ] ) <EOL> if self . appenlight_client . config [ '<STR_LIT>' ] and not environ . get ( '<STR_LIT>' ) : <EOL> if ( delta >= self . appenlight_client . config [ '<STR_LIT>' ] or slow_calls ) : <EOL> create_report = True <EOL> if '<STR_LIT>' in environ and not environ . get ( '<STR_LIT>' ) : <EOL> traceback = environ [ '<STR_LIT>' ] <EOL> del environ [ '<STR_LIT>' ] <EOL> http_status = <NUM_LIT> <EOL> create_report = True <EOL> if traceback and self . appenlight_client . config [ '<STR_LIT>' ] and not environ . get ( '<STR_LIT>' ) : <EOL> http_status = <NUM_LIT> <EOL> create_report = True <EOL> elif ( self . appenlight_client . config [ '<STR_LIT>' ] and http_status == <NUM_LIT> ) : <EOL> create_report = True <EOL> if create_report : <EOL> self . appenlight_client . py_report ( environ , traceback , <EOL> message = None , <EOL> http_status = http_status , <EOL> start_time = datetime . datetime . utcfromtimestamp ( start_time ) , <EOL> end_time = datetime . datetime . utcfromtimestamp ( end_time ) , <EOL> request_stats = stats , <EOL> slow_calls = slow_calls ) <EOL> del traceback <EOL> self . appenlight_client . save_request_stats ( stats , view_name = environ . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if self . appenlight_client . config [ '<STR_LIT>' ] : <EOL> records = self . appenlight_client . log_handlers_get_records ( ) <EOL> self . appenlight_client . log_handlers_clear_records ( ) <EOL> self . appenlight_client . py_log ( environ , <EOL> records = records , <EOL> r_uuid = environ [ '<STR_LIT>' ] , <EOL> created_report = create_report ) <EOL> self . appenlight_client . check_if_deliver ( self . appenlight_client . config [ '<STR_LIT>' ] or <EOL> environ . get ( '<STR_LIT>' ) ) </s>
|
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card