Skip to content

Commit

Permalink
removed dependency stringcase
Browse files Browse the repository at this point in the history
added custom casing module
update readme
Bump version
  • Loading branch information
alejcas committed Jul 4, 2024
1 parent c7be40b commit df0bf8c
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Almost every release features a lot of bugfixes but those are not listed here.


## Version 2.0.36 (2024-07-04)

Removed dependency: stringcase
Upgraded requirement requests-oauthlib
Added classifier python 3.12

## Version 2.0.35 (2024-06-29)

###Features:
Expand Down
2 changes: 1 addition & 1 deletion O365/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.35'
__version__ = '2.0.36'
14 changes: 7 additions & 7 deletions O365/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# noinspection PyUnresolvedReferences
from requests.packages.urllib3.util.retry import Retry
from requests_oauthlib import OAuth2Session
from stringcase import pascalcase, camelcase, snakecase
from tzlocal import get_localzone
from zoneinfo import ZoneInfoNotFoundError, ZoneInfo
from .utils import ME_RESOURCE, BaseTokenBackend, FileSystemTokenBackend, Token, get_windows_tz
from .utils import (ME_RESOURCE, BaseTokenBackend, FileSystemTokenBackend, Token, get_windows_tz, to_camel_case,
to_snake_case, to_pascal_case)
import datetime as dt

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self, *, protocol_url: Optional[str] = None,
self.service_url: str = '{}{}/'.format(protocol_url, api_version)
self.default_resource: str = default_resource or ME_RESOURCE
self.use_default_casing: bool = True if casing_function is None else False
self.casing_function: Callable = casing_function or camelcase
self.casing_function: Callable = casing_function or to_camel_case

# get_localzone() from tzlocal will try to get the system local timezone and if not will return UTC
self._timezone: ZoneInfo = get_localzone()
Expand Down Expand Up @@ -168,7 +168,7 @@ def to_api_case(key: str) -> str:
:param key: key to convert into snake_case
:return: key after case conversion
"""
return snakecase(key)
return to_snake_case(key)

def get_scopes_for(self, user_provided_scopes: Optional[Union[list, str, tuple]]) -> list:
""" Returns a list of scopes needed for each of the
Expand Down Expand Up @@ -234,7 +234,7 @@ def __init__(self, api_version='v1.0', default_resource=None,
super().__init__(protocol_url=self._protocol_url,
api_version=api_version,
default_resource=default_resource,
casing_function=camelcase,
casing_function=to_camel_case,
protocol_scope_prefix=self._oauth_scope_prefix,
**kwargs)

Expand Down Expand Up @@ -275,7 +275,7 @@ def __init__(self, api_version='v2.0', default_resource=None,
super().__init__(protocol_url=self._protocol_url,
api_version=api_version,
default_resource=default_resource,
casing_function=pascalcase,
casing_function=to_pascal_case,
protocol_scope_prefix=self._oauth_scope_prefix,
**kwargs)

Expand Down Expand Up @@ -326,7 +326,7 @@ def __init__(self, api_version='v1.0', default_resource=None, environment=None,
super().__init__(protocol_url=self._protocol_url,
api_version=api_version,
default_resource=default_resource,
casing_function=camelcase,
casing_function=to_camel_case,
protocol_scope_prefix=self._protocol_scope_prefix,
**kwargs)

Expand Down
5 changes: 2 additions & 3 deletions O365/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from urllib.parse import quote
import re

from stringcase import snakecase

from .drive import File
from .connection import MSOffice365Protocol
from .utils import ApiComponent, TrackerSet
from .utils import to_snake_case


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -836,7 +835,7 @@ def update(self):
data = response.json()

for field in self._track_changes:
setattr(self, snakecase(field), data.get(field))
setattr(self, to_snake_case(field), data.get(field))
self._track_changes.clear()

return True
Expand Down
1 change: 1 addition & 0 deletions O365/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .token import BaseTokenBackend, Token, FileSystemTokenBackend, FirestoreBackend, AWSS3Backend, AWSSecretsBackend, EnvTokenBackend
from .windows_tz import get_iana_tz, get_windows_tz
from .consent import consent_input_token
from .casing import to_snake_case, to_pascal_case, to_camel_case
46 changes: 46 additions & 0 deletions O365/utils/casing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import re


def to_snake_case(value: str) -> str:
"""Convert string into snake case"""
pass
value = re.sub(r"[\-.\s]", '_', str(value))
if not value:
return value
return str(value[0]).lower() + re.sub(
r"[A-Z]",
lambda matched: '_' + str(matched.group(0)).lower(),
value[1:]
)


def to_upper_lower_case(value: str, upper: bool = True) -> str:
"""Convert string into upper or lower case"""

value = re.sub(r"\w[\s\W]+\w", '', str(value))
if not value:
return value

first_letter = str(value[0])
if upper:
first_letter = first_letter.upper()
else:
first_letter = first_letter.lower()

return first_letter + re.sub(
r"[\-_.\s]([a-z])",
lambda matched: str(matched.group(1)).upper(),
value[1:]
)


def to_camel_case(value: str) -> str:
"""Convert string into camel case"""

return to_upper_lower_case(value, upper=False)


def to_pascal_case(value: str) -> str:
"""Convert string into pascal case"""

return to_upper_lower_case(value, upper=True)
6 changes: 3 additions & 3 deletions O365/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

from dateutil.parser import parse
from stringcase import snakecase

from .casing import to_snake_case
from .windows_tz import get_iana_tz, get_windows_tz
from .decorators import fluent

Expand All @@ -29,14 +29,14 @@ class CaseEnum(Enum):

def __new__(cls, value):
obj = object.__new__(cls)
obj._value_ = snakecase(value) # value will be transformed to snake_case
obj._value_ = to_snake_case(value) # value will be transformed to snake_case
return obj

@classmethod
def from_value(cls, value):
""" Gets a member by a snaked-case provided value"""
try:
return cls(snakecase(value))
return cls(to_snake_case(value))
except ValueError:
return None

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ Project dependencies installed by pip:
- requests
- requests-oauthlib
- beatifulsoup4
- stringcase
- python-dateutil
- tzlocal
- pytz
- tzdata


## Usage
Expand Down
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
requests>=2.31.0
requests-oauthlib>=1.2.0
requests-oauthlib>=2.0.0
python-dateutil>=2.7
tzlocal>=5.0
beautifulsoup4>=4.0.0
stringcase>=1.2.0
tzdata>=2023.4
Click>=7.0
pytest>=3.9.0
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
requests-oauthlib>=2.0.0
requests>=2.31.0
requests_oauthlib>=1.2.0
python-dateutil>=2.7
tzlocal>=5.0
beautifulsoup4>=4.0.0
stringcase>=1.2.0
tzdata>=2023.4
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages


VERSION = '2.0.35'
VERSION = '2.0.36'

# Available classifiers: https://pypi.org/pypi?%3Aaction=list_classifiers
CLASSIFIERS = [
Expand All @@ -17,6 +17,7 @@
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Operating System :: OS Independent',
]

Expand All @@ -28,11 +29,10 @@ def read(fname):

requires = [
'requests>=2.18.0',
'requests_oauthlib>=1.2.0',
'requests-oauthlib>=2.0.0',
'python-dateutil>=2.7',
'tzlocal>=5.0',
'beautifulsoup4>=4.0.0',
'stringcase>=1.2.0',
'tzdata>=2023.4'
]

Expand All @@ -43,10 +43,10 @@ def read(fname):
packages=find_packages(),
url='https://github.com/O365/python-o365',
license='Apache License 2.0',
author='Janscas, Roycem90, Narcolapser',
author_email='janscas@users.noreply.github.com',
maintainer='Janscas',
maintainer_email='janscas@users.noreply.github.com',
author='Alejcas, Roycem90, Narcolapser',
author_email='alejcas@users.noreply.github.com',
maintainer='alejcas',
maintainer_email='alejcas@users.noreply.github.com',
description='Microsoft Graph and Office 365 API made easy',
long_description=read('README.md'),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit df0bf8c

Please sign in to comment.