<s> from oaipmh import common , error <EOL> from datetime import datetime <EOL> import random <EOL> class FakeServerCommon ( object ) : <EOL> def identify ( self ) : <EOL> return common . Identify ( <EOL> repositoryName = '<STR_LIT>' , <EOL> baseURL = '<STR_LIT>' , <EOL> protocolVersion = "<STR_LIT>" , <EOL> adminEmails = [ '<STR_LIT>' ] , <EOL> earliestDatestamp = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> deletedRecord = '<STR_LIT>' , <EOL> granularity = '<STR_LIT>' , <EOL> compression = [ '<STR_LIT>' ] ) <EOL> def getRecord ( self , metadataPrefix , identifier ) : <EOL> try : <EOL> return self . _data [ int ( identifier ) ] <EOL> except IndexError : <EOL> raise error . IdDoesNotExistError , "<STR_LIT>" % identifier <EOL> class FakeServerBase ( FakeServerCommon ) : <EOL> def listIdentifiers ( self , metadataPrefix = None , from_ = None , until = None , <EOL> set = None ) : <EOL> result = [ ] <EOL> for header , metadata , about in self . _data : <EOL> if datestampInRange ( header , from_ , until ) : <EOL> result . append ( header ) <EOL> return result <EOL> def listRecords ( self , metadataPrefix = None , from_ = None , until = None , <EOL> set = None ) : <EOL> result = [ ] <EOL> for header , metadata , about in self . _data : <EOL> if datestampInRange ( header , from_ , until ) : <EOL> result . append ( ( header , metadata , about ) ) <EOL> return result <EOL> class BatchingFakeServerBase ( FakeServerCommon ) : <EOL> def listIdentifiers ( self , metadataPrefix = None , from_ = None , until = None , <EOL> set = None , cursor = <NUM_LIT:0> , batch_size = <NUM_LIT:10> ) : <EOL> result = [ ] <EOL> for header , metadata , about in self . _data : <EOL> if datestampInRange ( header , from_ , until ) : <EOL> result . append ( header ) <EOL> return result [ cursor : cursor + batch_size ] <EOL> def listRecords ( self , metadataPrefix = None , from_ = None , until = None , <EOL> set = None , cursor = <NUM_LIT:0> , batch_size = <NUM_LIT:10> ) : <EOL> result = [ ] <EOL> for header , metadata , about in self . _data : <EOL> if datestampInRange ( header , from_ , until ) : <EOL> result . append ( ( header , metadata , about ) ) <EOL> return result [ cursor : cursor + batch_size ] <EOL> def datestampInRange ( header , from_ , until ) : <EOL> if from_ is not None and header . datestamp ( ) < from_ : <EOL> return False <EOL> if until is not None and header . datestamp ( ) > until : <EOL> return False <EOL> return True <EOL> def createFakeData ( ) : <EOL> data = [ ] <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> year = <NUM_LIT> <EOL> month = i % <NUM_LIT:12> + <NUM_LIT:1> <EOL> day = i % <NUM_LIT> + <NUM_LIT:1> <EOL> hour = i % <NUM_LIT> <EOL> minute = i % <NUM_LIT> <EOL> second = i % <NUM_LIT> <EOL> fake_element = None <EOL> datestamp = datetime ( year , month , day , hour , minute , second ) <EOL> data . append ( ( common . Header ( fake_element , str ( i ) , datestamp , '<STR_LIT>' , False ) , <EOL> common . Metadata ( fake_element , { '<STR_LIT:title>' : [ '<STR_LIT>' % i ] } ) , <EOL> None ) ) <EOL> return data <EOL> class FakeServer ( FakeServerBase ) : <EOL> def __init__ ( self ) : <EOL> self . _data = createFakeData ( ) <EOL> class BatchingFakeServer ( BatchingFakeServerBase ) : <EOL> def __init__ ( self ) : <EOL> self . _data = createFakeData ( ) <EOL> class FakeServerWithDeletions ( FakeServerBase ) : <EOL> def __init__ ( self ) : <EOL> data = [ ] <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:12> ) : <EOL> year = <NUM_LIT> <EOL> month = i + <NUM_LIT:1> <EOL> day = <NUM_LIT:1> <EOL> datestamp = datetime ( year , month , day , <NUM_LIT:12> , <NUM_LIT:30> , <NUM_LIT:0> ) <EOL> fake_element = None <EOL> data . append ( ( common . Header ( fake_element , str ( i ) , datestamp , '<STR_LIT>' , False ) , <EOL> common . Metadata ( fake_element , { '<STR_LIT:title>' : [ '<STR_LIT>' % i ] } ) , <EOL> None ) ) <EOL> self . _data = data <EOL> def deletionEvent ( self ) : <EOL> data = [ ] <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:6> ) : <EOL> year = <NUM_LIT> <EOL> month = i + <NUM_LIT:1> <EOL> day = <NUM_LIT:1> <EOL> datestamp = datetime ( year , month , day , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> ) <EOL> fake_element = None <EOL> data . append ( ( common . Header ( fake_element , str ( i ) , datestamp , '<STR_LIT>' , True ) , <EOL> None , <EOL> None ) ) <EOL> self . _data = data + self . _data [ <NUM_LIT:6> : ] </s>
