Merge remote-tracking branch 'remotes/origin/master' into webif_js_rewrite
[enigma2-plugins.git] / webinterface / src / __init__.py
1 import Plugins.Plugin
2 from Components.Language import language
3 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
4 <<<<<<< HEAD
5 import os, gettext, sha
6 =======
7 import os, gettext, hashlib
8 >>>>>>> remotes/origin/master
9
10 __version__ = "1.6.8"
11
12 PluginLanguageDomain = "WebInterface"
13 PluginLanguagePath = "Extensions/WebInterface/locale"
14
15 def localeInit():
16         lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
17         os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
18         print "[WebInterface] set language to ", lang
19         gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
20
21 def _(txt):
22         t = gettext.dgettext(PluginLanguageDomain, txt)
23         if t == txt:
24                 print "[WebInterface] fallback to default translation for", txt
25                 t = gettext.gettext(txt)
26         return t
27
28 def bin2long(s):
29         return reduce( lambda x,y:(x<<8L)+y, map(ord, s))
30
31 def long2bin(l):
32         res = ""
33         for byte in range(128):
34                 res += chr((l >> (1024 - (byte + 1) * 8)) & 0xff)
35         return res
36
37 def rsa_pub1024(src, mod):
38         return long2bin(pow(bin2long(src), 65537, bin2long(mod)))
39         
40 def decrypt_block(src, mod):
41         if len(src) != 128 and len(src) != 202:
42                 return None
43         dest = rsa_pub1024(src[:128], mod)
44 <<<<<<< HEAD
45         hash = sha.new(dest[1:107])
46 =======
47         hash = hashlib.sha1(dest[1:107])
48 >>>>>>> remotes/origin/master
49         if len(src) == 202:
50                 hash.update(src[131:192])       
51         result = hash.digest()
52         if result == dest[107:127]:
53                 return dest
54         return None
55
56 localeInit()
57 language.addCallback(localeInit)