-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharepoint_utils.py
34 lines (28 loc) · 967 Bytes
/
sharepoint_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from tika import parser
import urllib.parse
def print_and_log(logger, level, message):
""" Prints the log messages
:param logger: logger name
:param level: log level
:param message: log message
"""
print(message)
getattr(logger, level.lower())(message)
def extract(content):
""" Extracts the contents
:param content: content to be extracted
Returns:
parsed_test: parsed text
"""
parsed = parser.from_buffer(content)
parsed_text = parsed['content']
return parsed_text
def encode(object_name):
"""Performs encoding on the name of objects
containing special characters in their url, and
replaces single quote with two single quote since quote
is treated as an escape character in odata
:param object_name: name that contains special characters
"""
name = urllib.parse.quote(object_name, safe="'")
return name.replace("'", "''")