### Navigation

- index
- modules |
- next |
- previous |
- rdflib 4.1.2 documentation »
- rdflib API docs »
- rdflib Package »
- plugins Package »
- parsers Package »
- pyRdfa Package »

# extras Package

## `extras` Package

Collection of external modules that are used by pyRdfa and are added for an easier distribution

## `httpheader` Module

Utility functions to work with HTTP headers.

This module provides some utility functions useful for parsing and dealing with some of the HTTP 1.1 protocol headers which are not adequately covered by the standard Python libraries.

Requires Python 2.2 or later.

The functionality includes the correct interpretation of the various Accept-* style headers, content negotiation, byte range requests, HTTP-style date/times, and more.

There are a few classes defined by this module:

> - class content_type – media types such as ‘text/plain’
> - class language_tag – language tags such as ‘en-US’
> - class range_set – a collection of (byte) range specifiers
> - class range_spec – a single (byte) range specifier

The primary functions in this module may be categorized as follows:

> - Content negotiation functions... * acceptable_content_type() * acceptable_language() * acceptable_charset() * acceptable_encoding()
> - Mid-level header parsing functions... * parse_accept_header() * parse_accept_language_header() * parse_range_header()
> - Date and time... * http_datetime() * parse_http_datetime()
> - Utility functions... * quote_string() * remove_comments() * canonical_charset()
> - Low level string parsing functions... * parse_comma_list() * parse_comment() * parse_qvalue_accept_list() * parse_media_type() * parse_number() * parse_parameter_list() * parse_quoted_string() * parse_range_set() * parse_range_spec() * parse_token() * parse_token_or_quoted_string()

And there are some specialized exception classes:

> - RangeUnsatisfiableError
> - RangeUnmergableError
> - ParseError

See also:

> > - RFC 2616, “Hypertext Transfer Protocol – HTTP/1.1”, June 1999.

> >     <http://www.ietf.org/rfc/rfc2616.txt> Errata at <http://purl.org/NET/http-errata>

> > - RFC 2046, “(MIME) Part Two: Media Types”, November 1996.

> >     <http://www.ietf.org/rfc/rfc2046.txt>

> > - RFC 3066, “Tags for the Identification of Languages”, January 2001.

> >     <http://www.ietf.org/rfc/rfc3066.txt>

> Note: I have made a small modification on the regexp for internet date, to make it more liberal (ie, accept a time zone string of the form +0000) Ivan Herman <http://www.ivan-herman.net>, March 2011.

> Have added statements to make it (hopefully) Python 3 compatible. Ivan Herman <http://www.ivan-herman.net>, August 2012.

exception `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``ParseError`(args, input_string, at_position)

  Bases: `exceptions.ValueError`

  Exception class representing a string parsing error.

  `__init__`(args, input_string, at_position)
  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'
  `__str__`()

exception `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``RangeUnmergableError`(reason=None)

  Bases: `exceptions.ValueError`

  Exception class when byte ranges are noncontiguous and can not be merged together.

  `__init__`(reason=None)
  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'

exception `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``RangeUnsatisfiableError`(reason=None)

  Bases: `exceptions.ValueError`

  Exception class when a byte range lies outside the file size boundaries.

  `__init__`(reason=None)
  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``acceptable_charset`(accept_charset_header, charsets, ignore_wildcard=True, default='ISO-8859-1')

  Determines if the given charset is acceptable to the user agent.

  The accept_charset_header should be the value present in the HTTP “Accept-Charset:” header. In mod_python this is typically obtained from the req.http_headers table; in WSGI it is environ[“Accept-Charset”]; other web frameworks may provide other methods of obtaining it.

  Optionally the accept_charset_header parameter can instead be the list returned from the parse_accept_header() function in this module.

  The charsets argument should either be a charset identifier string, or a sequence of them.

  This function returns the charset identifier string which is the most prefered and is acceptable to both the user agent and the caller. It will return the default value if no charset is negotiable.

  Note that the wildcarded charset “*” will be ignored. To override this, call with ignore_wildcard=False.

  See also: RFC 2616 section 14.2, and <http://www.iana.org/assignments/character-sets>

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``acceptable_content_type`(accept_header, content_types, ignore_wildcard=True)

  Determines if the given content type is acceptable to the user agent.

  The accept_header should be the value present in the HTTP “Accept:” header. In mod_python this is typically obtained from the req.http_headers_in table; in WSGI it is environ[“Accept”]; other web frameworks may provide other methods of obtaining it.

  Optionally the accept_header parameter can be pre-parsed, as returned from the parse_accept_header() function in this module.

  The content_types argument should either be a single MIME media type string, or a sequence of them. It represents the set of content types that the caller (server) is willing to send. Generally, the server content_types should not contain any wildcarded values.

  This function determines which content type which is the most preferred and is acceptable to both the user agent and the server. If one is negotiated it will return a four-valued tuple like:

  > (server_content_type, ua_content_range, qvalue, accept_parms)

  The first tuple value is one of the server’s content_types, while the remaining tuple values descript which of the client’s acceptable content_types was matched. In most cases accept_parms will be an empty list (see description of parse_accept_header() for more details).

  If no content type could be negotiated, then this function will return None (and the caller should typically cause an HTTP 406 Not Acceptable as a response).

  Note that the wildcarded content type “/” sent by the client will be ignored, since it is often incorrectly sent by web browsers that don’t really mean it. To override this, call with ignore_wildcard=False. Partial wildcards such as “image/*” will always be processed, but be at a lower priority than a complete matching type.

  See also: RFC 2616 section 14.1, and <http://www.iana.org/assignments/media-types/>

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``acceptable_language`(accept_header, server_languages, ignore_wildcard=True, assume_superiors=True)

  Determines if the given language is acceptable to the user agent.

  The accept_header should be the value present in the HTTP “Accept-Language:” header. In mod_python this is typically obtained from the req.http_headers_in table; in WSGI it is environ[“Accept-Language”]; other web frameworks may provide other methods of obtaining it.

  Optionally the accept_header parameter can be pre-parsed, as returned by the parse_accept_language_header() function defined in this module.

  The server_languages argument should either be a single language string, a language_tag object, or a sequence of them. It represents the set of languages that the server is willing to send to the user agent.

  Note that the wildcarded language tag “*” will be ignored. To override this, call with ignore_wildcard=False, and even then it will be the lowest-priority choice regardless of it’s quality factor (as per HTTP spec).

  If the assume_superiors is True then it the languages that the browser accepts will automatically include all superior languages. Any superior languages which must be added are done so with one half the qvalue of the language which is present. For example, if the accept string is “en-US”, then it will be treated as if it were “en-US, en;q=0.5”. Note that although the HTTP 1.1 spec says that browsers are supposed to encourage users to configure all acceptable languages, sometimes they don’t, thus the ability for this function to assume this. But setting assume_superiors to False will insure strict adherence to the HTTP 1.1 spec; which means that if the browser accepts “en-US”, then it will not be acceptable to send just “en” to it.

  This function returns the language which is the most prefered and is acceptable to both the user agent and the caller. It will return None if no language is negotiable, otherwise the return value is always an instance of language_tag.

  See also: RFC 3066 <http://www.ietf.org/rfc/rfc3066.txt>, and ISO 639, links at <http://en.wikipedia.org/wiki/ISO_639>, and <http://www.iana.org/assignments/language-tags>.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``canonical_charset`(charset)

  Returns the canonical or preferred name of a charset.

  Additional character sets can be recognized by this function by altering the character_set_aliases dictionary in this module. Charsets which are not recognized are simply converted to upper-case (as charset names are always case-insensitive).

  See <http://www.iana.org/assignments/character-sets>.

class `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``content_type`(content_type_string=None, with_parameters=True)

  Bases: `object`

  This class represents a media type (aka a MIME content type), including parameters.

  You initialize these by passing in a content-type declaration string, such as “text/plain; charset=ascii”, to the constructor or to the set() method. If you provide no string value, the object returned will represent the wildcard / content type.

  Normally you will get the value back by using str(), or optionally you can access the components via the ‘major’, ‘minor’, ‘media_type’, or ‘parmdict’ members.

  `__eq__`(other)

    Equality test.

    Note that this is an exact match, including any parameters if any.

  `__getstate__`()

    Pickler

  `__hash__`()

    Hash this object; the hash is dependent only upon the value.

  `__init__`(content_type_string=None, with_parameters=True)

    Create a new content_type object.

    See the set() method for a description of the arguments.

  `__len__`()

    Logical length of this media type. For example:

    > len(‘/‘) -> 0 len(‘image/*‘) -> 1 len(‘image/png’) -> 2 len(‘text/plain; charset=utf-8’) -> 3 len(‘text/plain; charset=utf-8; filename=xyz.txt’) -> 4

  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'
  `__ne__`(other)

    Inequality test.

  `__repr__`()

    Python representation of this object.

  `__setstate__`(state)

    Unpickler

  `__str__`()

    String value.

  `__unicode__`()

    Unicode string value.

  `is_composite`()

    Is this media type composed of multiple parts.

  `is_universal_wildcard`()

    Returns True if this is the unspecified ‘/‘ media type.

  `is_wildcard`()

    Returns True if this is a ‘something/*‘ media type.

  `is_xml`()

    Returns True if this media type is XML-based.

    Note this does not consider text/html to be XML, but application/xhtml+xml is.

  `major`

    Major media classification

  `media_type`

    Returns the just the media type ‘type/subtype’ without any paramters (read-only).

  `minor`

    Minor media sub-classification

  `set`(content_type_string, with_parameters=True)

    Parses the content type string and sets this object to it’s value.

    For a more complete description of the arguments, see the documentation for the parse_media_type() function in this module.

  `set_parameters`(parameter_list_or_dict)

    Sets the optional paramters based upon the parameter list.

    The paramter list should be a semicolon-separated name=value string. Any paramters which already exist on this object will be deleted, unless they appear in the given paramter_list.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``http_datetime`(dt=None)

  Formats a datetime as an HTTP 1.1 Date/Time string.

  Takes a standard Python datetime object and returns a string formatted according to the HTTP 1.1 date/time format.

  If no datetime is provided (or None) then the current time is used.

  ABOUT TIMEZONES: If the passed in datetime object is naive it is assumed to be in UTC already. But if it has a tzinfo component, the returned timestamp string will have been converted to UTC automatically. So if you use timezone-aware datetimes, you need not worry about conversion to UTC.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``is_token`(s)

  Determines if the string is a valid token.

class `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``language_tag`(tagname)

  Bases: `object`

  This class represents an RFC 3066 language tag.

  Initialize objects of this class with a single string representing the language tag, such as “en-US”.

  Case is insensitive. Wildcarded subtags are ignored or stripped as they have no significance, so that “en-” is the same as “en”. However the universal wildcard “” language tag is kept as-is.

  Note that although relational operators such as < are defined, they only form a partial order based upon specialization.

  Thus for example,
    “en” <= “en-US”
  but,
    not “en” <= “de”, and not “de” <= “en”.
  `__eq__`(other)

    == operator. Are the two languages the same?

  `__ge__`(other)

    >= operator. Returns True if this language is the same as or a more specialized dialect of the other one.

  `__gt__`(other)

    > operator. Returns True if this language is a more specialized dialect of the other one.

  `__init__`(tagname)

    Initialize objects of this class with a single string representing the language tag, such as “en-US”. Case is insensitive.

  `__le__`(other)

    <= operator. Returns True if the other language is the same as or a more specialized dialect of this one.

  `__len__`()

    Number of subtags in this tag.

  `__lt__`(other)

    < operator. Returns True if the other language is a more specialized dialect of this one.

  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'
  `__neq__`(other)

    != operator. Are the two languages different?

  `__repr__`()

    The python representation of this language tag.

  `__str__`()

    The standard string form of this language tag.

  `__unicode__`()

    The unicode string form of this language tag.

  `all_superiors`(include_wildcard=False)

    Returns a list of this language and all it’s superiors.

    If include_wildcard is False, then “*” will not be among the output list, unless this language is itself “*”.

  `dialect_of`(other, ignore_wildcard=True)

    Is this language a dialect (or subset/specialization) of another.

    This method returns True if this language is the same as or a specialization (dialect) of the other language_tag.

    If ignore_wildcard is False, then all languages will be considered to be a dialect of the special language tag of “*”.

  `is_universal_wildcard`()

    Returns True if this language tag represents all possible languages, by using the reserved tag of “*”.

  `superior`()

    Returns another instance of language_tag which is the superior.

    Thus en-US gives en, and en gives *.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_accept_header`(header_value)

  Parses the Accept: header.

  The value of the header as a string should be passed in; without the header name itself.

  This will parse the value of any of the HTTP headers “Accept”, “Accept-Charset”, “Accept-Encoding”, or “Accept-Language”. These headers are similarly formatted, in that they are a list of items with associated quality factors. The quality factor, or qvalue, is a number in the range [0.0..1.0] which indicates the relative preference of each item.

  This function returns a list of those items, sorted by preference (from most-prefered to least-prefered). Each item in the returned list is actually a tuple consisting of:

  > ( item_name, item_parms, qvalue, accept_parms )

  As an example, the following string,
    text/plain; charset=”utf-8”; q=.5; columns=80
  would be parsed into this resulting tuple,
    ( ‘text/plain’, [(‘charset’,’utf-8’)], 0.5, [(‘columns’,‘80’)] )

  The value of the returned item_name depends upon which header is being parsed, but for example it may be a MIME content or media type (without parameters), a language tag, or so on. Any optional parameters (delimited by semicolons) occuring before the “q=” attribute will be in the item_parms list as (attribute,value) tuples in the same order as they appear in the header. Any quoted values will have been unquoted and unescaped.

  The qvalue is a floating point number in the inclusive range 0.0 to 1.0, and roughly indicates the preference for this item. Values outside this range will be capped to the closest extreme.

  > (!) Note that a qvalue of 0 indicates that the item is explicitly NOT acceptable to the user agent, and should be handled differently by the caller.

  The accept_parms, like the item_parms, is a list of any attributes occuring after the “q=” attribute, and will be in the list as (attribute,value) tuples in the same order as they occur. Usually accept_parms will be an empty list, as the HTTP spec allows these extra parameters in the syntax but does not currently define any possible values.

  All empty items will be removed from the list. However, duplicate or conflicting values are not detected or handled in any way by this function.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_accept_language_header`(header_value)

  Parses the Accept-Language header.

  Returns a list of tuples, each like:

  > (language_tag, qvalue, accept_parameters)

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_comma_list`(s, start=0, element_parser=None, min_count=0, max_count=0)

  Parses a comma-separated list with optional whitespace.

  Takes an optional callback function element_parser, which is assumed to be able to parse an individual element. It will be passed the string and a start argument, and is expected to return a tuple (parsed_result, chars_consumed).

  If no element_parser is given, then either single tokens or quoted strings will be parsed.

  If min_count > 0, then at least that many non-empty elements must be in the list, or an error is raised.

  If max_count > 0, then no more than that many non-empty elements may be in the list, or an error is raised.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_comment`(s, start=0)

  Parses a ()-style comment from a header value.

  Returns tuple (comment, chars_consumed), where the comment will have had the outer-most parentheses and white space stripped. Any nested comments will still have their parentheses and whitespace left intact.

  All -escaped quoted pairs will have been replaced with the actual characters they represent, even within the inner nested comments.

  You should note that only a few HTTP headers, such as User-Agent or Via, allow ()-style comments within the header value.

  A comment is defined by RFC 2616 section 2.2 as:

  > comment = “(” *( ctext | quoted-pair | comment ) ”)” ctext = <any TEXT excluding “(” and ”)”>

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_http_datetime`(datestring, utc_tzinfo=None, strict=False)

  Returns a datetime object from an HTTP 1.1 Date/Time string.

  Note that HTTP dates are always in UTC, so the returned datetime object will also be in UTC.

  You can optionally pass in a tzinfo object which should represent the UTC timezone, and the returned datetime will then be timezone-aware (allowing you to more easly translate it into different timzeones later).

  If you set ‘strict’ to True, then only the RFC 1123 format is recognized. Otherwise the backwards-compatible RFC 1036 and Unix asctime(3) formats are also recognized.

  Please note that the day-of-the-week is not validated. Also two-digit years, although not HTTP 1.1 compliant, are treated according to recommended Y2K rules.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_media_type`(media_type, start=0, with_parameters=True)

  Parses a media type (MIME type) designator into it’s parts.

  Given a media type string, returns a nested tuple of it’s parts.

  > ((major,minor,parmlist), chars_consumed)

  where parmlist is a list of tuples of (parm_name, parm_value). Quoted-values are appropriately unquoted and unescaped.

  If ‘with_parameters’ is False, then parsing will stop immediately after the minor media type; and will not proceed to parse any of the semicolon-separated paramters.

  Examples:

    image/png -> ((‘image’,’png’,[]), 9) text/plain; charset=”utf-16be”

    > -> ((‘text’,’plain’,[(‘charset,’utf-16be’)]), 30)

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_number`(s, start=0)

  Parses a positive decimal integer number from the string.

  A tuple is returned (number, chars_consumed). If the string is not a valid decimal number, then (None,0) is returned.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_parameter_list`(s, start=0)

  Parses a semicolon-separated ‘parameter=value’ list.

  Returns a tuple (parmlist, chars_consumed), where parmlist is a list of tuples (parm_name, parm_value).

  The parameter values will be unquoted and unescaped as needed.

  Empty parameters (as in ”;;”) are skipped, as is insignificant white space. The list returned is kept in the same order as the parameters appear in the string.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_quoted_string`(s, start=0)

  Parses a quoted string.

  Returns a tuple (string, chars_consumed). The quote marks will have been removed and all -escapes will have been replaced with the characters they represent.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_qvalue_accept_list`(s, start=0, item_parser=<function parse_token at 0xf4ca7df4>)

  Parses any of the Accept-* style headers with quality factors.

  This is a low-level function. It returns a list of tuples, each like:
    (item, item_parms, qvalue, accept_parms)

  You can pass in a function which parses each of the item strings, or accept the default where the items must be simple tokens. Note that your parser should not consume any paramters (past the special “q” paramter anyway).

  The item_parms and accept_parms are each lists of (name,value) tuples.

  The qvalue is the quality factor, a number from 0 to 1 inclusive.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_range_header`(header_value, valid_units=('bytes', 'none'))

  Parses the value of an HTTP Range: header.

  The value of the header as a string should be passed in; without the header name itself.

  Returns a range_set object.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_range_set`(s, start=0, valid_units=('bytes', 'none'))

  Parses a (byte) range set specifier.

  Returns a tuple (range_set, chars_consumed).

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_range_spec`(s, start=0)

  Parses a (byte) range_spec.

  Returns a tuple (range_spec, chars_consumed).

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_token`(s, start=0)

  Parses a token.

  A token is a string defined by RFC 2616 section 2.2 as:
    token = 1*<any CHAR except CTLs or separators>

  Returns a tuple (token, chars_consumed), or (‘’,0) if no token starts at the given string position. On a syntax error, a ParseError exception will be raised.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``parse_token_or_quoted_string`(s, start=0, allow_quoted=True, allow_token=True)

  Parses a token or a quoted-string.

  ‘s’ is the string to parse, while start is the position within the string where parsing should begin. It will returns a tuple (token, chars_consumed), with all -escapes and quotation already processed.

  Syntax is according to BNF rules in RFC 2161 section 2.2, specifically the ‘token’ and ‘quoted-string’ declarations. Syntax errors in the input string will result in ParseError being raised.

  If allow_quoted is False, then only tokens will be parsed instead of either a token or quoted-string.

  If allow_token is False, then only quoted-strings will be parsed instead of either a token or quoted-string.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``quote_string`(s, always_quote=True)

  Produces a quoted string according to HTTP 1.1 rules.

  If always_quote is False and if the string is also a valid token, then this function may return a string without quotes.

class `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``range_set`

  Bases: `object`

  A collection of range_specs, with units (e.g., bytes).

  `__init__`()
  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'
  `__repr__`()
  `__slots__` = ['units', 'range_specs']
  `__str__`()
  `coalesce`()

    Collapses all consecutive range_specs which together define a contiguous range.

    Note though that this method will not re-sort the range_specs, so a potentially contiguous range may not be collapsed if they are not sorted. For example the ranges:

    > 10-20, 30-40, 20-30

    will not be collapsed to just 10-40. However if the ranges are sorted first as with:

    > 10-20, 20-30, 30-40

    then they will collapse to 10-40.

  `fix_to_size`(size)

    Changes all length-relative range_specs to absolute range_specs based upon given file size. If none of the range_specs in this set can be satisfied, then the entire set is considered unsatifiable and an error is raised. Otherwise any unsatisfiable range_specs will simply be removed from this set.

  `from_str`(s, valid_units=('bytes', 'none'))

    Sets this range set based upon a string, such as the Range: header.

    You can also use the parse_range_set() function for more control.

    If a parsing error occurs, the pre-exising value of this range set is left unchanged.

  `is_contiguous`()

    Can the collection of range_specs be coalesced into a single contiguous range?

  `is_single_range`()

    Does this range specifier consist of only a single range set?

  `range_specs`
  `units`

class `rdflib.plugins.parsers.pyRdfa.extras.httpheader.``range_spec`(first=0, last=None)

  Bases: `object`

  A single contiguous (byte) range.

  A range_spec defines a range (of bytes) by specifying two offsets, the ‘first’ and ‘last’, which are inclusive in the range. Offsets are zero-based (the first byte is offset 0). The range can not be empty or negative (has to satisfy first <= last).

  The range can be unbounded on either end, represented here by the None value, with these semantics:

  > - A ‘last’ of None always indicates the last possible byte

  > > (although that offset may not be known).

  > - A ‘first’ of None indicates this is a suffix range, where the last value is actually interpreted to be the number of bytes at the end of the file (regardless of file size).

  Note that it is not valid for both first and last to be None.

  `__contains__`(offset)

    Does this byte range contain the given byte offset?

    If the offset < 0, then it is taken as an offset from the end of the file, where -1 is the last byte. This type of offset will only work with suffix ranges.

  `__eq__`(other)

    Compare ranges for equality.

    Note that if non-specific ranges are involved (such as 34- and -5), they could compare as not equal even though they may represent the same set of bytes in some contexts.

  `__ge__`(other)

    >= operator is not defined

  `__gt__`(other)

    > operator is not defined

  `__init__`(first=0, last=None)
  `__le__`(other)

    <= operator is not defined

  `__lt__`(other)

    < operator is not defined

  `__module__` = 'rdflib.plugins.parsers.pyRdfa.extras.httpheader'
  `__ne__`(other)

    Compare ranges for inequality.

    Note that if non-specific ranges are involved (such as 34- and -5), they could compare as not equal even though they may represent the same set of bytes in some contexts.

  `__repr__`()
  `__slots__` = ['first', 'last']
  `__str__`()

    Returns a string form of the range as would appear in a Range: header.

  `copy`()

    Makes a copy of this range object.

  `first`
  `fix_to_size`(size)

    Changes a length-relative range to an absolute range based upon given file size.

    Ranges that are already absolute are left as is.

    Note that zero-length files are handled as special cases, since the only way possible to specify a zero-length range is with the suffix range “-0”. Thus unless this range is a suffix range, it can not satisfy a zero-length file.

    If the resulting range (partly) lies outside the file size then an error is raised.

  `is_fixed`()

    Returns True if this range is absolute and a fixed size.

    This occurs only if neither first or last is None. Converse is the is_unbounded() method.

  `is_suffix`()

    Returns True if this is a suffix range.

    A suffix range is one that specifies the last N bytes of a file regardless of file size.

  `is_unbounded`()

    Returns True if the number of bytes in the range is unspecified.

    This can only occur if either the ‘first’ or the ‘last’ member is None. Converse is the is_fixed() method.

  `is_whole_file`()

    Returns True if this range includes all possible bytes.

    This can only occur if the ‘last’ member is None and the first member is 0.

  `last`
  `merge_with`(other)

    Tries to merge the given range into this one.

    The size of this range may be enlarged as a result.

    An error is raised if the two ranges do not overlap or are not contiguous with each other.

  `set`(first, last)

    Sets the value of this range given the first and last offsets.

`rdflib.plugins.parsers.pyRdfa.extras.httpheader.``remove_comments`(s, collapse_spaces=True)

  Removes any ()-style comments from a string.

  In HTTP, ()-comments can nest, and this function will correctly deal with that.

  If ‘collapse_spaces’ is True, then if there is any whitespace surrounding the comment, it will be replaced with a single space character. Whitespace also collapses across multiple comment sequences, so that “a (b) (c) d” becomes just “a d”.

  Otherwise, if ‘collapse_spaces’ is False then all whitespace which is outside any comments is left intact as-is.

### Navigation

- index
- modules |
- next |
- previous |
- rdflib 4.1.2 documentation »
- rdflib API docs »
- rdflib Package »
- plugins Package »
- parsers Package »
- pyRdfa Package »