Skip to content

Commit

Permalink
Merge pull request #1341 from dumindux/Change_download_file_format
Browse files Browse the repository at this point in the history
Change download file format
  • Loading branch information
Cadair committed Mar 18, 2015
2 parents f9a42ac + 2b59a42 commit 7252af3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sunpy/net/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ def test_content_disposition_unicode():

def test_slugify():
assert sunpy.util.net.slugify(u"äb c", u"b_c")
assert sunpy.util.net.slugify(u"file.greg.fits") == u"file_greg.fits"
assert sunpy.util.net.slugify(u"file.greg.fits", u"x") == u"filexgreg.fits"
assert sunpy.util.net.slugify(u"filegreg.fits") == u"filegreg.fits"
assert sunpy.util.net.slugify(u"filegreg") == u"filegreg"
assert sunpy.util.net.slugify(u"f/i*l:e,gr.eg.fits") == u"f_i_l_e_gr_eg.fits"
assert sunpy.util.net.slugify(u"part1.part2.part3.part4.part5") == u"part1_part2_part3_part4.part5"
18 changes: 15 additions & 3 deletions sunpy/util/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,22 @@
def slugify(text, delim=u'_', encoding="ascii"):
""" Slugify given unicode text. """
text = normalize('NFKD', text)
return unicode(delim).join(ifilter(None, (

period = u'.'

name_and_extension = text.rsplit(period, 1)
name = name_and_extension[0]

name = unicode(delim).join(ifilter(None, (
word.encode(encoding, 'ignore')
for word in _punct_re.split(text.lower())
)))
for word in _punct_re.split(name.lower())
)))

if len(name_and_extension) == 2:
extension = name_and_extension[1]
return unicode(period).join([name, extension])
else:
return name


def get_content_disposition(content_disposition):
Expand Down

0 comments on commit 7252af3

Please sign in to comment.