Skip to content
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

add append_version feature into StaticResource url resolver #2158

Merged
merged 11 commits into from
Aug 5, 2017
Merged

add append_version feature into StaticResource url resolver #2158

merged 11 commits into from
Aug 5, 2017

Conversation

sky-code
Copy link
Contributor

@sky-code sky-code commented Aug 2, 2017

Are there changes in behavior for the user?

Fully backward compatible feature (has no impact on exists code)

Related issue number

Please goto #2157 for description and discussion

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the changes folder
    • name it <issue_id>.<type> for example (588.bug)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@asvetlov
Copy link
Member

asvetlov commented Aug 2, 2017

Please mention new parameter and behavior in docs

@sky-code
Copy link
Contributor Author

sky-code commented Aug 2, 2017

I have added documentation for url_for but not for url because it's deprecated

@asvetlov
Copy link
Member

asvetlov commented Aug 2, 2017

The PR only generates new version tag by url_for() call.

Should it return redirection response on version mismatch?

Should we move append_version parameter to constructor?

It might simplify the usage: just add static files handler with parameter set (app.router.add_static('/prefix', path_to_static, append_version=True)), no need to pass append_version=True to every url_for() call.

@sky-code
Copy link
Contributor Author

sky-code commented Aug 2, 2017

Should it return redirection response on version mismatch?
Not necessarily, no at this time. If someone asks to make it and provide good explanation of advantages then it will be added

Should we move append_version parameter to constructor?
maybe, set default value in constructor than override it in each call if necessary

@codecov-io
Copy link

codecov-io commented Aug 2, 2017

Codecov Report

Merging #2158 into master will increase coverage by 0.02%.
The diff coverage is 97.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2158      +/-   ##
==========================================
+ Coverage   97.09%   97.11%   +0.02%     
==========================================
  Files          39       39              
  Lines        7783     7878      +95     
  Branches     1357     1366       +9     
==========================================
+ Hits         7557     7651      +94     
  Misses        101      101              
- Partials      125      126       +1
Impacted Files Coverage Δ
aiohttp/web_urldispatcher.py 99.34% <97.14%> (-0.08%) ⬇️
aiohttp/helpers.py 97.32% <0%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6d88d8...e218008. Read the comment docs.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, let's don't redirect but add append_version to router.add_static

# with_query remove previous query options
url = self.url_for(filename=filename, append_version=append_version)
if query is not None:
return str(url.with_query(query))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be update_query

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return url
return url

def get_file_hash(self, byte_array):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add _ prefix to method name: it is not a part of public API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return url
except Exception as error:
# perm error or other kind!
# TODO log error here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should catch the exception.
url is useless: next GET will raise an error.
Moreover next open call might fail too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

filepath = self._directory.joinpath(filename).resolve()
if not self._follow_symlinks:
filepath.relative_to(self._directory)
except (ValueError, FileNotFoundError) as error:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What case could raise ValueError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, this is copied code from _handle method, anyway i remove it

… method

docs and tests is updated to reflect changes
Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document append_version parameter for add_staticin web_reference.rst too

# with_query remove previous query options
url = self.url_for(filename=filename, append_version=append_version)
if query is not None:
return str(url.update_query(query))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

url = URL(url)
if append_version is True:
try:
if filename.startswith('/'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test if filename doesn't start with /

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if filename.startswith('/'):
filename = filename[1:]
filepath = self._directory.joinpath(filename).resolve()
if not self._follow_symlinks:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test for _follow_symlink needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@asvetlov asvetlov merged commit ee69c40 into aio-libs:master Aug 5, 2017
@asvetlov
Copy link
Member

asvetlov commented Aug 5, 2017

Thanks!

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants