code
stringlengths
9
256k
<s> '''<STR_LIT>''' <EOL> from brain . database . db_query import SQL <EOL> class Retrieve_Entity ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . list_error = [ ] <EOL> self . sql = SQL ( ) <EOL> def get_title ( self , id_entity ) : <EOL> '''<STR_LIT>''' <EOL> self . sql . sql_connect ( '<STR_LIT>' ) <EOL> sql_statement = '<STR_LIT>' '<STR_LIT>' <EOL> args = ( id_entity ) <EOL> response = self . sql . sql_command ( sql_statement , '<STR_LIT>' , args ) <EOL> response_error = self . sql . get_errors ( ) <EOL> self . sql . sql_disconnect ( ) <EOL> if response_error : <EOL> return { '<STR_LIT:error>' : response_error , '<STR_LIT:result>' : None } <EOL> else : <EOL> return { '<STR_LIT:error>' : None , '<STR_LIT:result>' : response [ '<STR_LIT:result>' ] } </s>
<s> import os <EOL> class pathNavigator ( object ) : <EOL> def __pytermconfig__ ( self ) : <EOL> return { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . cd } <EOL> def cd ( self , * args , ** kwargs ) : <EOL> pyTerm = kwargs [ "<STR_LIT>" ] <EOL> try : <EOL> sequence = kwargs [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> sequence = "<STR_LIT>" <EOL> if sequence == "<STR_LIT:..>" : <EOL> currentPath = pyTerm . getPath ( ) . split ( "<STR_LIT:/>" ) [ : : - <NUM_LIT:1> ] [ <NUM_LIT:1> : : ] <EOL> if currentPath [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> pyTerm . setPath ( '<STR_LIT:/>' ) <EOL> else : <EOL> pyTerm . setPath ( "<STR_LIT:/>" . join ( currentPath [ : : - <NUM_LIT:1> ] ) ) <EOL> elif sequence == "<STR_LIT>" or sequence == "<STR_LIT>" : <EOL> pyTerm . setPath ( "<STR_LIT>" + pyTerm . getUser ( ) ) <EOL> else : <EOL> currentPath = os . path . join ( pyTerm . getPath ( ) , sequence ) <EOL> if os . path . isdir ( currentPath ) : <EOL> pyTerm . setPath ( currentPath ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> os . chdir ( pyTerm . currentPath ) </s>
<s> """<STR_LIT>""" <EOL> import datetime <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> db = SQLAlchemy ( ) <EOL> class Cloud ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . String , nullable = False ) <EOL> description = db . Column ( db . String , nullable = False ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class Machine ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> hostname = db . Column ( db . String , nullable = False ) <EOL> operating_system = db . Column ( db . String , nullable = False ) <EOL> description = db . Column ( db . String , nullable = False ) <EOL> cloud_id = db . Column ( db . Integer , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> cloud = db . relationship ( '<STR_LIT>' ) <EOL> is_running = db . Column ( db . Boolean , default = False , nullable = False ) <EOL> last_started_at = db . Column ( db . DateTime , default = datetime . datetime . now ( ) ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . hostname </s>
<s> def _readchar ( bstring ) : <EOL> for char in bstring : <EOL> yield char <EOL> def bencode ( canonical ) : <EOL> '''<STR_LIT>''' <EOL> in_dict = dict ( canonical ) <EOL> def encode_str ( in_str ) : <EOL> out_str = str ( len ( in_str ) ) + '<STR_LIT::>' + in_str <EOL> return out_str <EOL> def encode_int ( in_int ) : <EOL> out_str = str ( '<STR_LIT:i>' + str ( in_int ) + '<STR_LIT:e>' ) <EOL> return out_str <EOL> def encode_list ( in_list ) : <EOL> out_str = '<STR_LIT:l>' <EOL> for item in in_list : <EOL> out_str += encode_item ( item ) <EOL> else : <EOL> out_str += '<STR_LIT:e>' <EOL> return out_str <EOL> def encode_dict ( in_dict ) : <EOL> out_str = '<STR_LIT:d>' <EOL> keys = sorted ( in_dict . keys ( ) ) <EOL> for key in keys : <EOL> val = in_dict [ key ] <EOL> out_str = out_str + encode_item ( key ) + encode_item ( val ) <EOL> else : <EOL> out_str += '<STR_LIT:e>' <EOL> return out_str <EOL> def encode_item ( x ) : <EOL> if isinstance ( x , str ) : <EOL> return encode_str ( x ) <EOL> elif isinstance ( x , int ) : <EOL> return encode_int ( x ) <EOL> elif isinstance ( x , list ) : <EOL> return encode_list ( x ) <EOL> elif isinstance ( x , dict ) : <EOL> return encode_dict ( x ) <EOL> return encode_item ( in_dict ) <EOL> def bdecode ( bstring ) : <EOL> '''<STR_LIT>''' <EOL> def get_val ( ) : <EOL> i = reader . next ( ) <EOL> if i . isdigit ( ) : <EOL> str_len = get_len ( i ) <EOL> return get_str ( str_len ) <EOL> if i == '<STR_LIT:d>' : <EOL> return get_dict ( ) <EOL> if i == '<STR_LIT:l>' : <EOL> return get_list ( ) <EOL> if i == '<STR_LIT:i>' : <EOL> return get_int ( ) <EOL> if i == '<STR_LIT:e>' : <EOL> return None <EOL> def get_len ( i = '<STR_LIT>' ) : <EOL> len_str = str ( i ) <EOL> next_char = reader . next ( ) <EOL> if next_char == '<STR_LIT:e>' : <EOL> return None <EOL> while next_char is not '<STR_LIT::>' : <EOL> len_str += next_char <EOL> next_char = reader . next ( ) <EOL> else : <EOL> return int ( len_str ) <EOL> def get_dict ( ) : <EOL> this_dict = { } <EOL> while <NUM_LIT:1> : <EOL> str_len = get_len ( ) <EOL> if str_len is None : <EOL> return this_dict <EOL> key = get_str ( str_len ) <EOL> val = get_val ( ) <EOL> this_dict [ key ] = val <EOL> def get_int ( ) : <EOL> int_str = '<STR_LIT>' <EOL> i = reader . next ( ) <EOL> while i is not '<STR_LIT:e>' : <EOL> int_str += i <EOL> i = reader . next ( ) <EOL> else : <EOL> return int ( int_str ) <EOL> def get_str ( str_len ) : <EOL> this_str = '<STR_LIT>' <EOL> for i in range ( str_len ) : <EOL> this_str += reader . next ( ) <EOL> return this_str <EOL> def get_list ( ) : <EOL> this_list = [ ] <EOL> while <NUM_LIT:1> : <EOL> val = get_val ( ) <EOL> if not val : <EOL> return this_list <EOL> this_list . append ( val ) <EOL> reader = _readchar ( bstring ) <EOL> dict_repr = get_val ( ) <EOL> return dict_repr <EOL> def bdecode_file ( filename ) : <EOL> '''<STR_LIT>''' <EOL> with open ( filename ) as f : <EOL> return bdecode ( f . read ( ) ) </s>
<s> import re <EOL> from flatland . out . util import parse_trool <EOL> from flatland . schema import Array , Boolean <EOL> from flatland . util import Maybe , to_pairs <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _transforms = [ ] <EOL> _default_context = { } <EOL> _auto_tags = { } <EOL> _id_invalid_re = re . compile ( r'<STR_LIT>' ) <EOL> def transform ( tagname , attributes , contents , context , bind ) : <EOL> """<STR_LIT>""" <EOL> for fn in _transforms : <EOL> contents = fn ( tagname , attributes , contents , context , bind ) <EOL> return contents <EOL> class Context ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _frames = [ dict ( _default_context ) ] <EOL> def push ( self , ** options ) : <EOL> self . _frames . append ( self . _frames [ - <NUM_LIT:1> ] . copy ( ) ) <EOL> try : <EOL> self . update ( ** options ) <EOL> except KeyError : <EOL> self . pop ( ) <EOL> raise <EOL> def pop ( self ) : <EOL> if len ( self . _frames ) == <NUM_LIT:1> : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . _frames . pop ( ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . _frames [ - <NUM_LIT:1> ] [ key ] <EOL> def __setitem__ ( self , key , value ) : <EOL> if key not in self : <EOL> raise KeyError ( "<STR_LIT>" % ( <EOL> key , self . __class__ . __name__ ) ) <EOL> self . _frames [ - <NUM_LIT:1> ] [ key ] = value <EOL> def __contains__ ( self , key ) : <EOL> return key in self . _frames [ - <NUM_LIT:1> ] <EOL> def update ( self , * iterable , ** kwargs ) : <EOL> if len ( iterable ) : <EOL> if len ( iterable ) > <NUM_LIT:1> : <EOL> raise TypeError ( <EOL> "<STR_LIT>" % ( <EOL> len ( iterable ) ) ) <EOL> source = to_pairs ( iterable [ <NUM_LIT:0> ] ) <EOL> for key , value in source : <EOL> self [ key ] = value <EOL> for key , value in kwargs . iteritems ( ) : <EOL> self [ key . decode ( '<STR_LIT:ascii>' ) ] = value <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , self . _frames [ - <NUM_LIT:1> ] ) <EOL> class Markup ( unicode ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( ) <EOL> def __html__ ( self ) : <EOL> return self <EOL> _default_context [ '<STR_LIT>' ] = Markup <EOL> def transformer ( name , tags ) : <EOL> def decorator ( fn ) : <EOL> _transforms . append ( fn ) <EOL> _auto_tags [ name ] = set ( tags ) <EOL> return fn <EOL> return decorator <EOL> def defaults ( data ) : <EOL> def decorator ( fn ) : <EOL> _default_context . update ( data ) <EOL> return fn <EOL> return decorator <EOL> @ transformer ( u'<STR_LIT:name>' , ( u'<STR_LIT:input>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> @ defaults ( { u'<STR_LIT>' : True } ) <EOL> def transform_name ( tagname , attributes , contents , context , bind ) : <EOL> proceed , forced = _pop_toggle ( u'<STR_LIT>' , attributes , context ) <EOL> if not proceed or bind is None : <EOL> return contents <EOL> bound_name = bind . flattened_name ( ) <EOL> if not bound_name : <EOL> return contents <EOL> current = attributes . get ( u'<STR_LIT:name>' , None ) <EOL> if forced or current is None and tagname in _auto_tags [ u'<STR_LIT:name>' ] : <EOL> attributes [ u'<STR_LIT:name>' ] = bound_name <EOL> return contents <EOL> @ transformer ( u'<STR_LIT:value>' , ( u'<STR_LIT>' , u'<STR_LIT:input>' , u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> @ defaults ( { u'<STR_LIT>' : True } ) <EOL> def transform_value ( tagname , attributes , contents , context , bind ) : <EOL> proceed , forced = _pop_toggle ( u'<STR_LIT>' , attributes , context ) <EOL> if not proceed or bind is None : <EOL> return contents <EOL> if not forced and tagname not in _auto_tags [ u'<STR_LIT:value>' ] : <EOL> return contents <EOL> if tagname == u'<STR_LIT:input>' : <EOL> subtype = attributes . get ( u'<STR_LIT:type>' , u'<STR_LIT>' ) <EOL> if subtype in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> if subtype == u'<STR_LIT>' : <EOL> current = attributes . get ( u'<STR_LIT:value>' ) <EOL> if current is None and isinstance ( bind , Boolean ) : <EOL> attributes [ u'<STR_LIT:value>' ] = current = bind . true <EOL> else : <EOL> current = attributes . get ( u'<STR_LIT:value>' , u'<STR_LIT>' ) <EOL> if isinstance ( bind , Array ) : <EOL> toggle = current in bind <EOL> else : <EOL> toggle = current == bind . u <EOL> if toggle : <EOL> attributes [ u'<STR_LIT>' ] = u'<STR_LIT>' <EOL> else : <EOL> attributes . pop ( u'<STR_LIT>' , None ) <EOL> elif subtype in ( u'<STR_LIT:password>' , u'<STR_LIT:file>' , u'<STR_LIT:image>' ) : <EOL> if forced : <EOL> attributes [ u'<STR_LIT:value>' ] = bind . u <EOL> else : <EOL> current = attributes . get ( u'<STR_LIT:value>' ) <EOL> if current is None or forced : <EOL> attributes [ u'<STR_LIT:value>' ] = bind . u <EOL> elif tagname == u'<STR_LIT>' : <EOL> current = attributes . get ( u'<STR_LIT:value>' ) <EOL> if current is not None : <EOL> value = current <EOL> elif isinstance ( contents , unicode ) : <EOL> value = contents . strip ( ) <EOL> elif contents is None : <EOL> value = u'<STR_LIT>' <EOL> else : <EOL> value = contents <EOL> if isinstance ( bind , Array ) : <EOL> toggle = value in bind <EOL> else : <EOL> toggle = bind . u == value <EOL> if toggle : <EOL> attributes [ u'<STR_LIT>' ] = u'<STR_LIT>' <EOL> else : <EOL> attributes . pop ( u'<STR_LIT>' , None ) <EOL> elif tagname == u'<STR_LIT>' : <EOL> if contents is None or forced : <EOL> return context [ '<STR_LIT>' ] ( _markup_escape ( bind . u ) ) <EOL> else : <EOL> current = attributes . get ( u'<STR_LIT:value>' ) <EOL> if current is None or forced : <EOL> attributes [ u'<STR_LIT:value>' ] = bind . u <EOL> return contents <EOL> @ transformer ( u'<STR_LIT:id>' , ( u'<STR_LIT:input>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> @ defaults ( { u'<STR_LIT>' : False , u'<STR_LIT>' : u'<STR_LIT>' } ) <EOL> def transform_domid ( tagname , attributes , contents , context , bind ) : <EOL> proceed , forced = _pop_toggle ( u'<STR_LIT>' , attributes , context ) <EOL> if not proceed : <EOL> return contents <EOL> current = attributes . get ( u'<STR_LIT:id>' ) <EOL> if forced or current is None and tagname in _auto_tags [ u'<STR_LIT:id>' ] : <EOL> raw_id = _generate_raw_domid ( tagname , attributes , bind ) <EOL> if raw_id : <EOL> fmt = context [ u'<STR_LIT>' ] <EOL> attributes [ u'<STR_LIT:id>' ] = fmt % raw_id <EOL> return contents <EOL> @ transformer ( u'<STR_LIT>' , ( u'<STR_LIT:label>' , ) ) <EOL> @ defaults ( { u'<STR_LIT>' : False } ) <EOL> def transform_for ( tagname , attributes , contents , context , bind ) : <EOL> proceed , forced = _pop_toggle ( u'<STR_LIT>' , attributes , context ) <EOL> if not proceed or bind is None : <EOL> return contents <EOL> current = attributes . get ( u'<STR_LIT>' ) <EOL> if forced or current is None and tagname in _auto_tags [ u'<STR_LIT>' ] : <EOL> raw_id = _generate_raw_domid ( tagname , attributes , bind ) <EOL> if raw_id : <EOL> fmt = context [ u'<STR_LIT>' ] <EOL> attributes [ u'<STR_LIT>' ] = fmt % raw_id <EOL> return contents <EOL> @ transformer ( u'<STR_LIT>' , ( u'<STR_LIT:input>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> @ defaults ( { u'<STR_LIT>' : False , u'<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def transform_tabindex ( tagname , attributes , contents , context , bind ) : <EOL> proceed , forced = _pop_toggle ( u'<STR_LIT>' , attributes , context ) <EOL> if not proceed : <EOL> return contents <EOL> tabindex = context [ u'<STR_LIT>' ] <EOL> if tabindex == <NUM_LIT:0> : <EOL> return contents <EOL> current = attributes . get ( u'<STR_LIT>' ) <EOL> if forced or current is None and tagname in _auto_tags [ u'<STR_LIT>' ] : <EOL> attributes [ u'<STR_LIT>' ] = unicode ( tabindex ) <EOL> if tabindex > <NUM_LIT:0> : <EOL> context [ u'<STR_LIT>' ] = tabindex + <NUM_LIT:1> <EOL> return contents <EOL> @ defaults ( { u'<STR_LIT>' : False , u'<STR_LIT>' : ( ) } ) <EOL> def transform_filters ( tagname , attributes , contents , context , bind ) : <EOL> proceed , forced = _pop_toggle ( u'<STR_LIT>' , attributes , context ) <EOL> filters = context [ u'<STR_LIT>' ] <EOL> if not proceed : <EOL> return contents <EOL> for fn in filters : <EOL> want = getattr ( fn , '<STR_LIT>' , None ) <EOL> if want and tagname not in want : <EOL> continue <EOL> contents = fn ( tagname , attributes , contents , context , bind ) <EOL> return contents <EOL> _transforms . append ( transform_filters ) <EOL> def _pop_toggle ( key , attributes , context ) : <EOL> """<STR_LIT>""" <EOL> value = parse_trool ( attributes . pop ( key , Maybe ) ) <EOL> forced = value is True <EOL> if value is Maybe : <EOL> value = parse_trool ( context [ key ] ) <EOL> if value is Maybe : <EOL> value = _default_context [ key ] <EOL> return value , forced <EOL> def _generate_raw_domid ( tagname , attributes , bind ) : <EOL> if bind is not None : <EOL> basis = bind . flattened_name ( ) <EOL> else : <EOL> basis = attributes . get ( u'<STR_LIT:name>' ) <EOL> if not basis : <EOL> return <EOL> if ( tagname == u'<STR_LIT:input>' and <EOL> attributes . get ( u'<STR_LIT:type>' ) in ( u'<STR_LIT>' , u'<STR_LIT>' ) and <EOL> isinstance ( bind , Array ) ) : <EOL> suffix = _sanitize_domid_suffix ( attributes . get ( u'<STR_LIT:value>' , u'<STR_LIT>' ) ) <EOL> if suffix : <EOL> basis += u'<STR_LIT:_>' + suffix <EOL> return basis <EOL> def _sanitize_domid_suffix ( string ) : <EOL> """<STR_LIT>""" <EOL> return _id_invalid_re . sub ( u'<STR_LIT>' , string ) <EOL> def _markup_escape ( string ) : <EOL> if not string : <EOL> return u'<STR_LIT>' <EOL> elif hasattr ( string , '<STR_LIT>' ) : <EOL> return string . __html__ ( ) <EOL> else : <EOL> return string . replace ( u'<STR_LIT:&>' , u'<STR_LIT>' ) . replace ( u'<STR_LIT:<>' , u'<STR_LIT>' ) . replace ( u'<STR_LIT:>>' , u'<STR_LIT>' ) </s>
<s> from operator import attrgetter <EOL> from flatland . util import Unspecified <EOL> from . base import N_ , Validator <EOL> class Present ( Validator ) : <EOL> """<STR_LIT>""" <EOL> missing = N_ ( u'<STR_LIT>' ) <EOL> def validate ( self , element , state ) : <EOL> if element . u == u'<STR_LIT>' : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class IsTrue ( Validator ) : <EOL> """<STR_LIT>""" <EOL> false = N_ ( u'<STR_LIT>' ) <EOL> def validate ( self , element , state ) : <EOL> if not bool ( element . value ) : <EOL> return self . note_error ( element , state , '<STR_LIT:false>' ) <EOL> return True <EOL> class IsFalse ( Validator ) : <EOL> """<STR_LIT>""" <EOL> true = N_ ( u'<STR_LIT>' ) <EOL> def validate ( self , element , state ) : <EOL> if bool ( element . value ) : <EOL> return self . note_error ( element , state , '<STR_LIT:true>' ) <EOL> return True <EOL> class ValueIn ( Validator ) : <EOL> """<STR_LIT>""" <EOL> fail = N_ ( u'<STR_LIT>' ) <EOL> valid_options = ( ) <EOL> def __init__ ( self , valid_options = Unspecified , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> if valid_options is not Unspecified : <EOL> self . valid_options = valid_options <EOL> def validate ( self , element , state ) : <EOL> if element . value not in self . valid_options : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class Converted ( Validator ) : <EOL> """<STR_LIT>""" <EOL> incorrect = N_ ( u'<STR_LIT>' ) <EOL> def validate ( self , element , state ) : <EOL> if element . value is not None : <EOL> return True <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> class ShorterThan ( Validator ) : <EOL> """<STR_LIT>""" <EOL> exceeded = N_ ( u'<STR_LIT>' ) <EOL> maxlength = <NUM_LIT:0> <EOL> def __init__ ( self , maxlength = Unspecified , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> if maxlength is not Unspecified : <EOL> self . maxlength = maxlength <EOL> def validate ( self , element , state ) : <EOL> if len ( element . u ) > self . maxlength : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> NoLongerThan = ShorterThan <EOL> class LongerThan ( Validator ) : <EOL> """<STR_LIT>""" <EOL> short = N_ ( u'<STR_LIT>' ) <EOL> minlength = <NUM_LIT:0> <EOL> def __init__ ( self , minlength = Unspecified , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> if minlength is not Unspecified : <EOL> self . minlength = minlength <EOL> def validate ( self , element , state ) : <EOL> if len ( element . u ) < self . minlength : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class LengthBetween ( Validator ) : <EOL> """<STR_LIT>""" <EOL> breached = N_ ( u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> minlength = <NUM_LIT:0> <EOL> maxlength = <NUM_LIT:0> <EOL> def __init__ ( self , minlength = Unspecified , maxlength = Unspecified , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> if minlength is not Unspecified : <EOL> self . minlength = minlength <EOL> if maxlength is not Unspecified : <EOL> self . maxlength = maxlength <EOL> def validate ( self , element , state ) : <EOL> l = len ( element . u ) <EOL> if l < self . minlength or l > self . maxlength : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class ValueLessThan ( Validator ) : <EOL> """<STR_LIT>""" <EOL> failure = N_ ( u'<STR_LIT>' ) <EOL> def __init__ ( self , boundary , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> self . boundary = boundary <EOL> def validate ( self , element , state ) : <EOL> if not element . value < self . boundary : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class ValueAtMost ( Validator ) : <EOL> """<STR_LIT>""" <EOL> failure = N_ ( u'<STR_LIT>' ) <EOL> def __init__ ( self , maximum , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> self . maximum = maximum <EOL> def validate ( self , element , state ) : <EOL> if not element . value <= self . maximum : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class ValueGreaterThan ( Validator ) : <EOL> """<STR_LIT>""" <EOL> failure = N_ ( u'<STR_LIT>' ) <EOL> def __init__ ( self , boundary , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> self . boundary = boundary <EOL> def validate ( self , element , state ) : <EOL> if not element . value > self . boundary : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class ValueAtLeast ( Validator ) : <EOL> """<STR_LIT>""" <EOL> failure = N_ ( u'<STR_LIT>' ) <EOL> def __init__ ( self , minimum , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> self . minimum = minimum <EOL> def validate ( self , element , state ) : <EOL> if not element . value >= self . minimum : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class ValueBetween ( Validator ) : <EOL> """<STR_LIT>""" <EOL> failure_inclusive = N_ ( u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> failure_exclusive = N_ ( u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> inclusive = True <EOL> def __init__ ( self , minimum , maximum , ** kw ) : <EOL> Validator . __init__ ( self , ** kw ) <EOL> self . minimum = minimum <EOL> self . maximum = maximum <EOL> def validate ( self , element , state ) : <EOL> if self . inclusive : <EOL> if not self . minimum <= element . value <= self . maximum : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> else : <EOL> if not self . minimum < element . value < self . maximum : <EOL> return self . note_error ( element , state , '<STR_LIT>' ) <EOL> return True <EOL> class MapEqual ( Validator ) : <EOL> """<STR_LIT>""" <EOL> unequal = N_ ( u'<STR_LIT>' ) <EOL> field_paths = ( ) <EOL> transform = lambda el : el <EOL> def __init__ ( self , * field_paths , ** kw ) : <EOL> """<STR_LIT>""" <EOL> if not field_paths : <EOL> assert self . field_paths , '<STR_LIT>' <EOL> else : <EOL> assert len ( field_paths ) > <NUM_LIT:1> , '<STR_LIT>' <EOL> self . field_paths = field_paths <EOL> Validator . __init__ ( self , ** kw ) <EOL> def validate ( self , element , state ) : <EOL> elements = [ element . el ( name ) for name in self . field_paths ] <EOL> fn = self . transform <EOL> sample = fn ( elements [ <NUM_LIT:0> ] ) <EOL> if all ( fn ( el ) == sample for el in elements [ <NUM_LIT:1> : ] ) : <EOL> return True <EOL> labels = '<STR_LIT:U+002CU+0020>' . join ( el . label for el in elements [ : - <NUM_LIT:1> ] ) <EOL> last_label = elements [ - <NUM_LIT:1> ] . label <EOL> return self . note_error ( element , state , '<STR_LIT>' , <EOL> labels = labels , last_label = last_label ) <EOL> class ValuesEqual ( MapEqual ) : <EOL> """<STR_LIT>""" <EOL> transform = attrgetter ( '<STR_LIT:value>' ) <EOL> class UnisEqual ( MapEqual ) : <EOL> """<STR_LIT>""" <EOL> transform = attrgetter ( '<STR_LIT:u>' ) </s>
<s> from flatland import ( <EOL> Integer , <EOL> List , <EOL> String , <EOL> ) <EOL> from flatland . schema . base import Unspecified <EOL> from tests . _util import eq_ <EOL> def test_set_flat_linear ( ) : <EOL> pairs = [ ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:3> ) ] <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , len ( pairs ) ) <EOL> eq_ ( el . value , list ( pair [ <NUM_LIT:1> ] for pair in pairs ) ) <EOL> def test_set_flat_miss ( ) : <EOL> pairs = [ ( u'<STR_LIT>' , u'<STR_LIT:3>' ) , ( u'<STR_LIT>' , u'<STR_LIT:4>' ) ] <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:0> ) <EOL> eq_ ( el . value , [ ] ) <EOL> def test_set_flat_scalar ( ) : <EOL> pairs = [ ( u'<STR_LIT:l>' , u'<STR_LIT:1>' ) ] <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema ( ) <EOL> canary = [ ] <EOL> def setter ( self , value ) : <EOL> canary . append ( value ) <EOL> return type ( el ) . set ( self , value ) <EOL> el . set = setter . __get__ ( el , type ( el ) ) <EOL> el . set_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:0> ) <EOL> eq_ ( el . value , [ ] ) <EOL> eq_ ( canary , [ ] ) <EOL> def test_set_flat_pruned ( ) : <EOL> pairs = [ ( u'<STR_LIT>' , u'<STR_LIT:0>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT:3>' ) ] <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:2> ) <EOL> eq_ ( el . value , [ <NUM_LIT:0> , <NUM_LIT:3> ] ) <EOL> schema2 = schema . using ( maximum_set_flat_members = <NUM_LIT:1> ) <EOL> el = schema2 . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:1> ) <EOL> eq_ ( el . value , [ <NUM_LIT:0> ] ) <EOL> def test_set_flat_unpruned ( ) : <EOL> pairs = [ ( u'<STR_LIT>' , u'<STR_LIT:0>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT:3>' ) ] <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) . using ( prune_empty = False ) <EOL> el = schema . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:4> ) <EOL> eq_ ( el . value , [ <NUM_LIT:0> , None , None , <NUM_LIT:3> ] ) <EOL> schema2 = schema . using ( maximum_set_flat_members = <NUM_LIT:2> ) <EOL> el = schema2 . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:2> ) <EOL> eq_ ( el . value , [ <NUM_LIT:0> , None ] ) <EOL> def _assert_set_flat ( schema , pairs , bogus = [ ] ) : <EOL> el = schema . from_flat ( pairs + bogus ) <EOL> eq_ ( len ( el ) , len ( pairs ) ) <EOL> eq_ ( el . value , list ( pair [ <NUM_LIT:1> ] for pair in pairs ) ) <EOL> eq_ ( el . flatten ( ) , pairs ) <EOL> def test_set_flat_unnamed_child ( ) : <EOL> schema = List . named ( u'<STR_LIT:s>' ) . of ( String ) <EOL> pairs = [ ( u'<STR_LIT>' , u'<STR_LIT:abc>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) ] <EOL> bogus = [ ( u'<STR_LIT:s>' , u'<STR_LIT>' ) ] <EOL> _assert_set_flat ( schema , pairs , bogus ) <EOL> def test_set_flat_anon_list_named_child ( ) : <EOL> schema = List . of ( String . named ( u'<STR_LIT:s>' ) ) <EOL> pairs = [ ( u'<STR_LIT>' , u'<STR_LIT:abc>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) ] <EOL> bogus = [ ( u'<STR_LIT:s>' , u'<STR_LIT>' ) , ( u'<STR_LIT:0>' , u'<STR_LIT>' ) ] <EOL> _assert_set_flat ( schema , pairs , bogus ) <EOL> def test_set_flat_fully_anonymous ( ) : <EOL> schema = List . of ( String ) <EOL> pairs = [ ( u'<STR_LIT:0>' , u'<STR_LIT:abc>' ) , ( u'<STR_LIT:1>' , u'<STR_LIT>' ) ] <EOL> bogus = [ ( u'<STR_LIT:x>' , u'<STR_LIT>' ) ] <EOL> _assert_set_flat ( schema , pairs , bogus ) <EOL> def test_set_flat_anonymous_dict ( ) : <EOL> pairs = ( ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ( u'<STR_LIT>' , u'<STR_LIT>' ) , ) <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( String . named ( u'<STR_LIT:x>' ) , String . named ( u'<STR_LIT:y>' ) ) <EOL> el = schema . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:3> ) <EOL> eq_ ( el [ <NUM_LIT:0> ] . value , dict ( ( k [ - <NUM_LIT:1> ] , v ) for k , v in pairs [ <NUM_LIT:0> : <NUM_LIT:2> ] ) ) <EOL> eq_ ( el [ <NUM_LIT:1> ] . value , dict ( ( k [ - <NUM_LIT:1> ] , v ) for k , v in pairs [ <NUM_LIT:2> : <NUM_LIT:4> ] ) ) <EOL> eq_ ( el [ <NUM_LIT:2> ] . value , { u'<STR_LIT:x>' : u'<STR_LIT>' , u'<STR_LIT:y>' : None } ) <EOL> def test_set_flat_doubly_anonymous_dict ( ) : <EOL> pairs = ( ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , <EOL> ( u'<STR_LIT>' , u'<STR_LIT>' ) , ) <EOL> schema = List . of ( String . named ( u'<STR_LIT:x>' ) , String . named ( u'<STR_LIT:y>' ) ) <EOL> el = schema . from_flat ( pairs ) <EOL> eq_ ( len ( el ) , <NUM_LIT:3> ) <EOL> eq_ ( el [ <NUM_LIT:0> ] . value , dict ( ( k [ - <NUM_LIT:1> ] , v ) for k , v in pairs [ <NUM_LIT:0> : <NUM_LIT:2> ] ) ) <EOL> eq_ ( el [ <NUM_LIT:1> ] . value , dict ( ( k [ - <NUM_LIT:1> ] , v ) for k , v in pairs [ <NUM_LIT:2> : <NUM_LIT:4> ] ) ) <EOL> eq_ ( el [ <NUM_LIT:2> ] . value , { u'<STR_LIT:x>' : u'<STR_LIT>' , u'<STR_LIT:y>' : None } ) <EOL> def test_set_default_int ( ) : <EOL> def factory ( count , ** kw ) : <EOL> return List . named ( u'<STR_LIT:l>' ) . using ( default = count , ** kw ) . of ( <EOL> String . named ( u'<STR_LIT:s>' ) . using ( default = u'<STR_LIT>' ) ) <EOL> schema = factory ( <NUM_LIT:3> ) <EOL> el = schema ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:0> ) <EOL> eq_ ( el . value , [ ] ) <EOL> el = schema ( ) <EOL> el . set_default ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:3> ) <EOL> eq_ ( el . value , [ u'<STR_LIT>' ] * <NUM_LIT:3> ) <EOL> el . append ( None ) <EOL> eq_ ( len ( el ) , <NUM_LIT:4> ) <EOL> eq_ ( el [ - <NUM_LIT:1> ] . value , None ) <EOL> el [ - <NUM_LIT:1> ] . set_default ( ) <EOL> eq_ ( el [ - <NUM_LIT:1> ] . value , u'<STR_LIT>' ) <EOL> el = schema ( [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> eq_ ( len ( el ) , <NUM_LIT:2> ) <EOL> eq_ ( el . value , [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> el . set_default ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:3> ) <EOL> eq_ ( el . value , [ u'<STR_LIT>' ] * <NUM_LIT:3> ) <EOL> schema0 = factory ( <NUM_LIT:0> ) <EOL> el = schema0 ( ) <EOL> el . set_default ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:0> ) <EOL> eq_ ( el . value , [ ] ) <EOL> def calculated_default ( element ) : <EOL> assert isinstance ( element , List ) <EOL> return <NUM_LIT:2> <EOL> schemaf = List . named ( u'<STR_LIT:l>' ) . using ( default_factory = calculated_default ) . of ( <EOL> String . named ( u'<STR_LIT:s>' ) . using ( default = u'<STR_LIT>' ) ) <EOL> el = schemaf ( ) <EOL> el . set_default ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:2> ) <EOL> eq_ ( el . value , [ u'<STR_LIT>' ] * <NUM_LIT:2> ) <EOL> def test_set_default_value ( ) : <EOL> def factory ( default , ** kw ) : <EOL> return List . using ( default = default , ** kw ) . of ( <EOL> String . using ( default = u'<STR_LIT>' ) ) <EOL> schema = factory ( [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> el = schema ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:0> ) <EOL> eq_ ( el . value , [ ] ) <EOL> el = schema ( ) <EOL> el . set_default ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:2> ) <EOL> eq_ ( el . value , [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> el = schema ( [ u'<STR_LIT:c>' , u'<STR_LIT:d>' ] ) <EOL> eq_ ( el . value , [ u'<STR_LIT:c>' , u'<STR_LIT:d>' ] ) <EOL> el . set_default ( ) <EOL> eq_ ( el . value , [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> schema0 = factory ( [ ] ) <EOL> el = schema0 ( ) <EOL> el . set_default ( ) <EOL> eq_ ( len ( el ) , <NUM_LIT:0> ) <EOL> eq_ ( el . value , [ ] ) <EOL> def test_set_default_none ( ) : <EOL> def factory ( default , ** kw ) : <EOL> return List . using ( default = default , ** kw ) . of ( <EOL> String . using ( default = u'<STR_LIT>' ) ) <EOL> for default in None , Unspecified : <EOL> schema = factory ( default ) <EOL> el = schema ( ) <EOL> eq_ ( el . value , [ ] ) <EOL> el = schema ( ) <EOL> el . set_default ( ) <EOL> eq_ ( el . value , [ ] ) <EOL> schema = factory ( None ) <EOL> el = schema ( [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> eq_ ( el . value , [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> el . set_default ( ) <EOL> eq_ ( el . value , [ u'<STR_LIT:a>' , u'<STR_LIT:b>' ] ) <EOL> def test_set ( ) : <EOL> schema = List . of ( Integer ) <EOL> el = schema ( ) <EOL> assert list ( el ) == [ ] <EOL> el = schema ( ) <EOL> assert not el . set ( <NUM_LIT:1> ) <EOL> assert el . value == [ ] <EOL> el = schema ( ) <EOL> assert not el . set ( None ) <EOL> assert el . value == [ ] <EOL> el = schema ( ) <EOL> assert el . set ( range ( <NUM_LIT:3> ) ) <EOL> assert el . value == [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> el = schema ( ) <EOL> assert el . set ( xrange ( <NUM_LIT:3> ) ) <EOL> assert el . value == [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> el = schema ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert el . value == [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> el = schema ( ) <EOL> el . extend ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> assert el . value == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> el . set ( [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> assert el . value == [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> assert el . set ( [ ] ) <EOL> assert el . value == [ ] <EOL> def test_access ( ) : <EOL> pairs = ( ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , ) <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema . from_flat ( pairs ) <EOL> elements = list ( Integer . named ( u'<STR_LIT:i>' ) ( val ) <EOL> for val in ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> assert len ( el ) == <NUM_LIT:3> <EOL> assert el [ <NUM_LIT:0> ] == elements [ <NUM_LIT:0> ] <EOL> assert el [ <NUM_LIT:1> ] == elements [ <NUM_LIT:1> ] <EOL> assert el [ <NUM_LIT:2> ] == elements [ <NUM_LIT:2> ] <EOL> assert el [ <NUM_LIT:0> ] . value == <NUM_LIT:10> <EOL> assert el [ : <NUM_LIT:0> ] == elements [ : <NUM_LIT:0> ] <EOL> assert el [ : <NUM_LIT:1> ] == elements [ : <NUM_LIT:1> ] <EOL> assert el [ <NUM_LIT:0> : <NUM_LIT:5> ] == elements [ <NUM_LIT:0> : <NUM_LIT:5> ] <EOL> assert el [ - <NUM_LIT:2> : - <NUM_LIT:1> ] == elements [ - <NUM_LIT:2> : - <NUM_LIT:1> ] <EOL> assert el [ <NUM_LIT:0> ] in el <EOL> assert elements [ <NUM_LIT:0> ] in el <EOL> assert u'<STR_LIT>' in el <EOL> assert <NUM_LIT:10> in el <EOL> assert el . count ( elements [ <NUM_LIT:0> ] ) == <NUM_LIT:1> <EOL> assert el . count ( u'<STR_LIT>' ) == <NUM_LIT:1> <EOL> assert el . count ( <NUM_LIT:10> ) == <NUM_LIT:1> <EOL> assert el . index ( elements [ <NUM_LIT:0> ] ) == <NUM_LIT:0> <EOL> assert el . index ( u'<STR_LIT>' ) == <NUM_LIT:0> <EOL> assert el . index ( <NUM_LIT:10> ) == <NUM_LIT:0> <EOL> def test_mutation ( ) : <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema ( ) <EOL> new_element = Integer . named ( u'<STR_LIT:i>' ) <EOL> def order_ok ( ) : <EOL> slot_names = list ( _ . name for _ in el . _slots ) <EOL> for idx , name in enumerate ( slot_names ) : <EOL> assert name == str ( idx ) . decode ( '<STR_LIT:ascii>' ) <EOL> assert not el <EOL> order_ok ( ) <EOL> el . append ( new_element ( u'<STR_LIT:0>' ) ) <EOL> assert el . value == [ <NUM_LIT:0> ] <EOL> order_ok ( ) <EOL> el . append ( u'<STR_LIT>' ) <EOL> assert el . value == [ <NUM_LIT:0> , <NUM_LIT> ] <EOL> order_ok ( ) <EOL> el . extend ( [ u'<STR_LIT:4>' , u'<STR_LIT:5>' ] ) <EOL> assert el . value == [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> order_ok ( ) <EOL> el [ <NUM_LIT:0> ] = u'<STR_LIT:3>' <EOL> assert el . value == [ <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> order_ok ( ) <EOL> el . insert ( <NUM_LIT:0> , u'<STR_LIT:2>' ) <EOL> assert el . value == [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> order_ok ( ) <EOL> v = el . pop ( ) <EOL> assert v . value == <NUM_LIT:5> <EOL> assert not v . parent <EOL> order_ok ( ) <EOL> v = el . pop ( <NUM_LIT:0> ) <EOL> assert v . value == <NUM_LIT:2> <EOL> assert el . value == [ <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:4> ] <EOL> order_ok ( ) <EOL> el . remove ( u'<STR_LIT:3>' ) <EOL> assert el . value == [ <NUM_LIT> , <NUM_LIT:4> ] <EOL> order_ok ( ) <EOL> del el [ : ] <EOL> assert el . value == [ ] <EOL> order_ok ( ) <EOL> def test_mutate_slices ( ) : <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema ( ) <EOL> canary = [ ] <EOL> el . extend ( [ u'<STR_LIT:3>' , u'<STR_LIT:4>' ] ) <EOL> canary . extend ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> el [ <NUM_LIT:0> : <NUM_LIT:1> ] = [ u'<STR_LIT:1>' , u'<STR_LIT:2>' , u'<STR_LIT:3>' ] <EOL> canary [ <NUM_LIT:0> : <NUM_LIT:1> ] = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> eq_ ( el . value , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> eq_ ( canary , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> del el [ <NUM_LIT:2> : ] <EOL> del canary [ <NUM_LIT:2> : ] <EOL> assert el . value == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert canary == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> def test_reverse ( ) : <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema ( [ <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> assert el . flatten ( ) == [ ( u'<STR_LIT>' , u'<STR_LIT:2>' ) , ( u'<STR_LIT>' , u'<STR_LIT:1>' ) ] <EOL> el . reverse ( ) <EOL> assert el . value == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert el . flatten ( ) == [ ( u'<STR_LIT>' , u'<STR_LIT:1>' ) , ( u'<STR_LIT>' , u'<STR_LIT:2>' ) ] <EOL> def test_sort ( ) : <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema ( [ <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> el . sort ( key = lambda el : el . value ) <EOL> assert el . value == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert el . flatten ( ) == [ ( u'<STR_LIT>' , u'<STR_LIT:1>' ) , ( u'<STR_LIT>' , u'<STR_LIT:2>' ) ] <EOL> el . sort ( key = lambda el : el . value , reverse = True ) <EOL> assert el . value == [ <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> assert el . flatten ( ) == [ ( u'<STR_LIT>' , u'<STR_LIT:2>' ) , ( u'<STR_LIT>' , u'<STR_LIT:1>' ) ] <EOL> def test_slots ( ) : <EOL> schema = List . named ( u'<STR_LIT:l>' ) . of ( Integer . named ( u'<STR_LIT:i>' ) ) <EOL> el = schema ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert len ( list ( el . _slots ) ) == <NUM_LIT:2> <EOL> for slot in el . _slots : <EOL> assert repr ( slot ) <EOL> assert [ slot . value for slot in el . _slots ] == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> def test_u ( ) : <EOL> schema = List . of ( String ) <EOL> el = schema ( [ u'<STR_LIT:x>' , u'<STR_LIT:x>' ] ) <EOL> eq_ ( el . u , u"<STR_LIT>" ) <EOL> def test_value ( ) : <EOL> schema = List . of ( String ) <EOL> el = schema ( [ u'<STR_LIT:x>' , u'<STR_LIT:x>' ] ) <EOL> eq_ ( el . value , [ u'<STR_LIT:x>' , u'<STR_LIT:x>' ] ) </s>
<s> import os <EOL> import subprocess <EOL> import installation <EOL> def install ( data ) : <EOL> socket_path = os . path . join ( installation . paths . run_dir , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> subprocess . check_call ( [ installation . prereqs . git . path , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , socket_path ] ) <EOL> return True </s>
<s> import sys <EOL> import psycopg2 <EOL> import json <EOL> import argparse <EOL> import os <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int ) <EOL> arguments = parser . parse_args ( ) <EOL> os . setgid ( arguments . gid ) <EOL> os . setuid ( arguments . uid ) <EOL> data = json . load ( sys . stdin ) <EOL> import configuration <EOL> db = psycopg2 . connect ( ** configuration . database . PARAMETERS ) <EOL> cursor = db . cursor ( ) <EOL> try : <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> except psycopg2 . ProgrammingError : db . rollback ( ) <EOL> except : raise <EOL> cursor . execute ( """<STR_LIT>""" ) <EOL> db . commit ( ) <EOL> db . close ( ) </s>
<s> def basic ( ) : <EOL> import api <EOL> assert api . config . getBoolean ( "<STR_LIT>" , "<STR_LIT>" ) is True <EOL> assert api . config . getBoolean ( "<STR_LIT>" , "<STR_LIT>" ) is False <EOL> assert api . config . getInteger ( "<STR_LIT>" , "<STR_LIT>" ) == <NUM_LIT:10> <EOL> assert api . config . getString ( "<STR_LIT>" , "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert api . config . getValue ( "<STR_LIT>" , "<STR_LIT>" ) == [ "<STR_LIT:http>" ] <EOL> try : <EOL> api . config . getValue ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> except api . config . InvalidGroup as error : <EOL> assert error . message == "<STR_LIT>" <EOL> else : <EOL> assert False <EOL> try : <EOL> api . config . getValue ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> except api . config . InvalidKey as error : <EOL> assert error . message == "<STR_LIT>" <EOL> else : <EOL> assert False <EOL> try : <EOL> api . config . getBoolean ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> except api . config . WrongType as error : <EOL> assert error . message == ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> assert False <EOL> try : <EOL> api . config . getInteger ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> except api . config . WrongType as error : <EOL> assert error . message == ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> assert False <EOL> try : <EOL> api . config . getString ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> except api . config . WrongType as error : <EOL> assert error . message == ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> assert False <EOL> print "<STR_LIT>" </s>
<s> import sys <EOL> import os <EOL> import time <EOL> import traceback <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . abspath ( os . path . join ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) , "<STR_LIT:..>" ) ) ) <EOL> import background . utils <EOL> import dbutils <EOL> import gitutils <EOL> import mailutils <EOL> import configuration <EOL> DUMB_SUFFIX = "<STR_LIT:U+0020>" <EOL> class BranchTracker ( background . utils . BackgroundProcess ) : <EOL> def __init__ ( self ) : <EOL> super ( BranchTracker , self ) . __init__ ( service = configuration . services . BRANCHTRACKER ) <EOL> def update ( self , trackedbranch_id , repository_id , local_name , remote , remote_name , forced ) : <EOL> repository = gitutils . Repository . fromId ( self . db , repository_id ) <EOL> try : <EOL> with repository . relaycopy ( "<STR_LIT>" ) as relay : <EOL> relay . run ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:source>" , remote ) <EOL> current = None <EOL> new = None <EOL> tags = [ ] <EOL> if local_name == "<STR_LIT:*>" : <EOL> output = relay . run ( "<STR_LIT>" , "<STR_LIT:source>" , "<STR_LIT>" , include_stderr = True ) <EOL> for line in output . splitlines ( ) : <EOL> if "<STR_LIT>" in line : <EOL> tags . append ( line . rsplit ( "<STR_LIT:U+0020>" , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] ) <EOL> else : <EOL> relay . run ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:source>" , "<STR_LIT>" % ( remote_name , remote_name ) ) <EOL> try : <EOL> current = repository . revparse ( "<STR_LIT>" % local_name ) <EOL> except gitutils . GitReferenceError : <EOL> pass <EOL> new = relay . run ( "<STR_LIT>" , "<STR_LIT>" % remote_name ) . strip ( ) <EOL> if current != new or tags : <EOL> if local_name == "<STR_LIT:*>" : <EOL> refspecs = [ ( "<STR_LIT>" % tag ) for tag in tags ] <EOL> else : <EOL> refspecs = [ "<STR_LIT>" <EOL> % ( remote_name , local_name ) ] <EOL> returncode , stdout , stderr = relay . run ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , * refspecs , <EOL> env = { "<STR_LIT>" : "<STR_LIT>" % trackedbranch_id , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> check_errors = False ) <EOL> stderr_lines = [ ] <EOL> remote_lines = [ ] <EOL> for line in stderr . splitlines ( ) : <EOL> if line . endswith ( DUMB_SUFFIX ) : <EOL> line = line [ : - len ( DUMB_SUFFIX ) ] <EOL> stderr_lines . append ( line ) <EOL> if line . startswith ( "<STR_LIT>" ) : <EOL> line = line [ <NUM_LIT:8> : ] <EOL> remote_lines . append ( line ) <EOL> if returncode == <NUM_LIT:0> : <EOL> if local_name == "<STR_LIT:*>" : <EOL> for tag in tags : <EOL> self . info ( "<STR_LIT>" % tag ) <EOL> elif current : <EOL> self . info ( "<STR_LIT>" % ( local_name , current [ : <NUM_LIT:8> ] , new [ : <NUM_LIT:8> ] ) ) <EOL> else : <EOL> self . info ( "<STR_LIT>" % ( local_name , new [ : <NUM_LIT:8> ] ) ) <EOL> hook_output = "<STR_LIT>" <EOL> for line in remote_lines : <EOL> self . debug ( "<STR_LIT>" + line ) <EOL> hook_output += line + "<STR_LIT:\n>" <EOL> if local_name != "<STR_LIT:*>" : <EOL> cursor = self . db . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" , <EOL> ( trackedbranch_id , current if current else '<STR_LIT:0>' * <NUM_LIT> , new if new else '<STR_LIT:0>' * <NUM_LIT> , hook_output , True ) ) <EOL> self . db . commit ( ) <EOL> else : <EOL> if local_name == "<STR_LIT:*>" : <EOL> error = "<STR_LIT>" % remote <EOL> else : <EOL> error = "<STR_LIT>" % ( local_name , remote_name , remote ) <EOL> hook_output = "<STR_LIT>" <EOL> for line in stderr_lines : <EOL> error += "<STR_LIT>" + line <EOL> for line in remote_lines : <EOL> hook_output += line + "<STR_LIT:\n>" <EOL> self . error ( error ) <EOL> cursor = self . db . cursor ( ) <EOL> if local_name != "<STR_LIT:*>" : <EOL> cursor . execute ( """<STR_LIT>""" , <EOL> ( trackedbranch_id , current , new , hook_output , False ) ) <EOL> self . db . commit ( ) <EOL> cursor . execute ( "<STR_LIT>" , ( trackedbranch_id , ) ) <EOL> recipients = [ dbutils . User . fromId ( self . db , user_id ) for ( user_id , ) in cursor ] <EOL> if local_name == "<STR_LIT:*>" : <EOL> mailutils . sendMessage ( recipients , "<STR_LIT>" % ( repository . name , remote ) , <EOL> """<STR_LIT>""" % ( configuration . base . HOSTNAME , repository . path , remote , hook_output ) ) <EOL> else : <EOL> mailutils . sendMessage ( recipients , "<STR_LIT>" % ( local_name , remote_name , remote ) , <EOL> """<STR_LIT>""" % ( local_name , configuration . base . HOSTNAME , repository . path , remote_name , remote , hook_output ) ) <EOL> return False <EOL> else : <EOL> self . debug ( "<STR_LIT>" % ( remote_name , remote ) ) <EOL> return True <EOL> except : <EOL> exception = traceback . format_exc ( ) <EOL> if local_name == "<STR_LIT:*>" : <EOL> error = "<STR_LIT>" % remote <EOL> else : <EOL> error = "<STR_LIT>" % ( local_name , remote_name , remote ) <EOL> for line in exception . splitlines ( ) : <EOL> error += "<STR_LIT>" + line <EOL> self . error ( error ) <EOL> return True <EOL> def run ( self ) : <EOL> self . db = dbutils . Database ( ) <EOL> while not self . terminated : <EOL> self . interrupted = False <EOL> cursor = self . db . cursor ( ) <EOL> cursor . execute ( """<STR_LIT>""" ) <EOL> rows = cursor . fetchall ( ) <EOL> for trackedbranch_id , repository_id , local_name , remote , remote_name , forced in rows : <EOL> if local_name == "<STR_LIT:*>" : <EOL> self . info ( "<STR_LIT>" % remote ) <EOL> else : <EOL> self . info ( "<STR_LIT>" % ( remote_name , remote ) ) <EOL> cursor . execute ( """<STR_LIT>""" , <EOL> ( trackedbranch_id , ) ) <EOL> self . db . commit ( ) <EOL> if self . update ( trackedbranch_id , repository_id , local_name , remote , remote_name , forced ) : <EOL> cursor . execute ( """<STR_LIT>""" , <EOL> ( trackedbranch_id , ) ) <EOL> cursor . execute ( """<STR_LIT>""" , <EOL> ( trackedbranch_id , ) ) <EOL> self . info ( "<STR_LIT>" % cursor . fetchone ( ) ) <EOL> else : <EOL> cursor . execute ( """<STR_LIT>""" , <EOL> ( trackedbranch_id , ) ) <EOL> self . info ( "<STR_LIT>" ) <EOL> self . db . commit ( ) <EOL> if self . terminated : break <EOL> cursor . execute ( """<STR_LIT>""" ) <EOL> if not cursor . fetchone ( ) : <EOL> maintenance_delay = self . run_maintenance ( ) <EOL> if maintenance_delay is None : <EOL> maintenance_delay = <NUM_LIT> <EOL> cursor . execute ( """<STR_LIT>""" ) <EOL> enabled_branches , update_delay = cursor . fetchone ( ) <EOL> if not enabled_branches : <EOL> self . info ( "<STR_LIT>" ) <EOL> update_delay = <NUM_LIT> <EOL> else : <EOL> update_delay = max ( <NUM_LIT:0> , int ( update_delay ) ) <EOL> delay = min ( maintenance_delay , update_delay ) <EOL> if delay : <EOL> self . signal_idle_state ( ) <EOL> self . debug ( "<STR_LIT>" % delay ) <EOL> gitutils . Repository . forEach ( self . db , lambda db , repository : repository . stopBatch ( ) ) <EOL> self . db . commit ( ) <EOL> before = time . time ( ) <EOL> time . sleep ( delay ) <EOL> if self . interrupted : <EOL> self . debug ( "<STR_LIT>" % ( time . time ( ) - before ) ) <EOL> self . db . commit ( ) <EOL> def start_service ( ) : <EOL> tracker = BranchTracker ( ) <EOL> return tracker . start ( ) <EOL> background . utils . call ( "<STR_LIT>" , start_service ) </s>
<s> from dbaccess import ( IntegrityError , OperationalError , ProgrammingError , <EOL> TransactionRollbackError ) <EOL> from dbutils . session import Session <EOL> from dbutils . database import ( InvalidCursorError , FailedToLock , NOWAIT , <EOL> Database , boolean ) <EOL> from dbutils . user import InvalidUserId , NoSuchUser , User <EOL> from dbutils . review import NoSuchReview , ReviewState , Review <EOL> from dbutils . branch import Branch <EOL> from dbutils . paths import ( InvalidFileId , InvalidPath , File , find_file , <EOL> find_files , describe_file ) <EOL> from dbutils . timezones import ( loadTimezones , updateTimezones , sortedTimezones , <EOL> adjustTimestamp ) <EOL> from dbutils . system import ( getInstalledSHA1 , getURLPrefix , <EOL> getAdministratorContacts ) </s>
<s> import re <EOL> import configuration <EOL> import gitutils <EOL> import log . commitset <EOL> import changeset . utils <EOL> from communicate import ProcessTimeout , ProcessError <EOL> from extensions import getExtensionInstallPath <EOL> from extensions . extension import Extension <EOL> from extensions . execute import executeProcess <EOL> from extensions . manifest import Manifest , ManifestError , ProcessCommitsRole <EOL> def execute ( db , user , review , all_commits , old_head , new_head , output ) : <EOL> cursor = db . cursor ( ) <EOL> installs = Extension . getInstalls ( db , user ) <EOL> data = None <EOL> for extension_id , version_id , version_sha1 , is_universal in installs : <EOL> handlers = [ ] <EOL> extension = Extension . fromId ( db , extension_id ) <EOL> if version_id is not None : <EOL> cursor . execute ( """<STR_LIT>""" , <EOL> ( version_id , ) ) <EOL> handlers . extend ( cursor ) <EOL> if not handlers : <EOL> continue <EOL> extension_path = getExtensionInstallPath ( version_sha1 ) <EOL> manifest = Manifest . load ( extension_path ) <EOL> else : <EOL> manifest = Manifest . load ( extension . getPath ( ) ) <EOL> for role in manifest . roles : <EOL> if isinstance ( role , ProcessCommitsRole ) : <EOL> handlers . append ( ( role . script , role . function ) ) <EOL> if not handlers : <EOL> continue <EOL> if data is None : <EOL> commitset = log . commitset . CommitSet ( all_commits ) <EOL> assert old_head is None or old_head in commitset . getTails ( ) <EOL> assert new_head in commitset . getHeads ( ) <EOL> assert len ( commitset . getHeads ( ) ) == <NUM_LIT:1> <EOL> tails = commitset . getFilteredTails ( review . repository ) <EOL> if len ( tails ) == <NUM_LIT:1> : <EOL> tail = gitutils . Commit . fromSHA1 ( db , review . repository , tails . pop ( ) ) <EOL> changeset_id = changeset . utils . createChangeset ( <EOL> db , user , review . repository , from_commit = tail , to_commit = new_head ) [ <NUM_LIT:0> ] . id <EOL> changeset_arg = "<STR_LIT>" % changeset_id <EOL> else : <EOL> changeset_arg = "<STR_LIT:null>" <EOL> commits_arg = "<STR_LIT>" % "<STR_LIT:U+002C>" . join ( <EOL> [ ( "<STR_LIT>" % commit . getId ( db ) ) <EOL> for commit in all_commits ] ) <EOL> data = { "<STR_LIT>" : review . id , <EOL> "<STR_LIT>" : changeset_arg , <EOL> "<STR_LIT>" : commits_arg } <EOL> for script , function in handlers : <EOL> class Error ( Exception ) : <EOL> pass <EOL> def print_header ( ) : <EOL> header = "<STR_LIT>" % ( script , function ) <EOL> print >> output , ( "<STR_LIT>" <EOL> % ( extension . getName ( ) , header , <EOL> extension . getName ( ) , "<STR_LIT:=>" * len ( header ) ) ) <EOL> try : <EOL> argv = """<STR_LIT>""" % data <EOL> argv = re . sub ( "<STR_LIT>" , "<STR_LIT:U+0020>" , argv . strip ( ) ) <EOL> try : <EOL> stdout_data = executeProcess ( <EOL> manifest , "<STR_LIT>" , script , function , extension_id , user . id , <EOL> argv , configuration . extensions . SHORT_TIMEOUT ) <EOL> except ProcessTimeout : <EOL> raise Error ( "<STR_LIT>" % configuration . extensions . SHORT_TIMEOUT ) <EOL> except ProcessError as error : <EOL> if error . returncode < <NUM_LIT:0> : <EOL> raise Error ( "<STR_LIT>" % - error . returncode ) <EOL> else : <EOL> raise Error ( "<STR_LIT>" % ( error . returncode , error . stderr ) ) <EOL> if stdout_data . strip ( ) : <EOL> print_header ( ) <EOL> for line in stdout_data . splitlines ( ) : <EOL> print >> output , "<STR_LIT>" % ( extension . getName ( ) , line ) <EOL> except Error as error : <EOL> print_header ( ) <EOL> print >> output , "<STR_LIT>" % ( extension . getName ( ) , error . message ) </s>
<s> import sys <EOL> import os . path <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . dirname ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) ) ) <EOL> from dbaccess import connect <EOL> db = connect ( ) <EOL> cursor = db . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> preferences = cursor . fetchall ( ) <EOL> installpreferences_py = open ( os . path . join ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) , "<STR_LIT>" ) , "<STR_LIT:w>" ) <EOL> print >> installpreferences_py , "<STR_LIT>" , <EOL> for index , ( item , type , default_integer , default_string , description ) in enumerate ( preferences ) : <EOL> if index != <NUM_LIT:0> : <EOL> installpreferences_py . write ( """<STR_LIT:U+002CU+0020>""" ) <EOL> installpreferences_py . write ( """<STR_LIT>""" % ( item , type ) ) <EOL> if type == "<STR_LIT:string>" : <EOL> installpreferences_py . write ( """<STR_LIT>""" % default_string ) <EOL> else : <EOL> installpreferences_py . write ( """<STR_LIT>""" % default_integer ) <EOL> installpreferences_py . write ( """<STR_LIT>""" % description ) <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" <EOL> print >> installpreferences_py <EOL> print >> installpreferences_py , "<STR_LIT>" </s>
<s> import re <EOL> import urllib <EOL> import configuration <EOL> import dbutils <EOL> import gitutils <EOL> from operation import Operation , OperationResult , OperationFailure <EOL> def globToSQLPattern ( glob ) : <EOL> pattern = glob . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) . replace ( "<STR_LIT:%>" , "<STR_LIT>" ) . replace ( "<STR_LIT:?>" , "<STR_LIT:_>" ) . replace ( "<STR_LIT:*>" , "<STR_LIT:%>" ) <EOL> if "<STR_LIT:?>" in glob or "<STR_LIT:*>" in glob : <EOL> return pattern <EOL> return "<STR_LIT:%>" + pattern + "<STR_LIT:%>" <EOL> def pathToSQLRegExp ( path ) : <EOL> pattern = "<STR_LIT>" <EOL> if path . startswith ( "<STR_LIT:/>" ) : <EOL> pattern += "<STR_LIT>" <EOL> path = path . lstrip ( "<STR_LIT:/>" ) <EOL> escaped = re . sub ( r"<STR_LIT>" , lambda match : "<STR_LIT:\\>" + match . group ( ) , path ) <EOL> replacements = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:*>" : "<STR_LIT>" , "<STR_LIT:?>" : "<STR_LIT:.>" } <EOL> pattern += re . sub ( "<STR_LIT>" , lambda match : replacements [ match . group ( ) ] , escaped ) <EOL> return pattern <EOL> class Query ( object ) : <EOL> def __init__ ( self , parent = None ) : <EOL> if not parent : <EOL> self . tables = { "<STR_LIT>" : set ( ) } <EOL> self . arguments = [ ] <EOL> else : <EOL> self . tables = parent . tables <EOL> self . arguments = parent . arguments <EOL> self . conditions = [ ] <EOL> def addTable ( self , table , * conditions ) : <EOL> self . tables . setdefault ( table , set ( ) ) . update ( conditions ) <EOL> class Review ( object ) : <EOL> def __init__ ( self , review_id , summary ) : <EOL> self . review_id = review_id <EOL> self . summary = summary <EOL> def json ( self ) : <EOL> return { "<STR_LIT:id>" : self . review_id , "<STR_LIT>" : self . summary } <EOL> class InvalidFilter ( Exception ) : <EOL> def __init__ ( self , title , message ) : <EOL> self . title = title <EOL> self . message = message <EOL> class Filter ( object ) : <EOL> def __init__ ( self , db , value ) : <EOL> self . db = db <EOL> self . value = value <EOL> self . check ( db ) <EOL> def check ( self , db ) : <EOL> pass <EOL> def filter ( self , db , review ) : <EOL> return True <EOL> class SummaryFilter ( Filter ) : <EOL> def contribute ( self , query ) : <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( globToSQLPattern ( self . value ) ) <EOL> class DescriptionFilter ( Filter ) : <EOL> def contribute ( self , query ) : <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( globToSQLPattern ( self . value ) ) <EOL> class BranchFilter ( Filter ) : <EOL> def contribute ( self , query ) : <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( pathToSQLRegExp ( self . value ) ) <EOL> class PathFilter ( Filter ) : <EOL> def contribute ( self , query ) : <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if configuration . database . DRIVER == "<STR_LIT>" : <EOL> static_components = [ ] <EOL> for component in self . value . split ( "<STR_LIT:/>" ) : <EOL> if component and not ( "<STR_LIT:*>" in component or "<STR_LIT:?>" in component ) : <EOL> static_components . append ( component ) <EOL> if static_components : <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( static_components ) <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( pathToSQLRegExp ( self . value ) ) <EOL> class UserFilter ( Filter ) : <EOL> def check ( self , db ) : <EOL> self . user = dbutils . User . fromName ( db , self . value ) <EOL> def contribute ( self , query ) : <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( self . user . id ) <EOL> class OwnerFilter ( UserFilter ) : <EOL> def contribute ( self , query ) : <EOL> super ( OwnerFilter , self ) . contribute ( query ) <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> class ReviewerFilter ( UserFilter ) : <EOL> def contribute ( self , query ) : <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( self . user . id ) <EOL> class StateFilter ( Filter ) : <EOL> def check ( self , db ) : <EOL> if self . value not in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise InvalidFilter ( <EOL> title = "<STR_LIT>" % self . value , <EOL> message = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def contribute ( self , query ) : <EOL> state = "<STR_LIT>" if self . value in ( "<STR_LIT>" , "<STR_LIT>" ) else self . value <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( state ) <EOL> def filter ( self , db , review ) : <EOL> if self . value == "<STR_LIT>" : <EOL> return not dbutils . Review . isAccepted ( db , review . review_id ) <EOL> elif self . value == "<STR_LIT>" : <EOL> return dbutils . Review . isAccepted ( db , review . review_id ) <EOL> return True <EOL> class RepositoryFilter ( Filter ) : <EOL> def check ( self , db ) : <EOL> cursor = db . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" , ( self . value , ) ) <EOL> row = cursor . fetchone ( ) <EOL> if not row : <EOL> raise gitutils . NoSuchRepository ( self . value ) <EOL> self . repository_id = row [ <NUM_LIT:0> ] <EOL> def contribute ( self , query ) : <EOL> query . addTable ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> query . conditions . append ( "<STR_LIT>" ) <EOL> query . arguments . append ( self . repository_id ) <EOL> class OrFilter ( Filter ) : <EOL> def __init__ ( self , filters ) : <EOL> self . filters = filters <EOL> def contribute ( self , query ) : <EOL> conditions = [ ] <EOL> for search_filter in self . filters : <EOL> subquery = Query ( query ) <EOL> search_filter . contribute ( subquery ) <EOL> conditions . append ( "<STR_LIT>" % "<STR_LIT>" . join ( subquery . conditions ) ) <EOL> query . conditions . append ( "<STR_LIT>" % "<STR_LIT>" . join ( conditions ) ) <EOL> class SearchReview ( Operation ) : <EOL> def __init__ ( self ) : <EOL> Operation . __init__ ( self , { "<STR_LIT>" : str } , accept_anonymous_user = True ) <EOL> def process ( req , db , user , query ) : <EOL> terms = re . findall ( """<STR_LIT>""" , query ) <EOL> url_terms = [ ] <EOL> filters = [ ] <EOL> for term in terms : <EOL> if re . match ( "<STR_LIT>" , term ) : <EOL> keyword , _ , value = term . partition ( "<STR_LIT::>" ) <EOL> url_terms . append ( ( "<STR_LIT:q>" + keyword , value ) ) <EOL> if keyword == "<STR_LIT>" : <EOL> filter_classes = [ SummaryFilter ] <EOL> elif keyword == "<STR_LIT:description>" : <EOL> filter_classes = [ DescriptionFilter ] <EOL> elif keyword == "<STR_LIT:text>" : <EOL> filter_classes = [ SummaryFilter , DescriptionFilter ] <EOL> elif keyword in ( "<STR_LIT>" , "<STR_LIT:b>" ) : <EOL> filter_classes = [ BranchFilter ] <EOL> elif keyword in ( "<STR_LIT:path>" , "<STR_LIT:p>" ) : <EOL> filter_classes = [ PathFilter ] <EOL> elif keyword in ( "<STR_LIT:user>" , "<STR_LIT:u>" ) : <EOL> filter_classes = [ UserFilter ] <EOL> elif keyword in ( "<STR_LIT>" , "<STR_LIT:o>" ) : <EOL> filter_classes = [ OwnerFilter ] <EOL> elif keyword == "<STR_LIT>" : <EOL> filter_classes = [ ReviewerFilter ] <EOL> elif keyword == "<STR_LIT>" : <EOL> filter_classes = [ OwnerFilter , ReviewerFilter ] <EOL> elif keyword in ( "<STR_LIT:state>" , "<STR_LIT:s>" ) : <EOL> filter_classes = [ StateFilter ] <EOL> elif keyword in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:r>" ) : <EOL> filter_classes = [ RepositoryFilter ] <EOL> else : <EOL> raise OperationFailure ( <EOL> code = "<STR_LIT>" , <EOL> title = "<STR_LIT>" % keyword , <EOL> message = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if re . match ( "<STR_LIT>" , value ) : <EOL> value = value [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> try : <EOL> if len ( filter_classes ) > <NUM_LIT:1> : <EOL> keyword_filters = [ filter_class ( db , value ) <EOL> for filter_class in filter_classes ] <EOL> filters . append ( OrFilter ( keyword_filters ) ) <EOL> else : <EOL> filters . append ( filter_classes [ <NUM_LIT:0> ] ( db , value ) ) <EOL> except InvalidFilter as error : <EOL> raise OperationFailure ( <EOL> code = "<STR_LIT>" , <EOL> title = error . title , <EOL> message = error . message ) <EOL> except dbutils . NoSuchUser as error : <EOL> raise OperationFailure ( <EOL> code = "<STR_LIT>" , <EOL> title = "<STR_LIT>" % error . name , <EOL> message = ( "<STR_LIT>" <EOL> % ( keyword + "<STR_LIT::>" ) ) ) <EOL> except gitutils . NoSuchRepository as error : <EOL> raise OperationFailure ( <EOL> code = "<STR_LIT>" , <EOL> title = "<STR_LIT>" % error . name , <EOL> message = ( "<STR_LIT>" <EOL> % ( keyword + "<STR_LIT::>" ) ) ) <EOL> else : <EOL> url_terms . append ( ( "<STR_LIT:q>" , term ) ) <EOL> if re . match ( "<STR_LIT>" , term ) : <EOL> term = term [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> auto_filters = [ ] <EOL> auto_filters . append ( SummaryFilter ( db , term ) ) <EOL> auto_filters . append ( DescriptionFilter ( db , term ) ) <EOL> if not re . search ( r"<STR_LIT>" , term ) : <EOL> auto_filters . append ( BranchFilter ( db , term ) ) <EOL> if re . search ( r"<STR_LIT>" , term ) : <EOL> auto_filters . append ( PathFilter ( db , term ) ) <EOL> filters . append ( OrFilter ( auto_filters ) ) <EOL> if not filters : <EOL> raise OperationFailure ( <EOL> code = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> message = "<STR_LIT>" ) <EOL> query_params = Query ( ) <EOL> for search_filter in filters : <EOL> search_filter . contribute ( query_params ) <EOL> query_string = """<STR_LIT>""" <EOL> for conditions in query_params . tables . values ( ) : <EOL> query_params . conditions [ <NUM_LIT:0> : <NUM_LIT:0> ] = conditions <EOL> query = query_string % ( "<STR_LIT:U+002CU+0020>" . join ( query_params . tables . keys ( ) ) , <EOL> "<STR_LIT>" . join ( query_params . conditions ) ) <EOL> cursor = db . cursor ( ) <EOL> cursor . execute ( query , query_params . arguments ) <EOL> reviews = [ Review ( review_id , summary ) for review_id , summary in cursor ] <EOL> for search_filter in filters : <EOL> reviews = filter ( lambda review : search_filter . filter ( db , review ) , reviews ) <EOL> return OperationResult ( <EOL> reviews = map ( Review . json , reviews ) , <EOL> query_string = urllib . urlencode ( url_terms ) ) </s>
<s> import os <EOL> import socket <EOL> import time <EOL> import errno <EOL> import page . utils <EOL> import htmlutils <EOL> import dbutils <EOL> import configuration <EOL> import textutils <EOL> def renderServices ( req , db , user ) : <EOL> req . content_type = "<STR_LIT>" <EOL> document = htmlutils . Document ( req ) <EOL> document . setTitle ( "<STR_LIT>" ) <EOL> html = document . html ( ) <EOL> head = html . head ( ) <EOL> body = html . body ( ) <EOL> page . utils . generateHeader ( body , db , user , current_page = "<STR_LIT>" ) <EOL> document . addExternalStylesheet ( "<STR_LIT>" ) <EOL> document . addExternalScript ( "<STR_LIT>" ) <EOL> document . addInternalScript ( user . getJS ( ) ) <EOL> delay = <NUM_LIT:0.5> <EOL> connected = False <EOL> while not connected and delay <= <NUM_LIT:10> : <EOL> connection = socket . socket ( socket . AF_UNIX , socket . SOCK_STREAM ) <EOL> try : <EOL> connection . connect ( configuration . services . SERVICEMANAGER [ "<STR_LIT:address>" ] ) <EOL> connected = True <EOL> except socket . error as error : <EOL> if error [ <NUM_LIT:0> ] in ( errno . ENOENT , errno . ECONNREFUSED ) : <EOL> time . sleep ( delay ) <EOL> delay += delay <EOL> else : raise <EOL> if not connected : <EOL> raise page . utils . DisplayMessage ( "<STR_LIT>" ) <EOL> connection . send ( textutils . json_encode ( { "<STR_LIT>" : "<STR_LIT:status>" } ) ) <EOL> connection . shutdown ( socket . SHUT_WR ) <EOL> data = "<STR_LIT>" <EOL> while True : <EOL> received = connection . recv ( <NUM_LIT> ) <EOL> if not received : break <EOL> data += received <EOL> result = textutils . json_decode ( data ) <EOL> if result [ "<STR_LIT:status>" ] == "<STR_LIT:error>" : <EOL> raise page . utils . DisplayMessage ( result [ "<STR_LIT:error>" ] ) <EOL> paleyellow = page . utils . PaleYellowTable ( body , "<STR_LIT>" ) <EOL> def render ( target ) : <EOL> table = target . table ( "<STR_LIT>" ) <EOL> headings = table . tr ( "<STR_LIT>" ) <EOL> headings . th ( "<STR_LIT:name>" ) . text ( "<STR_LIT:Name>" ) <EOL> headings . th ( "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> headings . th ( "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> headings . th ( "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> headings . th ( "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> headings . th ( "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> headings . th ( "<STR_LIT>" ) . text ( ) <EOL> table . tr ( "<STR_LIT>" ) . td ( "<STR_LIT>" , colspan = <NUM_LIT:4> ) <EOL> def formatUptime ( seconds ) : <EOL> def inner ( seconds ) : <EOL> if seconds < <NUM_LIT> : return "<STR_LIT>" % seconds <EOL> elif seconds < <NUM_LIT> * <NUM_LIT> : return "<STR_LIT>" % ( seconds / <NUM_LIT> ) <EOL> elif seconds < <NUM_LIT> * <NUM_LIT> * <NUM_LIT> : return "<STR_LIT>" % ( seconds / ( <NUM_LIT> * <NUM_LIT> ) ) <EOL> else : return "<STR_LIT>" % ( seconds / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) <EOL> return inner ( int ( seconds ) ) . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) <EOL> def formatRSS ( bytes ) : <EOL> if bytes < <NUM_LIT> : return "<STR_LIT>" % bytes <EOL> elif bytes < <NUM_LIT> ** <NUM_LIT:2> : return "<STR_LIT>" % ( float ( bytes ) / <NUM_LIT> ) <EOL> elif bytes < <NUM_LIT> ** <NUM_LIT:3> : return "<STR_LIT>" % ( float ( bytes ) / <NUM_LIT> ** <NUM_LIT:2> ) <EOL> else : return "<STR_LIT>" % ( float ( bytes ) / <NUM_LIT> ** <NUM_LIT:3> ) <EOL> def formatCPU ( seconds ) : <EOL> minutes = int ( seconds / <NUM_LIT> ) <EOL> seconds = seconds - minutes * <NUM_LIT> <EOL> seconds = "<STR_LIT>" % seconds <EOL> if seconds . find ( "<STR_LIT:.>" ) == <NUM_LIT:1> : seconds = "<STR_LIT:0>" + seconds <EOL> return "<STR_LIT>" % ( minutes , seconds ) <EOL> def getProcessData ( pid ) : <EOL> try : <EOL> items = open ( "<STR_LIT>" % pid ) . read ( ) . split ( ) <EOL> return { "<STR_LIT>" : formatCPU ( float ( int ( items [ <NUM_LIT> ] ) + int ( items [ <NUM_LIT> ] ) ) / os . sysconf ( "<STR_LIT>" ) ) , <EOL> "<STR_LIT>" : formatRSS ( int ( items [ <NUM_LIT> ] ) * os . sysconf ( "<STR_LIT>" ) ) } <EOL> except : <EOL> return { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> for service_name , service_data in sorted ( result [ "<STR_LIT>" ] . items ( ) ) : <EOL> process_data = getProcessData ( service_data [ "<STR_LIT>" ] ) <EOL> row = table . tr ( "<STR_LIT>" ) <EOL> row . td ( "<STR_LIT:name>" ) . text ( service_name ) <EOL> row . td ( "<STR_LIT>" ) . text ( service_data [ "<STR_LIT>" ] ) <EOL> row . td ( "<STR_LIT>" ) . text ( service_data [ "<STR_LIT>" ] if service_data [ "<STR_LIT>" ] != - <NUM_LIT:1> else "<STR_LIT>" ) <EOL> row . td ( "<STR_LIT>" ) . text ( process_data [ "<STR_LIT>" ] ) <EOL> row . td ( "<STR_LIT>" ) . text ( process_data [ "<STR_LIT>" ] ) <EOL> row . td ( "<STR_LIT>" ) . innerHTML ( formatUptime ( service_data [ "<STR_LIT>" ] ) ) <EOL> commands = row . td ( "<STR_LIT>" ) <EOL> commands . a ( href = "<STR_LIT>" % htmlutils . jsify ( service_name ) ) . text ( "<STR_LIT>" ) <EOL> commands . a ( href = "<STR_LIT>" % htmlutils . jsify ( service_name ) ) . text ( "<STR_LIT>" ) <EOL> for index , pid in enumerate ( os . listdir ( configuration . paths . WSGI_PIDFILE_DIR ) ) : <EOL> startup = float ( open ( os . path . join ( configuration . paths . WSGI_PIDFILE_DIR , pid ) ) . read ( ) ) <EOL> uptime = time . time ( ) - startup <EOL> process_data = getProcessData ( int ( pid ) ) <EOL> row = table . tr ( "<STR_LIT>" ) <EOL> row . td ( "<STR_LIT:name>" ) . text ( "<STR_LIT>" % index ) <EOL> row . td ( "<STR_LIT>" ) . text ( ) <EOL> row . td ( "<STR_LIT>" ) . text ( pid ) <EOL> row . td ( "<STR_LIT>" ) . text ( process_data [ "<STR_LIT>" ] ) <EOL> row . td ( "<STR_LIT>" ) . text ( process_data [ "<STR_LIT>" ] ) <EOL> row . td ( "<STR_LIT>" ) . innerHTML ( formatUptime ( uptime ) ) <EOL> commands = row . td ( "<STR_LIT>" ) <EOL> commands . a ( href = "<STR_LIT>" ) . text ( "<STR_LIT>" ) <EOL> paleyellow . addCentered ( render ) <EOL> return document </s>
<s> import re <EOL> try : <EOL> import pygments . lexers <EOL> import pygments . token <EOL> except ImportError : <EOL> LANGUAGES = { } <EOL> else : <EOL> LANGUAGES = { "<STR_LIT>" : pygments . lexers . PythonLexer , <EOL> "<STR_LIT>" : pygments . lexers . PerlLexer , <EOL> "<STR_LIT>" : pygments . lexers . JavaLexer , <EOL> "<STR_LIT>" : pygments . lexers . RubyLexer , <EOL> "<STR_LIT>" : pygments . lexers . PhpLexer , <EOL> "<STR_LIT>" : pygments . lexers . MakefileLexer , <EOL> "<STR_LIT>" : pygments . lexers . JavascriptLexer , <EOL> "<STR_LIT>" : pygments . lexers . SqlLexer , <EOL> "<STR_LIT>" : pygments . lexers . ObjectiveCLexer , <EOL> "<STR_LIT>" : pygments . lexers . XmlLexer } <EOL> import htmlutils <EOL> class HighlightGeneric : <EOL> def __init__ ( self , lexer ) : <EOL> self . lexer = lexer <EOL> def highlightToken ( self , token , value ) : <EOL> def tag ( cls , value ) : return "<STR_LIT>" % ( cls , htmlutils . htmlify ( value ) ) <EOL> def tagm ( cls , value ) : <EOL> if value == "<STR_LIT:\n>" : return value <EOL> else : <EOL> res = [ ] <EOL> for line in value . splitlines ( ) : <EOL> if line : res . append ( tag ( cls , line ) ) <EOL> else : res . append ( line ) <EOL> if value . endswith ( "<STR_LIT:\n>" ) : res . append ( "<STR_LIT>" ) <EOL> return "<STR_LIT:\n>" . join ( res ) <EOL> value = value . encode ( "<STR_LIT:utf-8>" ) <EOL> if token in pygments . token . Token . Punctuation or token in pygments . token . Token . Operator : <EOL> self . output . write ( tag ( "<STR_LIT>" , value ) ) <EOL> elif token in pygments . token . Token . Name or token in pygments . token . Token . String . Symbol : <EOL> self . output . write ( tag ( "<STR_LIT:id>" , value ) ) <EOL> elif token in pygments . token . Token . Keyword : <EOL> self . output . write ( tag ( "<STR_LIT>" , value ) ) <EOL> elif token in pygments . token . Token . String : <EOL> self . output . write ( tagm ( "<STR_LIT:str>" , value ) ) <EOL> elif token in pygments . token . Token . Comment : <EOL> self . output . write ( tagm ( "<STR_LIT>" , value ) ) <EOL> elif token in pygments . token . Token . Number . Integer : <EOL> self . output . write ( tag ( "<STR_LIT:int>" , value ) ) <EOL> elif token in pygments . token . Token . Number . Float : <EOL> self . output . write ( tag ( "<STR_LIT>" , value ) ) <EOL> else : <EOL> self . output . write ( htmlutils . htmlify ( value ) ) <EOL> def __call__ ( self , source , output_file , contexts_path ) : <EOL> self . output = output_file <EOL> blocks = re . split ( "<STR_LIT>" , source , flags = re . MULTILINE ) <EOL> in_conflict = False <EOL> for index , block in enumerate ( blocks ) : <EOL> if ( index & <NUM_LIT:1> ) == <NUM_LIT:0> : <EOL> if in_conflict : <EOL> blocks = re . split ( "<STR_LIT>" , block , flags = re . MULTILINE ) <EOL> else : <EOL> blocks = [ block ] <EOL> for index , block in enumerate ( blocks ) : <EOL> if ( index & <NUM_LIT:1> ) == <NUM_LIT:0> : <EOL> if block : <EOL> for token , value in self . lexer . get_tokens ( block ) : <EOL> self . highlightToken ( token , value ) <EOL> else : <EOL> assert block [ <NUM_LIT:0> ] == "<STR_LIT:=>" <EOL> self . output . write ( htmlutils . htmlify ( block ) ) <EOL> else : <EOL> assert block [ <NUM_LIT:0> ] == "<STR_LIT:<>" or block [ <NUM_LIT:0> ] == "<STR_LIT:>>" <EOL> self . output . write ( htmlutils . htmlify ( block ) ) <EOL> in_conflict = block [ <NUM_LIT:0> ] == "<STR_LIT:<>" <EOL> @ staticmethod <EOL> def create ( language ) : <EOL> lexer = LANGUAGES . get ( language ) <EOL> if lexer : return HighlightGeneric ( lexer ( stripnl = False ) ) <EOL> else : return None <EOL> import syntaxhighlight <EOL> syntaxhighlight . LANGUAGES . update ( LANGUAGES . keys ( ) ) </s>
<s> frontend . page ( "<STR_LIT>" , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) <EOL> frontend . page ( "<STR_LIT>" , <EOL> params = { "<STR_LIT>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT>" : testing . expect . document_title ( u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . paleyellow_title ( <NUM_LIT:0> , u"<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . pageheader_links ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : testing . expect . script_no_user ( ) } ) </s>
<s> def expect_success ( argv , expected_output_lines = [ ] ) : <EOL> try : <EOL> output = instance . criticctl ( argv ) <EOL> except testing . CriticctlError as error : <EOL> logger . error ( "<STR_LIT>" <EOL> % ( "<STR_LIT:U+0020>" . join ( argv ) , error . stdout ) ) <EOL> return [ ] <EOL> else : <EOL> output_lines = set ( map ( str . strip , output . splitlines ( ) ) ) <EOL> for line in expected_output_lines : <EOL> if line . strip ( ) not in output_lines : <EOL> logger . error ( "<STR_LIT>" <EOL> % ( "<STR_LIT:U+0020>" . join ( argv ) , line ) ) <EOL> return output_lines <EOL> def expect_failure ( argv , expected_output_lines = [ ] ) : <EOL> try : <EOL> instance . criticctl ( argv ) <EOL> except testing . CriticctlError as error : <EOL> output_lines = set ( map ( str . strip , error . stderr . splitlines ( ) ) ) <EOL> for line in expected_output_lines : <EOL> if line . strip ( ) not in output_lines : <EOL> logger . error ( "<STR_LIT>" <EOL> % ( "<STR_LIT:U+0020>" . join ( argv ) , line ) ) <EOL> return output_lines <EOL> else : <EOL> logger . error ( "<STR_LIT>" <EOL> % "<STR_LIT:U+0020>" . join ( argv ) ) <EOL> return [ ] <EOL> try : <EOL> instance . execute ( [ "<STR_LIT>" ] ) <EOL> except testing . NotSupported : <EOL> pass <EOL> except testing . virtualbox . GuestCommandError as error : <EOL> output_lines = set ( map ( str . strip , error . stderr . splitlines ( ) ) ) <EOL> if "<STR_LIT>" not in output_lines : <EOL> logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> logger . error ( "<STR_LIT>" ) <EOL> usage_lines = expect_success ( [ ] , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> expect_success ( [ "<STR_LIT>" ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" , instance . etc_dir ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" + instance . etc_dir ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" , instance . etc_dir ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" + instance . etc_dir ] , <EOL> usage_lines ) <EOL> lines = expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] ) <EOL> expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> lines ) <EOL> lines = expect_failure ( [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" <EOL> "<STR_LIT>" ] ) <EOL> expect_failure ( [ "<STR_LIT>" ] , <EOL> lines ) <EOL> expect_success ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> usage_lines ) <EOL> expect_success ( [ "<STR_LIT>" ] , <EOL> usage_lines ) <EOL> lines = expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] ) <EOL> expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> lines ) <EOL> lines = expect_failure ( [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" <EOL> "<STR_LIT>" ] ) <EOL> expect_failure ( [ "<STR_LIT>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] ) <EOL> expect_failure ( [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] ) <EOL> lines = expect_failure ( [ "<STR_LIT:foo>" ] , <EOL> [ "<STR_LIT>" ] ) <EOL> expect_failure ( [ "<STR_LIT>" , instance . etc_dir , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" + instance . etc_dir , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" , instance . etc_dir , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" + instance . etc_dir , "<STR_LIT>" , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , instance . etc_dir , "<STR_LIT:foo>" ] , <EOL> lines ) <EOL> expect_failure ( [ "<STR_LIT>" , "<STR_LIT>" + instance . etc_dir , "<STR_LIT:foo>" ] , <EOL> lines ) </s>
<s> instance . extend ( repository ) </s>
<s> instance . unittest ( "<STR_LIT>" , [ "<STR_LIT>" ] ) </s>
<s> import sys <EOL> import os <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:..>' ) ) ) <EOL> extensions = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> templates_path = [ '<STR_LIT>' ] <EOL> source_suffix = '<STR_LIT>' <EOL> master_doc = '<STR_LIT:index>' <EOL> project = u'<STR_LIT>' <EOL> copyright = u'<STR_LIT>' <EOL> version = '<STR_LIT>' <EOL> release = '<STR_LIT>' <EOL> exclude_patterns = [ '<STR_LIT>' ] <EOL> pygments_style = '<STR_LIT>' <EOL> html_theme = '<STR_LIT:default>' <EOL> html_static_path = [ '<STR_LIT>' ] <EOL> htmlhelp_basename = '<STR_LIT>' <EOL> latex_elements = { <EOL> } <EOL> latex_documents = [ <EOL> ( '<STR_LIT:index>' , '<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> man_pages = [ <EOL> ( '<STR_LIT:index>' , '<STR_LIT>' , u'<STR_LIT>' , <EOL> [ u'<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> ] <EOL> texinfo_documents = [ <EOL> ( '<STR_LIT:index>' , '<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ] </s>
<s> from pylab import * <EOL> from numpy import * <EOL> from PIL import Image <EOL> from PCV . localdescriptors import harris <EOL> """<STR_LIT>""" <EOL> im = array ( Image . open ( '<STR_LIT>' ) . convert ( '<STR_LIT:L>' ) ) <EOL> harrisim = harris . compute_harris_response ( im ) <EOL> filtered_coords = harris . get_harris_points ( harrisim , <NUM_LIT:10> , threshold = <NUM_LIT> ) <EOL> harris . plot_harris_points ( im , filtered_coords ) <EOL> harris . plot_harris_points ( im , filtered_coords [ : <NUM_LIT:200> ] ) </s>
<s> from PIL import Image <EOL> import os <EOL> from numpy import * <EOL> from pylab import * <EOL> def process_image ( imagename , resultname , params = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if imagename [ - <NUM_LIT:3> : ] != '<STR_LIT>' : <EOL> im = Image . open ( imagename ) . convert ( '<STR_LIT:L>' ) <EOL> im . save ( '<STR_LIT>' ) <EOL> imagename = '<STR_LIT>' <EOL> cmmd = str ( "<STR_LIT>" + imagename + "<STR_LIT>" + resultname + <EOL> "<STR_LIT:U+0020>" + params ) <EOL> os . system ( cmmd ) <EOL> print '<STR_LIT>' , imagename , '<STR_LIT:to>' , resultname <EOL> def read_features_from_file ( filename ) : <EOL> """<STR_LIT>""" <EOL> f = loadtxt ( filename ) <EOL> return f [ : , : <NUM_LIT:4> ] , f [ : , <NUM_LIT:4> : ] <EOL> def write_features_to_file ( filename , locs , desc ) : <EOL> """<STR_LIT>""" <EOL> savetxt ( filename , hstack ( ( locs , desc ) ) ) <EOL> def plot_features ( im , locs , circle = False ) : <EOL> """<STR_LIT>""" <EOL> def draw_circle ( c , r ) : <EOL> t = arange ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) * <NUM_LIT:2> * pi <EOL> x = r * cos ( t ) + c [ <NUM_LIT:0> ] <EOL> y = r * sin ( t ) + c [ <NUM_LIT:1> ] <EOL> plot ( x , y , '<STR_LIT:b>' , linewidth = <NUM_LIT:2> ) <EOL> imshow ( im ) <EOL> if circle : <EOL> for p in locs : <EOL> draw_circle ( p [ : <NUM_LIT:2> ] , p [ <NUM_LIT:2> ] ) <EOL> else : <EOL> plot ( locs [ : , <NUM_LIT:0> ] , locs [ : , <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> axis ( '<STR_LIT>' ) <EOL> def match ( desc1 , desc2 ) : <EOL> """<STR_LIT>""" <EOL> desc1 = array ( [ d / linalg . norm ( d ) for d in desc1 ] ) <EOL> desc2 = array ( [ d / linalg . norm ( d ) for d in desc2 ] ) <EOL> dist_ratio = <NUM_LIT> <EOL> desc1_size = desc1 . shape <EOL> matchscores = zeros ( ( desc1_size [ <NUM_LIT:0> ] ) , '<STR_LIT:int>' ) <EOL> desc2t = desc2 . T <EOL> for i in range ( desc1_size [ <NUM_LIT:0> ] ) : <EOL> dotprods = dot ( desc1 [ i , : ] , desc2t ) <EOL> dotprods = <NUM_LIT> * dotprods <EOL> indx = argsort ( arccos ( dotprods ) ) <EOL> if arccos ( dotprods ) [ indx [ <NUM_LIT:0> ] ] < dist_ratio * arccos ( dotprods ) [ indx [ <NUM_LIT:1> ] ] : <EOL> matchscores [ i ] = int ( indx [ <NUM_LIT:0> ] ) <EOL> return matchscores <EOL> def appendimages ( im1 , im2 ) : <EOL> """<STR_LIT>""" <EOL> rows1 = im1 . shape [ <NUM_LIT:0> ] <EOL> rows2 = im2 . shape [ <NUM_LIT:0> ] <EOL> if rows1 < rows2 : <EOL> im1 = concatenate ( ( im1 , zeros ( ( rows2 - rows1 , im1 . shape [ <NUM_LIT:1> ] ) ) ) , axis = <NUM_LIT:0> ) <EOL> elif rows1 > rows2 : <EOL> im2 = concatenate ( ( im2 , zeros ( ( rows1 - rows2 , im2 . shape [ <NUM_LIT:1> ] ) ) ) , axis = <NUM_LIT:0> ) <EOL> return concatenate ( ( im1 , im2 ) , axis = <NUM_LIT:1> ) <EOL> def plot_matches ( im1 , im2 , locs1 , locs2 , matchscores , show_below = True ) : <EOL> """<STR_LIT>""" <EOL> im3 = appendimages ( im1 , im2 ) <EOL> if show_below : <EOL> im3 = vstack ( ( im3 , im3 ) ) <EOL> imshow ( im3 ) <EOL> cols1 = im1 . shape [ <NUM_LIT:1> ] <EOL> for i , m in enumerate ( matchscores ) : <EOL> if m > <NUM_LIT:0> : <EOL> plot ( [ locs1 [ i ] [ <NUM_LIT:1> ] , locs2 [ m ] [ <NUM_LIT:1> ] + cols1 ] , [ locs1 [ i ] [ <NUM_LIT:0> ] , locs2 [ m ] [ <NUM_LIT:0> ] ] , '<STR_LIT:c>' ) <EOL> axis ( '<STR_LIT>' ) <EOL> def match_twosided ( desc1 , desc2 ) : <EOL> """<STR_LIT>""" <EOL> matches_12 = match ( desc1 , desc2 ) <EOL> matches_21 = match ( desc2 , desc1 ) <EOL> ndx_12 = matches_12 . nonzero ( ) [ <NUM_LIT:0> ] <EOL> for n in ndx_12 : <EOL> if matches_21 [ int ( matches_12 [ n ] ) ] != n : <EOL> matches_12 [ n ] = <NUM_LIT:0> <EOL> return matches_12 </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 . IntegerField ( default = <NUM_LIT> ) , <EOL> preserve_default = True , <EOL> ) , <EOL> ] </s>
<s> import unittest <EOL> from hamlpy import nodes <EOL> class TestElementNode ( unittest . TestCase ) : <EOL> def test_calculates_indentation_properly ( self ) : <EOL> no_indentation = nodes . ElementNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , no_indentation . indentation ) <EOL> three_indentation = nodes . ElementNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:3> , three_indentation . indentation ) <EOL> six_indentation = nodes . ElementNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:6> , six_indentation . indentation ) <EOL> def test_indents_tabs_properly ( self ) : <EOL> no_indentation = nodes . ElementNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , no_indentation . spaces ) <EOL> one_tab = nodes . HamlNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:\t>' , one_tab . spaces ) <EOL> one_space = nodes . HamlNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:U+0020>' , one_space . spaces ) <EOL> three_tabs = nodes . HamlNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , three_tabs . spaces ) <EOL> tab_space = nodes . HamlNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , tab_space . spaces ) <EOL> space_tab = nodes . HamlNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:U+0020>' , space_tab . spaces ) <EOL> def test_lines_are_always_stripped_of_whitespace ( self ) : <EOL> some_space = nodes . ElementNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , some_space . haml ) <EOL> lots_of_space = nodes . ElementNode ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , lots_of_space . haml ) <EOL> def test_inserts_nodes_into_proper_tree_depth ( self ) : <EOL> no_indentation_node = nodes . ElementNode ( '<STR_LIT>' ) <EOL> one_indentation_node = nodes . ElementNode ( '<STR_LIT>' ) <EOL> two_indentation_node = nodes . ElementNode ( '<STR_LIT>' ) <EOL> another_one_indentation_node = nodes . ElementNode ( '<STR_LIT>' ) <EOL> no_indentation_node . add_node ( one_indentation_node ) <EOL> no_indentation_node . add_node ( two_indentation_node ) <EOL> no_indentation_node . add_node ( another_one_indentation_node ) <EOL> self . assertEqual ( one_indentation_node , no_indentation_node . children [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( two_indentation_node , no_indentation_node . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( another_one_indentation_node , no_indentation_node . children [ <NUM_LIT:1> ] ) <EOL> def test_adds_multiple_nodes_to_one ( self ) : <EOL> start = nodes . ElementNode ( '<STR_LIT>' ) <EOL> one = nodes . ElementNode ( '<STR_LIT>' ) <EOL> two = nodes . ElementNode ( '<STR_LIT>' ) <EOL> three = nodes . ElementNode ( '<STR_LIT>' ) <EOL> start . add_node ( one ) <EOL> start . add_node ( two ) <EOL> start . add_node ( three ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( start . children ) ) <EOL> def test_html_indentation_vs_haml_indentation ( self ) : <EOL> pass <EOL> def test_node_parent_function ( self ) : <EOL> root = nodes . ElementNode ( '<STR_LIT>' ) <EOL> elements = [ <EOL> { '<STR_LIT>' : nodes . ElementNode ( '<STR_LIT>' ) , '<STR_LIT>' : '<STR_LIT:root>' } , <EOL> { '<STR_LIT>' : nodes . ElementNode ( '<STR_LIT>' ) , '<STR_LIT>' : '<STR_LIT:root>' } , <EOL> { '<STR_LIT>' : nodes . ElementNode ( '<STR_LIT>' ) , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : nodes . ElementNode ( '<STR_LIT>' ) , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : nodes . ElementNode ( '<STR_LIT>' ) , '<STR_LIT>' : '<STR_LIT:root>' } , <EOL> ] <EOL> for el in elements : <EOL> self . assertEqual ( root . parent_of ( el [ '<STR_LIT>' ] ) , eval ( el [ '<STR_LIT>' ] ) ) <EOL> root . add_node ( el [ '<STR_LIT>' ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
<s> """<STR_LIT>""" <EOL> from base64 import b64encode <EOL> from contextlib import contextmanager <EOL> from json import loads <EOL> from os import environ <EOL> from os . path import dirname , exists , join <EOL> from shutil import copyfile , rmtree <EOL> from textwrap import dedent <EOL> from mock import patch <EOL> from nose . tools import assert_raises , eq_ , ok_ <EOL> from requests import codes <EOL> from cheddar . index . remote import iter_version_links <EOL> from cheddar . tests . fixtures import setup <EOL> class TestControllers ( object ) : <EOL> def setup ( self ) : <EOL> setup ( self ) <EOL> self . username = "<STR_LIT:username>" <EOL> self . password = "<STR_LIT:password>" <EOL> self . client = self . app . test_client ( ) <EOL> self . use_json = dict ( accept = "<STR_LIT>" ) <EOL> auth = b64encode ( "<STR_LIT>" . format ( self . username , self . password ) ) <EOL> self . use_auth = dict ( authorization = "<STR_LIT>" . format ( auth ) ) <EOL> self . app . redis . set ( "<STR_LIT>" . format ( self . username ) , self . password ) <EOL> def teardown ( self ) : <EOL> if self . previous_config_file is None : <EOL> del environ [ "<STR_LIT>" ] <EOL> else : <EOL> environ [ "<STR_LIT>" ] = self . previous_config_file <EOL> rmtree ( self . local_cache_dir ) <EOL> rmtree ( self . remote_cache_dir ) <EOL> rmtree ( self . config_dir ) <EOL> def test_index_template_render ( self ) : <EOL> result = self . client . get ( "<STR_LIT:/>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> def test_index_template_json ( self ) : <EOL> result = self . client . get ( "<STR_LIT:/>" , headers = self . use_json ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( loads ( result . data ) , dict ( history = [ ] ) ) <EOL> def test_get_projects_no_projects_template_render ( self ) : <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> def test_get_projects_no_project_json ( self ) : <EOL> result = self . client . get ( "<STR_LIT>" , headers = self . use_json ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( loads ( result . data ) , dict ( projects = [ ] ) ) <EOL> def test_get_projects_two_projects_json ( self ) : <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:foo>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" } ) <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:bar>" , "<STR_LIT:version>" : "<STR_LIT>" } ) <EOL> result = self . client . get ( "<STR_LIT>" , headers = self . use_json ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( loads ( result . data ) , dict ( projects = [ "<STR_LIT:bar>" , "<STR_LIT:foo>" ] ) ) <EOL> def test_get_project_local_template_render ( self ) : <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:foo>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:foo>" , "<STR_LIT:version>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:foo>" , "<STR_LIT:version>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> iter_ = iter_version_links ( result . data , "<STR_LIT:foo>" ) <EOL> eq_ ( iter_ . next ( ) , ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> eq_ ( iter_ . next ( ) , ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> eq_ ( iter_ . next ( ) , ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> with assert_raises ( StopIteration ) : <EOL> iter_ . next ( ) <EOL> def test_get_project_remote_template_render ( self ) : <EOL> with self . _mocked_get ( "<STR_LIT>" , codes . ok ) as mock_get : <EOL> mock_get . return_value . text = dedent ( """<STR_LIT>""" ) <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> iter_ = iter_version_links ( result . data , "<STR_LIT:foo>" ) <EOL> eq_ ( iter_ . next ( ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> with assert_raises ( StopIteration ) : <EOL> iter_ . next ( ) <EOL> def test_get_project_json ( self ) : <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:foo>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT:foo>" , "<STR_LIT:version>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> result = self . client . get ( "<STR_LIT>" , headers = self . use_json ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( loads ( result . data ) , dict ( project = "<STR_LIT:foo>" , <EOL> versions = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ) ) <EOL> def test_get_local_distribution ( self ) : <EOL> distribution = join ( self . local_cache_dir , "<STR_LIT>" , "<STR_LIT>" ) <EOL> copyfile ( join ( dirname ( __file__ ) , "<STR_LIT>" ) , distribution ) <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" , "<STR_LIT>" : distribution } ) <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( result . headers [ "<STR_LIT:Content-Type>" ] , "<STR_LIT>" ) <EOL> eq_ ( result . headers [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_get_remote_distribution ( self ) : <EOL> template = join ( dirname ( __file__ ) , "<STR_LIT>" ) <EOL> with self . _mocked_get ( "<STR_LIT>" , codes . ok ) as mock_get : <EOL> with open ( template ) as file_ : <EOL> mock_get . return_value . content = file_ . read ( ) <EOL> mock_get . return_value . headers = { "<STR_LIT:Content-Type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( result . headers [ "<STR_LIT:Content-Type>" ] , "<STR_LIT>" ) <EOL> eq_ ( result . headers [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_get_version_unknown_project ( self ) : <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . not_found ) <EOL> def test_get_version_unknown_version ( self ) : <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . not_found ) <EOL> def test_get_version ( self ) : <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> result = self . client . get ( "<STR_LIT>" , headers = self . use_json ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( loads ( result . data ) , dict ( project = "<STR_LIT>" , <EOL> version = "<STR_LIT:1.0>" , <EOL> metadata = dict ( name = "<STR_LIT>" , <EOL> version = "<STR_LIT:1.0>" , <EOL> _filename = "<STR_LIT>" ) ) ) <EOL> def test_get_remote_distribution_cached ( self ) : <EOL> template = join ( dirname ( __file__ ) , "<STR_LIT>" ) <EOL> distribution = join ( self . remote_cache_dir , "<STR_LIT>" , "<STR_LIT>" ) <EOL> copyfile ( template , distribution ) <EOL> result = self . client . get ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( result . headers [ "<STR_LIT:Content-Type>" ] , "<STR_LIT>" ) <EOL> eq_ ( result . headers [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_delete_version_requires_auth ( self ) : <EOL> result = self . client . delete ( "<STR_LIT>" ) <EOL> eq_ ( result . status_code , codes . unauthorized ) <EOL> def test_delete_version ( self ) : <EOL> distribution = join ( self . local_cache_dir , "<STR_LIT>" , "<STR_LIT>" ) <EOL> copyfile ( join ( dirname ( __file__ ) , "<STR_LIT>" ) , distribution ) <EOL> self . app . projects . add_metadata ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:version>" : "<STR_LIT:1.0>" , "<STR_LIT>" : distribution } ) <EOL> self . app . history . add ( "<STR_LIT>" , "<STR_LIT:1.0>" ) <EOL> eq_ ( self . app . redis . smembers ( "<STR_LIT>" ) , set ( [ "<STR_LIT>" ] ) ) <EOL> eq_ ( self . app . redis . smembers ( "<STR_LIT>" ) , set ( [ "<STR_LIT:1.0>" ] ) ) <EOL> eq_ ( loads ( self . app . redis . get ( "<STR_LIT>" ) ) , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : "<STR_LIT:1.0>" , <EOL> "<STR_LIT>" : distribution } ) <EOL> ok_ ( exists ( distribution ) ) <EOL> result = self . client . delete ( "<STR_LIT>" , headers = self . use_auth ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( self . app . redis . smembers ( "<STR_LIT>" ) , set ( ) ) <EOL> ok_ ( not self . app . redis . exists ( "<STR_LIT>" ) ) <EOL> ok_ ( not self . app . redis . exists ( "<STR_LIT>" ) ) <EOL> ok_ ( not exists ( distribution ) ) <EOL> ok_ ( not self . app . history ) <EOL> def test_register_missing_required_parameters ( self ) : <EOL> result = self . client . post ( "<STR_LIT>" , data = { } ) <EOL> eq_ ( result . status_code , codes . bad_request ) <EOL> def test_register_ok ( self ) : <EOL> result = self . client . post ( "<STR_LIT>" , data = { "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : "<STR_LIT:1.0>" } ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> def test_upload_requires_auth ( self ) : <EOL> with open ( join ( dirname ( __file__ ) , "<STR_LIT>" ) ) as file_ : <EOL> result = self . client . post ( "<STR_LIT>" , data = { "<STR_LIT:file>" : ( file_ , "<STR_LIT>" ) } ) <EOL> eq_ ( result . status_code , codes . unauthorized ) <EOL> def test_upload_bad_filename ( self ) : <EOL> with open ( join ( dirname ( __file__ ) , "<STR_LIT>" ) ) as file_ : <EOL> result = self . client . post ( "<STR_LIT>" , <EOL> data = { "<STR_LIT:file>" : ( file_ , "<STR_LIT>" ) } , <EOL> headers = self . use_auth ) <EOL> eq_ ( result . status_code , codes . bad_request ) <EOL> def test_upload_ok ( self ) : <EOL> with open ( join ( dirname ( __file__ ) , "<STR_LIT>" ) ) as file_ : <EOL> result = self . client . post ( "<STR_LIT>" , <EOL> data = { "<STR_LIT:file>" : ( file_ , "<STR_LIT>" ) } , <EOL> headers = self . use_auth ) <EOL> eq_ ( result . status_code , codes . ok ) <EOL> eq_ ( self . app . history . all ( ) , [ "<STR_LIT>" ] ) <EOL> @ contextmanager <EOL> def _mocked_get ( self , url , status_code , ) : <EOL> with patch ( "<STR_LIT>" ) as mock_get : <EOL> mock_get . return_value . status_code = status_code <EOL> mock_get . return_value . history = [ ] <EOL> mock_get . return_value . headers = { } <EOL> yield mock_get <EOL> mock_get . assert_called_with ( url , <EOL> timeout = self . app . config [ "<STR_LIT>" ] ) </s>
<s> from urllib import FancyURLopener <EOL> import os <EOL> import re <EOL> import sys <EOL> import logging <EOL> from unicodedata import normalize <EOL> from discogsalbum import DiscogsAlbum , TrackContainer <EOL> from discogsauth import DiscogsAuth , USER_AGENT <EOL> reload ( sys ) <EOL> sys . setdefaultencoding ( "<STR_LIT:utf-8>" ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> class TagOpener ( FancyURLopener , object ) : <EOL> version = USER_AGENT <EOL> def __init__ ( self ) : <EOL> FancyURLopener . __init__ ( self ) <EOL> class TaggerUtils ( object ) : <EOL> """<STR_LIT>""" <EOL> FILE_TYPE = ( "<STR_LIT>" , "<STR_LIT>" , ) <EOL> def __init__ ( self , sourcedir , destdir , use_lower , ogsrelid , split_artists , <EOL> split_genres_and_styles , copy_other_files , char_exceptions ) : <EOL> self . group_name = "<STR_LIT>" <EOL> self . dir_format = "<STR_LIT>" <EOL> self . m3u_format = "<STR_LIT>" <EOL> self . nfo_format = "<STR_LIT>" <EOL> self . song_format = "<STR_LIT>" <EOL> self . va_song_format = "<STR_LIT>" <EOL> self . images_format = "<STR_LIT>" <EOL> self . first_image_name = "<STR_LIT>" <EOL> self . copy_other_files = copy_other_files <EOL> self . char_exceptions = char_exceptions <EOL> self . sourcedir = sourcedir <EOL> self . destdir = destdir <EOL> result = self . _get_target_list ( ) <EOL> self . files_to_tag = result [ "<STR_LIT>" ] <EOL> if self . copy_other_files : <EOL> self . copy_files = result [ "<STR_LIT>" ] <EOL> self . album = DiscogsAlbum ( ogsrelid , split_artists , split_genres_and_styles ) <EOL> self . use_lower = use_lower <EOL> if len ( self . files_to_tag ) == len ( self . album . tracks ) : <EOL> self . tag_map = self . _get_tag_map ( ) <EOL> else : <EOL> self . tag_map = False <EOL> def _value_from_tag_format ( self , format , trackno = <NUM_LIT:1> , position = <NUM_LIT:1> , filetype = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" % format ) <EOL> logger . debug ( "<STR_LIT>" % trackno ) <EOL> logger . debug ( "<STR_LIT>" % position ) <EOL> logger . debug ( "<STR_LIT>" % len ( self . album . tracks ) ) <EOL> property_map = { <EOL> "<STR_LIT>" : self . album . title , <EOL> "<STR_LIT>" : self . album . artist , <EOL> "<STR_LIT>" : self . album . year , <EOL> "<STR_LIT>" : self . album . catno , <EOL> "<STR_LIT>" : self . album . genre , <EOL> "<STR_LIT>" : self . album . style , <EOL> "<STR_LIT>" : self . group_name , <EOL> "<STR_LIT>" : self . album . tracks [ position ] . artist , <EOL> "<STR_LIT>" : self . album . tracks [ position ] . title , <EOL> "<STR_LIT>" : self . album . tracks [ position ] . discnumber , <EOL> "<STR_LIT>" : "<STR_LIT>" % trackno , <EOL> "<STR_LIT>" : filetype , <EOL> "<STR_LIT>" : self . album . label , <EOL> } <EOL> for hashtag in property_map . keys ( ) : <EOL> format = format . replace ( hashtag , <EOL> str ( property_map [ hashtag ] ) ) <EOL> logger . debug ( "<STR_LIT>" % format ) <EOL> return format <EOL> def _value_from_tag ( self , format , trackno = <NUM_LIT:1> , position = <NUM_LIT:1> , filetype = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> format = self . _value_from_tag_format ( format , trackno , position , filetype ) <EOL> if self . use_lower : <EOL> format = format . lower ( ) <EOL> format = self . _get_clean_filename ( format ) <EOL> logger . debug ( "<STR_LIT>" % format ) <EOL> return format <EOL> def _get_target_list ( self ) : <EOL> """<STR_LIT>""" <EOL> copy_files = None <EOL> try : <EOL> dir_list = os . listdir ( self . sourcedir ) <EOL> dir_list . sort ( ) <EOL> target_list = [ os . path . join ( self . sourcedir , x ) for x in dir_list <EOL> if x . lower ( ) . endswith ( TaggerUtils . FILE_TYPE ) ] <EOL> if self . copy_other_files : <EOL> copy_files = [ os . path . join ( self . sourcedir , x ) for x in <EOL> dir_list if not x . lower ( ) . endswith ( TaggerUtils . FILE_TYPE ) ] <EOL> if not target_list : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> for y in dir_list : <EOL> tmp_list = [ ] <EOL> logger . debug ( "<STR_LIT>" % y ) <EOL> sub_dir = os . path . join ( self . sourcedir , y ) <EOL> if os . path . isdir ( sub_dir ) : <EOL> tmp_list . extend ( os . listdir ( sub_dir ) ) <EOL> tmp_list . sort ( ) <EOL> tmp_list = [ os . path . join ( sub_dir , y ) for y in tmp_list ] <EOL> target_list . extend ( [ z for z in tmp_list if <EOL> z . lower ( ) . endswith ( TaggerUtils . FILE_TYPE ) ] ) <EOL> if self . copy_other_files : <EOL> copy_files = [ z for z in tmp_list if not <EOL> z . lower ( ) . endswith ( TaggerUtils . FILE_TYPE ) ] <EOL> except OSError , e : <EOL> if e . errno == errno . EEXIST : <EOL> logger . error ( "<STR_LIT>" , self . sourcedir ) <EOL> raise IOError ( "<STR_LIT>" , self . sourcedir ) <EOL> else : <EOL> raise IOError ( "<STR_LIT>" % errno [ e ] ) <EOL> return { "<STR_LIT>" : target_list , "<STR_LIT>" : copy_files } <EOL> def _get_tag_map ( self ) : <EOL> """<STR_LIT>""" <EOL> tag_map = [ ] <EOL> for position , filename in enumerate ( self . files_to_tag ) : <EOL> logger . debug ( "<STR_LIT>" % position ) <EOL> logger . debug ( "<STR_LIT>" % ( filename , <EOL> self . album . tracks [ position ] . artist , <EOL> self . album . tracks [ position ] . title ) ) <EOL> pos = position + <NUM_LIT:1> <EOL> track = self . album . tracks [ position ] <EOL> track . orig_file = filename <EOL> fileext = os . path . splitext ( filename ) [ <NUM_LIT:1> ] <EOL> if self . album . artist == "<STR_LIT>" : <EOL> newfile = self . _value_from_tag ( self . va_song_format , <EOL> track . tracknumber , position , fileext ) <EOL> else : <EOL> newfile = self . _value_from_tag ( self . song_format , <EOL> track . tracknumber , position , fileext ) <EOL> track . new_file = self . _get_clean_filename ( newfile ) <EOL> tag_map . append ( track ) <EOL> return tag_map <EOL> @ property <EOL> def dest_dir_name ( self ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isabs ( self . destdir ) : <EOL> path_name = os . path . normpath ( self . destdir ) <EOL> else : <EOL> path_name = os . path . dirname ( os . path . normpath ( self . destdir ) ) <EOL> dest_dir = "<STR_LIT>" <EOL> for ddir in self . dir_format . split ( "<STR_LIT:/>" ) : <EOL> d_dir = self . _get_clean_filename ( self . _value_from_tag ( ddir ) ) <EOL> if dest_dir == "<STR_LIT>" : <EOL> dest_dir = d_dir <EOL> else : <EOL> dest_dir = dest_dir + "<STR_LIT:/>" + d_dir <EOL> dir_name = os . path . join ( path_name , dest_dir ) <EOL> return dir_name <EOL> @ property <EOL> def album_folder_name ( self ) : <EOL> """<STR_LIT>""" <EOL> folder_name = "<STR_LIT>" % ( self . _get_clean_filename ( str ( self . album . title ) ) , self . disc_folder_name ) <EOL> if self . use_lower : <EOL> folder_name = folder_name . lower ( ) <EOL> return folder_name <EOL> @ property <EOL> def m3u_filename ( self ) : <EOL> """<STR_LIT>""" <EOL> m3u = self . _value_from_tag ( self . m3u_format ) <EOL> return self . _get_clean_filename ( m3u ) <EOL> @ property <EOL> def nfo_filename ( self ) : <EOL> """<STR_LIT>""" <EOL> nfo = self . _value_from_tag ( self . nfo_format ) <EOL> return self . _get_clean_filename ( nfo ) <EOL> def _get_clean_filename ( self , f ) : <EOL> """<STR_LIT>""" <EOL> filename , fileext = os . path . splitext ( f ) <EOL> if not fileext in TaggerUtils . FILE_TYPE and not fileext in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> logger . debug ( "<STR_LIT>" % fileext ) <EOL> filename = f <EOL> fileext = "<STR_LIT>" <EOL> a = unicode ( filename , "<STR_LIT:utf-8>" ) <EOL> for k , v in self . char_exceptions . iteritems ( ) : <EOL> a = a . replace ( k , v ) <EOL> a = normalize ( "<STR_LIT>" , a ) . encode ( "<STR_LIT:ascii>" , "<STR_LIT:ignore>" ) <EOL> cf = re . compile ( r"<STR_LIT>" ) <EOL> cf = cf . sub ( "<STR_LIT>" , str ( a ) ) <EOL> cf = cf . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:_>" ) <EOL> cf = cf . replace ( "<STR_LIT>" , "<STR_LIT:_>" ) <EOL> cf = cf . replace ( "<STR_LIT>" , "<STR_LIT:->" ) <EOL> return "<STR_LIT>" % ( cf , fileext ) <EOL> def write_file ( filecontents , filename ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( os . path . dirname ( filename ) ) : <EOL> os . makedirs ( os . path . dirname ( filename ) ) <EOL> logger . debug ( "<STR_LIT>" % filename ) <EOL> try : <EOL> with open ( filename , "<STR_LIT:w>" ) as fh : <EOL> fh . write ( filecontents ) <EOL> except IOError : <EOL> logger . error ( "<STR_LIT>" % filename ) <EOL> return True <EOL> def create_nfo ( nfo , dest_dir , nfo_file ) : <EOL> """<STR_LIT>""" <EOL> return write_file ( nfo , os . path . join ( dest_dir , nfo_file ) ) <EOL> def create_m3u ( tag_map , folder_names , dest_dir_name , m3u_filename ) : <EOL> """<STR_LIT>""" <EOL> m3u = "<STR_LIT>" <EOL> for track in tag_map : <EOL> m3u += "<STR_LIT>" % ( track . artist , track . title ) <EOL> folder_name = folder_names [ track . discnumber ] <EOL> if folder_name is not "<STR_LIT>" : <EOL> folder_name = "<STR_LIT>" % folder_name <EOL> m3u += "<STR_LIT>" % ( folder_name , track . new_file ) <EOL> return write_file ( m3u , os . path . join ( dest_dir_name , m3u_filename ) ) <EOL> def get_images ( images , dest_dir_name , images_format , first_image_name ) : <EOL> """<STR_LIT>""" <EOL> if images : <EOL> discogs_auth = DiscogsAuth ( ) <EOL> for i , image in enumerate ( images , <NUM_LIT:0> ) : <EOL> logger . debug ( '<STR_LIT>' . format ( image ) ) <EOL> try : <EOL> picture_name = '<STR_LIT>' <EOL> if i == <NUM_LIT:0> : <EOL> picture_name = first_image_name <EOL> else : <EOL> picture_name = images_format + "<STR_LIT>" % i <EOL> resp , content = discogs_auth . handle . request ( image , '<STR_LIT:POST>' , <EOL> headers = { '<STR_LIT>' : USER_AGENT } ) <EOL> if resp [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> with open ( os . path . join ( dest_dir_name , picture_name ) , '<STR_LIT:w>' ) as fh : <EOL> fh . write ( content ) <EOL> except Exception as e : <EOL> logger . error ( "<STR_LIT>" . format ( <EOL> image , e ) ) </s>
<s> import os <EOL> from django . conf import settings <EOL> MEDIA_PATH = os . path . join ( os . path . abspath ( os . path . dirname ( __file__ ) ) , '<STR_LIT:..>' , '<STR_LIT>' ) <EOL> MEDIA_PREFIX = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> MEDIA_REGEX = r'<STR_LIT>' % MEDIA_PREFIX . lstrip ( '<STR_LIT:/>' ) <EOL> USER_AGENTS = { <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> } <EOL> USER_AGENTS . update ( getattr ( settings , '<STR_LIT>' , { } ) ) <EOL> TEMPLATE_MAPPING = { <EOL> '<STR_LIT:index>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> TEMPLATE_MAPPING . update ( getattr ( settings , '<STR_LIT>' , { } ) ) </s>
<s> from django . conf . urls . defaults import * <EOL> from staticfiles . urls import staticfiles_urlpatterns <EOL> urlpatterns = staticfiles_urlpatterns ( ) </s>
<s> """<STR_LIT>""" <EOL> LOG_EMERG = <NUM_LIT:0> <EOL> LOG_ALERT = <NUM_LIT:1> <EOL> LOG_CRIT = <NUM_LIT:2> <EOL> LOG_ERR = <NUM_LIT:3> <EOL> LOG_WARNING = <NUM_LIT:4> <EOL> LOG_NOTICE = <NUM_LIT:5> <EOL> LOG_INFO = <NUM_LIT:6> <EOL> LOG_DEBUG = <NUM_LIT:7> <EOL> LOG_KERN = <NUM_LIT:0> <EOL> LOG_USER = <NUM_LIT:1> <EOL> LOG_MAIL = <NUM_LIT:2> <EOL> LOG_DAEMON = <NUM_LIT:3> <EOL> LOG_AUTH = <NUM_LIT:4> <EOL> LOG_SYSLOG = <NUM_LIT:5> <EOL> LOG_LPR = <NUM_LIT:6> <EOL> LOG_NEWS = <NUM_LIT:7> <EOL> LOG_UUCP = <NUM_LIT:8> <EOL> LOG_CRON = <NUM_LIT:9> <EOL> LOG_AUTHPRIV = <NUM_LIT:10> <EOL> LOG_LOCAL0 = <NUM_LIT:16> <EOL> LOG_LOCAL1 = <NUM_LIT> <EOL> LOG_LOCAL2 = <NUM_LIT> <EOL> LOG_LOCAL3 = <NUM_LIT> <EOL> LOG_LOCAL4 = <NUM_LIT:20> <EOL> LOG_LOCAL5 = <NUM_LIT> <EOL> LOG_LOCAL6 = <NUM_LIT> <EOL> LOG_LOCAL7 = <NUM_LIT> <EOL> priority_names = { <EOL> "<STR_LIT>" : LOG_ALERT , <EOL> "<STR_LIT>" : LOG_CRIT , <EOL> "<STR_LIT>" : LOG_DEBUG , <EOL> "<STR_LIT>" : LOG_EMERG , <EOL> "<STR_LIT>" : LOG_ERR , <EOL> "<STR_LIT:error>" : LOG_ERR , <EOL> "<STR_LIT:info>" : LOG_INFO , <EOL> "<STR_LIT>" : LOG_NOTICE , <EOL> "<STR_LIT>" : LOG_EMERG , <EOL> "<STR_LIT>" : LOG_WARNING , <EOL> "<STR_LIT>" : LOG_WARNING , <EOL> } <EOL> facility_names = { <EOL> "<STR_LIT>" : LOG_AUTH , <EOL> "<STR_LIT>" : LOG_AUTHPRIV , <EOL> "<STR_LIT>" : LOG_CRON , <EOL> "<STR_LIT>" : LOG_DAEMON , <EOL> "<STR_LIT>" : LOG_KERN , <EOL> "<STR_LIT>" : LOG_LPR , <EOL> "<STR_LIT>" : LOG_MAIL , <EOL> "<STR_LIT>" : LOG_NEWS , <EOL> "<STR_LIT>" : LOG_AUTH , <EOL> "<STR_LIT>" : LOG_SYSLOG , <EOL> "<STR_LIT:user>" : LOG_USER , <EOL> "<STR_LIT>" : LOG_UUCP , <EOL> "<STR_LIT>" : LOG_LOCAL0 , <EOL> "<STR_LIT>" : LOG_LOCAL1 , <EOL> "<STR_LIT>" : LOG_LOCAL2 , <EOL> "<STR_LIT>" : LOG_LOCAL3 , <EOL> "<STR_LIT>" : LOG_LOCAL4 , <EOL> "<STR_LIT>" : LOG_LOCAL5 , <EOL> "<STR_LIT>" : LOG_LOCAL6 , <EOL> "<STR_LIT>" : LOG_LOCAL7 , <EOL> } <EOL> import socket <EOL> class syslog_client : <EOL> def __init__ ( self , address = '<STR_LIT>' ) : <EOL> self . address = address <EOL> if type ( address ) == type ( '<STR_LIT>' ) : <EOL> self . socket = socket . socket ( socket . AF_UNIX , socket . SOCK_STREAM ) <EOL> self . socket . connect ( address ) <EOL> self . unix = <NUM_LIT:1> <EOL> else : <EOL> self . socket = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) <EOL> self . unix = <NUM_LIT:0> <EOL> log_format_string = '<STR_LIT>' <EOL> def log ( self , message , facility = LOG_USER , priority = LOG_INFO ) : <EOL> message = self . log_format_string % ( <EOL> self . encode_priority ( facility , priority ) , <EOL> message <EOL> ) <EOL> if self . unix : <EOL> self . socket . send ( message ) <EOL> else : <EOL> self . socket . sendto ( message , self . address ) <EOL> def encode_priority ( self , facility , priority ) : <EOL> if type ( facility ) == type ( '<STR_LIT>' ) : <EOL> facility = facility_names [ facility ] <EOL> if type ( priority ) == type ( '<STR_LIT>' ) : <EOL> priority = priority_names [ priority ] <EOL> return ( facility << <NUM_LIT:3> ) | priority <EOL> def close ( self ) : <EOL> if self . unix : <EOL> self . socket . close ( ) </s>
<s> import numpy as np <EOL> from sklearn . decomposition import SparseCoder <EOL> def gammatone_function ( resolution , fc , center , fs = <NUM_LIT> , l = <NUM_LIT:4> , <EOL> b = <NUM_LIT> ) : <EOL> t = np . linspace ( <NUM_LIT:0> , resolution - ( center + <NUM_LIT:1> ) , resolution - center ) / fs <EOL> g = np . zeros ( ( resolution , ) ) <EOL> g [ center : ] = t ** ( l - <NUM_LIT:1> ) * np . exp ( - <NUM_LIT:2> * np . pi * b * erb ( fc ) * t ) * np . cos ( <NUM_LIT:2> * np . pi * fc * t ) <EOL> return g <EOL> def gammatone_matrix ( b , fc , resolution , step , fs = <NUM_LIT> , l = <NUM_LIT:4> , threshold = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> centers = np . arange ( <NUM_LIT:0> , resolution - step , step ) <EOL> D = [ ] <EOL> for i , center in enumerate ( centers ) : <EOL> t = np . linspace ( <NUM_LIT:0> , resolution - ( center + <NUM_LIT:1> ) , resolution - center ) / fs <EOL> env = t ** ( l - <NUM_LIT:1> ) * np . exp ( - <NUM_LIT:2> * np . pi * b * erb ( fc ) * t ) <EOL> if env [ - <NUM_LIT:1> ] / max ( env ) < threshold : <EOL> D . append ( gammatone_function ( resolution , fc , center , b = b , l = l ) ) <EOL> D = np . asarray ( D ) <EOL> D /= np . sqrt ( np . sum ( D ** <NUM_LIT:2> , axis = <NUM_LIT:1> ) ) [ : , np . newaxis ] <EOL> return D <EOL> def erb ( f ) : <EOL> return <NUM_LIT> + <NUM_LIT> * f <EOL> def erb_space ( low_freq , high_freq , num_channels , EarQ = <NUM_LIT> , minBW = <NUM_LIT> , order = <NUM_LIT:1> ) : <EOL> return - ( EarQ * minBW ) + np . exp ( np . arange ( <NUM_LIT:1> , num_channels + <NUM_LIT:1> ) * ( - np . log ( high_freq + EarQ * minBW ) + np . log ( low_freq + EarQ * minBW ) ) / num_channels ) * ( high_freq + EarQ * minBW ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from scipy . io import wavfile <EOL> from scikits . talkbox import segment_axis <EOL> resolution = <NUM_LIT> <EOL> step = <NUM_LIT:8> <EOL> b = <NUM_LIT> <EOL> n_channels = <NUM_LIT:64> <EOL> overlap = <NUM_LIT> <EOL> D_multi = np . r_ [ tuple ( gammatone_matrix ( b , fc , resolution , step ) for <EOL> fc in erb_space ( <NUM_LIT> , <NUM_LIT> , n_channels ) ) ] <EOL> fs , y = wavfile . read ( '<STR_LIT>' ) <EOL> y = y / <NUM_LIT> ** <NUM_LIT:15> <EOL> Y = segment_axis ( y , resolution , overlap = overlap , end = '<STR_LIT>' ) <EOL> Y = np . hanning ( resolution ) * Y <EOL> coder = SparseCoder ( dictionary = D_multi , transform_n_nonzero_coefs = None , transform_alpha = <NUM_LIT:1.> , transform_algorithm = '<STR_LIT>' ) <EOL> X = coder . transform ( Y ) <EOL> density = len ( np . flatnonzero ( X ) ) <EOL> out = np . zeros ( ( np . ceil ( len ( y ) / resolution ) + <NUM_LIT:1> ) * resolution ) <EOL> for k in range ( <NUM_LIT:0> , len ( X ) ) : <EOL> idx = range ( k * ( resolution - overlap ) , k * ( resolution - overlap ) + resolution ) <EOL> out [ idx ] += np . dot ( X [ k ] , D_multi ) <EOL> squared_error = np . sum ( ( y - out [ <NUM_LIT:0> : len ( y ) ] ) ** <NUM_LIT:2> ) <EOL> wavfile . write ( '<STR_LIT>' % ( resolution , overlap ) , fs , np . asarray ( out , dtype = np . float32 ) ) </s>
<s> from setuptools import setup , find_packages <EOL> version = __import__ ( '<STR_LIT>' ) . get_version ( ) <EOL> setup ( <EOL> name = "<STR_LIT>" , <EOL> version = version , <EOL> url = "<STR_LIT>" , <EOL> author = "<STR_LIT>" , <EOL> author_email = "<STR_LIT>" , <EOL> description = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> long_description = open ( "<STR_LIT>" ) . read ( ) , <EOL> download_url = "<STR_LIT>" , <EOL> packages = find_packages ( exclude = [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> license = open ( '<STR_LIT>' ) . read ( ) , <EOL> zip_safe = False , <EOL> install_requires = ( <EOL> "<STR_LIT>" <EOL> ) , <EOL> classifiers = [ <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> ) </s>
<s> import os <EOL> from setuptools import setup <EOL> from glob import glob <EOL> def read ( filename ) : <EOL> return open ( os . path . join ( os . path . dirname ( __file__ ) , filename ) ) . read ( ) <EOL> def requirements ( ) : <EOL> """<STR_LIT>""" <EOL> requirements = [ x . strip ( ) for x in read ( '<STR_LIT>' ) . split ( "<STR_LIT:\n>" ) ] <EOL> requirements = [ x for x in requirements if len ( x ) > <NUM_LIT:0> and x [ <NUM_LIT:0> ] != '<STR_LIT:#>' ] <EOL> return requirements <EOL> def scripts ( ) : <EOL> """<STR_LIT>""" <EOL> setup_dir = os . path . dirname ( __file__ ) <EOL> script_dir = os . path . join ( setup_dir , '<STR_LIT>' ) <EOL> scripts = glob ( os . path . join ( script_dir , '<STR_LIT:*>' ) ) <EOL> scripts = [ os . path . relpath ( p , setup_dir ) for p in scripts ] <EOL> scripts = [ s for s in scripts if s not in [ '<STR_LIT:.>' , '<STR_LIT:..>' ] ] <EOL> return scripts <EOL> setup ( <EOL> name = "<STR_LIT>" , <EOL> version = "<STR_LIT>" , <EOL> author = "<STR_LIT>" , <EOL> author_email = "<STR_LIT>" , <EOL> description = ( "<STR_LIT>" ) , <EOL> license = "<STR_LIT>" , <EOL> keywords = "<STR_LIT>" , <EOL> url = "<STR_LIT>" , <EOL> packages = [ '<STR_LIT>' ] , <EOL> include_package_data = True , <EOL> long_description = read ( '<STR_LIT>' ) , <EOL> scripts = scripts ( ) , <EOL> install_requires = requirements ( ) , <EOL> classifiers = [ <EOL> "<STR_LIT>" , <EOL> ] , <EOL> ) </s>
<s> """<STR_LIT>""" <EOL> from . user import Entity , User <EOL> class Session ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , oauth_token = None ) : <EOL> self . oauth_token = oauth_token <EOL> def User ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = self . oauth_token <EOL> return User ( * args , ** kwargs ) <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , * args ) : <EOL> pass <EOL> def session ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Session ( * args , ** kwargs ) </s>
<s> import datetime <EOL> from south . db import db <EOL> from south . v2 import SchemaMigration <EOL> from django . db import models <EOL> class Migration ( SchemaMigration ) : <EOL> def forwards ( self , orm ) : <EOL> db . add_column ( '<STR_LIT>' , '<STR_LIT>' , self . gf ( '<STR_LIT>' ) ( max_length = <NUM_LIT:255> , null = True , blank = True ) , keep_default = False ) <EOL> db . add_column ( '<STR_LIT>' , '<STR_LIT>' , self . gf ( '<STR_LIT>' ) ( null = True , blank = True ) , keep_default = False ) <EOL> db . add_column ( '<STR_LIT>' , '<STR_LIT>' , self . gf ( '<STR_LIT>' ) ( null = True , blank = True ) , keep_default = False ) <EOL> def backwards ( self , orm ) : <EOL> db . delete_column ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> db . delete_column ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> db . delete_column ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> models = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:Meta>' : { '<STR_LIT:object_name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT:id>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:primary_key>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' } ) <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:Meta>' : { '<STR_LIT:object_name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:default>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT:email>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT:id>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:primary_key>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT:location>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:to>' : "<STR_LIT>" , '<STR_LIT>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , [ ] , { '<STR_LIT:max_length>' : '<STR_LIT>' , '<STR_LIT:null>' : '<STR_LIT:True>' , '<STR_LIT:blank>' : '<STR_LIT:True>' } ) <EOL> } <EOL> } <EOL> complete_apps = [ '<STR_LIT>' ] </s>
<s> from collections import namedtuple <EOL> from textwrap import wrap <EOL> from operator import add , attrgetter <EOL> from itertools import repeat <EOL> ParsedArgs = namedtuple ( "<STR_LIT>" , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> CLArgument = namedtuple ( "<STR_LIT>" , [ "<STR_LIT:name>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:type>" , <EOL> "<STR_LIT:default>" , <EOL> "<STR_LIT:description>" ] ) <EOL> def parseArgs ( cllist , arg_proto , arg_proto_map = { } , argmap = { } ) : <EOL> '''<STR_LIT>''' <EOL> def etoi ( a ) : <EOL> '''<STR_LIT>''' <EOL> return arg_proto_map [ a ] . internal_name <EOL> if not bool ( argmap ) : <EOL> argmap = dict ( map ( attrgetter ( "<STR_LIT>" , "<STR_LIT:default>" ) , arg_proto ) ) <EOL> arg_proto_map = dict ( zip ( map ( attrgetter ( "<STR_LIT:name>" ) , arg_proto ) , arg_proto ) ) <EOL> if not cllist : <EOL> cllist = [ ] <EOL> if len ( cllist ) == <NUM_LIT:0> or not cllist [ <NUM_LIT:0> ] . startswith ( "<STR_LIT:->" ) : <EOL> return ParsedArgs ( argmap , cllist ) <EOL> cur = cllist [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> if not cur in arg_proto_map : <EOL> raise Exception , "<STR_LIT>" % cur <EOL> if arg_proto_map [ cur ] . type == argflag : <EOL> argmap [ etoi ( cur ) ] = True <EOL> return parseArgs ( cllist [ <NUM_LIT:1> : ] , arg_proto , arg_proto_map , argmap ) <EOL> if "<STR_LIT:=>" in cur : <EOL> k , v = cur . split ( "<STR_LIT:=>" ) <EOL> argmap [ etoi ( k ) ] = arg_proto_map [ k ] . type ( v ) <EOL> return parseArgs ( cllist [ <NUM_LIT:1> : ] , arg_proto , arg_proto_map , argmap ) <EOL> if not len ( cllist ) > <NUM_LIT:1> : <EOL> raise Exception , "<STR_LIT>" % cur <EOL> argmap [ etoi ( cur ) ] = arg_proto_map [ cur ] . type ( cllist [ <NUM_LIT:1> ] ) <EOL> return parseArgs ( cllist [ <NUM_LIT:2> : ] , arg_proto , arg_proto_map , argmap ) <EOL> def getHelpStr ( description , arguments ) : <EOL> '''<STR_LIT>''' <EOL> LEFT_COL_PADDING = <NUM_LIT> <EOL> WRAP_SIZE = <NUM_LIT:50> <EOL> ostring = description + "<STR_LIT>" <EOL> def once ( param , times = <NUM_LIT:0> ) : <EOL> while True : <EOL> if times == <NUM_LIT:0> : <EOL> times += <NUM_LIT:1> <EOL> yield param <EOL> else : <EOL> yield "<STR_LIT>" <EOL> wrap_s = WRAP_SIZE <EOL> d = reduce ( add , map ( lambda x : zip ( once ( "<STR_LIT:->" + x . name ) , <EOL> wrap ( x . description , wrap_s ) ) , arguments ) ) <EOL> pad = LEFT_COL_PADDING <EOL> ostring += "<STR_LIT:\n>" . join ( map ( lambda ( left , right ) : "<STR_LIT>" . join ( ( left . ljust ( pad ) , right ) ) , d ) ) <EOL> return ostring <EOL> def argrange ( a ) : <EOL> if "<STR_LIT::>" in a : <EOL> arr = map ( int , a . split ( "<STR_LIT::>" ) ) <EOL> if not len ( arr ) == <NUM_LIT:3> : <EOL> raise Exception , "<STR_LIT>" <EOL> return range ( * arr ) <EOL> elif "<STR_LIT:U+002C>" in a : <EOL> arr = map ( int , a . split ( "<STR_LIT:U+002C>" ) ) <EOL> return arr <EOL> return [ int ( a ) ] <EOL> def arglist ( a ) : <EOL> delim = None <EOL> if "<STR_LIT:U+002C>" in a : <EOL> delim = "<STR_LIT:U+002C>" <EOL> return a . split ( delim ) <EOL> def argflag ( ) : <EOL> pass </s>
<s> import sys <EOL> import os <EOL> from itertools import starmap , chain , imap <EOL> from operator import itemgetter <EOL> from seqio import iteratorFromExtension , recordToString , fastaRecordToString , seqlen <EOL> from nucio import fileIterator , openerFromExtension <EOL> from args import parseArgs , getHelpStr , argflag , CLArgument <EOL> from misc import defdef <EOL> description = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> argument_list = [ [ "<STR_LIT>" , "<STR_LIT>" , argflag , False , <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , int , <NUM_LIT:1> , <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ] ] <EOL> arguments = map ( CLArgument . _make , argument_list ) <EOL> if not len ( sys . argv ) > <NUM_LIT:1> : <EOL> sys . exit ( getHelpStr ( description , arguments ) + "<STR_LIT:\n>" ) <EOL> ( p_arg_map , args_remaining ) = parseArgs ( sys . argv [ <NUM_LIT:1> : ] , arguments ) <EOL> if not len ( args_remaining ) >= <NUM_LIT:3> : <EOL> sys . exit ( getHelpStr ( description , arguments ) + "<STR_LIT:\n>" ) <EOL> def pstr ( num ) : <EOL> return "<STR_LIT>" % num <EOL> ( rpf , fpd ) = map ( int , args_remaining [ : <NUM_LIT:2> ] ) <EOL> in_files = args_remaining [ <NUM_LIT:2> : ] <EOL> openers = map ( openerFromExtension , in_files ) <EOL> iterators = map ( iteratorFromExtension , imap ( itemgetter ( <NUM_LIT:1> ) , openers ) ) <EOL> openfuncs = map ( defdef ( open ) , imap ( itemgetter ( <NUM_LIT:0> ) , openers ) ) <EOL> input_data = chain . from_iterable ( starmap ( fileIterator , <EOL> zip ( in_files , iterators , openfuncs ) ) ) <EOL> total_reads = <NUM_LIT:0> <EOL> dnum = <NUM_LIT:0> <EOL> fnum = <NUM_LIT:0> <EOL> fh = None <EOL> readidx_fh = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> recordString = recordToString if p_arg_map [ "<STR_LIT>" ] else fastaRecordToString <EOL> for record in input_data : <EOL> if seqlen ( record ) < p_arg_map [ "<STR_LIT>" ] : <EOL> continue <EOL> if total_reads % rpf == <NUM_LIT:0> : <EOL> if total_reads % ( rpf * fpd ) == <NUM_LIT:0> : <EOL> dnum += <NUM_LIT:1> <EOL> fnum = <NUM_LIT:0> <EOL> os . mkdir ( pstr ( dnum ) ) <EOL> fnum += <NUM_LIT:1> <EOL> if fh : <EOL> fh . close ( ) <EOL> current_file = "<STR_LIT>" % ( pstr ( dnum ) , pstr ( fnum ) ) <EOL> fh = open ( current_file , "<STR_LIT:w>" ) <EOL> clean_name = str ( record . name ) . split ( ) [ <NUM_LIT:0> ] <EOL> clean_record = record . _replace ( name = clean_name ) <EOL> readidx_fh . write ( clean_name + "<STR_LIT:\t>" + current_file + "<STR_LIT:\n>" ) <EOL> fh . write ( recordString ( clean_record ) ) <EOL> fh . write ( "<STR_LIT:\n>" ) <EOL> total_reads += <NUM_LIT:1> <EOL> readidx_fh . close ( ) <EOL> fh . close ( ) </s>
<s> import numpy as np <EOL> import sqlite3 as sql <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> int_types = ( int , ) <EOL> string_types = ( str , ) <EOL> blob_type = bytes <EOL> else : <EOL> int_types = ( int , long ) <EOL> string_types = ( str , unicode ) <EOL> blob_type = buffer <EOL> def dict_to_dtypes ( data , order = None ) : <EOL> r"""<STR_LIT>""" <EOL> if hasattr ( data , '<STR_LIT>' ) : <EOL> data = [ data ] <EOL> all_types = { } <EOL> for x in data : <EOL> for key in x : <EOL> if key not in all_types : <EOL> all_types [ key ] = set ( ) <EOL> if x [ key ] is not None : <EOL> all_types [ key ] . add ( type ( x [ key ] ) ) <EOL> if order is None : <EOL> order = sorted ( all_types . keys ( ) ) <EOL> types = [ ] <EOL> for key in order : <EOL> t = list ( all_types [ key ] ) <EOL> if len ( t ) != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % key ) <EOL> tt = type ( np . asscalar ( np . array ( [ <NUM_LIT:0> ] , dtype = t [ <NUM_LIT:0> ] ) ) ) <EOL> types . append ( ( key , tt ) ) <EOL> return types <EOL> def sql_execute ( conn , cmd , fetchall = False , verbose = False ) : <EOL> r"""<STR_LIT>""" <EOL> if isinstance ( cmd , string_types ) : <EOL> cmd = [ cmd ] <EOL> with conn : <EOL> cur = conn . cursor ( ) <EOL> if verbose : <EOL> print ( "<STR_LIT:U+002CU+0020>" . join ( [ str ( x ) for x in cmd ] ) ) <EOL> cur . execute ( * cmd ) <EOL> if fetchall : <EOL> result = cur . fetchall ( ) <EOL> else : <EOL> result = None <EOL> return result </s>
<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , unicode_literals , print_function <EOL> import logging <EOL> import unittest <EOL> import urllib2 <EOL> from conftest import JmxMockedConnection , JvmTestCase <EOL> from jmx4py . jolokia . connection import JmxHttpConnection <EOL> from jmx4py . jolokia . client import * <EOL> log = logging . getLogger ( __name__ ) <EOL> class JmxEscapingTest ( unittest . TestCase ) : <EOL> DATA = ( <EOL> ( None , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:a>" , "<STR_LIT:a>" ) , <EOL> ( "<STR_LIT:!>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ) <EOL> def test_quote ( self ) : <EOL> for text , quoted in self . DATA : <EOL> self . assertEqual ( quote ( text ) , quoted ) <EOL> def test_unquote ( self ) : <EOL> for text , quoted in self . DATA : <EOL> self . assertEqual ( text , unquote ( quoted ) ) <EOL> def test_unquote_extra ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , unquote ( "<STR_LIT>" ) ) <EOL> def test_unquote_trail ( self ) : <EOL> self . failUnlessRaises ( ValueError , unquote , "<STR_LIT:!>" ) <EOL> self . failUnlessRaises ( ValueError , unquote , "<STR_LIT>" ) <EOL> class JmxClientTest ( unittest . TestCase ) : <EOL> def test_client_connection ( self ) : <EOL> proxy = JmxClient ( "<STR_LIT>" ) <EOL> self . failUnless ( isinstance ( proxy . connection , JmxMockedConnection ) ) <EOL> def test_host_port ( self ) : <EOL> proxy = JmxClient ( ( "<STR_LIT:localhost>" , "<STR_LIT>" ) ) <EOL> self . failUnless ( isinstance ( proxy . connection , JmxHttpConnection ) ) <EOL> self . failUnlessEqual ( proxy . connection . url , "<STR_LIT>" ) <EOL> def test_bad_scheme ( self ) : <EOL> self . failUnlessRaises ( urllib2 . URLError , JmxClient , "<STR_LIT>" ) <EOL> def test_bad_port ( self ) : <EOL> self . failUnlessRaises ( urllib2 . URLError , JmxClient , ( "<STR_LIT:localhost>" , "<STR_LIT:x>" ) ) <EOL> class JmxClientBasicsTest ( JvmTestCase ) : <EOL> def test_repr ( self ) : <EOL> self . failUnless ( "<STR_LIT:localhost>" in repr ( self . proxy ) ) <EOL> def test_bad_type ( self ) : <EOL> self . failUnlessRaises ( JmxResponseError , self . proxy . _execute , type = "<STR_LIT>" ) <EOL> self . failUnlessEqual ( self . proxy . connection . calls , <NUM_LIT:1> ) <EOL> self . failUnlessEqual ( self . proxy . connection . errors , <NUM_LIT:1> ) <EOL> class JmxClientReadTest ( JvmTestCase ) : <EOL> def test_read ( self ) : <EOL> resp = self . proxy . read ( "<STR_LIT>" ) <EOL> self . failUnless ( all ( i in resp . value for i in [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_read_with_path ( self ) : <EOL> resp = self . proxy . read ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . failUnless ( isinstance ( resp . value , int ) ) <EOL> def test_multi_read ( self ) : <EOL> resp = self . proxy . read ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . failUnlessEqual ( set ( resp . value . keys ( ) ) , set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_multi_read_with_path ( self ) : <EOL> self . failUnlessRaises ( JmxResponseError , self . proxy . read , <EOL> "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> class JmxClientWriteTest ( JvmTestCase ) : <EOL> def test_write ( self ) : <EOL> pass <EOL> class JmxClientInvokeTest ( JvmTestCase ) : <EOL> def test_invoke ( self ) : <EOL> pass <EOL> class JmxClientSearchTest ( JvmTestCase ) : <EOL> def test_search ( self ) : <EOL> pass <EOL> class JmxClientVersionTest ( JvmTestCase ) : <EOL> def test_version ( self ) : <EOL> version = self . proxy . version ( ) <EOL> self . failUnlessEqual ( self . proxy . connection . calls , <NUM_LIT:1> ) <EOL> self . failUnlessEqual ( self . proxy . connection . errors , <NUM_LIT:0> ) <EOL> self . failUnlessEqual ( version [ "<STR_LIT:status>" ] , <NUM_LIT:200> ) <EOL> self . failUnless ( isinstance ( version [ "<STR_LIT>" ] , int ) ) <EOL> self . failUnlessEqual ( version [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] , "<STR_LIT:version>" ) <EOL> self . failUnless ( version . protocol . startswith ( "<STR_LIT>" ) ) </s>
<s> from collections import defaultdict <EOL> from django . db . models import Manager <EOL> from django . db . models . query import QuerySet <EOL> from django . utils import timezone <EOL> from alert . utils import ALERT_TYPES , ALERT_BACKENDS <EOL> class AlertManager ( Manager ) : <EOL> pass <EOL> class PendingAlertManager ( AlertManager ) : <EOL> """<STR_LIT>""" <EOL> def get_query_set ( self , * args , ** kwargs ) : <EOL> qs = super ( PendingAlertManager , self ) . get_query_set ( * args , ** kwargs ) <EOL> return qs . filter ( when__lte = timezone . now ( ) , is_sent = False ) <EOL> def get_queryset ( self , * args , ** kwargs ) : <EOL> qs = super ( PendingAlertManager , self ) . get_queryset ( * args , ** kwargs ) <EOL> return qs . filter ( when__lte = timezone . now ( ) , is_sent = False ) <EOL> class AlertPrefsManager ( Manager ) : <EOL> def get_queryset_compat ( self , * args , ** kwargs ) : <EOL> getqs = self . get_queryset if hasattr ( Manager , "<STR_LIT>" ) else self . get_query_set <EOL> return getqs ( * args , ** kwargs ) <EOL> def get_user_prefs ( self , user ) : <EOL> if not user . is_authenticated ( ) : <EOL> return dict ( ( ( notice_type . id , backend . id ) , False ) <EOL> for notice_type in ALERT_TYPES . values ( ) <EOL> for backend in ALERT_BACKENDS . values ( ) <EOL> ) <EOL> alert_prefs = self . get_queryset_compat ( ) . filter ( user = user ) <EOL> prefs = { } <EOL> for pref in alert_prefs : <EOL> prefs [ pref . alert_type , pref . backend ] = pref . preference <EOL> for notice_type in ALERT_TYPES . values ( ) : <EOL> for backend in ALERT_BACKENDS . values ( ) : <EOL> if ( notice_type . id , backend . id ) not in prefs : <EOL> default_pref = notice_type . get_default ( backend . id ) <EOL> prefs [ notice_type . id , backend . id ] = default_pref <EOL> return prefs <EOL> def get_recipients_for_notice ( self , notice_type , users ) : <EOL> if isinstance ( notice_type , basestring ) : <EOL> notice_type = ALERT_TYPES [ notice_type ] <EOL> if not users : return ( ) <EOL> if isinstance ( users , QuerySet ) : <EOL> user_ids = list ( users . values_list ( "<STR_LIT:id>" , flat = True ) ) <EOL> else : <EOL> user_ids = [ u . id for u in users ] <EOL> alert_prefs = self . get_queryset_compat ( ) . filter ( alert_type = notice_type . id ) . filter ( user__in = user_ids ) <EOL> prefs = { } <EOL> for pref in alert_prefs : <EOL> prefs [ pref . user_id , pref . backend ] = pref . preference <EOL> user_cache = { } <EOL> for user in users : <EOL> user_cache [ user . id ] = user <EOL> for backend in ALERT_BACKENDS . values ( ) : <EOL> if ( user . id , backend . id ) not in prefs : <EOL> prefs [ user . id , backend . id ] = notice_type . get_default ( backend . id ) <EOL> return ( ( user_cache [ user_id ] , ALERT_BACKENDS [ backend_id ] ) for ( ( user_id , backend_id ) , pref ) in prefs . items ( ) if pref ) </s>
<s> import optparse <EOL> import os <EOL> import sys <EOL> try : <EOL> import socks <EOL> NO_SOCKS = False <EOL> except ImportError : <EOL> NO_SOCKS = True <EOL> import socket <EOL> try : <EOL> from bs4 import BeautifulSoup <EOL> HAVE_SOUP = True <EOL> except ImportError : <EOL> HAVE_SOUP = False <EOL> from parsers . thread import SiteParserThread <EOL> from util import fixFormatting , isImageLibAvailable <EOL> from xmlparser import MangaXmlParser <EOL> from outputManager . progressBarManager import progressBarManager <EOL> VERSION = '<STR_LIT>' <EOL> siteDict = { <EOL> <NUM_LIT:1> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT:2> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT:3> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT:4> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT:5> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> if HAVE_SOUP : <EOL> siteDict [ <NUM_LIT:6> ] = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class InvalidSite ( Exception ) : <EOL> pass <EOL> def printLicenseInfo ( ) : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> def main ( ) : <EOL> printLicenseInfo ( ) <EOL> parser = optparse . OptionParser ( usage = '<STR_LIT>' , <EOL> version = ( '<STR_LIT>' % VERSION ) ) <EOL> parser . set_defaults ( <EOL> all_chapters_FLAG = False , <EOL> auto = False , <EOL> conversion_FLAG = False , <EOL> convert_Directory = False , <EOL> device = '<STR_LIT>' , <EOL> downloadFormat = '<STR_LIT>' , <EOL> downloadPath = '<STR_LIT>' , <EOL> inputDir = None , <EOL> outputDir = '<STR_LIT>' , <EOL> overwrite_FLAG = False , <EOL> verbose_FLAG = False , <EOL> timeLogging_FLAG = False , <EOL> maxChapterThreads = <NUM_LIT:3> , <EOL> useShortName = False , <EOL> spaceToken = '<STR_LIT:.>' , <EOL> proxy = None , <EOL> siteSelect = <NUM_LIT:0> <EOL> ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> const = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> try : <EOL> options . siteSelect = int ( options . siteSelect ) <EOL> except : <EOL> options . siteSelect = <NUM_LIT:0> <EOL> try : <EOL> options . maxChapterThreads = int ( options . maxChapterThreads ) <EOL> except : <EOL> options . maxChapterThreads = <NUM_LIT:2> <EOL> if ( options . maxChapterThreads <= <NUM_LIT:0> ) : <EOL> options . maxChapterThreads = <NUM_LIT:2> ; <EOL> if ( len ( args ) == <NUM_LIT:0> and ( not ( options . convert_Directory or options . xmlfile_path != None ) ) ) : <EOL> parser . error ( '<STR_LIT>' ) <EOL> SetDownloadPathToName_Flag = False <EOL> SetOutputPathToDefault_Flag = False <EOL> if ( len ( args ) > <NUM_LIT:0> ) : <EOL> if ( options . downloadPath == '<STR_LIT>' ) : <EOL> SetDownloadPathToName_Flag = True <EOL> if ( options . outputDir == '<STR_LIT>' ) : <EOL> SetOutputPathToDefault_Flag = True <EOL> PILAvailable = isImageLibAvailable ( ) <EOL> if ( ( not PILAvailable ) and ( options . convert_Directory or options . conversion_FLAG ) ) : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( ) <EOL> else : <EOL> if ( PILAvailable ) : <EOL> from ConvertPackage . ConvertFile import convertFile <EOL> if ( options . convert_Directory ) : <EOL> options . inputDir = os . path . abspath ( options . inputDir ) <EOL> if ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) != "<STR_LIT>" ) : <EOL> os . chdir ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) ) <EOL> options . outputMgr = progressBarManager ( ) <EOL> options . outputMgr . start ( ) <EOL> try : <EOL> if ( options . convert_Directory ) : <EOL> if ( options . outputDir == '<STR_LIT>' ) : <EOL> options . outputDir = '<STR_LIT:.>' <EOL> print ( "<STR_LIT>" % options . inputDir ) <EOL> convertFile . convert ( options . outputMgr , options . inputDir , options . outputDir , options . device , options . verbose_FLAG ) <EOL> elif options . xmlfile_path != None : <EOL> xmlParser = MangaXmlParser ( options ) <EOL> xmlParser . downloadManga ( ) <EOL> else : <EOL> threadPool = [ ] <EOL> for manga in args : <EOL> print ( manga ) <EOL> options . manga = manga <EOL> if SetDownloadPathToName_Flag : <EOL> options . downloadPath = ( '<STR_LIT>' + fixFormatting ( options . manga , options . spaceToken ) ) <EOL> if SetOutputPathToDefault_Flag : <EOL> options . outputDir = options . downloadPath <EOL> options . downloadPath = os . path . realpath ( options . downloadPath ) + os . sep <EOL> if ( options . siteSelect == <NUM_LIT:0> ) : <EOL> print ( '<STR_LIT>' ) <EOL> for i in siteDict : <EOL> print ( siteDict [ i ] [ <NUM_LIT:1> ] ) <EOL> try : <EOL> options . siteSelect = raw_input ( ) <EOL> except NameError : <EOL> options . siteSelect = input ( ) <EOL> try : <EOL> options . site = siteDict [ int ( options . siteSelect ) ] [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> raise InvalidSite ( '<STR_LIT>' ) <EOL> threadPool . append ( SiteParserThread ( options , None , None ) ) <EOL> for thread in threadPool : <EOL> thread . start ( ) <EOL> thread . join ( ) <EOL> finally : <EOL> options . outputMgr . stop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
<s> import yaml <EOL> L = [ ] <EOL> def code ( url ) : <EOL> for c in "<STR_LIT>" : <EOL> url = url . replace ( c , "<STR_LIT:U+0020>" ) <EOL> for w in url . split ( ) : <EOL> if w not in [ "<STR_LIT:http>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:code>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return w <EOL> return "<STR_LIT:?>" <EOL> for item in yaml . load ( open ( "<STR_LIT>" ) . read ( ) ) : <EOL> if '<STR_LIT>' in item : <EOL> continue <EOL> if '<STR_LIT>' in item : <EOL> order = item [ '<STR_LIT>' ] <EOL> else : <EOL> order = <NUM_LIT:4> <EOL> chapter = item [ '<STR_LIT>' ] <EOL> name = item [ '<STR_LIT:name>' ] <EOL> links = item [ '<STR_LIT>' ] <EOL> L . append ( ( order , chapter , name , links ) ) <EOL> L . sort ( key = lambda t : ( t [ <NUM_LIT:1> ] . lower ( ) , t [ <NUM_LIT:2> ] . lower ( ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> for order , chapter , name , links in L : <EOL> hearts = "<STR_LIT>" % order + "<STR_LIT>" * order <EOL> print ( "<STR_LIT>" % ( chapter , hearts , name ) ) <EOL> for a in links : <EOL> print ( '<STR_LIT>' % ( a , code ( a ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) </s>
<s> def floyd_warshall ( weight ) : <EOL> """<STR_LIT>""" <EOL> V = range ( len ( weight ) ) <EOL> for k in V : <EOL> for u in V : <EOL> for v in V : <EOL> weight [ u ] [ v ] = min ( weight [ u ] [ v ] , <EOL> weight [ u ] [ k ] + weight [ k ] [ v ] ) <EOL> for v in V : <EOL> if weight [ v ] [ v ] < <NUM_LIT:0> : <EOL> return True <EOL> return False </s>
<s> def min_mean_cycle ( graph , weight , start = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> INF = float ( '<STR_LIT>' ) <EOL> n = len ( graph ) <EOL> dist = [ [ INF ] * n ] <EOL> prec = [ [ None ] * n ] <EOL> dist [ <NUM_LIT:0> ] [ start ] = <NUM_LIT:0> <EOL> for ell in range ( <NUM_LIT:1> , n + <NUM_LIT:1> ) : <EOL> dist . append ( [ INF ] * n ) <EOL> prec . append ( [ None ] * n ) <EOL> for node in range ( n ) : <EOL> for neighbor in graph [ node ] : <EOL> alt = dist [ ell - <NUM_LIT:1> ] [ node ] + weight [ node ] [ neighbor ] <EOL> if alt < dist [ ell ] [ neighbor ] : <EOL> dist [ ell ] [ neighbor ] = alt <EOL> prec [ ell ] [ neighbor ] = node <EOL> valmin = INF <EOL> argmin = None <EOL> for node in range ( n ) : <EOL> valmax = - INF <EOL> argmax = None <EOL> for k in range ( n ) : <EOL> alt = ( dist [ n ] [ node ] - dist [ k ] [ node ] ) / float ( n - k ) <EOL> if alt >= valmax : <EOL> valmax = alt <EOL> argmax = k <EOL> if argmax is not None and valmax < valmin : <EOL> valmin = valmax <EOL> argmin = ( node , argmax ) <EOL> if valmin == INF : <EOL> return None <EOL> C = [ ] <EOL> node , k = argmin <EOL> for l in range ( n , k , - <NUM_LIT:1> ) : <EOL> C . append ( node ) <EOL> node = prec [ l ] [ node ] <EOL> return C [ : : - <NUM_LIT:1> ] , valmin </s>
<s> '''<STR_LIT>''' <EOL> class UnknownKeyException ( Exception ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , keyid ) : <EOL> '''<STR_LIT>''' <EOL> Exception . __init__ ( self ) <EOL> self . keyid = keyid <EOL> MISSING_SIGNATURE = "<STR_LIT>" <EOL> MISSING_KEY_LOCATION = "<STR_LIT>" <EOL> BAD_KEY_OWNER = "<STR_LIT>" <EOL> class UnsupportedSignatureAlgorithm ( Exception ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , alg = None ) : <EOL> '''<STR_LIT>''' <EOL> Exception . __init__ ( self ) <EOL> self . alg = alg <EOL> class BadSignatureFormat ( Exception ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , message = None ) : <EOL> Exception . __init__ ( self ) <EOL> self . message = message <EOL> class MissingPublicKey ( Exception ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , message = None , keyid = None ) : <EOL> Exception . __init__ ( self ) <EOL> self . message = message <EOL> self . keyid = keyid </s>
<s> class CalibreEbookConvertGenerator ( object ) : <EOL> """<STR_LIT>""" <EOL> _DESCRIPTION = "<STR_LIT>" <EOL> format = None <EOL> use_cache = None <EOL> verbose = None <EOL> logger = None <EOL> def __init__ ( self , format = "<STR_LIT>" , use_cache = False , verbose = False , logger = None ) : <EOL> """<STR_LIT>""" <EOL> self . format = format <EOL> self . use_cache = use_cache <EOL> self . verbose = verbose <EOL> self . logger = logger <EOL> self . logger . debug ( self . _DESCRIPTION ) <EOL> def generate ( self , cfg ) : <EOL> """<STR_LIT>""" <EOL> self . logger . debug ( "<STR_LIT>" ) </s>
<s> '''<STR_LIT>''' <EOL> from __future__ import print_function <EOL> import sys <EOL> from music21 import * <EOL> import numpy as np <EOL> from grammar import * <EOL> from preprocess import * <EOL> from qa import * <EOL> import lstm <EOL> '''<STR_LIT>''' <EOL> def __sample ( a , temperature = <NUM_LIT:1.0> ) : <EOL> a = np . log ( a ) / temperature <EOL> a = np . exp ( a ) / np . sum ( np . exp ( a ) ) <EOL> return np . argmax ( np . random . multinomial ( <NUM_LIT:1> , a , <NUM_LIT:1> ) ) <EOL> '''<STR_LIT>''' <EOL> def __predict ( model , x , indices_val , diversity ) : <EOL> preds = model . predict ( x , verbose = <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> next_index = __sample ( preds , diversity ) <EOL> next_val = indices_val [ next_index ] <EOL> return next_val <EOL> '''<STR_LIT>''' <EOL> def __generate_grammar ( model , corpus , abstract_grammars , values , val_indices , <EOL> indices_val , max_len , max_tries , diversity ) : <EOL> curr_grammar = '<STR_LIT>' <EOL> start_index = np . random . randint ( <NUM_LIT:0> , len ( corpus ) - max_len ) <EOL> sentence = corpus [ start_index : start_index + max_len ] <EOL> running_length = <NUM_LIT:0.0> <EOL> while running_length <= <NUM_LIT> : <EOL> x = np . zeros ( ( <NUM_LIT:1> , max_len , len ( values ) ) ) <EOL> for t , val in enumerate ( sentence ) : <EOL> if ( not val in val_indices ) : print ( val ) <EOL> x [ <NUM_LIT:0> , t , val_indices [ val ] ] = <NUM_LIT:1.> <EOL> next_val = __predict ( model , x , indices_val , diversity ) <EOL> if ( running_length < <NUM_LIT> ) : <EOL> tries = <NUM_LIT:0> <EOL> while ( next_val . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:0> ] == '<STR_LIT:R>' or <EOL> len ( next_val . split ( '<STR_LIT:U+002C>' ) ) != <NUM_LIT:2> ) : <EOL> if tries >= max_tries : <EOL> print ( '<STR_LIT>' , max_tries , <EOL> '<STR_LIT>' ) <EOL> rand = np . random . randint ( <NUM_LIT:0> , len ( abstract_grammars ) ) <EOL> next_val = abstract_grammars [ rand ] . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] <EOL> else : <EOL> next_val = __predict ( model , x , indices_val , diversity ) <EOL> tries += <NUM_LIT:1> <EOL> sentence = sentence [ <NUM_LIT:1> : ] <EOL> sentence . append ( next_val ) <EOL> if ( running_length > <NUM_LIT> ) : curr_grammar += '<STR_LIT:U+0020>' <EOL> curr_grammar += next_val <EOL> length = float ( next_val . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> ] ) <EOL> running_length += length <EOL> return curr_grammar <EOL> '''<STR_LIT>''' <EOL> def generate ( data_fn , out_fn , N_epochs ) : <EOL> max_len = <NUM_LIT:20> <EOL> max_tries = <NUM_LIT:1000> <EOL> diversity = <NUM_LIT:0.5> <EOL> bpm = <NUM_LIT> <EOL> chords , abstract_grammars = get_musical_data ( data_fn ) <EOL> corpus , values , val_indices , indices_val = get_corpus_data ( abstract_grammars ) <EOL> print ( '<STR_LIT>' , len ( corpus ) ) <EOL> print ( '<STR_LIT>' , len ( values ) ) <EOL> model = lstm . build_model ( corpus = corpus , val_indices = val_indices , <EOL> max_len = max_len , N_epochs = N_epochs ) <EOL> out_stream = stream . Stream ( ) <EOL> curr_offset = <NUM_LIT:0.0> <EOL> loopEnd = len ( chords ) <EOL> for loopIndex in range ( <NUM_LIT:1> , loopEnd ) : <EOL> curr_chords = stream . Voice ( ) <EOL> for j in chords [ loopIndex ] : <EOL> curr_chords . insert ( ( j . offset % <NUM_LIT:4> ) , j ) <EOL> curr_grammar = __generate_grammar ( model = model , corpus = corpus , <EOL> abstract_grammars = abstract_grammars , <EOL> values = values , val_indices = val_indices , <EOL> indices_val = indices_val , <EOL> max_len = max_len , max_tries = max_tries , <EOL> diversity = diversity ) <EOL> curr_grammar = curr_grammar . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> curr_grammar = prune_grammar ( curr_grammar ) <EOL> curr_notes = unparse_grammar ( curr_grammar , curr_chords ) <EOL> curr_notes = prune_notes ( curr_notes ) <EOL> curr_notes = clean_up_notes ( curr_notes ) <EOL> print ( '<STR_LIT>' % ( len ( [ i for i in curr_notes <EOL> if isinstance ( i , note . Note ) ] ) ) ) <EOL> for m in curr_notes : <EOL> out_stream . insert ( curr_offset + m . offset , m ) <EOL> for mc in curr_chords : <EOL> out_stream . insert ( curr_offset + mc . offset , mc ) <EOL> curr_offset += <NUM_LIT> <EOL> out_stream . insert ( <NUM_LIT:0.0> , tempo . MetronomeMark ( number = bpm ) ) <EOL> play = lambda x : midi . realtime . StreamPlayer ( x ) . play ( ) <EOL> play ( out_stream ) <EOL> mf = midi . translate . streamToMidiFile ( out_stream ) <EOL> mf . open ( out_fn , '<STR_LIT:wb>' ) <EOL> mf . write ( ) <EOL> mf . close ( ) <EOL> '''<STR_LIT>''' <EOL> def main ( args ) : <EOL> try : <EOL> N_epochs = int ( args [ <NUM_LIT:1> ] ) <EOL> except : <EOL> N_epochs = <NUM_LIT> <EOL> data_fn = '<STR_LIT>' + '<STR_LIT>' <EOL> out_fn = '<STR_LIT>' '<STR_LIT>' + str ( N_epochs ) <EOL> if ( N_epochs == <NUM_LIT:1> ) : out_fn += '<STR_LIT>' <EOL> else : out_fn += '<STR_LIT>' <EOL> generate ( data_fn , out_fn , N_epochs ) <EOL> '''<STR_LIT>''' <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> main ( sys . argv ) </s>
<s> """<STR_LIT>""" <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . backends import ModelBackend <EOL> class EmailBackend ( ModelBackend ) : <EOL> """<STR_LIT>""" <EOL> def authenticate ( self , email = None , password = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> user = User . objects . get ( email = email ) <EOL> if user . check_password ( password ) : <EOL> return user <EOL> except User . DoesNotExist : <EOL> return None <EOL> def authenticate ( email = None , password = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> backend = EmailBackend ( ) <EOL> user = backend . authenticate ( email = email , password = password ) <EOL> except TypeError : <EOL> return None <EOL> if user : <EOL> user . backend = "<STR_LIT>" % ( <EOL> backend . __module__ , <EOL> backend . __class__ . __name__ <EOL> ) <EOL> return user </s>
<s> import nmrglue as ng <EOL> pdic , pdata = ng . pipe . read ( "<STR_LIT>" ) <EOL> pdic2 , pdata2 = ng . pipe . read ( "<STR_LIT>" ) <EOL> r1 , r2 = ng . misc . pair_similar ( pdic , pdata , pdic2 , pdata2 , verb = True ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> if r1 : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> if r2 : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" </s>
<s> import nmrglue as ng <EOL> import numpy as np <EOL> dic , data = ng . varian . read ( '<STR_LIT>' , as_2d = True ) <EOL> array_size = len ( dic [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> out_shape = int ( data . shape [ <NUM_LIT:0> ] / array_size ) , data . shape [ <NUM_LIT:1> ] <EOL> dic [ '<STR_LIT>' ] = out_shape [ <NUM_LIT:0> ] <EOL> for i , nredor in enumerate ( dic [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> dir_name = '<STR_LIT>' + nredor + '<STR_LIT>' <EOL> print "<STR_LIT>" , dir_name <EOL> sdata = np . empty ( out_shape , dtype = data . dtype ) <EOL> sdata [ : : <NUM_LIT:2> ] = data [ <NUM_LIT:2> * i : : <NUM_LIT:2> * array_size ] <EOL> sdata [ <NUM_LIT:1> : : <NUM_LIT:2> ] = data [ <NUM_LIT:2> * i + <NUM_LIT:1> : : <NUM_LIT:2> * array_size ] <EOL> ng . varian . write ( dir_name , dic , sdata , overwrite = True ) </s>
<s> import numpy as np <EOL> def integrate ( data , unit_conv , limits , unit = '<STR_LIT>' , noise_limits = None , <EOL> norm_to_range = None , calibrate = <NUM_LIT:1.0> ) : <EOL> """<STR_LIT>""" <EOL> limits = np . array ( limits ) <EOL> if limits . size == <NUM_LIT:2> : <EOL> limits = np . expand_dims ( limits , axis = <NUM_LIT:0> ) <EOL> inds = [ ( unit_conv ( x0 , unit ) , unit_conv ( x1 , unit ) ) for ( x0 , x1 ) in limits ] <EOL> inds = np . array ( [ sorted ( ind ) for ind in inds ] ) <EOL> sum_slice = np . array ( [ np . sum ( data [ slice ( * ind ) ] ) for ind in inds ] ) <EOL> scale = unit_conv . ppm_scale ( ) <EOL> dx = abs ( scale [ <NUM_LIT:1> ] - scale [ <NUM_LIT:0> ] ) <EOL> values = sum_slice * dx <EOL> if noise_limits is not None : <EOL> noise_inds = ( unit_conv ( noise_limits [ <NUM_LIT:0> ] , unit ) , <EOL> unit_conv ( noise_limits [ <NUM_LIT:1> ] , unit ) ) <EOL> noise_inds = sorted ( noise_inds ) <EOL> std = np . std ( data [ slice ( * noise_inds ) ] ) <EOL> errors = std * np . sqrt ( inds [ : , <NUM_LIT:1> ] - inds [ : , <NUM_LIT:0> ] ) <EOL> if norm_to_range is not None : <EOL> errors = ( errors / values [ norm_to_range ] ) * calibrate <EOL> values = ( values / values [ norm_to_range ] ) * calibrate <EOL> return np . vstack ( ( values , errors ) ) . T <EOL> else : <EOL> if norm_to_range is not None : <EOL> values = ( values / values [ norm_to_range ] ) * calibrate <EOL> return values <EOL> def ndintegrate ( data , unit_conv , limits , unit = '<STR_LIT>' , noise_limits = None ) : <EOL> """<STR_LIT>""" <EOL> d = np . ndim ( data ) <EOL> try : <EOL> iter ( unit_conv ) <EOL> except TypeError : <EOL> unit_conv = [ unit_conv , ] <EOL> if d != len ( unit_conv ) : <EOL> mesg = '<STR_LIT>' <EOL> raise ValueError ( mesg ) <EOL> limits = np . array ( limits ) <EOL> if limits . ndim == <NUM_LIT:1> : <EOL> limits = np . expand_dims ( limits , axis = <NUM_LIT:0> ) <EOL> if limits . shape [ <NUM_LIT:0> ] != d and limits . shape [ <NUM_LIT:1> ] != <NUM_LIT:2> : <EOL> mesg = '<STR_LIT>' <EOL> raise ValueError ( mesg ) <EOL> inds = [ ( uc ( x [ <NUM_LIT:0> ] , unit ) , uc ( x [ <NUM_LIT:1> ] , unit ) ) <EOL> for ( uc , x ) in zip ( unit_conv , limits ) ] <EOL> inds = [ sorted ( x ) for x in inds ] <EOL> ppm_scales = [ x . ppm_scale ( ) for x in unit_conv ] <EOL> dx = np . prod ( np . array ( [ abs ( x [ <NUM_LIT:1> ] - x [ <NUM_LIT:0> ] ) for x in ppm_scales ] ) ) <EOL> slice_sum = ( data [ [ slice ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] ) for x in np . flipud ( inds ) ] ] ) . sum ( ) <EOL> value = slice_sum * dx <EOL> if noise_limits is None : <EOL> return value <EOL> else : <EOL> noise_limits = np . array ( noise_limits ) <EOL> if noise_limits . size == <NUM_LIT:2> : <EOL> noise_limits = np . expand_dims ( noise_limits , axis = <NUM_LIT:0> ) <EOL> if noise_limits . shape [ <NUM_LIT:0> ] != d and noise_limits . shape [ <NUM_LIT:1> ] != <NUM_LIT:2> : <EOL> mesg = '<STR_LIT>' <EOL> raise ValueError ( mesg ) <EOL> noise_inds = [ ( uc ( x [ <NUM_LIT:0> ] , unit ) , uc ( x [ <NUM_LIT:1> ] , unit ) ) <EOL> for ( uc , x ) in zip ( unit_conv , noise_limits ) ] <EOL> noise_inds = [ sorted ( x ) for x in noise_inds ] <EOL> nm = np . prod ( np . array ( [ abs ( x [ <NUM_LIT:1> ] - x [ <NUM_LIT:0> ] ) for x in noise_inds ] ) ) <EOL> std = np . std ( data [ [ slice ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] ) for x in np . flipud ( noise_inds ) ] ] ) <EOL> error = std * np . sqrt ( nm ) <EOL> return np . hstack ( ( value , error ) ) </s>
<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> __developer_info__ = """<STR_LIT>""" <EOL> import numpy as np <EOL> import scipy . linalg <EOL> def lp ( data , pred = <NUM_LIT:1> , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , append = "<STR_LIT>" , <EOL> bad_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" , mirror = None , method = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if data . ndim == <NUM_LIT:1> : <EOL> return lp_1d ( data , pred , slice , order , mode , append , bad_roots , <EOL> fix_mode , mirror , method ) <EOL> elif data . ndim == <NUM_LIT:2> : <EOL> s = list ( data . shape ) <EOL> s [ - <NUM_LIT:1> ] = s [ - <NUM_LIT:1> ] + pred <EOL> new = np . empty ( s , dtype = data . dtype ) <EOL> for i , trace in enumerate ( data ) : <EOL> new [ i ] = lp_1d ( trace , pred , slice , order , mode , append , bad_roots , <EOL> fix_mode , mirror , method ) <EOL> return new <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def lp_svd ( data , pred = <NUM_LIT:1> , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , append = "<STR_LIT>" , <EOL> bad_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" , mirror = None ) : <EOL> """<STR_LIT>""" <EOL> return lp ( data , pred , slice , order , mode , append , bad_roots , fix_mode , <EOL> mirror , method = "<STR_LIT>" ) <EOL> def lp_qr ( data , pred = <NUM_LIT:1> , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , append = "<STR_LIT>" , <EOL> bad_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" , mirror = None ) : <EOL> """<STR_LIT>""" <EOL> return lp ( data , pred , slice , order , mode , append , bad_roots , fix_mode , <EOL> mirror , method = "<STR_LIT>" ) <EOL> def lp_cho ( data , pred = <NUM_LIT:1> , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , append = "<STR_LIT>" , <EOL> bad_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" , mirror = None ) : <EOL> """<STR_LIT>""" <EOL> return lp ( data , pred , slice , order , mode , append , bad_roots , fix_mode , <EOL> mirror , method = "<STR_LIT>" ) <EOL> def lp_tls ( data , pred = <NUM_LIT:1> , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , append = "<STR_LIT>" , <EOL> bad_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" , mirror = None ) : <EOL> """<STR_LIT>""" <EOL> return lp ( data , pred , slice , order , mode , append , bad_roots , fix_mode , <EOL> mirror , method = "<STR_LIT>" ) <EOL> def lp_1d ( trace , pred = <NUM_LIT:1> , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , append = "<STR_LIT>" , <EOL> bad_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" , mirror = None , method = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if mode not in [ "<STR_LIT:f>" , "<STR_LIT:b>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if append not in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if bad_roots not in [ None , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if fix_mode not in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if mirror not in [ None , "<STR_LIT:0>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if method not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if trace . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if bad_roots == "<STR_LIT>" : <EOL> if mode == "<STR_LIT:f>" or mode == "<STR_LIT>" : <EOL> bad_roots = "<STR_LIT>" <EOL> else : <EOL> bad_roots = "<STR_LIT>" <EOL> x = trace [ slice ] <EOL> if mirror is not None : <EOL> x = make_mirror ( x , mirror ) <EOL> if mode == "<STR_LIT>" : <EOL> a = find_lpc_fb ( x , order , bad_roots , fix_mode , method ) <EOL> mode = "<STR_LIT:f>" <EOL> elif mode == "<STR_LIT>" : <EOL> a = find_lpc_bf ( x , order , bad_roots , fix_mode , method ) <EOL> mode = "<STR_LIT:b>" <EOL> else : <EOL> D , d = make_Dd ( x , order , mode ) <EOL> a = find_lpc ( D , d , method ) <EOL> if bad_roots is not None : <EOL> poles = find_roots ( a , mode ) <EOL> poles = fix_roots ( poles , bad_roots , fix_mode ) <EOL> if ( mode == "<STR_LIT:b>" and append == "<STR_LIT>" ) or ( mode == "<STR_LIT:f>" and <EOL> append == "<STR_LIT>" ) : <EOL> poles = [ <NUM_LIT:1.> / pole for pole in poles ] <EOL> mode = { '<STR_LIT:f>' : '<STR_LIT:b>' , '<STR_LIT:b>' : '<STR_LIT:f>' } [ mode ] <EOL> a = find_coeff ( poles , mode ) <EOL> else : <EOL> if ( mode == "<STR_LIT:b>" and append == "<STR_LIT>" ) or ( mode == "<STR_LIT:f>" and <EOL> append == "<STR_LIT>" ) : <EOL> a = reverse_filter ( a , mode ) <EOL> ntrace = extrapolate ( trace , a , pred , append ) <EOL> return ntrace <EOL> def lp2d ( data , pred , P , M , mirror = '<STR_LIT:0>' , fix_points = True , method = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if data . ndim != <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if mirror not in [ '<STR_LIT:0>' , '<STR_LIT>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if method not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> D , d = make_lp2d_Dd ( data , P , M , '<STR_LIT:f>' ) <EOL> c = find_lpc ( D , d , method ) <EOL> C = c . reshape ( P , M ) <EOL> return extrapolate_2d ( data , C , pred , fix_points , mirror ) <EOL> def extrapolate_2d ( x , C , pred , fix_points , mirror ) : <EOL> """<STR_LIT>""" <EOL> P , M = C . shape <EOL> c = C . flatten ( ) <EOL> x_max = x . max ( ) <EOL> N_0 , N_1 = x . shape <EOL> if mirror == "<STR_LIT:0>" : <EOL> new = np . empty ( ( <NUM_LIT:2> * N_0 - <NUM_LIT:1> , N_1 + pred ) , dtype = x . dtype ) <EOL> plane = N_0 - <NUM_LIT:1> <EOL> else : <EOL> new = np . empty ( ( <NUM_LIT:2> * N_0 , N_1 + pred ) , dtype = x . dtype ) <EOL> plane = N_0 <EOL> last = new . shape [ <NUM_LIT:0> ] <EOL> for i in range ( N_1 ) : <EOL> new [ : , i ] = make_mirror ( x [ : , i ] , mirror ) <EOL> for j in range ( N_1 - M , N_1 - M + pred ) : <EOL> for i in range ( plane - P + <NUM_LIT:1> , last - P + <NUM_LIT:1> ) : <EOL> new [ i + P - <NUM_LIT:1> , j + M ] = np . sum ( new [ i : i + P , j : j + M ] . flat * c ) <EOL> if fix_points : <EOL> if new [ i + P - <NUM_LIT:1> , j + M ] > x_max : <EOL> new [ i + P - <NUM_LIT:1> , j + M ] = ( ( x_max * x_max ) / <EOL> ( new [ i + P - <NUM_LIT:1> , j + M ] ) ) <EOL> new [ : , j + M ] = make_mirror ( new [ plane : , j + M ] , mirror ) <EOL> return new [ plane : ] <EOL> def make_lp2d_Dd ( x , P , M , mode = '<STR_LIT:f>' ) : <EOL> """<STR_LIT>""" <EOL> if mode == '<STR_LIT:b>' : <EOL> raise NotImplemented <EOL> N_0 , N_1 = x . shape <EOL> count_P = N_0 - P + <NUM_LIT:1> <EOL> count_M = N_1 - M <EOL> D = np . empty ( ( count_P * count_M , P * M ) , dtype = x . dtype ) <EOL> d = np . empty ( ( count_P * count_M , <NUM_LIT:1> ) , dtype = x . dtype ) <EOL> for j in range ( count_M ) : <EOL> for i in range ( count_P ) : <EOL> D [ j * count_P + i ] = x [ i : i + P , j : j + M ] . flat <EOL> d [ j * count_P + i ] = x [ i + P - <NUM_LIT:1> , j + M ] <EOL> return D , d <EOL> def cadzow ( data , M , K , niter , min_var = False ) : <EOL> """<STR_LIT>""" <EOL> if data . ndim == <NUM_LIT:1> : <EOL> for i in range ( niter ) : <EOL> data = cadzow_single ( data , M , K , min_var ) <EOL> return data <EOL> elif data . ndim == <NUM_LIT:2> : <EOL> for trace in data : <EOL> for i in range ( niter ) : <EOL> trace = cadzow_single ( trace , M , K , min_var ) <EOL> return data <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def cadzow_single ( x , M , K , min_var = False ) : <EOL> """<STR_LIT>""" <EOL> N = len ( x ) <EOL> L = N - M + <NUM_LIT:1> <EOL> X = scipy . linalg . hankel ( x [ : L ] , x [ L - <NUM_LIT:1> : ] ) <EOL> U , s , Vh = scipy . linalg . svd ( X ) <EOL> Ul = np . mat ( U [ : , : K ] ) <EOL> Vlh = np . mat ( Vh [ : K , : ] ) <EOL> sl = s [ : K ] <EOL> if min_var : <EOL> s2 = ( <NUM_LIT:1.> / ( M - K ) ) * np . power ( s [ K : ] , <NUM_LIT:2> ) . sum ( ) <EOL> sl = np . array ( [ l - s2 / l for l in sl ] ) <EOL> Sl = np . mat ( np . diag ( sl ) ) <EOL> Xp = Ul * Sl * Vlh <EOL> xp = np . empty_like ( x ) <EOL> for i , v in enumerate ( range ( M - <NUM_LIT:1> , - L , - <NUM_LIT:1> ) ) : <EOL> xp [ i ] = np . diag ( Xp [ : , : : - <NUM_LIT:1> ] , v ) . mean ( ) <EOL> return xp <EOL> def lp_model ( trace , slice = slice ( None ) , order = <NUM_LIT:8> , mode = "<STR_LIT:f>" , mirror = None , <EOL> method = "<STR_LIT>" , full = False ) : <EOL> """<STR_LIT>""" <EOL> if mode not in [ "<STR_LIT:f>" , "<STR_LIT:b>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if method not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if trace . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> x = trace [ slice ] <EOL> if mirror is not None : <EOL> x = make_mirror ( x , mirror ) <EOL> if method in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> D , d = make_Dd ( x , order , mode ) <EOL> a = find_lpc ( D , d , method ) <EOL> poles = find_roots ( a , mode ) <EOL> elif method == "<STR_LIT>" : <EOL> poles = find_lproots_hsvd ( x , M = order , K = order , mode = mode , zmethod = '<STR_LIT>' ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if mode == "<STR_LIT:b>" : <EOL> poles = [ <NUM_LIT:1.> / pole for pole in poles ] <EOL> damp = [ root2damp ( pole ) for pole in poles ] <EOL> freq = [ root2freq ( pole ) for pole in poles ] <EOL> if full is False : <EOL> return damp , freq <EOL> poles = np . array ( poles ) <EOL> B = np . row_stack ( [ poles ** ( i ) for i in range ( len ( x ) ) ] ) <EOL> z , resid , rank , s = np . linalg . lstsq ( B , np . array ( x ) ) <EOL> amp = [ cof2amp ( cof ) for cof in z ] <EOL> phase = [ cof2phase ( cof ) for cof in z ] <EOL> return damp , freq , amp , phase <EOL> def root2damp ( pole ) : <EOL> """<STR_LIT>""" <EOL> return - <NUM_LIT:1.> / ( np . pi ) * np . log ( np . abs ( pole ) ) <EOL> def root2freq ( pole ) : <EOL> """<STR_LIT>""" <EOL> return np . arctan2 ( pole . imag , pole . real ) / ( <NUM_LIT> * np . pi ) <EOL> def cof2amp ( z ) : <EOL> """<STR_LIT>""" <EOL> return np . abs ( z ) <EOL> def cof2phase ( z ) : <EOL> """<STR_LIT>""" <EOL> return np . arctan2 ( z . imag , z . real ) <EOL> def make_D ( x , order , mode ) : <EOL> """<STR_LIT>""" <EOL> L = len ( x ) - order <EOL> if mode == "<STR_LIT:f>" : <EOL> return scipy . linalg . hankel ( x [ : L ] , x [ L - <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> elif mode == "<STR_LIT:b>" : <EOL> return scipy . linalg . hankel ( x [ <NUM_LIT:1> : L + <NUM_LIT:1> ] , x [ L : ] ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def make_little_d ( x , order , mode ) : <EOL> """<STR_LIT>""" <EOL> if mode == "<STR_LIT:f>" : <EOL> return x [ order : ] . reshape ( len ( x ) - order , <NUM_LIT:1> ) <EOL> elif mode == "<STR_LIT:b>" : <EOL> L = len ( x ) - order <EOL> return x [ : L ] . reshape ( L , <NUM_LIT:1> ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def make_Dd ( x , order , mode ) : <EOL> """<STR_LIT>""" <EOL> return make_D ( x , order , mode ) , make_little_d ( x , order , mode ) <EOL> def make_mirror ( x , mode ) : <EOL> """<STR_LIT>""" <EOL> if mode == "<STR_LIT:0>" : <EOL> return np . concatenate ( ( x [ : <NUM_LIT:0> : - <NUM_LIT:1> ] , x ) ) <EOL> elif mode == "<STR_LIT>" : <EOL> return np . concatenate ( ( x [ : : - <NUM_LIT:1> ] , x ) ) <EOL> def find_lpc ( D , d , method ) : <EOL> """<STR_LIT>""" <EOL> if method == "<STR_LIT>" : <EOL> return find_lpc_svd ( D , d ) <EOL> elif method == "<STR_LIT>" : <EOL> return find_lpc_qr ( D , d ) <EOL> elif method == "<STR_LIT>" : <EOL> return find_lpc_cholesky ( D , d ) <EOL> elif method == "<STR_LIT>" : <EOL> return find_lpc_tls ( D , d ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def find_lpc_svd ( D , d ) : <EOL> """<STR_LIT>""" <EOL> L = D . shape [ <NUM_LIT:0> ] <EOL> m = D . shape [ <NUM_LIT:1> ] <EOL> U , s , Vh = scipy . linalg . svd ( D ) <EOL> U , Vh = np . mat ( U ) , np . mat ( Vh ) <EOL> Si = pinv_diagsvd ( s , m , L ) <EOL> return np . array ( Vh . H * Si * U . H * d ) <EOL> eps = np . finfo ( '<STR_LIT:float>' ) . eps <EOL> feps = np . finfo ( '<STR_LIT>' ) . eps <EOL> _array_precision = { '<STR_LIT:f>' : <NUM_LIT:0> , '<STR_LIT:d>' : <NUM_LIT:1> , '<STR_LIT:F>' : <NUM_LIT:0> , '<STR_LIT:D>' : <NUM_LIT:1> } <EOL> def pinv_diagsvd ( s , m , L ) : <EOL> """<STR_LIT>""" <EOL> t = s . dtype . char <EOL> cond = { <NUM_LIT:0> : feps * <NUM_LIT> , <NUM_LIT:1> : eps * <NUM_LIT> } [ _array_precision [ t ] ] <EOL> cutoff = s [ <NUM_LIT:0> ] * cond <EOL> Si = np . zeros ( ( m , L ) , t ) <EOL> for i in range ( len ( s ) ) : <EOL> if s [ i ] > cutoff : <EOL> Si [ i , i ] = <NUM_LIT:1.0> / np . conj ( s [ i ] ) <EOL> return Si <EOL> def find_lpc_qr ( D , d ) : <EOL> """<STR_LIT>""" <EOL> L = D . shape [ <NUM_LIT:0> ] <EOL> m = D . shape [ <NUM_LIT:1> ] <EOL> q , r = scipy . linalg . qr ( D ) <EOL> q , r = np . mat ( q ) , np . mat ( r ) <EOL> return scipy . linalg . pinv2 ( r ) * q . H * d <EOL> def find_lpc_cholesky ( D , d ) : <EOL> """<STR_LIT>""" <EOL> D = np . mat ( D ) <EOL> DhD = np . mat ( np . dot ( D . H , D ) ) <EOL> Dhd = np . mat ( np . dot ( D . H , d ) ) <EOL> c , lower = scipy . linalg . cho_factor ( DhD ) <EOL> return scipy . linalg . cho_solve ( ( c , lower ) , Dhd ) <EOL> def find_lpc_tls ( D , d ) : <EOL> """<STR_LIT>""" <EOL> m = D . shape [ <NUM_LIT:1> ] <EOL> E = np . append ( D , d , axis = <NUM_LIT:1> ) <EOL> U , s , Vh = scipy . linalg . svd ( E ) <EOL> V = np . conj ( Vh . T ) <EOL> return ( - <NUM_LIT:1.> / V [ m , m ] * V [ : m , m ] ) . reshape ( ( m , <NUM_LIT:1> ) ) <EOL> def find_lpc_fb ( x , order , bad_roots , fix_mode , method ) : <EOL> """<STR_LIT>""" <EOL> D , d = make_Dd ( x , order , '<STR_LIT:f>' ) <EOL> a = find_lpc ( D , d , method ) <EOL> if bad_roots is not None : <EOL> poles = find_roots ( a , '<STR_LIT:f>' ) <EOL> poles = fix_roots ( poles , bad_roots , fix_mode ) <EOL> a = find_coeff ( poles , '<STR_LIT:f>' ) <EOL> forward_a = a . copy ( ) <EOL> D , d = make_Dd ( x , order , '<STR_LIT:b>' ) <EOL> a = find_lpc ( D , d , method ) <EOL> poles = find_roots ( a , '<STR_LIT:b>' ) <EOL> poles = [ <NUM_LIT:1.> / pole for pole in poles ] <EOL> if bad_roots is not None : <EOL> poles = fix_roots ( poles , bad_roots , fix_mode ) <EOL> backward_a = find_coeff ( poles , '<STR_LIT:f>' ) <EOL> return ( forward_a + backward_a ) / <NUM_LIT> <EOL> def find_lpc_bf ( x , order , bad_roots , fix_mode , method ) : <EOL> """<STR_LIT>""" <EOL> D , d = make_Dd ( x , order , '<STR_LIT:b>' ) <EOL> a = find_lpc ( D , d , method ) <EOL> if bad_roots is not None : <EOL> poles = find_roots ( a , '<STR_LIT:b>' ) <EOL> poles = fix_roots ( poles , bad_roots , fix_mode ) <EOL> a = find_coeff ( poles , '<STR_LIT:b>' ) <EOL> backward_a = a . copy ( ) <EOL> D , d = make_Dd ( x , order , '<STR_LIT:f>' ) <EOL> a = find_lpc ( D , d , method ) <EOL> poles = find_roots ( a , '<STR_LIT:f>' ) <EOL> poles = [ <NUM_LIT:1.> / pole for pole in poles ] <EOL> if bad_roots is not None : <EOL> poles = fix_roots ( poles , bad_roots , fix_mode ) <EOL> forward_a = find_coeff ( poles , '<STR_LIT:b>' ) <EOL> return ( forward_a + backward_a ) / <NUM_LIT> <EOL> def find_lproots_hsvd ( x , M , K , mode , zmethod = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if mode not in [ '<STR_LIT:f>' , '<STR_LIT:b>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if zmethod not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if K > min ( M + <NUM_LIT:1> , len ( x ) - M ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> N = len ( x ) <EOL> L = N - M - <NUM_LIT:1> <EOL> if mode == "<STR_LIT:f>" : <EOL> X = scipy . linalg . hankel ( x [ : L + <NUM_LIT:1> ] , x [ L : ] ) <EOL> else : <EOL> X = scipy . linalg . hankel ( x [ : M - <NUM_LIT:1> : - <NUM_LIT:1> ] , x [ M : : - <NUM_LIT:1> ] ) <EOL> U , s , Vh = scipy . linalg . svd ( X ) <EOL> Uk = np . mat ( U [ : , : K ] ) <EOL> Ub = Uk [ : - <NUM_LIT:1> ] <EOL> Ut = Uk [ <NUM_LIT:1> : ] <EOL> if zmethod == '<STR_LIT>' : <EOL> Zp , resid , rank , s = scipy . linalg . lstsq ( Ub , Ut ) <EOL> else : <EOL> uh = Uk [ - <NUM_LIT:1> ] <EOL> u = uh . H <EOL> Zp = ( np . eye ( K , dtype = u . dtype ) + ( u * uh / ( <NUM_LIT:1.> - uh * u ) ) ) * Ub . H * Ut <EOL> return scipy . linalg . eigvals ( Zp ) <EOL> def find_roots ( a , mode = "<STR_LIT:f>" ) : <EOL> """<STR_LIT>""" <EOL> if mode not in [ '<STR_LIT:f>' , '<STR_LIT:b>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> p = np . empty ( len ( a ) + <NUM_LIT:1> , dtype = a . dtype ) <EOL> p [ <NUM_LIT:0> ] = ( <NUM_LIT:1.0> + <NUM_LIT> ) <EOL> if mode == "<STR_LIT:f>" : <EOL> p [ <NUM_LIT:1> : ] = - a . flat [ : : - <NUM_LIT:1> ] <EOL> else : <EOL> p [ <NUM_LIT:1> : ] = - a . flat [ : ] <EOL> return np . roots ( p ) <EOL> def find_coeff ( poles , mode = "<STR_LIT:f>" ) : <EOL> """<STR_LIT>""" <EOL> if mode not in [ '<STR_LIT:f>' , '<STR_LIT:b>' ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if mode == '<STR_LIT:f>' : <EOL> return np . squeeze ( - np . poly ( poles ) [ : <NUM_LIT:0> : - <NUM_LIT:1> ] ) <EOL> else : <EOL> return np . squeeze ( - np . poly ( poles ) [ <NUM_LIT:1> : ] ) <EOL> def reverse_filter ( a , mode ) : <EOL> """<STR_LIT>""" <EOL> nmode = { '<STR_LIT:f>' : '<STR_LIT:b>' , '<STR_LIT:b>' : '<STR_LIT:f>' } [ mode ] <EOL> return find_coeff ( [ <NUM_LIT:1.> / pole for pole in find_roots ( a , mode ) ] , nmode ) <EOL> def fix_roots ( poles , fix_roots = "<STR_LIT>" , fix_mode = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if fix_roots not in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if fix_mode not in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if fix_roots == "<STR_LIT>" : <EOL> for i , pole in enumerate ( poles ) : <EOL> if np . abs ( pole ) > <NUM_LIT:1> : <EOL> if fix_mode == "<STR_LIT>" : <EOL> poles [ i ] = pole / np . abs ( pole ) <EOL> else : <EOL> poles [ i ] = <NUM_LIT:1> / np . conj ( pole ) <EOL> else : <EOL> for i , pole in enumerate ( poles ) : <EOL> if np . abs ( pole ) < <NUM_LIT:1> : <EOL> if fix_mode == "<STR_LIT>" : <EOL> poles [ i ] = pole / np . abs ( pole ) <EOL> else : <EOL> poles [ i ] = <NUM_LIT:1> / np . conj ( pole ) <EOL> return poles <EOL> def extrapolate ( trace , a , pred , append ) : <EOL> """<STR_LIT>""" <EOL> m = len ( a ) <EOL> M = len ( trace ) <EOL> ntrace = np . empty ( ( M + pred ) , dtype = trace . dtype ) <EOL> if append not in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if append == "<STR_LIT>" : <EOL> ntrace [ : M ] = trace <EOL> for i in range ( pred ) : <EOL> ntrace [ M + i ] = np . sum ( np . multiply ( ntrace [ M - m + i : M + i ] , <EOL> a . flat ) ) <EOL> return ntrace <EOL> if append == "<STR_LIT>" : <EOL> ntrace [ - M : ] = trace <EOL> for i in range ( pred ) : <EOL> ntrace [ pred - i - <NUM_LIT:1> ] = np . sum ( np . multiply ( <EOL> ntrace [ pred - i : pred + m - i ] , a . flat ) ) <EOL> return ntrace </s>
<s> """<STR_LIT>""" <EOL> import nmrglue . fileio . pipe as pipe <EOL> import nmrglue . process . pipe_proc as p <EOL> d , a = pipe . read ( "<STR_LIT>" ) <EOL> d , a = p . ls ( d , a , ls = <NUM_LIT> , sw = True ) <EOL> pipe . write ( "<STR_LIT>" , d , a , overwrite = True ) <EOL> d , a = pipe . read ( "<STR_LIT>" ) <EOL> d , a = p . ls ( d , a , ls = - <NUM_LIT> , sw = True ) <EOL> pipe . write ( "<STR_LIT>" , d , a , overwrite = True ) <EOL> d , a = pipe . read ( "<STR_LIT>" ) <EOL> d , a = p . ls ( d , a , ls = <NUM_LIT> , sw = True ) <EOL> pipe . write ( "<STR_LIT>" , d , a , overwrite = True ) <EOL> d , a = pipe . read ( "<STR_LIT>" ) <EOL> d , a = p . ls ( d , a , ls = <NUM_LIT> , sw = True ) <EOL> pipe . write ( "<STR_LIT>" , d , a , overwrite = True ) <EOL> d , a = pipe . read ( "<STR_LIT>" ) <EOL> d , a = p . ls ( d , a , ls = - <NUM_LIT> , sw = True ) <EOL> pipe . write ( "<STR_LIT>" , d , a , overwrite = True ) </s>
<s> """<STR_LIT>""" <EOL> import tempfile <EOL> import os <EOL> import shutil <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal <EOL> import nmrglue as ng <EOL> from nose . plugins . attrib import attr <EOL> from setup import DATA_DIR <EOL> def write_readback ( dic , data ) : <EOL> """<STR_LIT>""" <EOL> td = tempfile . mkdtemp ( dir = "<STR_LIT:.>" ) <EOL> ng . varian . write ( td , dic , data ) <EOL> rdic , rdata = ng . varian . read ( td ) <EOL> shutil . rmtree ( td ) <EOL> assert_array_equal ( data , rdata ) <EOL> assert dic == rdic <EOL> def lowmem_write_readback ( dic , data ) : <EOL> """<STR_LIT>""" <EOL> td = tempfile . mkdtemp ( dir = "<STR_LIT:.>" ) <EOL> ng . varian . write_lowmem ( td , dic , data ) <EOL> rdic , rdata = ng . varian . read_lowmem ( td ) <EOL> s = tuple ( range ( data . ndim ) ) <EOL> assert data [ s ] == rdata [ s ] <EOL> assert dic == rdic <EOL> shutil . rmtree ( td ) <EOL> def write_fid_readback ( dic , data , shape , torder ) : <EOL> """<STR_LIT>""" <EOL> tf = tempfile . mktemp ( dir = "<STR_LIT:.>" ) <EOL> ng . varian . write_fid ( tf , dic , data , torder = torder ) <EOL> rdic , rdata = ng . varian . read_fid ( tf , shape = shape , torder = torder ) <EOL> os . remove ( tf ) <EOL> assert_array_equal ( data , rdata ) <EOL> assert dic == rdic <EOL> def lowmem_fid_write_readback ( dic , data , shape , torder ) : <EOL> """<STR_LIT>""" <EOL> tf = tempfile . mktemp ( dir = "<STR_LIT:.>" ) <EOL> ng . varian . write_fid_lowmem ( tf , dic , data , torder = torder ) <EOL> rdic , rdata = ng . varian . read_fid_lowmem ( tf , shape = shape , torder = torder ) <EOL> s = tuple ( range ( data . ndim ) ) <EOL> assert data [ s ] == rdata [ s ] <EOL> assert dic == rdic <EOL> os . remove ( tf ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_1d ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read ( os . path . join ( DATA_DIR , "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , ) <EOL> assert np . abs ( data [ <NUM_LIT:0> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:1> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:1> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_2d ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read ( os . path . join ( DATA_DIR , "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_2d_lowmem ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read_lowmem ( os . path . join ( DATA_DIR , "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> lowmem_write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_2d_tppi ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read ( os . path . join ( DATA_DIR , "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . real - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . real - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_2d_tppi_lowmem ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read_lowmem ( os . path . join ( DATA_DIR , <EOL> "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . real - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . real - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> lowmem_write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_3d ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read ( os . path . join ( DATA_DIR , "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] . imag - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . real - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_3d_lowmem ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read_lowmem ( os . path . join ( DATA_DIR , "<STR_LIT>" ) ) <EOL> assert data . shape == ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] . imag - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . real - - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . imag - - <NUM_LIT> ) <= <NUM_LIT> <EOL> lowmem_write_readback ( dic , data ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_4d ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read_fid ( os . path . join ( DATA_DIR , "<STR_LIT>" ) , <EOL> shape = ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> ) , torder = '<STR_LIT:r>' ) <EOL> assert data . shape == ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] . imag - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:3> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:3> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . imag - <NUM_LIT> ) <= <NUM_LIT> <EOL> write_fid_readback ( dic , data , ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> ) , '<STR_LIT:r>' ) <EOL> @ attr ( speed = '<STR_LIT>' ) <EOL> def test_4d_lowmem ( ) : <EOL> """<STR_LIT>""" <EOL> dic , data = ng . varian . read_fid_lowmem ( <EOL> os . path . join ( DATA_DIR , "<STR_LIT>" ) , <EOL> shape = ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> ) , torder = '<STR_LIT:r>' ) <EOL> assert data . shape == ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> ) <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] . imag - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:3> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . real - <NUM_LIT> ) <= <NUM_LIT> <EOL> assert np . abs ( data [ <NUM_LIT:3> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> ] . imag - <NUM_LIT> ) <= <NUM_LIT> <EOL> lowmem_fid_write_readback ( dic , data , ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> ) , '<STR_LIT:r>' ) </s>
<s> """<STR_LIT>""" <EOL> SECRET_KEY = '<STR_LIT:test>' <EOL> INSTALLED_APPS = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> MIDDLEWARE_CLASSES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> DATABASES = { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> ROOT_URLCONF = [ ] </s>
<s> from __future__ import unicode_literals <EOL> import json <EOL> from zerotest . request import Request <EOL> from zerotest . response import Response <EOL> class Formatter ( object ) : <EOL> def write_record ( self , writeable , request , response ) : <EOL> record = dict ( request = request . __dict__ , response = response . __dict__ ) <EOL> writeable . write ( json . dumps ( record ) ) <EOL> writeable . write ( "<STR_LIT:\n>" ) <EOL> def read_record ( self , readable ) : <EOL> line = readable . readline ( ) <EOL> if not line : <EOL> return None <EOL> record = json . loads ( line ) <EOL> request = Request ( ) <EOL> request . __dict__ . update ( record [ '<STR_LIT>' ] ) <EOL> response = Response ( ) <EOL> response . __dict__ . update ( record [ '<STR_LIT>' ] ) <EOL> return request , response </s>
<s> """<STR_LIT>""" <EOL> from httpie . plugins . base import ( <EOL> AuthPlugin , FormatterPlugin , <EOL> ConverterPlugin , TransportPlugin <EOL> ) <EOL> from httpie . plugins . manager import PluginManager <EOL> from httpie . plugins . builtin import BasicAuthPlugin , DigestAuthPlugin <EOL> from httpie . output . formatters . headers import HeadersFormatter <EOL> from httpie . output . formatters . json import JSONFormatter <EOL> from httpie . output . formatters . colors import ColorFormatter <EOL> plugin_manager = PluginManager ( ) <EOL> plugin_manager . register ( BasicAuthPlugin , <EOL> DigestAuthPlugin ) <EOL> plugin_manager . register ( HeadersFormatter , <EOL> JSONFormatter , <EOL> ColorFormatter ) </s>
<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import time <EOL> import json <EOL> import tempfile <EOL> from httpie import ExitStatus , EXIT_STATUS_LABELS <EOL> from httpie . context import Environment <EOL> from httpie . core import main <EOL> from httpie . compat import bytes , str <EOL> TESTS_ROOT = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> CRLF = '<STR_LIT:\r\n>' <EOL> COLOR = '<STR_LIT>' <EOL> HTTP_OK = '<STR_LIT>' <EOL> HTTP_OK_COLOR = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def mk_config_dir ( ) : <EOL> dirname = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> return dirname <EOL> def add_auth ( url , auth ) : <EOL> proto , rest = url . split ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> return proto + '<STR_LIT>' + auth + '<STR_LIT:@>' + rest <EOL> class TestEnvironment ( Environment ) : <EOL> """<STR_LIT>""" <EOL> colors = <NUM_LIT:0> <EOL> stdin_isatty = True , <EOL> stdout_isatty = True <EOL> is_windows = False <EOL> def __init__ ( self , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = tempfile . TemporaryFile ( <EOL> mode = '<STR_LIT>' , <EOL> prefix = '<STR_LIT>' <EOL> ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = tempfile . TemporaryFile ( <EOL> mode = '<STR_LIT>' , <EOL> prefix = '<STR_LIT>' <EOL> ) <EOL> super ( TestEnvironment , self ) . __init__ ( ** kwargs ) <EOL> self . _delete_config_dir = False <EOL> @ property <EOL> def config ( self ) : <EOL> if not self . config_dir . startswith ( tempfile . gettempdir ( ) ) : <EOL> self . config_dir = mk_config_dir ( ) <EOL> self . _delete_config_dir = True <EOL> return super ( TestEnvironment , self ) . config <EOL> def cleanup ( self ) : <EOL> if self . _delete_config_dir : <EOL> assert self . config_dir . startswith ( tempfile . gettempdir ( ) ) <EOL> from shutil import rmtree <EOL> rmtree ( self . config_dir ) <EOL> def __del__ ( self ) : <EOL> try : <EOL> self . cleanup ( ) <EOL> except Exception : <EOL> pass <EOL> class BaseCLIResponse ( object ) : <EOL> """<STR_LIT>""" <EOL> stderr = None <EOL> json = None <EOL> exit_status = None <EOL> class BytesCLIResponse ( bytes , BaseCLIResponse ) : <EOL> """<STR_LIT>""" <EOL> class StrCLIResponse ( str , BaseCLIResponse ) : <EOL> @ property <EOL> def json ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _json = None <EOL> if COLOR in self : <EOL> pass <EOL> elif self . strip ( ) . startswith ( '<STR_LIT:{>' ) : <EOL> self . _json = json . loads ( self ) <EOL> elif ( self . count ( '<STR_LIT>' ) == <NUM_LIT:1> and <EOL> '<STR_LIT:application/json>' in self ) : <EOL> try : <EOL> j = self . strip ( ) [ self . strip ( ) . rindex ( '<STR_LIT>' ) : ] <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> try : <EOL> self . _json = json . loads ( j ) <EOL> except ValueError : <EOL> pass <EOL> return self . _json <EOL> class ExitStatusError ( Exception ) : <EOL> pass <EOL> def http ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> error_exit_ok = kwargs . pop ( '<STR_LIT>' , False ) <EOL> env = kwargs . get ( '<STR_LIT>' ) <EOL> if not env : <EOL> env = kwargs [ '<STR_LIT>' ] = TestEnvironment ( ) <EOL> stdout = env . stdout <EOL> stderr = env . stderr <EOL> args = list ( args ) <EOL> args_with_config_defaults = args + env . config . default_options <EOL> add_to_args = [ ] <EOL> if '<STR_LIT>' not in args_with_config_defaults : <EOL> if '<STR_LIT>' not in args_with_config_defaults : <EOL> add_to_args . append ( '<STR_LIT>' ) <EOL> if not any ( '<STR_LIT>' in arg for arg in args_with_config_defaults ) : <EOL> add_to_args . append ( '<STR_LIT>' ) <EOL> args = add_to_args + args <EOL> def dump_stderr ( ) : <EOL> stderr . seek ( <NUM_LIT:0> ) <EOL> sys . stderr . write ( stderr . read ( ) ) <EOL> try : <EOL> try : <EOL> exit_status = main ( args = args , ** kwargs ) <EOL> if '<STR_LIT>' in args : <EOL> time . sleep ( <NUM_LIT> ) <EOL> except SystemExit : <EOL> if error_exit_ok : <EOL> exit_status = ExitStatus . ERROR <EOL> else : <EOL> dump_stderr ( ) <EOL> raise <EOL> except Exception : <EOL> stderr . seek ( <NUM_LIT:0> ) <EOL> sys . stderr . write ( stderr . read ( ) ) <EOL> raise <EOL> else : <EOL> if not error_exit_ok and exit_status != ExitStatus . OK : <EOL> dump_stderr ( ) <EOL> raise ExitStatusError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> exit_status , <EOL> EXIT_STATUS_LABELS [ exit_status ] <EOL> ) <EOL> ) <EOL> stdout . seek ( <NUM_LIT:0> ) <EOL> stderr . seek ( <NUM_LIT:0> ) <EOL> output = stdout . read ( ) <EOL> try : <EOL> output = output . decode ( '<STR_LIT:utf8>' ) <EOL> except UnicodeDecodeError : <EOL> r = BytesCLIResponse ( output ) <EOL> else : <EOL> r = StrCLIResponse ( output ) <EOL> r . stderr = stderr . read ( ) <EOL> r . exit_status = exit_status <EOL> if r . exit_status != ExitStatus . OK : <EOL> sys . stderr . write ( r . stderr ) <EOL> return r <EOL> finally : <EOL> stdout . close ( ) <EOL> stderr . close ( ) <EOL> env . cleanup ( ) </s>
<s> """<STR_LIT>""" <EOL> from flask import render_template , send_from_directory <EOL> import os <EOL> class Viewer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app , template_path , upload_path = None ) : <EOL> super ( Viewer , self ) . __init__ ( ) <EOL> self . app = app <EOL> self . template_path = template_path <EOL> self . static_path = os . path . join ( app . root_path , '<STR_LIT>' , template_path , app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if upload_path is None : <EOL> self . upload_path = os . path . join ( app . root_path , '<STR_LIT>' ) <EOL> else : <EOL> self . upload_path = upload_path <EOL> def view ( self , rule , ** options ) : <EOL> """<STR_LIT>""" <EOL> complete_rule = '<STR_LIT>' % ( self . app . config [ '<STR_LIT>' ] , self . app . config [ '<STR_LIT>' ] [ rule ] ) <EOL> def decorator ( f ) : <EOL> self . app . add_url_rule ( complete_rule , f . __name__ , f , ** options ) <EOL> return f <EOL> return decorator <EOL> def render ( self , template , ** options ) : <EOL> """<STR_LIT>""" <EOL> template_path = os . path . join ( self . template_path , self . app . config [ '<STR_LIT>' ] , template ) <EOL> return render_template ( template_path , ** options ) <EOL> def static ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> return send_from_directory ( self . static_path , filename ) <EOL> def uploaded ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> return send_from_directory ( self . upload_path , filename ) </s>
<s> """<STR_LIT>""" <EOL> import datetime <EOL> import inspect <EOL> import oauth2 as oauth <EOL> import oauth_provider <EOL> import provider as oauth2_provider <EOL> from oauth_provider . store import store as oauth_provider_store <EOL> from rest_framework . authentication import BaseAuthentication , get_authorization_header <EOL> from rest_framework import exceptions <EOL> from django . conf import settings <EOL> def check_nonce ( request , oauth_request , oauth_nonce , oauth_timestamp ) : <EOL> check_nonce_args = inspect . getargspec ( oauth_provider_store . check_nonce ) . args <EOL> if '<STR_LIT>' in check_nonce_args : <EOL> return oauth_provider_store . check_nonce ( <EOL> request , oauth_request , oauth_nonce , oauth_timestamp <EOL> ) <EOL> return oauth_provider_store . check_nonce ( <EOL> request , oauth_request , oauth_nonce <EOL> ) <EOL> if oauth2_provider . __version__ in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> provider_now = datetime . datetime . now <EOL> else : <EOL> from django . utils . timezone import now as provider_now <EOL> class OAuthAuthentication ( BaseAuthentication ) : <EOL> """<STR_LIT>""" <EOL> www_authenticate_realm = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( OAuthAuthentication , self ) . __init__ ( * args , ** kwargs ) <EOL> def authenticate ( self , request ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> oauth_request = oauth_provider . utils . get_oauth_request ( request ) <EOL> except oauth . Error as err : <EOL> raise exceptions . AuthenticationFailed ( err . message ) <EOL> if not oauth_request : <EOL> return None <EOL> oauth_params = oauth_provider . consts . OAUTH_PARAMETERS_NAMES <EOL> found = any ( param for param in oauth_params if param in oauth_request ) <EOL> missing = list ( param for param in oauth_params if param not in oauth_request ) <EOL> if not found : <EOL> return None <EOL> if missing : <EOL> msg = '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( missing ) ) <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> if not self . check_nonce ( request , oauth_request ) : <EOL> msg = '<STR_LIT>' <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> try : <EOL> consumer_key = oauth_request . get_parameter ( '<STR_LIT>' ) <EOL> consumer = oauth_provider_store . get_consumer ( request , oauth_request , consumer_key ) <EOL> except oauth_provider . store . InvalidConsumerError : <EOL> msg = '<STR_LIT>' % oauth_request . get_parameter ( '<STR_LIT>' ) <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> if consumer . status != oauth_provider . consts . ACCEPTED : <EOL> msg = '<STR_LIT>' % consumer . get_status_display ( ) <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> try : <EOL> token_param = oauth_request . get_parameter ( '<STR_LIT>' ) <EOL> token = oauth_provider_store . get_access_token ( request , oauth_request , consumer , token_param ) <EOL> except oauth_provider . store . InvalidTokenError : <EOL> msg = '<STR_LIT>' % oauth_request . get_parameter ( '<STR_LIT>' ) <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> try : <EOL> self . validate_token ( request , consumer , token ) <EOL> except oauth . Error as err : <EOL> raise exceptions . AuthenticationFailed ( err . message ) <EOL> user = token . user <EOL> if not user . is_active : <EOL> msg = '<STR_LIT>' % user . username <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> return ( token . user , token ) <EOL> def authenticate_header ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % self . www_authenticate_realm <EOL> def validate_token ( self , request , consumer , token ) : <EOL> """<STR_LIT>""" <EOL> oauth_server , oauth_request = oauth_provider . utils . initialize_server_request ( request ) <EOL> oauth_server . verify_request ( oauth_request , consumer , token ) <EOL> def check_nonce ( self , request , oauth_request ) : <EOL> """<STR_LIT>""" <EOL> oauth_nonce = oauth_request [ '<STR_LIT>' ] <EOL> oauth_timestamp = oauth_request [ '<STR_LIT>' ] <EOL> return check_nonce ( request , oauth_request , oauth_nonce , oauth_timestamp ) <EOL> class OAuth2Authentication ( BaseAuthentication ) : <EOL> """<STR_LIT>""" <EOL> www_authenticate_realm = '<STR_LIT>' <EOL> allow_query_params_token = settings . DEBUG <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( OAuth2Authentication , self ) . __init__ ( * args , ** kwargs ) <EOL> def authenticate ( self , request ) : <EOL> """<STR_LIT>""" <EOL> auth = get_authorization_header ( request ) . split ( ) <EOL> if len ( auth ) == <NUM_LIT:1> : <EOL> msg = '<STR_LIT>' <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> elif len ( auth ) > <NUM_LIT:2> : <EOL> msg = '<STR_LIT>' <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> if auth and auth [ <NUM_LIT:0> ] . lower ( ) == b'<STR_LIT>' : <EOL> access_token = auth [ <NUM_LIT:1> ] <EOL> elif '<STR_LIT>' in request . POST : <EOL> access_token = request . POST [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in request . GET and self . allow_query_params_token : <EOL> access_token = request . GET [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> return self . authenticate_credentials ( request , access_token ) <EOL> def authenticate_credentials ( self , request , access_token ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> token = oauth2_provider . oauth2 . models . AccessToken . objects . select_related ( '<STR_LIT:user>' ) <EOL> token = token . get ( token = access_token , expires__gt = provider_now ( ) ) <EOL> except oauth2_provider . oauth2 . models . AccessToken . DoesNotExist : <EOL> raise exceptions . AuthenticationFailed ( '<STR_LIT>' ) <EOL> user = token . user <EOL> if not user . is_active : <EOL> msg = '<STR_LIT>' % user . username <EOL> raise exceptions . AuthenticationFailed ( msg ) <EOL> return ( user , token ) <EOL> def authenticate_header ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % self . www_authenticate_realm </s>
<s> from django . contrib . auth . models import User , Group <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from rubberstamp . tests . base import RubberStampTestCase <EOL> from rubberstamp . models import AppPermission <EOL> from rubberstamp . tests . testapp . models import TestModel <EOL> class ViewTest ( RubberStampTestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . user = User . objects . get ( username = '<STR_LIT:user>' ) <EOL> def test_app_list ( self ) : <EOL> """<STR_LIT>""" <EOL> xr = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> xr = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> r = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> ap_ct = ContentType . objects . get ( app_label = '<STR_LIT>' , model = '<STR_LIT>' ) <EOL> tm_ct = ContentType . objects . get ( app_label = '<STR_LIT>' , model = '<STR_LIT>' ) <EOL> otm_ct = ContentType . objects . get ( app_label = '<STR_LIT>' , model = '<STR_LIT>' ) <EOL> apps = [ <EOL> { <EOL> '<STR_LIT:label>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : [ ap_ct ] <EOL> } , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT:label>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : [ tm_ct ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : [ otm_ct , tm_ct ] <EOL> } , <EOL> ] , <EOL> } , <EOL> ] <EOL> self . assertEqual ( repr ( r . context [ '<STR_LIT>' ] ) , repr ( apps ) ) <EOL> def test_type_to_user ( self ) : <EOL> """<STR_LIT>""" <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> assign_form = r . context [ '<STR_LIT>' ] <EOL> self . assertFalse ( assign_form . is_bound ) <EOL> self . assertRaises ( KeyError , lambda : r . context [ '<STR_LIT>' ] ) <EOL> post_dict = { <EOL> '<STR_LIT>' : [ '<STR_LIT:4>' , '<STR_LIT:5>' ] , <EOL> } <EOL> rp = self . client . post ( '<STR_LIT>' , post_dict ) <EOL> self . assertEqual ( rp . status_code , <NUM_LIT:200> ) <EOL> assign_form = rp . context [ '<STR_LIT>' ] <EOL> self . assertTrue ( assign_form . is_valid ( ) ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> self . assertTrue ( user4 . has_perm ( '<STR_LIT>' ) ) <EOL> def test_type_to_group ( self ) : <EOL> """<STR_LIT>""" <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> post_dict = { <EOL> '<STR_LIT>' : [ '<STR_LIT:1>' ] , <EOL> } <EOL> rp = self . client . post ( '<STR_LIT>' , post_dict ) <EOL> self . assertEqual ( rp . status_code , <NUM_LIT:200> ) <EOL> assign_form = rp . context [ '<STR_LIT>' ] <EOL> self . assertTrue ( assign_form . is_valid ( ) ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> self . assertFalse ( user4 . has_perm ( '<STR_LIT>' ) ) <EOL> group = Group . objects . get ( pk = <NUM_LIT:1> ) <EOL> user4 . groups . add ( group ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> self . assertTrue ( user4 . has_perm ( '<STR_LIT>' ) ) <EOL> def test_type_remove ( self ) : <EOL> """<STR_LIT>""" <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , user4 ) <EOL> self . assertTrue ( user4 . has_perm ( '<STR_LIT>' ) ) <EOL> rp = self . client . post ( '<STR_LIT>' , { } ) <EOL> self . assertEqual ( rp . status_code , <NUM_LIT:200> ) <EOL> assign_form = rp . context [ '<STR_LIT>' ] <EOL> self . assertTrue ( assign_form . is_valid ( ) ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> self . assertFalse ( user4 . has_perm ( '<STR_LIT>' ) ) <EOL> user5 = User . objects . get ( pk = <NUM_LIT:5> ) <EOL> group = Group . objects . get ( pk = <NUM_LIT:1> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , group ) <EOL> user5 . groups . add ( group ) <EOL> self . assertTrue ( user5 . has_perm ( '<STR_LIT>' ) ) <EOL> rp = self . client . post ( '<STR_LIT>' , { } ) <EOL> user5 = User . objects . get ( pk = <NUM_LIT:5> ) <EOL> self . assertFalse ( user5 . has_perm ( '<STR_LIT>' ) ) <EOL> def test_object_list ( self ) : <EOL> """<STR_LIT>""" <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> objects = r . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( objects ) , <NUM_LIT:2> ) <EOL> def test_object_to_user ( self ) : <EOL> """<STR_LIT>""" <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> xr = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( xr . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> assign_form = r . context [ '<STR_LIT>' ] <EOL> self . assertFalse ( assign_form . is_bound ) <EOL> self . assertRaises ( KeyError , lambda : r . context [ '<STR_LIT>' ] ) <EOL> post_dict = { <EOL> '<STR_LIT>' : [ '<STR_LIT:4>' , '<STR_LIT:5>' ] , <EOL> } <EOL> rp = self . client . post ( '<STR_LIT>' , post_dict ) <EOL> self . assertEqual ( rp . status_code , <NUM_LIT:200> ) <EOL> assign_form = rp . context [ '<STR_LIT>' ] <EOL> self . assertTrue ( assign_form . is_valid ( ) ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> obj = TestModel . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertTrue ( user4 . has_perm ( '<STR_LIT>' , obj = obj ) ) <EOL> def test_form_preselection ( self ) : <EOL> AppPermission . objects . assign ( '<STR_LIT>' , self . user ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> form = r . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( form . initial [ '<STR_LIT>' ] , [ ] ) <EOL> user4 = User . objects . get ( pk = <NUM_LIT:4> ) <EOL> obj = TestModel . objects . get ( pk = <NUM_LIT:1> ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , user4 ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> form = r . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( form . initial [ '<STR_LIT>' ] , [ user4 ] ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> form = r . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( form . initial [ '<STR_LIT>' ] , [ ] ) <EOL> AppPermission . objects . assign ( '<STR_LIT>' , user4 , obj = obj ) <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> form = r . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( form . initial [ '<STR_LIT>' ] , [ user4 ] ) <EOL> __all__ = ( '<STR_LIT>' , ) </s>
<s> __author__ = '<STR_LIT>' </s>
<s> __doc__ = """<STR_LIT>""" <EOL> import os <EOL> def ld_linux_path ( root ) : <EOL> """<STR_LIT>""" <EOL> return os . path . join ( root , '<STR_LIT>' , '<STR_LIT>' ) </s>
<s> from factory import SubFactory , DjangoModelFactory <EOL> from telegrambot . test . factories . user import UserWebFactory <EOL> from telegrambot . models import AuthToken <EOL> class AuthTokenFactory ( DjangoModelFactory ) : <EOL> user = SubFactory ( UserWebFactory ) <EOL> class Meta : <EOL> model = AuthToken </s>
<s> """<STR_LIT>""" <EOL> import helpers <EOL> import itertools <EOL> import numpy as np <EOL> import pyltr <EOL> class TestDCG ( helpers . TestMetric ) : <EOL> def get_metric ( self ) : <EOL> return pyltr . metrics . DCG ( k = <NUM_LIT:3> ) <EOL> def get_queries_with_values ( self ) : <EOL> yield [ ] , <NUM_LIT:0.0> <EOL> yield [ <NUM_LIT:0> ] , <NUM_LIT:0.0> <EOL> yield [ <NUM_LIT:1> ] , <NUM_LIT:1.0> <EOL> yield [ <NUM_LIT:2> ] , <NUM_LIT> <EOL> yield [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <NUM_LIT> <EOL> yield [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:0.0> <EOL> yield [ <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:1> ] , <NUM_LIT> <EOL> yield [ <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:9> ] , <NUM_LIT> <EOL> def get_queries ( self ) : <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> for tup in itertools . product ( * ( [ ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) ] * i ) ) : <EOL> yield np . array ( tup ) <EOL> class TestNDCG ( helpers . TestMetric ) : <EOL> def get_metric ( self ) : <EOL> return pyltr . metrics . NDCG ( k = <NUM_LIT:3> ) <EOL> def get_queries_with_values ( self ) : <EOL> yield [ ] , <NUM_LIT:0.0> <EOL> yield [ <NUM_LIT:0> ] , <NUM_LIT:0.0> <EOL> yield [ <NUM_LIT:1> ] , <NUM_LIT:1.0> <EOL> yield [ <NUM_LIT:2> ] , <NUM_LIT:1.0> <EOL> yield [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <NUM_LIT:1.0> <EOL> yield [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ] , <NUM_LIT> <EOL> yield [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:0.0> <EOL> yield [ <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:1> ] , <NUM_LIT> <EOL> yield [ <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:9> ] , <NUM_LIT> <EOL> yield [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1> ] , <NUM_LIT:1.0> <EOL> def get_queries ( self ) : <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> for tup in itertools . product ( * ( [ ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) ] * i ) ) : <EOL> yield np . array ( tup ) </s>
<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import shutil <EOL> import time <EOL> from elodie import geolocation <EOL> from elodie import constants <EOL> from elodie . localstorage import Db <EOL> class FileSystem ( object ) : <EOL> """<STR_LIT>""" <EOL> def create_directory ( self , directory_path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if os . path . exists ( directory_path ) : <EOL> return True <EOL> else : <EOL> os . makedirs ( directory_path ) <EOL> return True <EOL> except OSError : <EOL> pass <EOL> return False <EOL> def delete_directory_if_empty ( self , directory_path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . rmdir ( directory_path ) <EOL> return True <EOL> except OSError : <EOL> pass <EOL> return False <EOL> def get_all_files ( self , path , extensions = None ) : <EOL> """<STR_LIT>""" <EOL> files = [ ] <EOL> for dirname , dirnames , filenames in os . walk ( path ) : <EOL> for filename in filenames : <EOL> if ( <EOL> extensions is None or <EOL> filename . lower ( ) . endswith ( extensions ) <EOL> ) : <EOL> files . append ( os . path . join ( dirname , filename ) ) <EOL> return files <EOL> def get_current_directory ( self ) : <EOL> """<STR_LIT>""" <EOL> return os . getcwd ( ) <EOL> def get_file_name ( self , media ) : <EOL> """<STR_LIT>""" <EOL> if ( not media . is_valid ( ) ) : <EOL> return None <EOL> metadata = media . get_metadata ( ) <EOL> if ( metadata is None ) : <EOL> return None <EOL> base_name = re . sub ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metadata [ '<STR_LIT>' ] <EOL> ) <EOL> if ( len ( base_name ) == <NUM_LIT:0> ) : <EOL> base_name = metadata [ '<STR_LIT>' ] <EOL> if ( <EOL> '<STR_LIT:title>' in metadata and <EOL> metadata [ '<STR_LIT:title>' ] is not None and <EOL> len ( metadata [ '<STR_LIT:title>' ] ) > <NUM_LIT:0> <EOL> ) : <EOL> title_sanitized = re . sub ( '<STR_LIT>' , '<STR_LIT:->' , metadata [ '<STR_LIT:title>' ] . strip ( ) ) <EOL> base_name = base_name . replace ( '<STR_LIT>' % title_sanitized , '<STR_LIT>' ) <EOL> base_name = '<STR_LIT>' % ( base_name , title_sanitized ) <EOL> file_name = '<STR_LIT>' % ( <EOL> time . strftime ( <EOL> '<STR_LIT>' , <EOL> metadata [ '<STR_LIT>' ] <EOL> ) , <EOL> base_name , <EOL> metadata [ '<STR_LIT>' ] ) <EOL> return file_name . lower ( ) <EOL> def get_folder_name_by_date ( self , time_obj ) : <EOL> """<STR_LIT>""" <EOL> return time . strftime ( '<STR_LIT>' , time_obj ) <EOL> def get_folder_path ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> path = [ ] <EOL> if ( metadata [ '<STR_LIT>' ] is not None ) : <EOL> path . append ( time . strftime ( '<STR_LIT>' , metadata [ '<STR_LIT>' ] ) ) <EOL> if ( metadata [ '<STR_LIT>' ] is not None ) : <EOL> path . append ( metadata [ '<STR_LIT>' ] ) <EOL> elif ( <EOL> metadata [ '<STR_LIT>' ] is not None and <EOL> metadata [ '<STR_LIT>' ] is not None <EOL> ) : <EOL> place_name = geolocation . place_name ( <EOL> metadata [ '<STR_LIT>' ] , <EOL> metadata [ '<STR_LIT>' ] <EOL> ) <EOL> if ( place_name is not None ) : <EOL> path . append ( place_name ) <EOL> if ( len ( path ) < <NUM_LIT:2> ) : <EOL> path . append ( '<STR_LIT>' ) <EOL> return os . path . join ( * path ) <EOL> def process_file ( self , _file , destination , media , ** kwargs ) : <EOL> move = False <EOL> if ( '<STR_LIT>' in kwargs ) : <EOL> move = kwargs [ '<STR_LIT>' ] <EOL> allow_duplicate = False <EOL> if ( '<STR_LIT>' in kwargs ) : <EOL> allow_duplicate = kwargs [ '<STR_LIT>' ] <EOL> if ( not media . is_valid ( ) ) : <EOL> print '<STR_LIT>' % _file <EOL> return <EOL> metadata = media . get_metadata ( ) <EOL> directory_name = self . get_folder_path ( metadata ) <EOL> dest_directory = os . path . join ( destination , directory_name ) <EOL> file_name = self . get_file_name ( media ) <EOL> dest_path = os . path . join ( dest_directory , file_name ) <EOL> db = Db ( ) <EOL> checksum = db . checksum ( _file ) <EOL> if ( checksum is None ) : <EOL> if ( constants . debug is True ) : <EOL> print '<STR_LIT>' % _file <EOL> return <EOL> if ( allow_duplicate is False and db . check_hash ( checksum ) is True ) : <EOL> if ( constants . debug is True ) : <EOL> print '<STR_LIT>' % ( <EOL> _file , <EOL> db . get_hash ( checksum ) <EOL> ) <EOL> return <EOL> self . create_directory ( dest_directory ) <EOL> if ( move is True ) : <EOL> stat = os . stat ( _file ) <EOL> shutil . move ( _file , dest_path ) <EOL> os . utime ( dest_path , ( stat . st_atime , stat . st_mtime ) ) <EOL> else : <EOL> shutil . copy2 ( _file , dest_path ) <EOL> db . add_hash ( checksum , dest_path ) <EOL> db . update_hash_db ( ) <EOL> return dest_path <EOL> def set_date_from_path_video ( self , video ) : <EOL> """<STR_LIT>""" <EOL> date_taken = None <EOL> video_file_path = video . get_file_path ( ) <EOL> ( year , month , day ) = [ None ] * <NUM_LIT:3> <EOL> directory = os . path . dirname ( video_file_path ) <EOL> year_month_match = re . search ( '<STR_LIT>' , directory ) <EOL> if ( year_month_match is not None ) : <EOL> ( year , month ) = year_month_match . groups ( ) <EOL> day_match = re . search ( <EOL> '<STR_LIT>' , <EOL> os . path . basename ( video . get_file_path ( ) ) <EOL> ) <EOL> if ( day_match is not None ) : <EOL> day = day_match . group ( <NUM_LIT:1> ) <EOL> if ( year is not None and month is not None ) : <EOL> if ( day is not None ) : <EOL> date_taken = time . strptime ( <EOL> '<STR_LIT>' . format ( year , month , day ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> date_taken = time . strptime ( <EOL> '<STR_LIT>' . format ( year , month ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> os . utime ( video_file_path , ( time . time ( ) , time . mktime ( date_taken ) ) ) </s>
<s> import copy <EOL> import six <EOL> from apispec . core import VALID_METHODS <EOL> from apispec . ext . marshmallow import swagger <EOL> from marshmallow import Schema <EOL> from marshmallow . utils import is_instance_or_subclass <EOL> from flask_apispec . paths import rule_to_path , rule_to_params <EOL> from flask_apispec . utils import resolve_instance , resolve_annotations , merge_recursive <EOL> class Converter ( object ) : <EOL> def __init__ ( self , app ) : <EOL> self . app = app <EOL> def convert ( self , target , endpoint = None , blueprint = None ) : <EOL> endpoint = endpoint or target . __name__ . lower ( ) <EOL> if blueprint : <EOL> endpoint = '<STR_LIT>' . format ( blueprint , endpoint ) <EOL> rules = self . app . url_map . _rules_by_endpoint [ endpoint ] <EOL> return [ self . get_path ( rule , target ) for rule in rules ] <EOL> def get_path ( self , rule , target ) : <EOL> operations = self . get_operations ( rule , target ) <EOL> parent = self . get_parent ( target ) <EOL> return { <EOL> '<STR_LIT>' : target , <EOL> '<STR_LIT:path>' : rule_to_path ( rule ) , <EOL> '<STR_LIT>' : { <EOL> method . lower ( ) : self . get_operation ( rule , view , parent = parent ) <EOL> for method , view in six . iteritems ( operations ) <EOL> if method . lower ( ) in ( set ( VALID_METHODS ) - { '<STR_LIT>' } ) <EOL> } , <EOL> } <EOL> def get_operations ( self , rule , target ) : <EOL> return { } <EOL> def get_operation ( self , rule , view , parent = None ) : <EOL> annotation = resolve_annotations ( view , '<STR_LIT>' , parent ) <EOL> docs = merge_recursive ( annotation . options ) <EOL> operation = { <EOL> '<STR_LIT>' : self . get_responses ( view , parent ) , <EOL> '<STR_LIT>' : self . get_parameters ( rule , view , docs , parent ) , <EOL> } <EOL> docs . pop ( '<STR_LIT>' , None ) <EOL> return merge_recursive ( [ operation , docs ] ) <EOL> def get_parent ( self , view ) : <EOL> return None <EOL> def get_parameters ( self , rule , view , docs , parent = None ) : <EOL> annotation = resolve_annotations ( view , '<STR_LIT:args>' , parent ) <EOL> args = merge_recursive ( annotation . options ) <EOL> converter = ( <EOL> swagger . schema2parameters <EOL> if is_instance_or_subclass ( args . get ( '<STR_LIT:args>' , { } ) , Schema ) <EOL> else swagger . fields2parameters <EOL> ) <EOL> options = copy . copy ( args . get ( '<STR_LIT>' , { } ) ) <EOL> locations = options . pop ( '<STR_LIT>' , None ) <EOL> if locations : <EOL> options [ '<STR_LIT>' ] = locations [ <NUM_LIT:0> ] <EOL> return converter ( <EOL> args . get ( '<STR_LIT:args>' , { } ) , <EOL> dump = False , <EOL> ** options <EOL> ) + rule_to_params ( rule , docs . get ( '<STR_LIT>' ) ) <EOL> def get_responses ( self , view , parent = None ) : <EOL> annotation = resolve_annotations ( view , '<STR_LIT>' , parent ) <EOL> return merge_recursive ( annotation . options ) <EOL> class ViewConverter ( Converter ) : <EOL> def get_operations ( self , rule , view ) : <EOL> return { method : view for method in rule . methods } <EOL> class ResourceConverter ( Converter ) : <EOL> def get_operations ( self , rule , resource ) : <EOL> return { <EOL> method : getattr ( resource , method . lower ( ) ) <EOL> for method in rule . methods <EOL> if hasattr ( resource , method . lower ( ) ) <EOL> } <EOL> def get_parent ( self , resource ) : <EOL> return resolve_instance ( resource ) </s>
<s> import os <EOL> import sys <EOL> import webbrowser <EOL> from invoke import run <EOL> from invoke import task <EOL> docs_dir = '<STR_LIT>' <EOL> build_dir = os . path . join ( docs_dir , '<STR_LIT>' ) <EOL> @ task <EOL> def test ( ) : <EOL> import pytest <EOL> errcode = pytest . main ( [ '<STR_LIT>' ] ) <EOL> sys . exit ( errcode ) <EOL> @ task <EOL> def watch ( ) : <EOL> """<STR_LIT>""" <EOL> import pytest <EOL> errcode = pytest . main ( [ '<STR_LIT>' ] ) <EOL> sys . exit ( errcode ) <EOL> @ task <EOL> def clean ( ) : <EOL> run ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' ) <EOL> clean_docs ( ) <EOL> print ( '<STR_LIT>' ) <EOL> @ task <EOL> def clean_docs ( ) : <EOL> run ( '<STR_LIT>' . format ( build_dir ) ) <EOL> @ task <EOL> def browse_docs ( ) : <EOL> path = os . path . join ( build_dir , '<STR_LIT>' ) <EOL> webbrowser . open_new_tab ( path ) <EOL> @ task <EOL> def docs ( clean = False , browse = False , watch = False ) : <EOL> """<STR_LIT>""" <EOL> if clean : <EOL> clean_docs ( ) <EOL> run ( '<STR_LIT>' . format ( docs_dir , build_dir ) , pty = True ) <EOL> if browse : <EOL> browse_docs ( ) <EOL> if watch : <EOL> watch_docs ( ) <EOL> @ task <EOL> def watch_docs ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import sphinx_autobuild <EOL> except ImportError : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> docs ( ) <EOL> run ( '<STR_LIT>' . format ( docs_dir , build_dir ) , pty = True ) <EOL> @ task <EOL> def readme ( browse = False ) : <EOL> run ( '<STR_LIT>' , pty = True ) <EOL> if browse : <EOL> webbrowser . open_new_tab ( '<STR_LIT>' ) <EOL> @ task <EOL> def publish ( test = False ) : <EOL> """<STR_LIT>""" <EOL> clean ( ) <EOL> if test : <EOL> run ( '<STR_LIT>' , echo = True ) <EOL> run ( '<STR_LIT>' , echo = True ) <EOL> else : <EOL> run ( '<STR_LIT>' , echo = True ) <EOL> run ( '<STR_LIT>' , echo = True ) </s>
<s> import unittest <EOL> from nose . tools import * <EOL> from bs4 import BeautifulSoup <EOL> from robobrowser import helpers <EOL> class TestEnsureSoup ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . html = '<STR_LIT>' <EOL> self . tag = BeautifulSoup ( self . html ) . find ( ) <EOL> self . htmls = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> self . tags = [ <EOL> BeautifulSoup ( html ) . find ( ) <EOL> for html in self . htmls <EOL> ] <EOL> def test_handle_string ( self ) : <EOL> ensured = helpers . ensure_soup ( self . html ) <EOL> assert_equal ( ensured , self . tag ) <EOL> def test_handle_soup ( self ) : <EOL> ensured = helpers . ensure_soup ( BeautifulSoup ( self . html ) ) <EOL> assert_equal ( ensured , self . tag ) <EOL> def test_handle_tag ( self ) : <EOL> ensured = helpers . ensure_soup ( BeautifulSoup ( self . html ) . find ( ) ) <EOL> assert_equal ( ensured , self . tag ) <EOL> def test_handle_string_list ( self ) : <EOL> ensured = helpers . ensure_soup ( self . htmls ) <EOL> assert_equal ( ensured , self . tags ) <EOL> def test_handle_soup_list ( self ) : <EOL> ensured = helpers . ensure_soup ( [ <EOL> BeautifulSoup ( html ) <EOL> for html in self . htmls <EOL> ] ) <EOL> assert_equal ( ensured , self . tags ) <EOL> def test_handle_tag_list ( self ) : <EOL> ensured = helpers . ensure_soup ( [ <EOL> BeautifulSoup ( html ) . find ( ) <EOL> for html in self . htmls <EOL> ] ) <EOL> assert_equal ( ensured , self . tags ) </s>
<s> import sys <EOL> from time import clock <EOL> import openpyxl <EOL> import pyexcelerate <EOL> import xlsxwriter <EOL> import xlwt <EOL> from openpyxl . cell import get_column_letter <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> row_max = int ( sys . argv [ <NUM_LIT:1> ] ) <EOL> col_max = <NUM_LIT:50> <EOL> else : <EOL> row_max = <NUM_LIT:1000> <EOL> col_max = <NUM_LIT:50> <EOL> if len ( sys . argv ) > <NUM_LIT:2> : <EOL> col_max = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> def print_elapsed_time ( module_name , elapsed ) : <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" % ( module_name , elapsed ) ) <EOL> def time_xlsxwriter ( ) : <EOL> """<STR_LIT>""" <EOL> start_time = clock ( ) <EOL> workbook = xlsxwriter . Workbook ( '<STR_LIT>' ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> for row in range ( row_max // <NUM_LIT:2> ) : <EOL> for col in range ( col_max ) : <EOL> worksheet . write_string ( row * <NUM_LIT:2> , col , "<STR_LIT>" % ( row , col ) ) <EOL> for col in range ( col_max ) : <EOL> worksheet . write_number ( row * <NUM_LIT:2> + <NUM_LIT:1> , col , row + col ) <EOL> workbook . close ( ) <EOL> elapsed = clock ( ) - start_time <EOL> print_elapsed_time ( '<STR_LIT>' , elapsed ) <EOL> def time_xlsxwriter_optimised ( ) : <EOL> """<STR_LIT>""" <EOL> start_time = clock ( ) <EOL> workbook = xlsxwriter . Workbook ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : True } ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> for row in range ( row_max // <NUM_LIT:2> ) : <EOL> for col in range ( col_max ) : <EOL> worksheet . write_string ( row * <NUM_LIT:2> , col , "<STR_LIT>" % ( row , col ) ) <EOL> for col in range ( col_max ) : <EOL> worksheet . write_number ( row * <NUM_LIT:2> + <NUM_LIT:1> , col , row + col ) <EOL> workbook . close ( ) <EOL> elapsed = clock ( ) - start_time <EOL> print_elapsed_time ( '<STR_LIT>' , elapsed ) <EOL> def time_openpyxl ( ) : <EOL> """<STR_LIT>""" <EOL> start_time = clock ( ) <EOL> workbook = openpyxl . workbook . Workbook ( ) <EOL> worksheet = workbook . active <EOL> for row in range ( row_max // <NUM_LIT:2> ) : <EOL> for col in range ( col_max ) : <EOL> colletter = get_column_letter ( col + <NUM_LIT:1> ) <EOL> worksheet . cell ( '<STR_LIT>' % ( colletter , row * <NUM_LIT:2> + <NUM_LIT:1> ) ) . value = "<STR_LIT>" % ( row , col ) <EOL> for col in range ( col_max ) : <EOL> colletter = get_column_letter ( col + <NUM_LIT:1> ) <EOL> worksheet . cell ( '<STR_LIT>' % ( colletter , row * <NUM_LIT:2> + <NUM_LIT:2> ) ) . value = row + col <EOL> workbook . save ( '<STR_LIT>' ) <EOL> elapsed = clock ( ) - start_time <EOL> print_elapsed_time ( '<STR_LIT>' , elapsed ) <EOL> def time_openpyxl_optimised ( ) : <EOL> """<STR_LIT>""" <EOL> start_time = clock ( ) <EOL> workbook = openpyxl . workbook . Workbook ( optimized_write = True ) <EOL> worksheet = workbook . create_sheet ( ) <EOL> for row in range ( row_max // <NUM_LIT:2> ) : <EOL> string_data = [ "<STR_LIT>" % ( row , col ) for col in range ( col_max ) ] <EOL> worksheet . append ( string_data ) <EOL> num_data = [ row + col for col in range ( col_max ) ] <EOL> worksheet . append ( num_data ) <EOL> workbook . save ( '<STR_LIT>' ) <EOL> elapsed = clock ( ) - start_time <EOL> print_elapsed_time ( '<STR_LIT>' , elapsed ) <EOL> def time_pyexcelerate ( ) : <EOL> """<STR_LIT>""" <EOL> start_time = clock ( ) <EOL> workbook = pyexcelerate . Workbook ( ) <EOL> worksheet = workbook . new_sheet ( '<STR_LIT>' ) <EOL> for row in range ( row_max // <NUM_LIT:2> ) : <EOL> for col in range ( col_max ) : <EOL> worksheet . set_cell_value ( row * <NUM_LIT:2> + <NUM_LIT:1> , col + <NUM_LIT:1> , "<STR_LIT>" % ( row , col ) ) <EOL> for col in range ( col_max ) : <EOL> worksheet . set_cell_value ( row * <NUM_LIT:2> + <NUM_LIT:2> , col + <NUM_LIT:1> , row + col ) <EOL> workbook . save ( '<STR_LIT>' ) <EOL> elapsed = clock ( ) - start_time <EOL> print_elapsed_time ( '<STR_LIT>' , elapsed ) <EOL> def time_xlwt ( ) : <EOL> """<STR_LIT>""" <EOL> start_time = clock ( ) <EOL> workbook = xlwt . Workbook ( ) <EOL> worksheet = workbook . add_sheet ( '<STR_LIT>' ) <EOL> for row in range ( row_max // <NUM_LIT:2> ) : <EOL> for col in range ( col_max ) : <EOL> worksheet . write ( row * <NUM_LIT:2> , col , "<STR_LIT>" % ( row , col ) ) <EOL> for col in range ( col_max ) : <EOL> worksheet . write ( row * <NUM_LIT:2> + <NUM_LIT:1> , col , row + col ) <EOL> workbook . save ( '<STR_LIT>' ) <EOL> elapsed = clock ( ) - start_time <EOL> print_elapsed_time ( '<STR_LIT>' , elapsed ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % ( '<STR_LIT>' , sys . version [ : <NUM_LIT:5> ] ) ) <EOL> print ( "<STR_LIT>" % ( '<STR_LIT>' , openpyxl . __version__ ) ) <EOL> print ( "<STR_LIT>" % ( '<STR_LIT>' , pyexcelerate . __version__ ) ) <EOL> print ( "<STR_LIT>" % ( '<STR_LIT>' , xlsxwriter . __version__ ) ) <EOL> print ( "<STR_LIT>" % ( '<STR_LIT>' , xlwt . __VERSION__ ) ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % row_max ) <EOL> print ( "<STR_LIT>" % col_max ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> time_pyexcelerate ( ) <EOL> time_xlwt ( ) <EOL> time_xlsxwriter_optimised ( ) <EOL> time_xlsxwriter ( ) <EOL> time_openpyxl_optimised ( ) <EOL> time_openpyxl ( ) <EOL> print ( "<STR_LIT>" ) </s>
<s> import xlsxwriter <EOL> workbook = xlsxwriter . Workbook ( '<STR_LIT>' ) <EOL> worksheet1 = workbook . add_worksheet ( ) <EOL> worksheet2 = workbook . add_worksheet ( ) <EOL> worksheet3 = workbook . add_worksheet ( ) <EOL> worksheet4 = workbook . add_worksheet ( ) <EOL> worksheet5 = workbook . add_worksheet ( ) <EOL> worksheet6 = workbook . add_worksheet ( ) <EOL> worksheet7 = workbook . add_worksheet ( ) <EOL> worksheet8 = workbook . add_worksheet ( ) <EOL> text_wrap = workbook . add_format ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> worksheet1 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet1 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet1 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> cell_text = '<STR_LIT>' <EOL> comment = '<STR_LIT>' <EOL> worksheet1 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet1 . write_comment ( '<STR_LIT>' , comment ) <EOL> worksheet2 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet2 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet2 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> cell_text = '<STR_LIT>' <EOL> comment = '<STR_LIT>' <EOL> worksheet2 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet2 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : True } ) <EOL> cell_text = "<STR_LIT>" <EOL> worksheet2 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet2 . write_comment ( '<STR_LIT>' , comment ) <EOL> worksheet3 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet3 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet3 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> worksheet3 . set_row ( <NUM_LIT:8> , <NUM_LIT:50> ) <EOL> worksheet3 . show_comments ( ) <EOL> cell_text = '<STR_LIT>' <EOL> comment = '<STR_LIT>' <EOL> worksheet3 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet3 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet3 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet3 . write_comment ( '<STR_LIT>' , comment ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet3 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet3 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : False } ) <EOL> worksheet4 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet4 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet4 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> worksheet4 . set_row ( <NUM_LIT:8> , <NUM_LIT:50> ) <EOL> worksheet4 . set_row ( <NUM_LIT:15> , <NUM_LIT:50> ) <EOL> worksheet4 . show_comments ( ) <EOL> cell_text = '<STR_LIT>' <EOL> comment = '<STR_LIT>' <EOL> worksheet4 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet4 . write_comment ( '<STR_LIT>' , comment ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet4 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet4 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet4 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet4 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet4 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet4 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet4 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet4 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT:width>' : <NUM_LIT:200> , '<STR_LIT>' : <NUM_LIT:20> } ) <EOL> worksheet5 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet5 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet5 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> worksheet5 . set_row ( <NUM_LIT:8> , <NUM_LIT:50> ) <EOL> worksheet5 . set_row ( <NUM_LIT:11> , <NUM_LIT:50> ) <EOL> worksheet5 . show_comments ( ) <EOL> cell_text = '<STR_LIT>' <EOL> comment = '<STR_LIT>' <EOL> worksheet5 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet5 . write_comment ( '<STR_LIT>' , comment ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet5 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet5 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet5 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet5 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : <NUM_LIT:8> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet5 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet5 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : <NUM_LIT:30> , '<STR_LIT>' : <NUM_LIT:12> } ) <EOL> worksheet6 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet6 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet6 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> worksheet6 . set_row ( <NUM_LIT:8> , <NUM_LIT:50> ) <EOL> worksheet6 . show_comments ( ) <EOL> cell_text = '<STR_LIT>' <EOL> comment = '<STR_LIT>' <EOL> worksheet6 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet6 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet6 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet6 . write_comment ( '<STR_LIT>' , comment ) <EOL> cell_text = '<STR_LIT>' <EOL> worksheet6 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet6 . write_comment ( '<STR_LIT>' , comment , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> worksheet7 . set_column ( '<STR_LIT>' , <NUM_LIT:30> ) <EOL> worksheet7 . set_row ( <NUM_LIT:2> , <NUM_LIT:50> ) <EOL> worksheet7 . set_row ( <NUM_LIT:5> , <NUM_LIT:50> ) <EOL> worksheet7 . set_row ( <NUM_LIT:8> , <NUM_LIT:50> ) <EOL> author = '<STR_LIT>' <EOL> cell = '<STR_LIT>' <EOL> cell_text = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> comment = '<STR_LIT>' <EOL> worksheet7 . write ( cell , cell_text , text_wrap ) <EOL> worksheet7 . write_comment ( cell , comment ) <EOL> author = '<STR_LIT>' <EOL> cell = '<STR_LIT>' <EOL> cell_text = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> worksheet7 . write ( cell , cell_text , text_wrap ) <EOL> worksheet7 . write_comment ( cell , comment , { '<STR_LIT>' : author } ) <EOL> worksheet8 . set_column ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet8 . set_row ( <NUM_LIT:2> , <NUM_LIT> ) <EOL> worksheet8 . show_comments ( ) <EOL> cell_text = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> comment = '<STR_LIT>' <EOL> worksheet8 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet8 . write_comment ( '<STR_LIT>' , comment ) <EOL> cell_text = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> worksheet8 . write ( '<STR_LIT>' , cell_text , text_wrap ) <EOL> worksheet8 . write_comment ( '<STR_LIT>' , comment ) <EOL> workbook . close ( ) </s>
<s> import pandas as pd <EOL> df = pd . DataFrame ( { '<STR_LIT>' : [ <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:15> , <NUM_LIT:30> , <NUM_LIT> ] } ) <EOL> writer = pd . ExcelWriter ( '<STR_LIT>' , engine = '<STR_LIT>' ) <EOL> df . to_excel ( writer , sheet_name = '<STR_LIT>' ) <EOL> workbook = writer . book <EOL> worksheet = writer . sheets [ '<STR_LIT>' ] <EOL> worksheet . conditional_format ( '<STR_LIT>' , { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> writer . save ( ) </s>
<s> from . import chart <EOL> from warnings import warn <EOL> class ChartBar ( chart . Chart ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , options = None ) : <EOL> """<STR_LIT>""" <EOL> super ( ChartBar , self ) . __init__ ( ) <EOL> if options is None : <EOL> options = { } <EOL> self . subtype = options . get ( '<STR_LIT>' ) <EOL> if not self . subtype : <EOL> self . subtype = '<STR_LIT>' <EOL> self . cat_axis_position = '<STR_LIT:l>' <EOL> self . val_axis_position = '<STR_LIT:b>' <EOL> self . horiz_val_axis = <NUM_LIT:0> <EOL> self . horiz_cat_axis = <NUM_LIT:1> <EOL> self . show_crosses = <NUM_LIT:0> <EOL> self . x_axis [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { '<STR_LIT>' : <NUM_LIT:1> } <EOL> self . y_axis [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> if self . subtype == '<STR_LIT>' : <EOL> self . x_axis [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . label_position_default = '<STR_LIT>' <EOL> self . label_positions = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . set_x_axis ( { } ) <EOL> self . set_y_axis ( { } ) <EOL> def combine ( self , chart = None ) : <EOL> """<STR_LIT>""" <EOL> if chart is None : <EOL> return <EOL> if not chart . is_secondary : <EOL> warn ( '<STR_LIT>' ) <EOL> self . combined = chart <EOL> def _write_chart_type ( self , args ) : <EOL> if args [ '<STR_LIT>' ] : <EOL> tmp = self . y_axis <EOL> self . y_axis = self . x_axis <EOL> self . x_axis = tmp <EOL> if self . y2_axis [ '<STR_LIT>' ] == '<STR_LIT:r>' : <EOL> self . y2_axis [ '<STR_LIT>' ] = '<STR_LIT:t>' <EOL> self . _write_bar_chart ( args ) <EOL> def _write_bar_chart ( self , args ) : <EOL> if args [ '<STR_LIT>' ] : <EOL> series = self . _get_primary_axes_series ( ) <EOL> else : <EOL> series = self . _get_secondary_axes_series ( ) <EOL> if not len ( series ) : <EOL> return <EOL> subtype = self . subtype <EOL> if subtype == '<STR_LIT>' : <EOL> subtype = '<STR_LIT>' <EOL> if '<STR_LIT>' in self . subtype : <EOL> if self . series_overlap_1 is None : <EOL> self . series_overlap_1 = <NUM_LIT:100> <EOL> self . _xml_start_tag ( '<STR_LIT>' ) <EOL> self . _write_bar_dir ( ) <EOL> self . _write_grouping ( subtype ) <EOL> for data in series : <EOL> self . _write_ser ( data ) <EOL> self . _write_marker_value ( ) <EOL> if args [ '<STR_LIT>' ] : <EOL> self . _write_gap_width ( self . series_gap_1 ) <EOL> else : <EOL> self . _write_gap_width ( self . series_gap_2 ) <EOL> if args [ '<STR_LIT>' ] : <EOL> self . _write_overlap ( self . series_overlap_1 ) <EOL> else : <EOL> self . _write_overlap ( self . series_overlap_2 ) <EOL> self . _write_axis_ids ( args ) <EOL> self . _xml_end_tag ( '<STR_LIT>' ) <EOL> def _write_bar_dir ( self ) : <EOL> val = '<STR_LIT:bar>' <EOL> attributes = [ ( '<STR_LIT>' , val ) ] <EOL> self . _xml_empty_tag ( '<STR_LIT>' , attributes ) <EOL> def _write_err_dir ( self , val ) : <EOL> pass </s>
<s> import unittest <EOL> from ... compatibility import StringIO <EOL> from . . helperfunctions import _xml_to_list <EOL> from ... chartsheet import Chartsheet <EOL> class TestAssembleChartsheet ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_assemble_xml_file ( self ) : <EOL> """<STR_LIT>""" <EOL> self . maxDiff = None <EOL> fh = StringIO ( ) <EOL> chartsheet = Chartsheet ( ) <EOL> chartsheet . _set_filehandle ( fh ) <EOL> chartsheet . drawing = <NUM_LIT:1> <EOL> chartsheet . _assemble_xml_file ( ) <EOL> exp = _xml_to_list ( """<STR_LIT>""" ) <EOL> got = _xml_to_list ( fh . getvalue ( ) ) <EOL> self . assertEqual ( got , exp ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> chart . set_x_axis ( { <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> } <EOL> } ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT:bar>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . set_x_axis ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> chart . set_y_axis ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> chart . set_title ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . set_style ( <NUM_LIT:1> ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:value>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } , <EOL> } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> data = [ <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT:10> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . set_legend ( { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : - <NUM_LIT:1> } } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . add_series ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . set_plotarea ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:x>' : <NUM_LIT> , <EOL> '<STR_LIT:y>' : <NUM_LIT> , <EOL> '<STR_LIT:width>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:3> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:4> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:5> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:6> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:7> ] ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> chart = workbook . add_chart ( { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> chart . axis_ids = [ <NUM_LIT> , <NUM_LIT> ] <EOL> data = [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:15> ] , <EOL> ] <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:0> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:1> ] ) <EOL> worksheet . write_column ( '<STR_LIT>' , data [ <NUM_LIT:2> ] ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:size>' : <NUM_LIT:5> } , <EOL> } ) <EOL> chart . add_series ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:size>' : <NUM_LIT:5> } , <EOL> } ) <EOL> worksheet . insert_chart ( '<STR_LIT>' , chart ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet . write_comment ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet . set_comments_author ( '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . data_validation ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:list>' , <EOL> '<STR_LIT:value>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ) <EOL> input_title = '<STR_LIT>' <EOL> input_message = '<STR_LIT>' + ( '<STR_LIT:a>' * <NUM_LIT> ) <EOL> values = [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> import warnings <EOL> warnings . filterwarnings ( '<STR_LIT:ignore>' ) <EOL> worksheet . data_validation ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:list>' , <EOL> '<STR_LIT:value>' : values , <EOL> '<STR_LIT>' : input_title , <EOL> '<STR_LIT>' : input_message , <EOL> } <EOL> ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> workbook . default_url_format = None <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . write_url ( '<STR_LIT>' , '<STR_LIT>' , None , '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . image_dir = test_dir + '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . set_header ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : self . image_dir + '<STR_LIT>' } ) <EOL> worksheet . set_footer ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : self . image_dir + '<STR_LIT>' } ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> workbook . default_url_format = None <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . write_url ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . image_dir = test_dir + '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . insert_image ( '<STR_LIT>' , self . image_dir + '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename , { '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False } ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . ignore_elements = { '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . print_area ( '<STR_LIT>' ) <EOL> worksheet . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> bold = workbook . add_format ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> italic = workbook . add_format ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> worksheet . write ( '<STR_LIT>' , '<STR_LIT>' , bold ) <EOL> worksheet . write ( '<STR_LIT>' , '<STR_LIT>' , italic ) <EOL> worksheet . write_rich_string ( '<STR_LIT>' , bold , '<STR_LIT:abc>' , italic , '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet1 = workbook . add_worksheet ( ) <EOL> worksheet2 = workbook . add_worksheet ( '<STR_LIT>' ) <EOL> worksheet3 = workbook . add_worksheet ( ) <EOL> bold = workbook . add_format ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> worksheet1 . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet1 . write ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet3 . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet3 . write ( '<STR_LIT>' , '<STR_LIT>' , bold ) <EOL> worksheet3 . write ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet2 . activate ( ) <EOL> worksheet2 . select ( ) <EOL> worksheet3 . select ( ) <EOL> worksheet3 . activate ( ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) <EOL> def test_create_file_in_memory ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename , { '<STR_LIT>' : True } ) <EOL> worksheet1 = workbook . add_worksheet ( ) <EOL> worksheet2 = workbook . add_worksheet ( '<STR_LIT>' ) <EOL> worksheet3 = workbook . add_worksheet ( ) <EOL> bold = workbook . add_format ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> worksheet1 . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet1 . write ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet3 . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet3 . write ( '<STR_LIT>' , '<STR_LIT>' , bold ) <EOL> worksheet3 . write ( '<STR_LIT>' , <NUM_LIT> ) <EOL> worksheet2 . activate ( ) <EOL> worksheet2 . select ( ) <EOL> worksheet3 . select ( ) <EOL> worksheet3 . activate ( ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_create_file ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . insert_textbox ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> worksheet . insert_textbox ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> from . . excel_comparsion_test import ExcelComparisonTest <EOL> from ... workbook import Workbook <EOL> class TestCompareXLSXFiles ( ExcelComparisonTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> filename = '<STR_LIT>' <EOL> test_dir = '<STR_LIT>' <EOL> self . got_filename = test_dir + '<STR_LIT>' + filename <EOL> self . exp_filename = test_dir + '<STR_LIT>' + filename <EOL> self . ignore_files = [ ] <EOL> self . ignore_elements = { } <EOL> def test_write_boolean ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . write_boolean ( <NUM_LIT:0> , <NUM_LIT:0> , True ) <EOL> worksheet . write_boolean ( <NUM_LIT:1> , <NUM_LIT:0> , False ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) <EOL> def test_write_boolean_write ( self ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( self . got_filename ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> worksheet . write ( <NUM_LIT:0> , <NUM_LIT:0> , True ) <EOL> worksheet . write ( <NUM_LIT:1> , <NUM_LIT:0> , False ) <EOL> workbook . close ( ) <EOL> self . assertExcelEqual ( ) </s>
<s> import unittest <EOL> from ... compatibility import StringIO <EOL> from ... drawing import Drawing <EOL> class TestWriteXdrcNvPr ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . fh = StringIO ( ) <EOL> self . drawing = Drawing ( ) <EOL> self . drawing . _set_filehandle ( self . fh ) <EOL> def test_write_c_nv_pr ( self ) : <EOL> """<STR_LIT>""" <EOL> self . drawing . _write_c_nv_pr ( <NUM_LIT:2> , '<STR_LIT>' ) <EOL> exp = """<STR_LIT>""" <EOL> got = self . fh . getvalue ( ) <EOL> self . assertEqual ( got , exp ) <EOL> options = { '<STR_LIT:url>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . drawing . _write_c_nv_pr ( <NUM_LIT:2> , '<STR_LIT>' , options ) <EOL> exp = """<STR_LIT>""" <EOL> got = self . fh . getvalue ( ) <EOL> self . assertEqual ( got , exp ) </s>
<s> import unittest <EOL> from ... compatibility import StringIO <EOL> from ... styles import Styles <EOL> from ... format import Format <EOL> class TestWriteBorder ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . fh = StringIO ( ) <EOL> self . styles = Styles ( ) <EOL> self . styles . _set_filehandle ( self . fh ) <EOL> def test_write_border ( self ) : <EOL> """<STR_LIT>""" <EOL> xf_format = Format ( ) <EOL> xf_format . has_border = <NUM_LIT:1> <EOL> self . styles . _write_border ( xf_format ) <EOL> exp = """<STR_LIT>""" <EOL> got = self . fh . getvalue ( ) <EOL> self . assertEqual ( got , exp ) </s>