Is territory assignment possible from a custom function?

Is territory assignment possible from a custom function?

Territory assignment in Zoho is meant by creating rules for each territory. However, if I have too many countries in a territory, the allowed number of rules (25) is easy to be exceeded. Anyway, it is a cumbersome task to click ca. 200 countries' criteria one by one.

What if i want to create a custom function that is responsible for territory assignment? I have a neat list of countries with territory codes, so I could make the assignment in a script.

Is it possible? How can I reference a territory? There is no such module 'Territories'.

I can add my custom Territory field to leads, but it is not the same that is used when I actually assign a lead to a territory.

Please give me some hint how can I access territories in a Deluge script.

Thanks.