strutils: Defer import of pyparsing

This is a slow import and the single user of it, the 'split_by_commas'
helper, does not appear to have any users outside of python-glareclient
(which is a dead project). We might want to remove the user at some
point, but for now simply defer loading of the library.

Change-Id: I91d0c6eec5333a660f995a9d1436e4b068693900
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2022-05-18 12:51:01 +01:00
parent 383789ce70
commit 0eaa7de6a7

View File

@ -23,8 +23,6 @@ import re
import unicodedata
import urllib
import pyparsing as pp
from oslo_utils._i18n import _
from oslo_utils import encodeutils
@ -577,8 +575,13 @@ def split_by_commas(value):
.. versionadded:: 3.17
"""
word = (pp.QuotedString(quoteChar='"', escChar='\\') |
pp.Word(pp.printables, excludeChars='",'))
# pyparsing is a slow import; defer loading until we need it
import pyparsing as pp
word = (
pp.QuotedString(quoteChar='"', escChar='\\') |
pp.Word(pp.printables, excludeChars='",')
)
grammar = pp.stringStart + pp.delimitedList(word) + pp.stringEnd
try: