Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Apr 23, 2021
1 parent c736a76 commit 763d12c
Show file tree
Hide file tree
Showing 9 changed files with 4,715 additions and 4,387 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change log
==========

2.4.0 (2021-XX-XX)
------------------

- Source code formatting of `examples` 5171ee5
- Package rename to pyrfc 47143f5
- get_nwrfclib_version at package and Connection level
- Build from source is now the default installation method on Linux. Cython is required, cpp sources not packaged any more.

2.3.0 (2020-12-02)
------------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.4.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from setuptools import setup, find_packages, Extension

MODULE_NAME = "pyrfc"
PYPIPACKAGE = "pynwrfc"
PYPIPACKAGE = "pyrfc"
HERE = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(HERE, "VERSION"), "rb", "utf-8") as version_file:
VERSION = version_file.read().strip()
Expand Down
4 changes: 3 additions & 1 deletion src/pyrfc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from .pyrfc import (
get_nwrfclib_version,
py_to_string,
string_to_py,
set_ini_file_directory,
Connection,
Throughput,
Expand All @@ -39,6 +41,6 @@
__VERSION__,
)

__author__: str = """"Srdjan Boskovic"""
__author__: str = """"SAP SE"""
__email__: str = "[email protected]"
__version__: str = __VERSION__
9,010 changes: 4,648 additions & 4,362 deletions src/pyrfc/_pyrfc.cpp

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions src/pyrfc/_pyrfc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
""" The _pyrfc C-extension module """

import sys
import signal
import time
import datetime
import collections
import locale
import os.path
import pickle
from decimal import Decimal
from libc.stdlib cimport malloc, free
from libc.stdint cimport uintptr_t
Expand All @@ -21,7 +21,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from . csapnwrfc cimport *
from . _exception import *

__VERSION__ = "2.3.0"
__VERSION__ = "2.4.0"

# inverts the enumeration of RFC_DIRECTION
_direction2rfc = {'RFC_IMPORT': RFC_IMPORT, 'RFC_EXPORT': RFC_EXPORT,
Expand Down Expand Up @@ -72,6 +72,12 @@ _MASK_RSTRIP = 0x04
# NW RFC LIB FUNCTIONALITY
################################################################################

def py_to_string(obj):
return pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)

def string_to_py(objstr):
return pickle.loads(objstr)

def get_nwrfclib_version():
"""Get SAP NW RFC Lib version
:returns: tuple of major, minor and patch level
Expand All @@ -80,7 +86,7 @@ def get_nwrfclib_version():
cdef unsigned minor = 0
cdef unsigned patchlevel = 0
RfcGetVersion(&major, &minor, &patchlevel)
return (major, minor, patchlevel)
return {'major': major, 'minor': minor, 'patchLevel': patchlevel, 'platform': sys.platform}

def set_ini_file_directory(path_name):
"""Sets the directory in which to search for the sapnwrfc.ini file
Expand Down Expand Up @@ -2319,9 +2325,9 @@ cdef wrapString(const SAP_UC* uc, uclen=-1, rstrip=False):
utf8[result_len] = 0
try:
if rstrip:
return utf8[:result_len].rstrip().decode('UTF-8')
return utf8[:result_len].rstrip().decode('utf-8')
else:
return utf8[:result_len].decode('UTF-8')
return utf8[:result_len].decode('utf-8')
finally:
free(utf8)

Expand Down Expand Up @@ -2357,7 +2363,7 @@ cdef class Throughput:
_registry = []

cdef RFC_THROUGHPUT_HANDLE _throughput_handle
cpdef _connections
cdef _connections

def __init__(self, connections = []):
cdef RFC_ERROR_INFO errorInfo
Expand Down
25 changes: 19 additions & 6 deletions src/pyrfc/pyrfc.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
from typing import Any, Optional, Dict, TypedDict

from typing import Any, Optional, Dict
def get_nwrfclib_version(): tuple
def set_ini_file_directory(path_name: str): None
class NWRFCSDKVersion(TypedDict):
major: int
minor: int
patchLevel: int
platform: str

class Connection():
version: {major: int, minor: int, patchLevel: int}
def __init__(self, config: Optional[Dict] = {}, *params: Any) -> None: ...
class ClientOptions(TypedDict):
dtime: bool = False
return_import_params: bool = False
rstrip: bool = True

def get_nwrfclib_version() -> NWRFCSDKVersion: ...
def set_ini_file_directory(path_name: str) -> None: ...

class Connection:
version: NWRFCSDKVersion
def __init__(
self, config: ClientOptions = {"dtime": False, "return_import_params": False, "rstrip": True}, **kwargs: str
) -> None: ...

__VERSION__: str
9 changes: 9 additions & 0 deletions tests/server/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pyrfc import Connection

import pickle

client = Connection(dest="MME")

fd = client.get_function_description("BAPI_USER_GET_DETAIL")

print(fd)
24 changes: 14 additions & 10 deletions tests/server/server.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import os
from pyrfc import Server, set_ini_file_directory

# server function
def my_stfc_connection(request_context=None, REQUTEXT=""):
print("stfc invoked");
print("request_context", request_context);
print(f"REQUTEXT: {REQUTEXT}");
print("stfc invoked")
print("request_context", request_context)
print(f"REQUTEXT: {REQUTEXT}")

return {"ECHOTEXT": REQUTEXT, "RESPTEXT": "Python server here"}

return {
"ECHOTEXT": REQUTEXT,
"RESPTEXT": "Python server here"
}

def my_auth_check(func_name=False, request_context = {}):
# server authorisation check
def my_auth_check(func_name=False, request_context={}):
print(f"authorization check for '{func_name}'")
print("request_context", request_context)
return 0


dir_path = os.path.dirname(os.path.realpath(__file__))
set_ini_file_directory(dir_path)

# create server instance
server = Server({"dest": "gateway"}, {"dest": "MME"}, {"port": 8081, "server_log": False})
# server = Server({"dest": "gateway"}, {"dest": "MME"}, {"auth_check": my_auth_check, "server_log": True})

server.add_function("STFC_CONNECTION", my_stfc_connection )
# expose python function my_stfc_connection as ABAP function STFC_CONNECTION, that ABAP server can call
server.add_function("STFC_CONNECTION", my_stfc_connection)

# start server
server.serve()

# server = Server({"dest": "gateway"}, {"dest": "MME"}, {"auth_check": my_auth_check, "server_log": True})

0 comments on commit 763d12c

Please sign in to comment.