Sourcery Starbot ⭐ refactored gosirys/sqlmap#1
Sourcery Starbot ⭐ refactored gosirys/sqlmap#1SourceryAI wants to merge 1 commit intogosirys:masterfrom
Conversation
SourceryAI
left a comment
There was a problem hiding this comment.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
| errMsg = "your system does not properly handle non-ASCII paths. " | ||
| errMsg += "Please move the sqlmap's directory to the other location" | ||
| errMsg = ( | ||
| "your system does not properly handle non-ASCII paths. " | ||
| + "Please move the sqlmap's directory to the other location" | ||
| ) | ||
| logger.critical(errMsg) | ||
| raise SystemExit | ||
|
|
||
| if LooseVersion(VERSION) < LooseVersion("1.0"): | ||
| errMsg = "your runtime environment (e.g. PYTHONPATH) is " | ||
| errMsg += "broken. Please make sure that you are not running " | ||
| errMsg = ( | ||
| "your runtime environment (e.g. PYTHONPATH) is " | ||
| + "broken. Please make sure that you are not running " | ||
| ) |
There was a problem hiding this comment.
Function checkEnvironment refactored with the following changes:
- Replace assignment and augmented assignment with single assignment [×2] (
merge-assign-and-aug-assign)
| # Reference: https://lists.gnu.org/archive/html/emacs-devel/2014-09/msg00815.html | ||
| def _cygwin_beep(filename): | ||
| os.system("play-sound-file '%s' 2>/dev/null" % filename) | ||
| os.system(f"play-sound-file '{filename}' 2>/dev/null") |
There was a problem hiding this comment.
Function _cygwin_beep refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| def _linux_wav_play(filename): | ||
| for _ in ("aplay", "paplay", "play"): | ||
| if not os.system("%s '%s' 2>/dev/null" % (_, filename)): | ||
| if not os.system(f"{_} '{filename}' 2>/dev/null"): |
There was a problem hiding this comment.
Function _linux_wav_play refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
|
|
||
| def main(): | ||
| usage = '%s [-d] -i <input file> [-o <output file>]' % sys.argv[0] | ||
| usage = f'{sys.argv[0]} [-d] -i <input file> [-o <output file>]' |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace if statement with if expression [×2] (
assign-if-exp) - Swap positions of nested conditionals [×6] (
swap-nested-ifs) - Hoist nested repeated code outside conditional statements [×6] (
hoist-similar-statement-from-if) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Use
withwhen opening file to ensure closure (ensure-file-closed) - Swap if/else branches (
swap-if-else-branches)
| print("ERROR: the provided input file '%s' is too big for debug.exe" % inputFile) | ||
| print(f"ERROR: the provided input file '{inputFile}' is too big for debug.exe") | ||
| sys.exit(1) | ||
|
|
||
| script = "n %s\nr cx\n" % os.path.basename(inputFile.replace(".", "_")) | ||
| script += "%x\nf 0100 ffff 00\n" % fileSize | ||
| scrString = "" | ||
| counter = 256 | ||
| counter2 = 0 | ||
|
|
||
| fp = open(inputFile, "rb") | ||
| fileContent = fp.read() | ||
|
|
||
| for fileChar in fileContent: | ||
| for counter, fileChar in enumerate(fileContent, start=256): |
There was a problem hiding this comment.
Function convert refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| vector = "%s%s" % (vector, comment) | ||
| vector = f"{vector}{comment}" |
There was a problem hiding this comment.
Function _formatInjection refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| data = "".join(set(_formatInjection(_) for _ in kb.injections)).rstrip("\n") | ||
| data = "".join({_formatInjection(_) for _ in kb.injections}).rstrip("\n") | ||
| conf.dumper.string(header, data) | ||
|
|
||
| if conf.tamper: | ||
| warnMsg = "changes made by tampering scripts are not " | ||
| warnMsg += "included in shown payload content(s)" | ||
| warnMsg = ( | ||
| "changes made by tampering scripts are not " | ||
| + "included in shown payload content(s)" | ||
| ) | ||
| logger.warning(warnMsg) | ||
|
|
||
| if conf.hpp: | ||
| warnMsg = "changes made by HTTP parameter pollution are not " | ||
| warnMsg += "included in shown payload content(s)" | ||
| warnMsg = ( | ||
| "changes made by HTTP parameter pollution are not " | ||
| + "included in shown payload content(s)" | ||
| ) |
There was a problem hiding this comment.
Function _showInjections refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension) - Replace assignment and augmented assignment with single assignment [×2] (
merge-assign-and-aug-assign)
| if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, value): | ||
| if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, retVal): | ||
| message = "do you want to fill blank fields with random values? [Y/n] " | ||
|
|
||
| if readInput(message, default='Y', boolean=True): | ||
| for match in re.finditer(EMPTY_FORM_FIELDS_REGEX, retVal): | ||
| item = match.group("result") | ||
| if not any(_ in item for _ in IGNORE_PARAMETERS) and not re.search(ASP_NET_CONTROL_REGEX, item): | ||
| if all( | ||
| _ not in item for _ in IGNORE_PARAMETERS | ||
| ) and not re.search(ASP_NET_CONTROL_REGEX, item): | ||
| newValue = randomStr() if not re.search(r"^id|id$", item, re.I) else randomInt() | ||
| if item[-1] == DEFAULT_GET_POST_DELIMITER: | ||
| retVal = retVal.replace(item, "%s%s%s" % (item[:-1], newValue, DEFAULT_GET_POST_DELIMITER)) | ||
| retVal = retVal.replace( | ||
| item, | ||
| f"{item[:-1]}{newValue}{DEFAULT_GET_POST_DELIMITER}", | ||
| ) | ||
| else: | ||
| retVal = retVal.replace(item, "%s%s" % (item, newValue)) | ||
| retVal = retVal.replace(item, f"{item}{newValue}") |
There was a problem hiding this comment.
Function _randomFillBlankFields refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable) - Invert any/all to simplify comparisons (
invert-any-all) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| techniques = dict((_[1], _[0]) for _ in getPublicTypeMembers(PAYLOAD.TECHNIQUE)) | ||
| techniques = {_[1]: _[0] for _ in getPublicTypeMembers(PAYLOAD.TECHNIQUE)} |
There was a problem hiding this comment.
Function _saveToResultsFile refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| else: | ||
| if not isinstance(ex, NameError): | ||
| raise | ||
| else: | ||
| msg = "support for direct connection to '%s' is not available. " % dbms | ||
| msg += "Please rerun with '--dependencies'" | ||
| raise SqlmapConnectionException(msg) | ||
| if not isinstance(ex, NameError): | ||
| raise | ||
| msg = f"support for direct connection to '{dbms}' is not available. " | ||
| msg += "Please rerun with '--dependencies'" | ||
| raise SqlmapConnectionException(msg) |
There was a problem hiding this comment.
Function setHandler refactored with the following changes:
- Split conditional into multiple branches [×5] (
split-or-ifs) - Merge duplicate blocks in conditional [×5] (
merge-duplicate-blocks) - Remove unnecessary else after guard condition [×2] (
remove-unnecessary-else) - Swap if/else branches [×4] (
swap-if-else-branches) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Remove redundant conditional [×5] (
remove-redundant-if)
| value = "%s%s AND %s LIKE %s" % (origValue, match.group() if match else "", _, _ + 1) | ||
| value = f'{origValue}{match.group() if match else ""} AND {_} LIKE {_ + 1}' | ||
| elif conf.invalidBignum: | ||
| value = randomInt(6) | ||
| elif conf.invalidString: | ||
| value = randomStr(6) | ||
| else: | ||
| if newValue.startswith("-"): | ||
| value = "" | ||
| else: | ||
| value = "-%s" % randomInt() | ||
| value = "" if newValue.startswith("-") else f"-{randomInt()}" | ||
| elif where == PAYLOAD.WHERE.REPLACE: | ||
| value = "" | ||
| else: | ||
| value = origValue | ||
|
|
||
| newValue = "%s%s" % (value, newValue) | ||
| newValue = f"{value}{newValue}" |
There was a problem hiding this comment.
Function Agent.payload refactored with the following changes:
- Replace interpolated string formatting with f-string [×12] (
replace-interpolation-with-fstring) - Replace if statement with if expression (
assign-if-exp)
| # If the technique is stacked queries (<stype>) do not put a space | ||
| # after the prefix or it is in GROUP BY / ORDER BY (<clause>) | ||
| elif getTechnique() == PAYLOAD.TECHNIQUE.STACKED: | ||
| query = kb.injection.prefix | ||
| elif kb.injection.clause == [2, 3] or kb.injection.clause == [2] or kb.injection.clause == [3]: | ||
| elif kb.injection.clause in [[2, 3], [2], [3]]: | ||
| query = kb.injection.prefix | ||
| elif clause == [2, 3] or clause == [2] or clause == [3]: | ||
| elif clause in [[2, 3], [2], [3]]: | ||
| query = prefix | ||
|
|
||
| # In any other case prepend with the full prefix |
There was a problem hiding this comment.
Function Agent.prefixQuery refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator [×2] (merge-comparisons)
This removes the following comments ( why? ):
# If the technique is stacked queries (<stype>) do not put a space
# In any other case prepend with the full prefix
# after the prefix or it is in GROUP BY / ORDER BY (<clause>)
| payload = getUnicode(payload).replace("[ORIGVALUE]", origValue if origValue.isdigit() else unescaper.escape("'%s'" % origValue)) | ||
| payload = getUnicode(payload).replace( | ||
| "[ORIGVALUE]", | ||
| origValue | ||
| if origValue.isdigit() | ||
| else unescaper.escape(f"'{origValue}'"), | ||
| ) |
There was a problem hiding this comment.
Function Agent.cleanupPayload refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign)
| except IOError as ex: | ||
| errMsg = "exception occurred while retrieving data " | ||
| errMsg += "from a temporary file ('%s')" % ex | ||
| errMsg += f"from a temporary file ('{ex}')" |
There was a problem hiding this comment.
Function BigArray.pop refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| for index in xrange(len(self)): | ||
| if self[index] == value: | ||
| return index | ||
|
|
||
| return ValueError, "%s is not in list" % value | ||
| return next( | ||
| (index for index in xrange(len(self)) if self[index] == value), | ||
| (ValueError, f"{value} is not in list"), | ||
| ) |
There was a problem hiding this comment.
Function BigArray.index refactored with the following changes:
- Use the built-in function
nextinstead of a for-loop (use-next) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if not isNoneValue(versions): | ||
| return versions[0] | ||
| else: | ||
| return None | ||
| return versions[0] if not isNoneValue(versions) else None |
There was a problem hiding this comment.
Function Backend.getVersion refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if not isNoneValue(versions): | ||
| return versions | ||
| else: | ||
| return None | ||
| return versions if not isNoneValue(versions) else None |
There was a problem hiding this comment.
Function Backend.getVersionList refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| singleTimeWarnMessage("identified ('%s') and fingerprinted ('%s') DBMSes differ. If you experience problems in enumeration phase please rerun with '--flush-session'" % (Backend.getIdentifiedDbms(), Backend.getDbms())) | ||
| singleTimeWarnMessage( | ||
| f"identified ('{Backend.getIdentifiedDbms()}') and fingerprinted ('{Backend.getDbms()}') DBMSes differ. If you experience problems in enumeration phase please rerun with '--flush-session'" | ||
| ) |
There was a problem hiding this comment.
Function Backend.isDbms refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| for _ in Backend.getVersionList(): | ||
| if _ != UNKNOWN_DBMS_VERSION and _ in versionList: | ||
| return True | ||
|
|
||
| return False | ||
| return any( | ||
| _ != UNKNOWN_DBMS_VERSION and _ in versionList | ||
| for _ in Backend.getVersionList() | ||
| ) |
There was a problem hiding this comment.
Function Backend.isVersionWithin refactored with the following changes:
- Use any() instead of for loop (
use-any)
| match = re.search(r"\A(\d[\d.]*)", version or "") | ||
|
|
||
| if match: | ||
| if match := re.search(r"\A(\d[\d.]*)", version or ""): |
There was a problem hiding this comment.
Function LooseVersion refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| except: | ||
| warnMsg = "problem occurred while serializing " | ||
| warnMsg += "instance of a type '%s'" % type(value) | ||
| warnMsg += f"instance of a type '{type(value)}'" |
There was a problem hiding this comment.
Function base64pickle refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| return six.text_type(value, UNICODE_ENCODING, errors="reversible") | ||
| elif isListLike(value): | ||
| value = list(getUnicode(_, encoding, noneToNull) for _ in value) | ||
| value = [getUnicode(_, encoding, noneToNull) for _ in value] |
There was a problem hiding this comment.
Function getUnicode refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| match = re.search(r": (\d{3,})", output or "") | ||
|
|
||
| if match: | ||
| if match := re.search(r": (\d{3,})", output or ""): | ||
| try: | ||
| candidate = "cp%s" % match.group(1) | ||
| candidate = f"cp{match.group(1)}" |
There was a problem hiding this comment.
Function stdoutEncode refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| if isinstance(value, six.text_type): | ||
| retVal = sum((2 if ord(_) >= 0x3000 else 1) for _ in value) | ||
| else: | ||
| retVal = len(value) | ||
|
|
||
| return retVal | ||
| return ( | ||
| sum((2 if ord(_) >= 0x3000 else 1) for _ in value) | ||
| if isinstance(value, six.text_type) | ||
| else len(value) | ||
| ) |
There was a problem hiding this comment.
Function getConsoleLength refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| except KeyError: | ||
| if self.keycheck: | ||
| raise AttributeError("unable to access item '%s'" % item) | ||
| raise AttributeError(f"unable to access item '{item}'") |
There was a problem hiding this comment.
Function AttribDict.__getattr__ refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| except ImportError as ex: | ||
| raise SqlmapMissingDependence("missing dependence ('%s')" % getSafeExString(ex)) | ||
| raise SqlmapMissingDependence(f"missing dependence ('{getSafeExString(ex)}')") | ||
|
|
There was a problem hiding this comment.
Function runGui refactored with the following changes:
- Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring)
This removes the following comments ( why? ):
# Reference: https://www.reddit.com/r/learnpython/comments/985umy/limit_user_input_to_only_int_with_tkinter/e4dj9k9?utm_source=share&utm_medium=web2x
# Reference: https://code.activestate.com/recipes/580726-tkinter-notebook-that-fits-to-the-height-of-every-/
|
|
||
| match = re.search(r"\[([A-Z ]+)\]", message) # log level | ||
| if match: | ||
| if match := re.search(r"\[([A-Z ]+)\]", message): |
There was a problem hiding this comment.
Function _ColorizingStreamHandler.colorize refactored with the following changes:
- Use named expression to simplify assignment and conditional [×6] (
use-named-expression) - Merge else clause's nested if statement into elif [×2] (
merge-else-if-into-elif) - Replace interpolated string formatting with f-string [×11] (
replace-interpolation-with-fstring)
This removes the following comments ( why? ):
# counter
# time
# dirty patch
# log level
| except Exception as ex: | ||
| errMsg = "something appears to be wrong with " | ||
| errMsg += "the file '%s' ('%s'). Please make " % (paths.QUERIES_XML, getSafeExString(ex)) | ||
| errMsg += f"the file '{paths.QUERIES_XML}' ('{getSafeExString(ex)}'). Please make " |
There was a problem hiding this comment.
Function _loadQueries refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| return | ||
|
|
||
| debugMsg = "parsing targets list from '%s'" % conf.logFile | ||
| debugMsg = f"parsing targets list from '{conf.logFile}'" |
There was a problem hiding this comment.
Function _setMultipleTargets refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign)
| errMsg = "specified HTTP request file '%s' " % requestFile | ||
| errMsg = f"specified HTTP request file '{requestFile}' " | ||
| errMsg += "does not exist" | ||
| raise SqlmapFilePathException(errMsg) | ||
|
|
||
| infoMsg = "parsing HTTP request from '%s'" % requestFile | ||
| infoMsg = f"parsing HTTP request from '{requestFile}'" |
There was a problem hiding this comment.
Function _setRequestFromFile refactored with the following changes:
- Replace interpolated string formatting with f-string [×6] (
replace-interpolation-with-fstring)
|
??? |
This is definitely a scam! Please do not agree or sign up to any of these services! |
|
Big phishing scam going on with GH right now I got hit by it and revoked access from the offending app. But they sent out the fake messages under my account and many others. https://github.com/orgs/community/discussions/109171 |
Real ballsy to target a site full of Developers, and Security researchers. |
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run: