-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
405 (Method not allowed) for SELECT QUERY with # street address in comment #232
Comments
the comment pattern will not catch a comment in line #1 So i asked ChatGPT comments_pattern = re.compile(r"(^|\n)\s#.*?\n") does not find comments in line 1 how to fix?* The regular expression comments_pattern = re.compile(r"(^|\n)\s*#.*?\n") is designed to match comments that are either at the beginning of the string or after a newline character, followed by optional whitespace and then the # symbol. However, it expects the comment to end with a newline (\n). If the comment is on the first line and the string doesn't start with a newline or if the file doesn't end with a newline, it might not match as intended. To fix the regular expression so it can also find comments on the first line, you can modify the regular expression pattern to consider the start of the string (^) and the start of the line after any newline (\n) as potential starts for the comment. Additionally, you can adjust the end of the pattern to allow for the end of the string ($) as a valid end for a comment, not just a newline. This ensures that it matches comments that might be at the very end of the text without a trailing newline. Here's how you can modify it: import re
# Modified pattern to match comments at the start of the string or after a newline
# and consider end of string as a valid end for a comment
comments_pattern = re.compile(r"(?m)^\s*#.*")
# Test strings
test_string1 = "# This is a comment at the start of the string"
test_string2 = "Some code\n # This is an indented comment"
# Finding and printing matches
print(comments_pattern.findall(test_string1))
print(comments_pattern.findall(test_string2)) Explanation of the pattern r"(?m)^\s*#.*":
With this regular expression, comments at the start of the string, the start of any line, or at the end of the string will be matched appropriately. |
my workaround is: def fix_comments(self, query_string: str) -> str:
"""
make sure broken SPARQLWrapper will find comments
"""
return "#\n"+query_string |
see WolfgangFahl/pyLoDStorage#119
When sending the query
try it!
with SPARQLWrapper 1.8.5 and 2.0.0 the query is interpreted as an ADD query since the _parseQueryType and def _cleanComments functions don't handle this case appropriately.
The text was updated successfully, but these errors were encountered: