Skip to content

Commit

Permalink
1) Add URL Library hooks to Ezhil - readonly -
Browse files Browse the repository at this point in the history
2) Partial resolution of issue #163
#163;
3) Added unittest
4) update dir() to be called only on non-windows platforms
  • Loading branch information
Muthiah Annamalai committed Dec 27, 2015
1 parent bb13d9c commit 84efd17
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ezhil/Interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
## (C) 2007, 2008, 2013, 2014, 2015 Muthiah Annamalai,
## Licensed under GPL Version 3
##
##
## TODO: extract scanner and AST members into a module for sharing.
from __future__ import print_function

import argparse
Expand Down Expand Up @@ -57,6 +55,7 @@
TransformSemanticAnalyzer, TransformConstantFolder

from ezhil_serializer import SerializerXML
from ezhil_library import Load_URL_APIs

def ezhil_version():
return 0.8
Expand Down Expand Up @@ -712,6 +711,10 @@ def install_builtins(self):

self.builtin_map["update"]= BuiltinFunction(dict.update,"update",1)

# URL API's - load except in safe mode
if not self.SAFE_MODE:
Load_URL_APIs( self )

# open-tamil API
# get tamil letters
self.add_builtin("get_tamil_letters",tamil.utf8.get_letters,nargin=1,ta_alias=u"தமிழ்_எழுத்துக்கள்")
Expand Down
35 changes: 35 additions & 0 deletions ezhil/ezhil_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## -*- coding: utf-8 -*-
## (C) 2007, 2008, 2013, 2014, 2015 Muthiah Annamalai,
## Licensed under GPL Version 3
##
from __future__ import print_function
import sys
from runtime import BuiltinFunction

PYTHON3 = (sys.version[0] == '3')

if PYTHON3:
# For Python 3.0 and later
from urllib.request import urlopen
else:
# Fall back to Python 2's urllib2
from urllib2 import urlopen

def ezhil_urlopen(*args):
html = urlopen(*args)
return html

def ezhil_urlread(html):
data = html.read()
if not PYTHON3:
return data.decode("utf-8")
return data

def ezhil_urlclose(html):
html.close()

def Load_URL_APIs(interpreter):
interpreter.add_builtin("urlopen",ezhil_urlopen,nargin=1,ta_alias="இணைய_இணைப்பு_திற")
interpreter.add_builtin("urlread",ezhil_urlread,nargin=1,ta_alias="இணைய_இணைப்பு_படி")
interpreter.add_builtin("urlclose",ezhil_urlclose,nargin=1,ta_alias="இணைய_இணைப்பு_மூடு")

1 change: 1 addition & 0 deletions test_cases
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ partition_estimate.n
envchecks.n
ifparse.n
foo.n
urldemo.n
5 changes: 4 additions & 1 deletion tests/fact.n
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
ans = fact ( ப + 4 )
பதிப்பி assert( ans == (1*2*3*4*5*6*7*8) )
profile("begin")
dir("fa") #list all ezhil builtin and user defined functions starting with 'fa'

@( sys_platform() != "win32") ஆனால்
dir("fa") #list all ezhil builtin and user defined functions starting with 'fa'
முடி

ans = fact ( ப - 4/2 )
பதிப்பி ans, assert( ans == 2 )
Expand Down
23 changes: 23 additions & 0 deletions tests/urldemo.n
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# (C) 2015, Ezhil Language Project
# (C) 2015 முத்தையா அண்ணாமலை
# இது ஒரு எழில் தமிழ் நிரலாக்க மொழி உதாரணம்

# Networking Example:
# இங்கு 'urllib' Python library functions Ezhil language வழியாக
# பயன் படுத்துமாறு நிரல் எ.கா உள்ளது

இணைய_முகவரி = "http://www.bing.com"
பிங்_தொடர்பு = urlopen( இணைய_முகவரி )
அடங்கல் = urlread( பிங்_தொடர்பு )

@( sys_platform() != "win32") ஆனால்
பதிப்பி "பிங்_தொடர்பு அடங்கல் => கீழே"
பதிப்பி அடங்கல்
இல்லை
பதிப்பி "Test does not print on Windows"
முடி

பதிப்பி "Size of contents = ",len(அடங்கல்)

urlclose( பிங்_தொடர்பு )
exit(0)

0 comments on commit 84efd17

Please sign in to comment.