-
Notifications
You must be signed in to change notification settings - Fork 10
Sourcery Starbot ⭐ refactored scyclops/Readable-Feeds #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,10 +317,10 @@ def _quote(str, LegalChars=_LegalChars, | |
| # the string in doublequotes and precede quote (with a \) | ||
| # special characters. | ||
| # | ||
| if "" == translate(str, idmap, LegalChars): | ||
| if translate(str, idmap, LegalChars) == "": | ||
| return str | ||
| else: | ||
| return '"' + _nulljoin( map(_Translator.get, str, str) ) + '"' | ||
| return f'"{_nulljoin(map(_Translator.get, str, str))}"' | ||
| # end _quote | ||
|
|
||
|
|
||
|
|
@@ -359,12 +359,10 @@ def _unquote(str): | |
| if Omatch: j = Omatch.start(0) | ||
| if Qmatch: k = Qmatch.start(0) | ||
| if Qmatch and ( not Omatch or k < j ): # QuotePatt matched | ||
| res.append(str[i:k]) | ||
| res.append(str[k+1]) | ||
| res.extend((str[i:k], str[k+1])) | ||
| i = k+2 | ||
| else: # OctalPatt matched | ||
| res.append(str[i:j]) | ||
| res.append( chr( int(str[j+1:j+4], 8) ) ) | ||
| else: # OctalPatt matched | ||
| res.extend((str[i:j], chr( int(str[j+1:j+4], 8) ))) | ||
|
Comment on lines
-362
to
+365
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| i = j+4 | ||
| return _nulljoin(res) | ||
| # end _unquote | ||
|
|
@@ -437,8 +435,8 @@ def __init__(self): | |
|
|
||
| def __setitem__(self, K, V): | ||
| K = K.lower() | ||
| if not K in self._reserved: | ||
| raise CookieError("Invalid Attribute %s" % K) | ||
| if K not in self._reserved: | ||
| raise CookieError(f"Invalid Attribute {K}") | ||
|
Comment on lines
-440
to
+439
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dict.__setitem__(self, K, V) | ||
| # end __setitem__ | ||
|
|
||
|
|
@@ -452,9 +450,9 @@ def set(self, key, val, coded_val, | |
| # First we verify that the key isn't a reserved word | ||
| # Second we make sure it only contains legal characters | ||
| if key.lower() in self._reserved: | ||
| raise CookieError("Attempt to set a reserved key: %s" % key) | ||
| if "" != translate(key, idmap, LegalChars): | ||
| raise CookieError("Illegal key value: %s" % key) | ||
| raise CookieError(f"Attempt to set a reserved key: {key}") | ||
| if translate(key, idmap, LegalChars) != "": | ||
| raise CookieError(f"Illegal key value: {key}") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # It's a good key, so save it. | ||
| self.key = key | ||
|
|
@@ -463,13 +461,12 @@ def set(self, key, val, coded_val, | |
| # end set | ||
|
|
||
| def output(self, attrs=None, header = "Set-Cookie:"): | ||
| return "%s %s" % ( header, self.OutputString(attrs) ) | ||
| return f"{header} {self.OutputString(attrs)}" | ||
|
Comment on lines
-466
to
+464
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| __str__ = output | ||
|
|
||
| def __repr__(self): | ||
| return '<%s: %s=%s>' % (self.__class__.__name__, | ||
| self.key, repr(self.value) ) | ||
| return f'<{self.__class__.__name__}: {self.key}={repr(self.value)}>' | ||
|
Comment on lines
-471
to
+469
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def js_output(self, attrs=None): | ||
| # Print javascript | ||
|
|
@@ -489,7 +486,7 @@ def OutputString(self, attrs=None): | |
| RA = result.append | ||
|
|
||
| # First, the key=value pair | ||
| RA("%s=%s" % (self.key, self.coded_value)) | ||
| RA(f"{self.key}={self.coded_value}") | ||
|
Comment on lines
-492
to
+489
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # Now add any defined attributes | ||
| if attrs is None: | ||
|
|
@@ -500,15 +497,15 @@ def OutputString(self, attrs=None): | |
| if V == "": continue | ||
| if K not in attrs: continue | ||
| if K == "expires" and type(V) == type(1): | ||
| RA("%s=%s" % (self._reserved[K], _getdate(V))) | ||
| RA(f"{self._reserved[K]}={_getdate(V)}") | ||
| elif K == "max-age" and type(V) == type(1): | ||
| RA("%s=%d" % (self._reserved[K], V)) | ||
| elif K == "secure": | ||
| RA(str(self._reserved[K])) | ||
| elif K == "httponly": | ||
| RA(str(self._reserved[K])) | ||
| else: | ||
| RA("%s=%s" % (self._reserved[K], V)) | ||
| RA(f"{self._reserved[K]}={V}") | ||
|
|
||
| # Return the result | ||
| return _semispacejoin(result) | ||
|
|
@@ -589,31 +586,25 @@ def __setitem__(self, key, value): | |
|
|
||
| def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"): | ||
| """Return a string suitable for HTTP.""" | ||
| result = [] | ||
| items = self.items() | ||
| items.sort() | ||
| for K,V in items: | ||
| result.append( V.output(attrs, header) ) | ||
| result = [V.output(attrs, header) for K, V in items] | ||
|
Comment on lines
-592
to
+591
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return sep.join(result) | ||
| # end output | ||
|
|
||
| __str__ = output | ||
|
|
||
| def __repr__(self): | ||
| L = [] | ||
| items = self.items() | ||
| items.sort() | ||
| for K,V in items: | ||
| L.append( '%s=%s' % (K,repr(V.value) ) ) | ||
| return '<%s: %s>' % (self.__class__.__name__, _spacejoin(L)) | ||
| L = [f'{K}={repr(V.value)}' for K, V in items] | ||
| return f'<{self.__class__.__name__}: {_spacejoin(L)}>' | ||
|
Comment on lines
-603
to
+601
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def js_output(self, attrs=None): | ||
| """Return a string suitable for JavaScript.""" | ||
| result = [] | ||
| items = self.items() | ||
| items.sort() | ||
| for K,V in items: | ||
| result.append( V.js_output(attrs) ) | ||
| result = [V.js_output(attrs) for K, V in items] | ||
|
Comment on lines
-612
to
+607
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return _nulljoin(result) | ||
| # end js_output | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
_quoterefactored with the following changes:flip-comparison)use-fstring-for-concatenation)