<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> from functools import partial <EOL> from . exceptions import SourceMapDecodeError <EOL> from . objects import Token , SourceMapIndex <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> PY3 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> <EOL> text_type = str if PY3 else unicode <EOL> class SourceMapDecoder ( object ) : <EOL> def parse_vlq ( self , segment ) : <EOL> """<STR_LIT>""" <EOL> values = [ ] <EOL> cur , shift = <NUM_LIT:0> , <NUM_LIT:0> <EOL> for c in segment : <EOL> val = B64 [ ord ( c ) ] <EOL> val , cont = val & <NUM_LIT> , val >> <NUM_LIT:5> <EOL> cur += val << shift <EOL> shift += <NUM_LIT:5> <EOL> if not cont : <EOL> cur , sign = cur >> <NUM_LIT:1> , cur & <NUM_LIT:1> <EOL> if sign : <EOL> cur = - cur <EOL> values . append ( cur ) <EOL> cur , shift = <NUM_LIT:0> , <NUM_LIT:0> <EOL> if cur or shift : <EOL> raise SourceMapDecodeError ( '<STR_LIT>' ) <EOL> return values <EOL> def decode ( self , source ) : <EOL> """<STR_LIT>""" <EOL> if source [ : <NUM_LIT:4> ] == "<STR_LIT>" or source [ : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> source = source . split ( '<STR_LIT:\n>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> smap = json . loads ( source ) <EOL> sources = smap [ '<STR_LIT>' ] <EOL> sourceRoot = smap . get ( '<STR_LIT>' ) <EOL> names = list ( map ( text_type , smap [ '<STR_LIT>' ] ) ) <EOL> mappings = smap [ '<STR_LIT>' ] <EOL> lines = mappings . split ( '<STR_LIT:;>' ) <EOL> if sourceRoot is not None : <EOL> sources = map ( partial ( os . path . join , sourceRoot ) , sources ) <EOL> tokens = [ ] <EOL> line_index = [ ] <EOL> index = { } <EOL> dst_col , src_id , src_line , src_col , name_id = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> for dst_line , line in enumerate ( lines ) : <EOL> line_index . append ( [ ] ) <EOL> segments = line . split ( '<STR_LIT:U+002C>' ) <EOL> dst_col = <NUM_LIT:0> <EOL> for segment in segments : <EOL> if not segment : <EOL> continue <EOL> parse = self . parse_vlq ( segment ) <EOL> dst_col += parse [ <NUM_LIT:0> ] <EOL> src = None <EOL> name = None <EOL> if len ( parse ) > <NUM_LIT:1> : <EOL> try : <EOL> src_id += parse [ <NUM_LIT:1> ] <EOL> if not <NUM_LIT:0> <= src_id < len ( sources ) : <EOL> raise SourceMapDecodeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( segment , src_id , len ( sources ) ) <EOL> ) <EOL> src = sources [ src_id ] <EOL> src_line += parse [ <NUM_LIT:2> ] <EOL> src_col += parse [ <NUM_LIT:3> ] <EOL> if len ( parse ) > <NUM_LIT:4> : <EOL> name_id += parse [ <NUM_LIT:4> ] <EOL> if not <NUM_LIT:0> <= name_id < len ( names ) : <EOL> raise SourceMapDecodeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( segment , name_id , len ( names ) ) <EOL> ) <EOL> name = names [ name_id ] <EOL> except IndexError : <EOL> raise SourceMapDecodeError ( <EOL> "<STR_LIT>" <EOL> % ( segment , parse ) <EOL> ) <EOL> try : <EOL> assert dst_line >= <NUM_LIT:0> , ( '<STR_LIT>' , dst_line ) <EOL> assert dst_col >= <NUM_LIT:0> , ( '<STR_LIT>' , dst_col ) <EOL> assert src_line >= <NUM_LIT:0> , ( '<STR_LIT>' , src_line ) <EOL> assert src_col >= <NUM_LIT:0> , ( '<STR_LIT>' , src_col ) <EOL> except AssertionError as e : <EOL> raise SourceMapDecodeError ( <EOL> "<STR_LIT>" <EOL> % ( segment , e . message [ <NUM_LIT:0> ] , e . message [ <NUM_LIT:1> ] , src ) <EOL> ) <EOL> token = Token ( dst_line , dst_col , src , src_line , src_col , name ) <EOL> tokens . append ( token ) <EOL> index [ ( dst_line , dst_col ) ] = token <EOL> line_index [ dst_line ] . append ( dst_col ) <EOL> return SourceMapIndex ( smap , tokens , line_index , index , sources ) <EOL> B64 = [ - <NUM_LIT:1> ] * <NUM_LIT> <EOL> for i , c in enumerate ( '<STR_LIT>' ) : <EOL> B64 [ ord ( c ) ] = i </s>
