_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q30300 | generate_scope_string | train | def generate_scope_string(date, region):
"""
Generate scope string.
:param date: Date is input from :meth:`datetime.datetime`
:param region: Region should be set to bucket region.
"""
formatted_date = date.strftime("%Y%m%d") | python | {
"resource": ""
} |
q30301 | generate_authorization_header | train | def generate_authorization_header(access_key, date, region,
signed_headers, signature):
"""
Generate authorization header.
:param access_key: Server access key.
:param date: Date is input from :meth:`datetime.datetime`
:param region: Region should be set to bucket ... | python | {
"resource": ""
} |
q30302 | parse_multipart_upload_result | train | def parse_multipart_upload_result(data):
"""
Parser for complete multipart upload response.
:param data: Response data for complete multipart upload.
:return: :class:`MultipartUploadResult <MultipartUploadResult>`.
"""
root = S3Element.fromstring('CompleteMultipartUploadResult', data)
| python | {
"resource": ""
} |
q30303 | parse_copy_object | train | def parse_copy_object(bucket_name, object_name, data):
"""
Parser for copy object response.
:param data: Response data for copy object.
:return: :class:`CopyObjectResult <CopyObjectResult>`
"""
root = S3Element.fromstring('CopyObjectResult', data)
| python | {
"resource": ""
} |
q30304 | parse_list_buckets | train | def parse_list_buckets(data):
"""
Parser for list buckets response.
:param data: Response data for list buckets.
:return: List of :class:`Bucket <Bucket>`.
"""
root = S3Element.fromstring('ListBucketsResult', | python | {
"resource": ""
} |
q30305 | _parse_objects_from_xml_elts | train | def _parse_objects_from_xml_elts(bucket_name, contents, common_prefixes):
"""Internal function that extracts objects and common prefixes from
list_objects responses.
"""
objects = [
Object(bucket_name,
content.get_child_text('Key'),
content.get_localized_time_elem('... | python | {
"resource": ""
} |
q30306 | parse_list_objects | train | def parse_list_objects(data, bucket_name):
"""
Parser for list objects response.
:param data: Response data for list objects.
:param bucket_name: Response for the bucket.
:return: Replies back three distinctive components.
- List of :class:`Object <Object>`
- True if list is truncated... | python | {
"resource": ""
} |
q30307 | parse_list_objects_v2 | train | def parse_list_objects_v2(data, bucket_name):
"""
Parser for list objects version 2 response.
:param data: Response data for list objects.
:param bucket_name: Response for the bucket.
:return: Returns three distinct components:
- List of :class:`Object <Object>`
- True if list is trun... | python | {
"resource": ""
} |
q30308 | parse_list_multipart_uploads | train | def parse_list_multipart_uploads(data, bucket_name):
"""
Parser for list multipart uploads response.
:param data: Response data for list multipart uploads.
:param bucket_name: Response for the bucket.
:return: Replies back four distinctive components.
- List of :class:`IncompleteUpload <Inco... | python | {
"resource": ""
} |
q30309 | parse_list_parts | train | def parse_list_parts(data, bucket_name, object_name, upload_id):
"""
Parser for list parts response.
:param data: Response data for list parts.
:param bucket_name: Response for the bucket.
:param object_name: Response for the object.
:param upload_id: Upload id of object name for
the act... | python | {
"resource": ""
} |
q30310 | _iso8601_to_localized_time | train | def _iso8601_to_localized_time(date_string):
"""
Convert iso8601 date string into UTC time.
:param date_string: iso8601 formatted date string.
:return: :class:`datetime.datetime`
"""
parsed_date | python | {
"resource": ""
} |
q30311 | parse_get_bucket_notification | train | def parse_get_bucket_notification(data):
"""
Parser for a get_bucket_notification response from S3.
:param data: Body of response from get_bucket_notification.
:return: Returns bucket notification configuration
"""
root = S3Element.fromstring('GetBucketNotificationResult', data)
notificati... | python | {
"resource": ""
} |
q30312 | parse_multi_object_delete_response | train | def parse_multi_object_delete_response(data):
"""Parser for Multi-Object Delete API response.
:param data: XML response body content from service.
:return: Returns list of error objects for each delete object that
had an error.
"""
root = S3Element.fromstring('MultiObjectDeleteResult', data)
... | python | {
"resource": ""
} |
q30313 | S3Element.fromstring | train | def fromstring(cls, root_name, data):
"""Initialize S3Element from name and XML string data.
:param name: Name for XML data. Used in XML errors.
:param data: string data to be parsed.
:return: Returns an S3Element.
"""
try:
return cls(root_name, cElementTree.... | python | {
"resource": ""
} |
q30314 | S3Element.get_child_text | train | def get_child_text(self, name, strict=True):
"""Extract text of a child element. If strict, and child element is
not present, raises InvalidXMLError and otherwise returns
None.
"""
if strict:
try:
return self.element.find('s3:{}'.format(name), _S3_NS)... | python | {
"resource": ""
} |
q30315 | dump_http | train | def dump_http(method, url, request_headers, response, output_stream):
"""
Dump all headers and response headers into output_stream.
:param request_headers: Dictionary of HTTP request headers.
:param response_headers: Dictionary of HTTP response headers.
:param output_stream: Stream where the reques... | python | {
"resource": ""
} |
q30316 | read_full | train | def read_full(data, size):
"""
read_full reads exactly `size` bytes from reader. returns
`size` bytes.
:param data: Input stream to read from.
:param size: Number of bytes to read from `data`.
:return: Returns :bytes:`part_data`
"""
default_read_size = 32768 # 32KiB per read operation.
| python | {
"resource": ""
} |
q30317 | get_target_url | train | def get_target_url(endpoint_url, bucket_name=None, object_name=None,
bucket_region='us-east-1', query=None):
"""
Construct final target url.
:param endpoint_url: Target endpoint url where request is served to.
:param bucket_name: Bucket component for the target url.
:param object... | python | {
"resource": ""
} |
q30318 | is_valid_endpoint | train | def is_valid_endpoint(endpoint):
"""
Verify if endpoint is valid.
:type endpoint: string
:param endpoint: An endpoint. Must have at least a scheme and a hostname.
:return: True if the endpoint is valid. Raise :exc:`InvalidEndpointError`
otherwise.
"""
try:
if urlsplit(endpoin... | python | {
"resource": ""
} |
q30319 | is_virtual_host | train | def is_virtual_host(endpoint_url, bucket_name):
"""
Check to see if the ``bucket_name`` can be part of virtual host
style.
:param endpoint_url: Endpoint url which will be used for virtual host.
:param bucket_name: Bucket name to be validated against.
"""
is_valid_bucket_name(bucket_name)
... | python | {
"resource": ""
} |
q30320 | is_valid_bucket_name | train | def is_valid_bucket_name(bucket_name):
"""
Check to see if the ``bucket_name`` complies with the
restricted DNS naming conventions necessary to allow
access via virtual-hosting style.
:param bucket_name: Bucket name in *str*.
:return: True if the bucket is valid. Raise :exc:`InvalidBucketError`... | python | {
"resource": ""
} |
q30321 | is_non_empty_string | train | def is_non_empty_string(input_string):
"""
Validate if non empty string
:param input_string: Input is a *str*.
:return: True if input is string and non | python | {
"resource": ""
} |
q30322 | is_valid_policy_type | train | def is_valid_policy_type(policy):
"""
Validate if policy is type str
:param policy: S3 style Bucket policy.
:return: True if policy parameter is of a valid type, 'string'.
Raise :exc:`TypeError` otherwise.
"""
if _is_py3:
string_type = str,
elif _is_py2:
| python | {
"resource": ""
} |
q30323 | is_valid_sse_object | train | def is_valid_sse_object(sse):
"""
Validate the SSE object and type
:param sse: SSE object defined.
"""
| python | {
"resource": ""
} |
q30324 | optimal_part_info | train | def optimal_part_info(length, part_size):
"""
Calculate optimal part size for multipart uploads.
:param length: Input length to calculate part size of.
:return: Optimal part size.
"""
# object size is '-1' set it to 5TiB.
if length == -1:
length = MAX_MULTIPART_OBJECT_SIZE
if le... | python | {
"resource": ""
} |
q30325 | urlencode | train | def urlencode(resource):
"""
This implementation of urlencode supports all unicode characters
:param: resource: Resource value to be url encoded.
"""
if isinstance(resource, | python | {
"resource": ""
} |
q30326 | ResponseError.get_exception | train | def get_exception(self):
"""
Gets the error exception derived from the initialization of
an ErrorResponse object
:return: The derived exception or ResponseError exception
""" | python | {
"resource": ""
} |
q30327 | ResponseError._handle_error_response | train | def _handle_error_response(self, bucket_name=None):
"""
Sets error response uses xml body if available, otherwise
relies on HTTP | python | {
"resource": ""
} |
q30328 | ResponseError._set_error_response_without_body | train | def _set_error_response_without_body(self, bucket_name=None):
"""
Sets all the error response fields from response headers.
"""
if self._response.status == 404:
if bucket_name:
if self.object_name:
self.code = 'NoSuchKey'
... | python | {
"resource": ""
} |
q30329 | Minio.set_app_info | train | def set_app_info(self, app_name, app_version):
"""
Sets your application name and version to
default user agent in the following format.
MinIO (OS; ARCH) LIB/VER APP/VER
Example:
client.set_app_info('my_app', '1.0.2')
:param app_name: application name... | python | {
"resource": ""
} |
q30330 | Minio.make_bucket | train | def make_bucket(self, bucket_name, location='us-east-1'):
"""
Make a new bucket on the server.
Optionally include Location.
['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'eu-west-1',
'eu-west-2', 'ca-central-1', 'eu-central-1', 'sa-east-1',
'cn-north-1'... | python | {
"resource": ""
} |
q30331 | Minio.list_buckets | train | def list_buckets(self):
"""
List all buckets owned by the user.
Example:
bucket_list = minio.list_buckets()
for bucket in bucket_list:
print(bucket.name, bucket.created_date)
:return: An iterator of buckets owned by the current user.
"""
... | python | {
"resource": ""
} |
q30332 | Minio.bucket_exists | train | def bucket_exists(self, bucket_name):
"""
Check if the bucket exists and if the user has access to it.
:param bucket_name: To test the existence and user access.
:return: True on success.
"""
is_valid_bucket_name(bucket_name)
try:
| python | {
"resource": ""
} |
q30333 | Minio.remove_bucket | train | def remove_bucket(self, bucket_name):
"""
Remove a bucket.
:param bucket_name: Bucket to remove
"""
is_valid_bucket_name(bucket_name)
self._url_open('DELETE', bucket_name=bucket_name)
| python | {
"resource": ""
} |
q30334 | Minio.get_bucket_policy | train | def get_bucket_policy(self, bucket_name):
"""
Get bucket policy of given bucket name.
:param bucket_name: Bucket name.
"""
is_valid_bucket_name(bucket_name)
response = self._url_open("GET",
| python | {
"resource": ""
} |
q30335 | Minio.set_bucket_policy | train | def set_bucket_policy(self, bucket_name, policy):
"""
Set bucket policy of given bucket name.
:param bucket_name: Bucket name.
:param policy: Access policy/ies in string format.
"""
is_valid_policy_type(policy)
is_valid_bucket_name(bucket_name)
headers ... | python | {
"resource": ""
} |
q30336 | Minio.get_bucket_notification | train | def get_bucket_notification(self, bucket_name):
"""
Get notifications configured for the given bucket.
:param bucket_name: Bucket name.
"""
is_valid_bucket_name(bucket_name)
response = self._url_open(
"GET",
| python | {
"resource": ""
} |
q30337 | Minio.set_bucket_notification | train | def set_bucket_notification(self, bucket_name, notifications):
"""
Set the given notifications on the bucket.
:param bucket_name: Bucket name.
:param notifications: Notifications structure
"""
is_valid_bucket_name(bucket_name)
is_valid_bucket_notification_config(... | python | {
"resource": ""
} |
q30338 | Minio.remove_all_bucket_notification | train | def remove_all_bucket_notification(self, bucket_name):
"""
Removes all bucket notification configs configured
previously, this call disable event notifications
on a bucket. This operation cannot be undone, to
set notifications again you should use
``set_bucket_notificatio... | python | {
"resource": ""
} |
q30339 | Minio.listen_bucket_notification | train | def listen_bucket_notification(self, bucket_name, prefix='', suffix='',
events=['s3:ObjectCreated:*',
's3:ObjectRemoved:*',
's3:ObjectAccessed:*']):
"""
Yeilds new event notifications... | python | {
"resource": ""
} |
q30340 | Minio.fget_object | train | def fget_object(self, bucket_name, object_name, file_path, request_headers=None, sse=None):
"""
Retrieves an object from a bucket and writes at file_path.
Examples:
minio.fget_object('foo', 'bar', 'localfile')
:param bucket_name: Bucket to read object from.
:param o... | python | {
"resource": ""
} |
q30341 | Minio.copy_object | train | def copy_object(self, bucket_name, object_name, object_source,
conditions=None, source_sse=None, sse=None, metadata=None):
"""
Copy a source object on object storage server to a new object.
NOTE: Maximum object size supported by this API is 5GB.
Examples:
:... | python | {
"resource": ""
} |
q30342 | Minio.list_objects | train | def list_objects(self, bucket_name, prefix='', recursive=False):
"""
List objects in the given bucket.
Examples:
objects = minio.list_objects('foo')
for current_object in objects:
print(current_object)
# hello
# hello/
... | python | {
"resource": ""
} |
q30343 | Minio.list_objects_v2 | train | def list_objects_v2(self, bucket_name, prefix='', recursive=False):
"""
List objects in the given bucket using the List objects V2 API.
Examples:
objects = minio.list_objects_v2('foo')
for current_object in objects:
print(current_object)
# hel... | python | {
"resource": ""
} |
q30344 | Minio.stat_object | train | def stat_object(self, bucket_name, object_name, sse=None):
"""
Check if an object exists.
:param bucket_name: Bucket of object.
:param object_name: Name of object
:return: Object metadata if object exists
"""
headers = {}
if sse:
is_valid_sse... | python | {
"resource": ""
} |
q30345 | Minio.remove_object | train | def remove_object(self, bucket_name, object_name):
"""
Remove an object from the bucket.
:param bucket_name: Bucket of object to remove
:param object_name: Name of object to remove
:return: None
"""
is_valid_bucket_name(bucket_name)
is_non_empty_string(ob... | python | {
"resource": ""
} |
q30346 | Minio._process_remove_objects_batch | train | def _process_remove_objects_batch(self, bucket_name, objects_batch):
"""
Requester and response parser for remove_objects
"""
# assemble request content for objects_batch
content = xml_marshal_delete_objects(objects_batch)
# compute headers
headers = {
... | python | {
"resource": ""
} |
q30347 | Minio.remove_objects | train | def remove_objects(self, bucket_name, objects_iter):
"""
Removes multiple objects from a bucket.
:param bucket_name: Bucket from which to remove objects
:param objects_iter: A list, tuple or iterator that provides
objects names to delete.
:return: An iterator of MultiD... | python | {
"resource": ""
} |
q30348 | Minio.list_incomplete_uploads | train | def list_incomplete_uploads(self, bucket_name, prefix='',
recursive=False):
"""
List all in-complete uploads for a given bucket.
Examples:
incomplete_uploads = minio.list_incomplete_uploads('foo')
for current_upload in incomplete_uploads:
... | python | {
"resource": ""
} |
q30349 | Minio._list_incomplete_uploads | train | def _list_incomplete_uploads(self, bucket_name, prefix='',
recursive=False, is_aggregate_size=True):
"""
List incomplete uploads list all previously uploaded incomplete multipart objects.
:param bucket_name: Bucket name to list uploaded objects.
:param p... | python | {
"resource": ""
} |
q30350 | Minio._get_total_multipart_upload_size | train | def _get_total_multipart_upload_size(self, bucket_name, object_name,
upload_id):
"""
Get total multipart upload size.
:param bucket_name: Bucket name to list parts for.
:param object_name: Object name to list parts for.
:param upload_id: ... | python | {
"resource": ""
} |
q30351 | Minio._list_object_parts | train | def _list_object_parts(self, bucket_name, object_name, upload_id):
"""
List all parts.
:param bucket_name: Bucket name to list parts for.
:param object_name: Object name to list parts for.
:param upload_id: Upload id of the previously uploaded object name.
"""
is... | python | {
"resource": ""
} |
q30352 | Minio.remove_incomplete_upload | train | def remove_incomplete_upload(self, bucket_name, object_name):
"""
Remove all in-complete uploads for a given bucket_name and object_name.
:param bucket_name: Bucket to drop incomplete uploads
:param object_name: Name of object to remove incomplete uploads
:return: None
"... | python | {
"resource": ""
} |
q30353 | Minio.presigned_url | train | def presigned_url(self, method,
bucket_name,
object_name,
expires=timedelta(days=7),
response_headers=None,
request_date=None):
"""
Presigns a method on an object and provides a url
Example:
... | python | {
"resource": ""
} |
q30354 | Minio.presigned_get_object | train | def presigned_get_object(self, bucket_name, object_name,
expires=timedelta(days=7),
response_headers=None,
request_date=None):
"""
Presigns a get object request and provides a url
Example:
from d... | python | {
"resource": ""
} |
q30355 | Minio.presigned_put_object | train | def presigned_put_object(self, bucket_name, object_name,
expires=timedelta(days=7)):
"""
Presigns a put object request and provides a url
Example:
from datetime import timedelta
presignedURL = presigned_put_object('bucket_name',
... | python | {
"resource": ""
} |
q30356 | Minio.presigned_post_policy | train | def presigned_post_policy(self, post_policy):
"""
Provides a POST form data that can be used for object uploads.
Example:
post_policy = PostPolicy()
post_policy.set_bucket_name('bucket_name')
post_policy.set_key_startswith('objectPrefix/')
expire... | python | {
"resource": ""
} |
q30357 | Minio._do_put_object | train | def _do_put_object(self, bucket_name, object_name, part_data,
part_size, upload_id='', part_number=0,
metadata=None, sse=None, progress=None):
"""
Initiate a multipart PUT operation for a part number
or single PUT object.
:param bucket_name:... | python | {
"resource": ""
} |
q30358 | Minio._stream_put_object | train | def _stream_put_object(self, bucket_name, object_name,
data, content_size,
metadata=None, sse=None,
progress=None, part_size=MIN_PART_SIZE):
"""
Streaming multipart upload operation.
:param bucket_name: Bucket name... | python | {
"resource": ""
} |
q30359 | Minio._remove_incomplete_upload | train | def _remove_incomplete_upload(self, bucket_name, object_name, upload_id):
"""
Remove incomplete multipart request.
:param bucket_name: Bucket name of the incomplete upload.
:param object_name: Object name of incomplete upload.
:param upload_id: Upload id of the incomplete upload... | python | {
"resource": ""
} |
q30360 | Minio._new_multipart_upload | train | def _new_multipart_upload(self, bucket_name, object_name,
metadata=None, sse=None):
"""
Initialize new multipart upload request.
:param bucket_name: Bucket name of the new multipart request.
:param object_name: Object name of the new multipart request.
... | python | {
"resource": ""
} |
q30361 | Minio._complete_multipart_upload | train | def _complete_multipart_upload(self, bucket_name, object_name,
upload_id, uploaded_parts):
"""
Complete an active multipart upload request.
:param bucket_name: Bucket name of the multipart request.
:param object_name: Object name of the multipart reque... | python | {
"resource": ""
} |
q30362 | Minio._get_bucket_region | train | def _get_bucket_region(self, bucket_name):
"""
Get region based on the bucket name.
:param bucket_name: Bucket name for which region will be fetched.
:return: Region of bucket name.
"""
# Region set in constructor, return right here.
if self._region:
... | python | {
"resource": ""
} |
q30363 | Minio._get_bucket_location | train | def _get_bucket_location(self, bucket_name):
"""
Get bucket location.
:param bucket_name: Fetches location of the Bucket name.
:return: location of bucket name is returned.
"""
method = 'GET'
url = self._endpoint_url + '/' + bucket_name + '?location='
hea... | python | {
"resource": ""
} |
q30364 | open | train | def open(data_dir=nlpir.PACKAGE_DIR, encoding=ENCODING,
encoding_errors=ENCODING_ERRORS, license_code=None):
"""Initializes the NLPIR API.
This calls the function :func:`~pynlpir.nlpir.Init`.
:param str data_dir: The absolute path to the directory that has NLPIR's
`Data` directory (defaul... | python | {
"resource": ""
} |
q30365 | _attempt_to_raise_license_error | train | def _attempt_to_raise_license_error(data_dir):
"""Raise an error if NLPIR has detected a missing or expired license.
:param str data_dir: The directory containing NLPIR's `Data` directory.
:raises LicenseError: The NLPIR license appears to be missing or expired.
"""
if isinstance(data_dir, bytes):... | python | {
"resource": ""
} |
q30366 | update_license_file | train | def update_license_file(data_dir):
"""Update NLPIR license file if it is out-of-date or missing.
:param str data_dir: The NLPIR data directory that houses the license.
:returns bool: Whether or not an update occurred.
"""
license_file = os.path.join(data_dir, LICENSE_FILENAME)
temp_dir = tempf... | python | {
"resource": ""
} |
q30367 | update | train | def update(data_dir):
"""Update NLPIR license."""
try:
license_updated = update_license_file(data_dir)
except URLError:
click.secho('Error: unable to fetch newest license.', fg='red')
exit(1)
except (IOError, OSError):
click.secho('Error: unable to move license to data di... | python | {
"resource": ""
} |
q30368 | load_library | train | def load_library(platform, is_64bit, lib_dir=LIB_DIR):
"""Loads the NLPIR library appropriate for the user's system.
This function is called automatically when this module is loaded.
:param str platform: The platform identifier for the user's system.
:param bool is_64bit: Whether or not the user's sys... | python | {
"resource": ""
} |
q30369 | get_func | train | def get_func(name, argtypes=None, restype=c_int, lib=libNLPIR):
"""Retrieves the corresponding NLPIR function.
:param str name: The name of the NLPIR function to get.
:param list argtypes: A list of :mod:`ctypes` data types that correspond
to the function's argument types.
:param restype: A :mo... | python | {
"resource": ""
} |
q30370 | Parser.parse | train | def parse(self, text):
"""Parses and renders a text as HTML regarding current format.
"""
if self.format == 'markdown':
try:
import markdown
except ImportError:
raise RuntimeError(u"Looks like markdown is not installed")
if tex... | python | {
"resource": ""
} |
q30371 | CodeHighlightingMacro.descape | train | def descape(self, string, defs=None):
"""Decodes html entities from a given string"""
if defs is None:
defs = html_entities.entitydefs
| python | {
"resource": ""
} |
q30372 | get_path_url | train | def get_path_url(path, relative=False):
""" Returns an absolute or relative path url given a path
"""
if relative:
| python | {
"resource": ""
} |
q30373 | html_parts | train | def html_parts(input_string, source_path=None, destination_path=None,
input_encoding='unicode', doctitle=1, initial_header_level=1):
"""
Given an input string, returns a dictionary of HTML document parts.
Dictionary keys are the names of parts, and values are Unicode strings;
encoding is... | python | {
"resource": ""
} |
q30374 | html_body | train | def html_body(input_string, source_path=None, destination_path=None,
input_encoding='unicode', doctitle=1, initial_header_level=1):
"""
Given an input string, returns an HTML fragment as a string.
The return value is the contents of the <body> element.
Parameters (see `html_parts()` for ... | python | {
"resource": ""
} |
q30375 | Generator.add_user_css | train | def add_user_css(self, css_list):
""" Adds supplementary user css files to the presentation. The
``css_list`` arg can be either a ``list`` or a string.
"""
if isinstance(css_list, string_types):
css_list = [css_list]
for css_path in css_list:
if css_p... | python | {
"resource": ""
} |
q30376 | Generator.add_user_js | train | def add_user_js(self, js_list):
""" Adds supplementary user javascript files to the presentation. The
``js_list`` arg can be either a ``list`` or a string.
"""
if isinstance(js_list, string_types):
js_list = [js_list]
for js_path in js_list:
if js_path... | python | {
"resource": ""
} |
q30377 | Generator.add_toc_entry | train | def add_toc_entry(self, title, level, slide_number):
""" Adds a new entry to current presentation Table of Contents.
"""
| python | {
"resource": ""
} |
q30378 | Generator.toc | train | def toc(self):
""" Smart getter for Table of Content list.
"""
toc = []
stack = [toc]
for entry in self.__toc:
entry['sub'] = []
while entry['level'] < len(stack):
stack.pop()
| python | {
"resource": ""
} |
q30379 | Generator.execute | train | def execute(self):
""" Execute this generator regarding its current configuration.
"""
if self.direct:
if self.file_type == 'pdf':
raise IOError(u"Direct output mode is not available for PDF "
"export")
else:
... | python | {
"resource": ""
} |
q30380 | Generator.get_template_file | train | def get_template_file(self):
""" Retrieves Jinja2 template file path.
"""
if os.path.exists(os.path.join(self.theme_dir, 'base.html')):
return os.path.join(self.theme_dir, 'base.html')
default_dir = os.path.join(THEMES_DIR, 'default')
| python | {
"resource": ""
} |
q30381 | Generator.fetch_contents | train | def fetch_contents(self, source):
""" Recursively fetches Markdown contents from a single file or
directory containing itself Markdown files.
"""
slides = []
if type(source) is list:
for entry in source:
slides.extend(self.fetch_contents(entry))
... | python | {
"resource": ""
} |
q30382 | Generator.find_theme_dir | train | def find_theme_dir(self, theme, copy_theme=False):
""" Finds them dir path from its name.
"""
if os.path.exists(theme):
self.theme_dir = theme
elif os.path.exists(os.path.join(THEMES_DIR, theme)):
self.theme_dir = os.path.join(THEMES_DIR, theme)
else:
... | python | {
"resource": ""
} |
q30383 | Generator.get_css | train | def get_css(self):
""" Fetches and returns stylesheet file path or contents, for both
print and screen contexts, depending if we want a standalone
presentation or not.
"""
css = {}
print_css = os.path.join(self.theme_dir, 'css', 'print.css')
if not os.pa... | python | {
"resource": ""
} |
q30384 | Generator.get_js | train | def get_js(self):
""" Fetches and returns javascript file path or contents, depending if
we want a standalone presentation or not.
"""
js_file = os.path.join(self.theme_dir, 'js', 'slides.js')
if not os.path.exists(js_file):
js_file = os.path.join(THEMES_DIR, 'de... | python | {
"resource": ""
} |
q30385 | Generator.get_slide_vars | train | def get_slide_vars(self, slide_src, source=None):
""" Computes a single slide template vars from its html source code.
Also extracts slide informations for the table of contents.
"""
presenter_notes = None
find = re.search(r'<h\d[^>]*>presenter notes</h\d>', slide_src,
... | python | {
"resource": ""
} |
q30386 | Generator.get_template_vars | train | def get_template_vars(self, slides):
""" Computes template vars from slides html source code.
"""
try:
head_title = slides[0]['title']
except (IndexError, TypeError):
head_title = "Untitled Presentation"
for slide_index, slide_vars in enumerate(slides):
... | python | {
"resource": ""
} |
q30387 | Generator.parse_config | train | def parse_config(self, config_source):
""" Parses a landslide configuration file and returns a normalized
python dict.
"""
self.log(u"Config %s" % config_source)
try:
raw_config = configparser.RawConfigParser()
raw_config.read(config_source)
... | python | {
"resource": ""
} |
q30388 | Generator.process_macros | train | def process_macros(self, content, source=None):
""" Processed all macros.
"""
macro_options = {'relative': self.relative, 'linenos': self.linenos}
classes = []
for macro_class in self.macros:
try:
macro = macro_class(logger=self.logger, embed=self.embe... | python | {
"resource": ""
} |
q30389 | Generator.register_macro | train | def register_macro(self, *macros):
""" Registers macro classes passed a method arguments.
"""
for m in macros:
if inspect.isclass(m) and issubclass(m, macro_module.Macro):
self.macros.append(m)
else:
| python | {
"resource": ""
} |
q30390 | Generator.render | train | def render(self):
""" Returns generated html code.
"""
with codecs.open(self.template_file, encoding=self.encoding) as template_src:
template = jinja2.Template(template_src.read())
slides = self.fetch_contents(self.source)
context = self.get_template_vars(slides)
... | python | {
"resource": ""
} |
q30391 | Generator.write | train | def write(self):
""" Writes generated presentation code into the destination file.
"""
html = self.render()
if self.file_type == 'pdf':
self.write_pdf(html)
else:
| python | {
"resource": ""
} |
q30392 | Generator.write_pdf | train | def write_pdf(self, html):
""" Tries to write a PDF export from the command line using Prince if
available.
"""
try:
f = tempfile.NamedTemporaryFile(delete=False, suffix='.html')
f.write(html.encode('utf_8', 'xmlcharrefreplace'))
f.close()
... | python | {
"resource": ""
} |
q30393 | log | train | def log(message, type):
"""Log notices to stdout and errors to stderr"""
(sys.stdout if | python | {
"resource": ""
} |
q30394 | run | train | def run(input_file, options):
"""Runs the Generator using parsed options."""
options.logger = log | python | {
"resource": ""
} |
q30395 | get_subhash | train | def get_subhash(hash):
"""Get a second hash based on napiprojekt's hash.
:param str hash: napiprojekt's hash.
:return: the subhash.
:rtype: str
"""
idx = [0xe, 0x3, 0x6, 0x8, 0x2]
mul = [2, 2, 5, 4, 3]
add = [0, 0xd, 0x10, 0xb, 0x5]
b = []
for | python | {
"resource": ""
} |
q30396 | get_subtitle_path | train | def get_subtitle_path(video_path, language=None, extension='.srt'):
"""Get the subtitle path using the `video_path` and `language`.
:param str video_path: path to the video.
:param language: language of the subtitle to put in the path.
:type language: :class:`~babelfish.language.Language`
:param st... | python | {
"resource": ""
} |
q30397 | guess_matches | train | def guess_matches(video, guess, partial=False):
"""Get matches between a `video` and a `guess`.
If a guess is `partial`, the absence information won't be counted as a match.
:param video: the video.
:type video: :class:`~subliminal.video.Video`
:param guess: the guess.
:type guess: dict
:p... | python | {
"resource": ""
} |
q30398 | Subtitle.text | train | def text(self):
"""Content as string
If :attr:`encoding` is None, the encoding is guessed with :meth:`guess_encoding`
"""
if not self.content:
return
if self.encoding:
| python | {
"resource": ""
} |
q30399 | Subtitle.guess_encoding | train | def guess_encoding(self):
"""Guess encoding using the language, falling back on chardet.
:return: the guessed encoding.
:rtype: str
"""
logger.info('Guessing encoding for language %s', self.language)
# always try utf-8 first
encodings = ['utf-8']
# add... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.