splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

Python 2.6 Syntax Errors

Open Vye opened this issue 10 years ago • 3 comments

The README states that Python 2.6 is supported. However, I am getting syntax errors, one of them being a dictionary comprehension which I know isn't supported in 2.6. I'm surprised no one has reported this yet. Did I do something wrong?

Traceback (most recent call last):
  File "/opt/splunk/etc/apps/ExampleApp/bin/downtime.py", line 8, in <module>
    from splunklib.searchcommands import \
  File "/usr/lib/python2.6/site-packages/splunklib/searchcommands/__init__.py", line 146, in <module>
    from .decorators import *
  File "/usr/lib/python2.6/site-packages/splunklib/searchcommands/decorators.py", line 23, in <module>
    from .internals import ConfigurationSettingsType, json_encode_string
  File "/usr/lib/python2.6/site-packages/splunklib/searchcommands/internals.py", line 766
    metadata = str(''.join(self._iterencode_json({n: v for n, v in metadata if v is not None}, 0)))
                                                         ^
SyntaxError: invalid syntax

After fixing the above with self._iterencode_json(dict((n, v) for n, v in metadata if v is not None), 0) I got another syntax error:

Traceback (most recent call last):
  File "/opt/splunk/etc/apps/ExampleApp/bin/downtime.py", line 8, in <module>
    from splunklib.searchcommands import \
  File "/usr/lib/python2.6/site-packages/splunklib/searchcommands/__init__.py", line 149, in <module>
    from .generating_command import GeneratingCommand
  File "/usr/lib/python2.6/site-packages/splunklib/searchcommands/generating_command.py", line 20, in <module>
    from .search_command import SearchCommand
  File "/usr/lib/python2.6/site-packages/splunklib/searchcommands/search_command.py", line 576
    n: ','.join(v) if isinstance(v, (list, tuple)) else v for n, v in self._configuration.iteritems()})
                                                            ^
SyntaxError: invalid syntax

There may be more. Is splunk-sdk supposed to support Python 2.6? If so, can these errors be fixed? You can reproduce with the following code:

from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators

My environment:

$ python -V
Python 2.6.6
$ pip freeze | grep splunk
splunk-sdk==1.5.0

Thanks!

Vye avatar Apr 26 '16 21:04 Vye

Thanks for the issue @Vye. There are a handful dictionary comprehensions in splunklib/searchcommands/internals.py that are not currently Python 2.6 compatible. We're open to a pull request if you're interested in fixing these

shakeelmohamed avatar Apr 26 '16 21:04 shakeelmohamed

I started fixing this but found I have an upgrade path to 2.7. I submitted a PR that partially fixes this but will not pursue py2.6 support further.

Oddly, I wasn't able to see test failures in py2.6 unless I called tests/searchcommands/test_* directly. I'm not familiar enough with your test suite to know why that is.

Vye avatar Apr 27 '16 17:04 Vye

@Vye this is fixed in v1.6.0, thanks again for bringing this to our attention

shakeelmohamed avatar May 19 '16 21:05 shakeelmohamed