Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created November 7, 2012 00:23
Show Gist options
  • Select an option

  • Save wesrog/4028654 to your computer and use it in GitHub Desktop.

Select an option

Save wesrog/4028654 to your computer and use it in GitHub Desktop.
python indentation
# aligned
return str('%s://%s/%s%s' % (
self.url_scheme,
self.get_host(domain_part),
posixpath.join(self.script_name[:-1].lstrip('/'),
url_quote(path_info.lstrip('/'), self.map.charset,
safe='/:|+')),
suffix
))
# hanging
return str('%s://%s/%s%s' % (
self.url_scheme,
self.get_host(domain_part),
posixpath.join(self.script_name[:-1].lstrip('/'),
url_quote(path_info.lstrip('/'), self.map.charset,
safe='/:|+')),
suffix
))
# aligned (again)
return str('%s://%s/%s%s' % (
self.url_scheme,
self.get_host(domain_part),
posixpath.join(
self.script_name[:-1].lstrip('/'),
url_quote(
path_info.lstrip('/'),
self.map.charset,
safe='/:|+'
)
),
suffix
)
)
@vreon

vreon commented Nov 7, 2012

Copy link
Copy Markdown
# without thinking about it a whole lot, here's what I would have done
# (assuming, of course, breaking it up into multiple statements
# is against the spirit of the exercise :) )

return str('%s://%s/%s%s' % (
    self.url_scheme,
    self.get_host(domain_part),
    posixpath.join(
        self.script_name[:-1].lstrip('/'),
        url_quote(
            path_info.lstrip('/'),
            self.map.charset,
            safe='/:|+',
        )
    ),
    suffix
))

# seems closest to "aligned (again)" - changes annotated
return str('%s://%s/%s%s' % (
    self.url_scheme,
    self.get_host(domain_part),
    posixpath.join(
        self.script_name[:-1].lstrip('/'),
        url_quote(
            path_info.lstrip('/'),
            self.map.charset,
            safe='/:|+',  # trailing comma
        )  # match indentation of url_quote identifier
    ),
    suffix
))  # 'soft' closing paren matches the soft opening paren

@wesrog

wesrog commented Nov 7, 2012

Copy link
Copy Markdown
Author

+1 I like how you would have done it. I agree with the 'soft' closing parens also and would change mine to do the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment