Skip to content

Commit d6b3647

Browse files
committed
Add protect and unprotect casts
1 parent 45a3ba2 commit d6b3647

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/tivars.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ def test_all_tokens(self):
196196
self.assertEqual(test_program.bytes(), file.read()[:-2])
197197
self.assertEqual(test_program.is_protected, False)
198198

199+
def test_protection(self):
200+
test_program = TIProtectedProgram(name="SETDATE")
201+
test_program.load_string("setDate(1")
202+
test_program.unprotect()
203+
204+
test_program.version = 0x04
205+
with open("tests/data/var/Program.8xp", 'rb') as file:
206+
file.seek(55)
207+
self.assertEqual(test_program.bytes(), file.read()[:-2])
208+
199209

200210
class NumericTests(unittest.TestCase):
201211
def real_float_test(self, real_type, filename, name, sign, exponent, mantissa, string, dec):

tivars/types/tokenized.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,22 @@ def name(self, value) -> str:
315315

316316
return varname
317317

318+
def protect(self):
319+
"""
320+
Cast this program to a protected program
321+
"""
322+
323+
self.type_id = 0x06
324+
self.coerce()
325+
326+
def unprotect(self):
327+
"""
328+
Cast this program to an unprotected program
329+
"""
330+
331+
self.type_id = 0x05
332+
self.coerce()
333+
318334

319335
class TIProtectedProgram(TIProgram, register=True):
320336
"""

0 commit comments

Comments
 (0)