Skip to content

change: add csv deserializer#737

Merged
laurenyu merged 3 commits intoaws:masterfrom
laurenyu:csv-deserializer
Apr 4, 2019
Merged

change: add csv deserializer#737
laurenyu merged 3 commits intoaws:masterfrom
laurenyu:csv-deserializer

Conversation

@laurenyu
Copy link
Copy Markdown
Contributor

@laurenyu laurenyu commented Apr 4, 2019

Description of changes:
a counterpart to our CSV serializer

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

  • I have read the CONTRIBUTING doc
  • I used the commit message format described in CONTRIBUTING
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated any necessary documentation (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


def __call__(self, stream, content_type):
try:
return list(csv.reader(stream.read().decode('utf-8').splitlines()))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we make encoding configurable as well here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point

result = csv_deserializer(io.BytesIO(b'1,2,3\n3,4,5'), 'text/csv')
assert result == [['1', '2', '3'], ['3', '4', '5']]


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would add a test with just one line and one value. YMMV

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

class _CsvDeserializer(object):
def __init__(self):
self.content_type = CONTENT_TYPE_CSV
def __init__(self, encoding='utf-8'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you need to pass the accept in as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was staying consistent with:

class _CsvSerializer(object):
    def __init__(self):
        self.content_type = CONTENT_TYPE_CSV

open to changing it though if there's a compelling use case

@jesterhazy
Copy link
Copy Markdown
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Copy Markdown
Contributor

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants