@@ -170,15 +170,8 @@ from sage.interfaces.giac import giac
170
170
171
171
172
172
# Python3 compatibility ############################
173
- def decstring23( s) :
174
- return s. decode( )
175
-
176
-
177
173
def encstring23( s) :
178
174
return bytes( s, 'UTF-8')
179
-
180
-
181
- listrange = list, range
182
175
# End of Python3 compatibility #####################
183
176
184
177
@@ -848,7 +841,7 @@ cdef class Pygen(GiacMethods_base):
848
841
self. gptr = new gen(( <Pygen>s) . gptr[0 ])
849
842
sig_off( )
850
843
851
- elif isinstance( s, listrange ) :
844
+ elif isinstance( s, ( list, range ) ) :
852
845
sig_on( )
853
846
self. gptr = new gen( _wrap_pylist( <list>s) ,<short int>0)
854
847
sig_off( )
@@ -866,7 +859,7 @@ cdef class Pygen(GiacMethods_base):
866
859
s = s. _giac_init_( )
867
860
except AttributeError:
868
861
s = SRexpressiontoGiac( s)
869
- if not( isinstance( s, str)) : #modif python3
862
+ if not isinstance( s, str) :
870
863
s = s. __str__( )
871
864
sig_on( )
872
865
self. gptr = new gen( <string>encstring23( s) ,context_ptr)
@@ -882,7 +875,7 @@ cdef class Pygen(GiacMethods_base):
882
875
sig_off( )
883
876
if t < 6000:
884
877
sig_on( )
885
- result = decstring23 ( GIAC_print( self. gptr[0 ], context_ptr) . c_str( )) #python3
878
+ result = GIAC_print( self. gptr[0 ], context_ptr) . c_str( ) . decode ( )
886
879
sig_off( )
887
880
return result
888
881
else:
@@ -895,7 +888,7 @@ cdef class Pygen(GiacMethods_base):
895
888
#if self. gptr == NULL:
896
889
# return ''
897
890
sig_on( )
898
- result = decstring23 ( GIAC_print( self. gptr[0 ], context_ptr) . c_str( ))
891
+ result = GIAC_print( self. gptr[0 ], context_ptr) . c_str( ) . decode ( )
899
892
sig_off( )
900
893
return result
901
894
@@ -926,7 +919,7 @@ cdef class Pygen(GiacMethods_base):
926
919
TESTS::
927
920
928
921
sage: from sage. libs. giac. giac import libgiac
929
- sage: l=libgiac( list( range( 10^ 6))) ;l[5 ] #python3
922
+ sage: l=libgiac( list( range( 10^ 6))) ;l[5 ]
930
923
5
931
924
sage: l[35:50:7 ]
932
925
[35,42,49 ]
@@ -1156,7 +1149,7 @@ cdef class Pygen(GiacMethods_base):
1156
1149
sig_off( )
1157
1150
return _wrap_gen( result)
1158
1151
1159
- # PB / in python3 is truediv
1152
+ # PB / in python3 is truediv
1160
1153
def __div__( self, right) :
1161
1154
"""
1162
1155
TESTS::
@@ -1296,8 +1289,8 @@ cdef class Pygen(GiacMethods_base):
1296
1289
# if ( not lang in ['en', 'fr', 'el' ]) :
1297
1290
# lang='en'
1298
1291
# try:
1299
- # url=decstring23 ( browser_help( self. gptr[0 ],l[lang ])) #python3
1300
- # giacbasedir=decstring23 ( GIAC_giac_aide_dir( )) # python3
1292
+ # url=browser_help( self. gptr[0 ],l[lang ]) . decode ( )
1293
+ # giacbasedir=GIAC_giac_aide_dir( ) . decode ( )
1301
1294
# except:
1302
1295
# raise RuntimeError( 'giac docs dir not found')
1303
1296
# print( url)
@@ -1338,7 +1331,7 @@ cdef class Pygen(GiacMethods_base):
1338
1331
\f rac{... x^ {4} ... -... y... }{... y^ {2} -3... x... }
1339
1332
"""
1340
1333
sig_on( )
1341
- result = decstring23 ( GIAC_gen2tex( self. gptr[0 ], context_ptr) . c_str( ))
1334
+ result = GIAC_gen2tex( self. gptr[0 ], context_ptr) . c_str( ) . decode ( )
1342
1335
sig_off( )
1343
1336
return result
1344
1337
@@ -1787,7 +1780,7 @@ cdef vecteur _wrap_pylist(L) except +:
1787
1780
cdef vecteur * V
1788
1781
cdef int i
1789
1782
1790
- if ( isinstance(L, tuple) or isinstance(L, listrange) ):
1783
+ if isinstance(L, ( tuple, list, range ):
1791
1784
n=len(L)
1792
1785
V=new vecteur()
1793
1786
@@ -1807,14 +1800,14 @@ cdef vecteur _getgiacslice(Pygen L,slice sl) except +:
1807
1800
cdef vecteur * V
1808
1801
cdef int u
1809
1802
1810
- if ( L.type()=="DOM_LIST") :
1803
+ if L.type()=="DOM_LIST":
1811
1804
n=len(L)
1812
1805
V=new vecteur()
1813
1806
1814
1807
sig_on()
1815
1808
# for u in range(n)[sl]: #pb python3
1816
- (b,e,st)= sl.indices(n)
1817
- for u in range(b,e, st):
1809
+ b, e, st = sl.indices(n)
1810
+ for u in range(b, e, st):
1818
1811
V.push_back((L.gptr[0])[u])
1819
1812
sig_off()
1820
1813
return V[0]
0 commit comments