fixed locale/sids file reading, added default encoding

migr_to_spyne
idziubenko 3 years ago
parent bdbe108991
commit adeb90fa58

@ -61,7 +61,8 @@ def makeRequest(pubkey, pkey, serv_host, auto=False):
username = clVars.Get('ur_fullname')
# Get language
lang = clVars.Get('os_locale_locale')[:2]
print("DEBUG lang clieng make request")
print(lang)
if c.lower() in ['y', 'yes']:
# if serv_host in host_name:
# host_name = host_name.replace('.'+serv_host, '')

@ -14,7 +14,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# from server.cl_server import main
# print(main)
def core_main():
import sys
@ -33,7 +34,7 @@ def core_main():
sys.exit(1)
try:
from calculate.core.server.cl_server import main
from server.cl_server import main
reload(sys)
from calculate.lib.datavars import CriticalError, DataVarsError
@ -59,3 +60,7 @@ def core_main():
except KeyboardInterrupt:
print
print _("Task interrupted")
if (__name__ == "__main__"):
core_main()

@ -33,7 +33,7 @@ _ = lambda x: x
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_core3', sys.modules[__name__])
String.Attributes.encoding = "utf-8"
#####
# API
#####
@ -629,7 +629,7 @@ class CoreWsdl(CoreServiceInterface):
Метод смены локализации интерфейса на лету (во время выбора
параметров метода)
"""
print("DEBUG fix install")
print("DEBUG fixInstallLocalization")
print(dv)
if "--start" not in sys.argv:
return False
@ -637,7 +637,9 @@ class CoreWsdl(CoreServiceInterface):
curThread = threading.currentThread()
curThread.lang = dv.Get('install.os_install_locale_lang')
print("LOCALE DEBUG: thread lang: %s" % curThread.lang)
currentLang = cls.get_cache(sid, "install", "lang")
print("LOCALE DEBUG: cached lang: %s" % currentLang)
if currentLang != curThread.lang:
dv.clearGroups()
cls.install_vars(dv)

@ -18,9 +18,7 @@ import os
import sys
from spyne import rpc
from spyne import Service
from spyne import String, Integer, Array
from calculate.core.server.core_interfaces import CoreServiceInterface
@ -41,6 +39,8 @@ import post_cert
import post_request
import send_cert
String.Attributes.encoding = "utf-8"
# class Basic(CoreServiceInterface):
class Basic(Service, CoreServiceInterface):
""" Basic server class """

@ -30,7 +30,7 @@ from spyne.protocol.soap import Soap11
from spyne import Application
# from spyne.server.wsgi import WsgiApplication
from spyne_service_adapter import CoreInnerWsdl, make_service
from spyne_adapter import CoreInnerWsdl, make_service
_ = lambda x: x
setLocalTranslate('cl_core3', sys.modules[__name__])
@ -43,7 +43,9 @@ _('No module named %s')
@clearDataVars
def main(*args, **keywords):
_args = list(unpack_single_opts(sys.argv[1:]))
if os.path.basename(sys.argv[0]) != 'cl-core':
#DEBUG
if False:
# if os.path.basename(sys.argv[0]) != 'cl-core':
parser = cert_cmd.parse(full=False)
args, unknown_args = parser.parse_known_args(_args)
args.method = '_temp_'
@ -249,7 +251,7 @@ def main(*args, **keywords):
tc = ClService()
tc.set_comb_class_ref(tc)
return local_method(tc, args, unknown_args)
# print(Basic.public_methods)
ClService = make_service(Basic, core_wsdl_classes, outer_wsdl_classes, "ClService")
from server_class import ClApplication, OpenSSLAdapter

@ -43,11 +43,7 @@ from calculate.lib.datavars import DataVarsError, CriticalError, Variable
from calculate.lib.utils.content import getCfgFiles
from itertools import *
from spyne import String, Integer, Boolean
from spyne import Array
from spyne import String, Integer, Boolean, Array
from calculate.core.server.api_types import ReturnedMessage, CommonInfo
from calculate.core.server.api_types import (Field,
@ -828,7 +824,8 @@ def commonView(self, sid, params, arg):
def catchExcept(*skipException):
class wrapper:
def __init__(self, f):
def __init__(self, f_static):
f = f_static.__func__
self.f = f
self.func_name = f.func_name
self.func_code = f.func_code
@ -901,7 +898,9 @@ class CoreWsdl(CoreServiceInterface):
def active_clients(cls, sid):
# curThread = threading.currentThread()
# REMOTE_ADDR = curThread.REMOTE_ADDR
cls.get_lang(cls, sid, "from active clients")
#why is this here?
# cls.get_lang(cls, sid, "from active clients")
if 0 < sid < cls.max_sid:
try:
# open file its session
@ -1482,34 +1481,82 @@ class CoreWsdl(CoreServiceInterface):
@staticmethod
def get_lang(cls, sid, method_name=""):
""" get clients lang """
print("-------------------------------------")
print("DEBUG get_lang")
lang = None
SIDS_DIR = cls.sids
with cls.sid_locker:
sid_file = SIDS_DIR + "/%d.sid" % int(sid)
if os.path.exists(sid_file):
fd = open(sid_file, 'r')
while True:
# fd = open(sid_file, 'r')
with open(sid_file, 'r') as fd:
try:
print("file exists: %s " % sid_file)
print("sid: %s" % sid)
list_sid = pickle.load(fd)
except (IOError, KeyError, EOFError):
break
# if session id found
if sid == list_sid[0]:
fd.close()
lang = list_sid[3]
break
fd.close()
list_sid_sid = int(list_sid[0])
print(list_sid)
print(list_sid_sid)
print(sid)
print(sid == list_sid_sid)
print(type(list_sid_sid))
print(type(sid))
if sid == list_sid_sid:
print("SID FOUND")
lang = list_sid[3]
except IOError:
print("some io error")
except KeyError:
print("Key error")
except EOFError:
print("EOF error")
# while True:
# list_sid_sid = None
# try:
# list_sid = pickle.load(fd)
# list_sid_sid = list_sid[0]
# print(list_sid_sid)
# if sid == list_sid_sid:
# print("SID FOUND")
# fd.close()
# lang = list_sid[3]
# break
# print(list_sid)
# except IOError:
# print("some io error")
# break
# except KeyError:
# print("Key error")
# break
# except EOFError:
# print("EOF error")
# print(list_sid_sid)
# if list_sid_sid and list_sid_sid == sid:
# print("SID FOUND (in except)")
# lang = list_sid[3]
# break
# fd.close()
try:
print(lang)
if lang.lower() not in ('uk', 'fr', 'ru', 'en'):
lang = "en"
except AttributeError:
print("Attr error")
lang = "en"
import locale
try:
lang = locale.locale_alias[lang.lower()]
print("lang got from locale: %s" % lang)
except (TypeError, AttributeError, IndexError, KeyError):
print("SOMESORTAERROR")
lang = locale.locale_alias['en']
print("Setting lang: %s " % lang)
return lang
@ -1703,8 +1750,6 @@ class WsdlMeta(type):
info_obj = mcs.create_info_obj(**kwargs)
info_class = type("%sInfo" % kwargs["method_name"], (CommonInfo,),
info_obj)
# return rpc(Integer, info_class,
# _returns=Array(ReturnedMessage))(func)
#total hack: carry over info_class for later use
func.__func__.info_class = info_class
@ -1760,6 +1805,9 @@ class WsdlMeta(type):
if kwargs["method_name"] == 'install':
lang_changed = cls.fixInstallLocalization(cls, sid, dv)
lang = dv.Get('install.os_install_locale_lang')
print("DEBUG view constructor")
print("lang: %s " % lang)
print("lang_changed: %s " % lang_changed)
cls.set_cache(sid, "install", "lang", lang, smart=False)
dv.processRefresh()
@ -1780,10 +1828,7 @@ class WsdlMeta(type):
wrapper.func_name = "%s_view" % kwargs['method_name']
wrapper = staticmethod(wrapper)
# return rpc(Integer, ViewParams, _returns=ViewInfo)(
# catchExcept(kwargs.get("native_error", ()))(wrapper))
# return catchExcept(kwargs.get("native_error", ()))(wrapper)
return wrapper
return catchExcept(kwargs.get("native_error", ()))(wrapper)
@classmethod
def datavars_constructor(mcs, **kwargs):

@ -302,14 +302,15 @@ class ClApplication(WsgiApplication):
length = http_req_env.get("CONTENT_LENGTH")
input = http_req_env["wsgi.input"]
body = input.read(int(length))
res = re.search(">(.*?)<\/.*sid>", body)
#horrbile hack:
#cherrypy provides rfile in req_env which is consumed upon .read() without
# workarounds, and both we and spyne need the data on it
#so we pass a dummy with the data and read() method on to spyne
http_req_env["wsgi.input"] = io.StringIO(body)
res = re.search(">(.*?)<\/sid>", body)
if(res):
return res.group(1)
return int(res.group(1))
else:
return None
@ -324,12 +325,14 @@ class ClApplication(WsgiApplication):
'Content-Type': 'text/xml',
'Content-Length': '0',
}
print("DEBUG handle_rpc")
curthread = threading.currentThread()
curthread.REMOTE_ADDR = req_env.get('REMOTE_ADDR')
curthread.REMOTE_PORT = req_env.get('REMOTE_PORT')
ip = req_env.get('REMOTE_ADDR')
self.create_path()
sid = self.get_sid_from_soap(req_env)
print("sid: %s" % sid)
method_name = self.get_method_name_from_http(req_env)
if method_name is None:
resp = "Could not extract method name from the request!"
@ -360,8 +363,11 @@ class ClApplication(WsgiApplication):
http_resp_headers['Content-Length'] = str(len(resp))
start_response(HTTP_403, http_resp_headers.items())
return [resp]
if sid:
curthread.lang = service.get_lang(sid, method_name)
curthread.lang = service.get_lang(service, sid, method_name)
print("lang: %s" % curthread.lang)
if curthread.client_cert:
certobj = OpenSSL.crypto.load_certificate(
OpenSSL.SSL.FILETYPE_PEM, curthread.client_cert)

@ -134,7 +134,7 @@ class CoreWsdl(CoreServiceInterface):
results = []
# Check pid presence and conformity sid
with CoreWsdl.sid_pid_locker:
with cls.sid_pid_locker:
fd = open(cls.sids_pids, 'r')
while 1:
try:

@ -70,7 +70,7 @@ def make_service(basic_class, wsdl_core_class_list, outer_wsdl_class_list, servi
functions_to_add = {}
for klass in outer_wsdl_class_list:
for meth in klass.__dict__:
for meth in klass.__dict__:
if not meth.startswith("__") and not meth == "methods":
if meth.endswith("_view"):
functions_to_add[meth] = make_rpc_func_view(getattr(klass, meth))

Loading…
Cancel
Save