Skip to content

Commit db107cc

Browse files
committed
Make changes on scope
1 parent 12537a6 commit db107cc

11 files changed

Lines changed: 212 additions & 2905 deletions

File tree

BScript/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from BScript import exceptions
33
from BScript import execute
44
from BScript.execute import *
5-
__version__ = "1.0.0"
5+
__version__ = "1.2.2"

BScript/bs_types.py

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
from BScript import exceptions
33
def raise_exception(exception):
44
raise exception
5-
6-
undefined = type("undefined",(),{
5+
class BS_type(object):
6+
name = ""
7+
def __sub_init__(cls,*args,**kwargs):
8+
cls.name = cls.__name__
9+
return cls()
10+
undefined = type("undefined",(BS_type,),{
711
# "__init__":lambda self: raise_exception(TypeError("undefined is not a function")),
812
"__str__":lambda self: "undefined",
913
"__repr__":lambda self: "undefined",
@@ -13,7 +17,9 @@ def raise_exception(exception):
1317
})
1418

1519
def variable2BS(value):
16-
if isinstance(value,bool):
20+
if isinstance(value,BS_type):
21+
return value
22+
elif isinstance(value,bool):
1723
return bool(value)
1824
elif isinstance(value,int):
1925
return BS_int(value)
@@ -33,14 +39,10 @@ def __init__(self,obj,attr):
3339
def __call__(self,value):
3440

3541
if isinstance(self.obj,BS_object):
36-
self.obj.setattr(**{self.attr:value})
42+
BS_object.setitem(self.obj,self.attr,value)
3743
else:
3844
self.obj[self.attr] = value
39-
class BS_type(object):
40-
name = ""
41-
def __sub_init__(cls,*args,**kwargs):
42-
cls.name = cls.__name__
43-
return cls()
45+
4446
class required(BS_type):
4547
pass
4648
def flatten(itemlist):
@@ -49,7 +51,7 @@ def flatten(itemlist):
4951
and otherwise the dimensions of it"""
5052
flatten_list = []
5153
for item in itemlist:
52-
if isinstance(item,list):
54+
if isinstance(item,list) and not isinstance(item,BS_array):
5355

5456
flatten_list.extend(flatten(item))
5557
else:
@@ -66,52 +68,38 @@ def flatten(itemlist):
6668
__reserved__keys__ = {"this","undefined","Infinity"}
6769
__reserveds__.add("__private__")
6870
__protected__ = {"__class__"}
69-
class BS_object(dict):
71+
class BS_object(BS_type,dict):
7072

7173

7274

7375
def __init__(self, *args, **kwargs):
7476
super(BS_object, self).__init__(*args, **kwargs)
7577
self.this = self
78+
for i in {"clear","copy","fromkeys","get","items","keys","pop","popitem","setdefault","update","values","setitem","getitem"}:
79+
if hasattr(self,i):
80+
setattr(self,i,undefined())
7681
# def __init__(self, *args, **kwargs):
7782
# self.__reserveds__ = set(dict().__class__.__dict__.keys())
7883
# self.update(*args, **kwargs)
7984
# self.this = self
8085
def __getattribute__(self,name):
8186
if name == "__class__":
8287
return super().__getattribute__(name)
83-
elif name in __reserveds__:
84-
return super().__getattribute__(name)
88+
8589
else:
8690
if name in self:
8791
return dict.__getitem__(self,name)
8892
else:
8993
return super().__getattribute__(name)
90-
def update(self, *args, **kwargs):
91-
super().update(*args, **kwargs)
92-
for arg in args:
93-
if isinstance(arg,dict):
94-
self.setattr(**arg)
95-
else:
96-
raise TypeError(f"Expected type dict|BS_object, got {type(arg)} instead")
97-
98-
self.setattr(**kwargs)
99-
def setattr(self,**kwargs):
100-
for k,v in kwargs.items():
101-
# if k in self.__reserveds__:
102-
# raise exceptions.UnexpectedIdentifierException(f"'{k}' attribute is reserved")
103-
# else:
104-
self[k] = v
105-
@classmethod
106-
def create(cls,obj):
107-
if isinstance(obj,BS_object):
108-
return cls(obj.__dict__)
109-
else:
110-
raise Exception("")
11194

95+
96+
def setitem(self,key,val):
97+
self[key] = val
98+
def getitem(self,key):
99+
return self[key]
112100
NoneType = type(None)
113101

114-
class BS_int(int):
102+
class BS_int(BS_type,int):
115103
def toString(self):
116104
return BS_string(self.__str__())
117105
slicer = {
@@ -120,7 +108,7 @@ def toString(self):
120108
(BS_int,BS_int):lambda obj,x,y: obj[x:y]
121109

122110
}
123-
class BS_string(str):
111+
class BS_string(BS_type,str):
124112
def __new__(cls, *args, **kw):
125113
cls.toUpperCase = cls.upper
126114
cls.toLowerCase = cls.lower
@@ -161,7 +149,7 @@ def split(self,seperator: str = None):
161149
return super().split(seperator)
162150

163151

164-
class BS_array(list):
152+
class BS_array(BS_type,list):
165153
def toString(self):
166154
return ",".join(self)
167155
def join(self,chr):
@@ -203,7 +191,7 @@ def max(self):
203191
def forEach(self,function):
204192

205193
for index,value in enumerate(self):
206-
temp_kwargs = {"index":variable2BS(index),"value":variable2BS(value),"array":self}
194+
temp_kwargs = {"index":variable2BS(index),"value":variable2BS(value),"array":self.copy()}
207195

208196
function(**{k:temp_kwargs[k] for k in function.args})
209197
def map(self,function):

BScript/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class SandBoxPrivilegesException(BaseException):
44
"""
55
Raise: when sandbox doesn't have required privileges to do something
66
"""
7+
class SandboxMemoryOverflowException(BaseException):
8+
"""
9+
Raise: when memory usage is overflowed
10+
"""
711
class UnsupportedOperationException(BaseException):
812
"""
913
Raise: when BinaryExpression tries executing the process with an unsupported operator

0 commit comments

Comments
 (0)