@@ -28,6 +28,13 @@ function extend(obj:{}, ...args) {
2828 return obj ;
2929}
3030
31+ /**
32+ * gets a random int from 0-10000000000
33+ */
34+ function getRandomInt ( ) {
35+ return Math . floor ( Math . random ( ) * 10000000000 ) ;
36+ }
37+
3138export interface Options extends SpawnOptions {
3239 mode ?: 'text' | 'json' | 'binary'
3340 formatter ?: ( param :string ) => any
@@ -218,8 +225,8 @@ export class PythonShell extends EventEmitter{
218225 * @returns {Promise } rejects w/ stderr if syntax failure
219226 */
220227 static async checkSyntax ( code :string ) {
221- let randomInt = PythonShell . getRandomInt ( ) ;
222- let filePath = tmpdir ( ) + sep + `pythonShellSyntaxCheck${ randomInt } .py`
228+ const randomInt = getRandomInt ( ) ;
229+ const filePath = tmpdir ( ) + sep + `pythonShellSyntaxCheck${ randomInt } .py`
223230
224231 // todo: replace this with util.promisify (once we no longer support node v7)
225232 return new Promise ( ( resolve , reject ) => {
@@ -276,8 +283,8 @@ export class PythonShell extends EventEmitter{
276283 static runString ( code :string , options ?:Options , callback ?:( err :PythonShellError , output ?:any [ ] ) => any ) {
277284
278285 // put code in temp file
279- let randomInt = PythonShell . getRandomInt ( ) ;
280- let filePath = tmpdir + sep + `pythonShellFile${ randomInt } .py`
286+ const randomInt = getRandomInt ( ) ;
287+ const filePath = tmpdir + sep + `pythonShellFile${ randomInt } .py`
281288 writeFileSync ( filePath , code ) ;
282289
283290 return PythonShell . run ( filePath , options , callback ) ;
@@ -314,13 +321,6 @@ export class PythonShell extends EventEmitter{
314321 return error ;
315322 } ;
316323
317- /**
318- * gets a random int from 0-10000000000
319- */
320- private static getRandomInt ( ) {
321- return Math . floor ( Math . random ( ) * 10000000000 ) ;
322- }
323-
324324 /**
325325 * Sends a message to the Python shell through stdin
326326 * Override this method to format data to be sent to the Python process
0 commit comments