Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from . import config
__version__ = config.VERSION
# Module API
from .cli import cli
from .package import Package
from .resource import Resource
from .group import Group
from .profile import Profile
from .validate import validate
from .infer import infer
from .exceptions import DataPackageException
from .exceptions import TableSchemaException
from .exceptions import LoadError
from .exceptions import CastError
from .exceptions import IntegrityError
"""
descriptor.setdefault('profile', config.DEFAULT_RESOURCE_PROFILE)
if descriptor['profile'] == 'tabular-data-resource':
# Schema
schema = descriptor.get('schema')
if schema is not None:
for field in schema.get('fields', []):
field.setdefault('type', config.DEFAULT_FIELD_TYPE)
field.setdefault('format', config.DEFAULT_FIELD_FORMAT)
schema.setdefault('missingValues', config.DEFAULT_MISSING_VALUES)
# Dialect
dialect = descriptor.get('dialect')
if dialect is not None:
for key, value in config.DEFAULT_DIALECT.items():
dialect.setdefault(key, value)
return descriptor
def expand_resource_descriptor(descriptor):
"""Apply defaults to resource descriptor (IN-PLACE FOR NOW).
"""
descriptor.setdefault('profile', config.DEFAULT_RESOURCE_PROFILE)
if descriptor['profile'] == 'tabular-data-resource':
# Schema
schema = descriptor.get('schema')
if schema is not None:
for field in schema.get('fields', []):
field.setdefault('type', config.DEFAULT_FIELD_TYPE)
field.setdefault('format', config.DEFAULT_FIELD_FORMAT)
schema.setdefault('missingValues', config.DEFAULT_MISSING_VALUES)
# Dialect
dialect = descriptor.get('dialect')
if dialect is not None:
for key, value in config.DEFAULT_DIALECT.items():
dialect.setdefault(key, value)
raise exceptions.DataPackageException(
'Local path "%s" is not safe' % path[0])
# Not base path
if not base_path:
raise exceptions.DataPackageException(
'Local path "%s" requires base path' % path[0])
inspection['source'] = os.path.join(base_path, path[0])
inspection['local'] = True
# Inspect
filename = os.path.basename(path[0])
inspection['format'] = os.path.splitext(filename)[1][1:]
inspection['name'] = os.path.splitext(filename)[0]
inspection['tabular'] = inspection['format'] in config.TABULAR_FORMATS
# Multipart Local/Remote
elif len(path) > 1:
inspections = list(map(lambda item: _inspect_source(None, item, base_path, None), path))
inspection.update(inspections[0])
inspection['source'] = list(map(lambda item: item['source'], inspections))
inspection['multipart'] = True
return inspection
def expand_resource_descriptor(descriptor):
"""Apply defaults to resource descriptor (IN-PLACE FOR NOW).
"""
descriptor.setdefault('profile', config.DEFAULT_RESOURCE_PROFILE)
if descriptor['profile'] == 'tabular-data-resource':
# Schema
schema = descriptor.get('schema')
if schema is not None:
for field in schema.get('fields', []):
field.setdefault('type', config.DEFAULT_FIELD_TYPE)
field.setdefault('format', config.DEFAULT_FIELD_FORMAT)
schema.setdefault('missingValues', config.DEFAULT_MISSING_VALUES)
# Dialect
dialect = descriptor.get('dialect')
if dialect is not None:
for key, value in config.DEFAULT_DIALECT.items():
dialect.setdefault(key, value)
return descriptor
def expand_resource_descriptor(descriptor):
"""Apply defaults to resource descriptor (IN-PLACE FOR NOW).
"""
descriptor.setdefault('profile', config.DEFAULT_RESOURCE_PROFILE)
if descriptor['profile'] == 'tabular-data-resource':
# Schema
schema = descriptor.get('schema')
if schema is not None:
for field in schema.get('fields', []):
field.setdefault('type', config.DEFAULT_FIELD_TYPE)
field.setdefault('format', config.DEFAULT_FIELD_FORMAT)
schema.setdefault('missingValues', config.DEFAULT_MISSING_VALUES)
# Dialect
dialect = descriptor.get('dialect')
if dialect is not None:
for key, value in config.DEFAULT_DIALECT.items():
dialect.setdefault(key, value)
return descriptor
@click.version_option(config.VERSION, message='%(version)s')
def cli():
"""Command-line interface
```
Usage: datapackage [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
infer
validate
```
"""
def expand_package_descriptor(descriptor):
"""Apply defaults to data package descriptor (IN-PLACE FOR NOW).
"""
descriptor.setdefault('profile', config.DEFAULT_DATA_PACKAGE_PROFILE)
for resource in descriptor.get('resources', []):
expand_resource_descriptor(resource)
return descriptor
def expand_resource_descriptor(descriptor):
"""Apply defaults to resource descriptor (IN-PLACE FOR NOW).
"""
descriptor.setdefault('profile', config.DEFAULT_RESOURCE_PROFILE)
if descriptor['profile'] == 'tabular-data-resource':
# Schema
schema = descriptor.get('schema')
if schema is not None:
for field in schema.get('fields', []):
field.setdefault('type', config.DEFAULT_FIELD_TYPE)
field.setdefault('format', config.DEFAULT_FIELD_FORMAT)
schema.setdefault('missingValues', config.DEFAULT_MISSING_VALUES)
# Dialect
dialect = descriptor.get('dialect')
if dialect is not None:
for key, value in config.DEFAULT_DIALECT.items():
dialect.setdefault(key, value)
return descriptor
"""
# Error for inline
if self.inline:
message = 'Methods raw_iter/raw_read are not supported for inline data'
raise exceptions.DataPackageException(message)
# Get filelike
if self.multipart:
filelike = _MultipartSource(self.source, remote=self.remote)
elif self.remote:
if self.__table_options.get('http_session'):
http_session = self.__table_options['http_session']
else:
http_session = requests.Session()
http_session.headers = config.HTTP_HEADERS
res = http_session.get(self.source, stream=True)
filelike = res.raw
else:
filelike = io.open(self.source, 'rb')
return filelike