#NEWLINE# def py2js( v ) : #NEWLINE# #INDENT# 'Note that None values are rendered as ``null`` (not ``undefined``.\n\n    ' #NEWLINE# for cv in CONVERTERS : #NEWLINE# #INDENT# v = cv ( v ) #NEWLINE# #UNINDENT# if isinstance ( v , Value ) : #NEWLINE# #INDENT# return v . as_ext ( ) #NEWLINE# #UNINDENT# if isinstance ( v , Promise ) : #NEWLINE# #INDENT# return json . dumps ( force_text ( v . encode ( 'utf8' ) ) ) #NEWLINE# #UNINDENT# if isinstance ( v , types . GeneratorType ) : #NEWLINE# #INDENT# return '' . join ( [ py2js ( x ) for x in v ] ) #NEWLINE# #UNINDENT# if etree . iselement ( v ) : #NEWLINE# #INDENT# return json . dumps ( etree . tostring ( v ) ) #NEWLINE# #UNINDENT# if callable ( v ) : #NEWLINE# #INDENT# return '\n' . join ( [ ln for ln in v ( ) ] ) #NEWLINE# #UNINDENT# if isinstance ( v , js_code ) : #NEWLINE# #INDENT# return str ( v . s ) #NEWLINE# #UNINDENT# if ( v is None ) : #NEWLINE# #INDENT# return 'null' #NEWLINE# #UNINDENT# if isinstance ( v , ( list , tuple ) ) : #NEWLINE# #INDENT# elems = [ py2js ( x ) for x in v if ( ( not isinstance ( x , VisibleComponent ) ) or x . get_view_permission ( _for_user_profile ) ) ] #NEWLINE# return ( '[ %s ]' % ', ' . join ( elems ) ) #NEWLINE# #UNINDENT# if isinstance ( v , dict ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# items = [ i for i in sorted ( v . items ( ) ) if ( ( not isinstance ( v , VisibleComponent ) ) or v . get_view_permission ( _for_user_profile ) ) ] #NEWLINE# #UNINDENT# except TypeError as e : #NEWLINE# #INDENT# raise TypeError ( 'Failed to sort {0} : {1}' . format ( v , e ) ) #NEWLINE# #UNINDENT# return ( '{ %s }' % ', ' . join ( [ ( '%s: %s' % ( py2js ( k ) , py2js ( i ) ) ) for ( k , i ) in items ] ) ) #NEWLINE# #UNINDENT# if isinstance ( v , bool ) : #NEWLINE# #INDENT# return str ( v ) . lower ( ) #NEWLINE# #UNINDENT# if isinstance ( v , Quantity ) : #NEWLINE# #INDENT# return ( '"%s"' % v ) #NEWLINE# #UNINDENT# if isinstance ( v , ( int , decimal . Decimal , fractions . Fraction ) ) : #NEWLINE# #INDENT# return str ( v ) #NEWLINE# #UNINDENT# if isinstance ( v , IncompleteDate ) : #NEWLINE# #INDENT# return ( '"%s"' % v . strftime ( settings . SITE . date_format_strftime ) ) #NEWLINE# #UNINDENT# if isinstance ( v , datetime . datetime ) : #NEWLINE# #INDENT# return ( '"%s"' % v . strftime ( settings . SITE . datetime_format_strftime ) ) #NEWLINE# #UNINDENT# if isinstance ( v , datetime . time ) : #NEWLINE# #INDENT# return ( '"%s"' % v . strftime ( settings . SITE . time_format_strftime ) ) #NEWLINE# #UNINDENT# if isinstance ( v , datetime . date ) : #NEWLINE# #INDENT# if ( v . year < 1900 ) : #NEWLINE# #INDENT# v = IncompleteDate ( v ) #NEWLINE# return ( '"%s"' % v . strftime ( settings . SITE . date_format_strftime ) ) #NEWLINE# #UNINDENT# return ( '"%s"' % v . strftime ( settings . SITE . date_format_strftime ) ) #NEWLINE# #UNINDENT# if isinstance ( v , float ) : #NEWLINE# #INDENT# return repr ( v ) #NEWLINE# #UNINDENT# return json . dumps ( v )