<s> from StringIO import StringIO <EOL> import json , re <EOL> from totalimpact . providers import provider <EOL> from totalimpact . providers . provider import Provider , ProviderContentMalformedError , ProviderTimeout , ProviderServerError <EOL> from totalimpact import unicode_helpers <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class Bibjson ( Provider ) : <EOL> example_id = None <EOL> url = "<STR_LIT>" <EOL> descr = "<STR_LIT>" <EOL> def _to_unicode ( self , text ) : <EOL> text = unicode_helpers . to_unicode_or_bust ( text ) <EOL> return text <EOL> def parse ( self , bibjson_list ) : <EOL> ret = [ ] <EOL> for bibjson_entry in bibjson_list : <EOL> full_entry = bibjson_entry <EOL> try : <EOL> full_entry [ "<STR_LIT>" ] = self . _to_unicode ( re . sub ( "<STR_LIT>" , "<STR_LIT>" , full_entry [ "<STR_LIT>" ] ) ) <EOL> except ( KeyError , AttributeError ) : <EOL> full_entry [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> try : <EOL> full_entry [ "<STR_LIT>" ] = self . _to_unicode ( full_entry [ "<STR_LIT>" ] . split ( "<STR_LIT:U+002C>" ) [ <NUM_LIT:0> ] ) <EOL> except ( KeyError , AttributeError ) : <EOL> full_entry [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> try : <EOL> pages = full_entry [ "<STR_LIT>" ] <EOL> full_entry [ "<STR_LIT>" ] = pages . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> full_entry [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> try : <EOL> full_entry [ "<STR_LIT:title>" ] = full_entry [ "<STR_LIT>" ] <EOL> except ( KeyError , AttributeError ) : <EOL> pass <EOL> ret . append ( full_entry ) <EOL> return ret <EOL> def member_items ( self , bibjson_contents , cache_enabled = True ) : <EOL> logger . debug ( u"<STR_LIT>" % ( self . provider_name ) ) <EOL> parsed_bibjson = self . parse ( bibjson_contents ) <EOL> aliases = [ ( "<STR_LIT>" , entry ) for entry in parsed_bibjson ] <EOL> return ( aliases ) </s>
