Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created November 7, 2012 00:23
Show Gist options
  • Save wesrog/4028654 to your computer and use it in GitHub Desktop.
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
Copy link

vreon commented Nov 7, 2012

# 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
Copy link
Author

wesrog commented Nov 7, 2012

+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