Changeset 71bfce0 for server


Ignore:
Timestamp:
Dec 20, 2011, 1:07:05 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
5fe360e
Parents:
cf32fee
git-author:
Jessica B. Hamrick <jhamrick@…> (12/20/11 13:07:05)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/20/11 13:07:05)
Message:

Add dictionaries to ipp/constants to map attribute names to value tags

Location:
server/lib/gutenbach/ipp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/ipp/__init__.py

    r08a764a r71bfce0  
    55from constants import Tags
    66import operations as ops
     7import exceptions as errors
    78
    8 __all__ = ['Attribute', 'AttributeGroup', 'Request', 'Value', 'Tags', 'ops']
     9__all__ = ['Attribute', 'AttributeGroup', 'Request', 'Value', 'Tags', 'ops', 'errors']
  • server/lib/gutenbach/ipp/constants.py

    r110d8be r71bfce0  
    313313class Tags(AttributeTags, OutOfBandTags, IntegerTags, OctetStringTags, CharacterStringTags):
    314314    pass
     315
     316operations_attribute_value_tags = {
     317    'attributes-charset': CharacterStringTags.CHARSET,
     318    'attributes-natural-language': CharacterStringTags.NATURAL_LANGUAGE,
     319    'printer-uri': CharacterStringTags.URI,
     320    'requesting-user-name': CharacterStringTags.NAME_WITHOUT_LANGUAGE
     321    }
     322
     323job_attribute_value_tags = {
     324    'job-id': IntegerTags.INTEGER,
     325    'job-name': CharacterStringTags.NAME_WITHOUT_LANGUAGE,
     326    'job-originating-user-name': CharacterStringTags.NAME_WITHOUT_LANGUAGE,
     327    'job-k-octets': IntegerTags.INTEGER,
     328    'job-state': IntegerTags.ENUM,
     329    'job-printer-uri': CharacterStringTags.URI
     330    }
     331
     332printer_attribute_value_tags = {
     333    "printer-uri-supported": CharacterStringTags.URI,
     334    "uri-authentication-supported": CharacterStringTags.KEYWORD,
     335    "uri-security-supported": CharacterStringTags.KEYWORD,
     336    "printer-name": CharacterStringTags.NAME_WITHOUT_LANGUAGE,
     337    "printer-state": IntegerTags.ENUM,
     338    "printer-state-reasons": CharacterStringTags.KEYWORD,
     339    "ipp-versions-supported": CharacterStringTags.KEYWORD,
     340    "operations-supported": IntegerTags.ENUM,
     341    "charset-configured": CharacterStringTags.CHARSET,
     342    "charset-supported": CharacterStringTags.CHARSET,
     343    "natural-language-configured": CharacterStringTags.NATURAL_LANGUAGE,
     344    "generated-natural-language-supported": CharacterStringTags.NATURAL_LANGUAGE,
     345    "document-format-default": CharacterStringTags.MIME_MEDIA_TYPE,
     346    "document-format-supported": CharacterStringTags.MIME_MEDIA_TYPE,
     347    "printer-is-accepting-jobs": IntegerTags.BOOLEAN,
     348    "queued-job-count": IntegerTags.INTEGER,
     349    "pdl-override-supported": CharacterStringTags.KEYWORD,
     350    "printer-up-time": IntegerTags.INTEGER,
     351    "compression-supported": CharacterStringTags.KEYWORD
     352    }
     353   
  • server/lib/gutenbach/ipp/operations.py

    rcf32fee r71bfce0  
    33from .attributegroup import AttributeGroup
    44from .request import Request
    5 from .constants import AttributeTags, Tags
     5from .constants import AttributeTags, operations_attribute_value_tags
    66import exceptions as err
    77
     
    5454    # check charset value
    5555    charset_value = charset_attr.values[0]
    56     if charset_value.tag != Tags.CHARSET:
    57         raise err.BadRequest(
    58             "Charset value does not have CHARSET tag: 0x%x" % charset_value.tag)
     56    if charset_value.tag != operations_attribute_value_tags['attributes-charset']:
     57        raise err.BadRequest(
     58            "Wrong tag for charset value: 0x%x" % charset_value.tag)
    5959    if charset_value.value != 'utf-8':
    6060        raise err.CharsetNotSupported(str(charset_value.value))
     
    7171    # check natural language value
    7272    natlang_value = natlang_attr.values[0]
    73     if natlang_value.tag != Tags.NATURAL_LANGUAGE:
     73    if natlang_value.tag != operations_attribute_value_tags['attributes-natural-language']:
    7474        raise err.BadRequest(
    7575            "Natural language value does not have NATURAL_LANGUAGE tag: 0x%x" natlang_value.tag)
     
    7878            "Invalid natural language value: %s" % natlang_value.value, [natlang_attr])
    7979
     80def verify_printer_uri(uri_attr):
     81    if uri_attr.name != 'printer-uri':
     82        raise err.BadRequest(
     83            "Unexpected name for attribute 'printer-uri': %s" % uri_attr.name)
     84    if len(uri_attr.values) != 1:
     85        raise err.BadRequest(
     86            "Requesting printer uri attribute has too many values: %d" % len(uri_attr.values))
     87    printer_name_value = uri_attr.values[0]
     88    if printer_name_value.tag != operations_attribute_value_tags['printer-uri']:
     89        raise err.BadRequest(
     90            "Bad value tag (expected URI): 0x%x" % printer_name_value_tag)
     91   
     92    # actually get the printer name
     93    printer_name_value = printer_name_attr.values[0].value
     94    # XXX: hack -- CUPS will strip the port from the request, so
     95    # we can't do an exact comparison (also the hostname might be
     96    # different, depending on the CNAME or whether it's localhost)
     97    printer_name = printer_name_value.split("/")[-1]
     98    return printer_name
     99
    80100def verify_requesting_username(requser_attr):
    81     if requser_attr.tag != Tags.NAME_WITHOUT_LANGUAGE:
    82         raise err.BadRequest(
    83             "Requesting user name attribute tag is not NAME_WITHOUT_LANGUAGE: 0x%x" % \
    84             requser_attr.tag)
     101    if requser_attr.name != 'requesting-user-name':
     102        raise err.BadRequest(
     103            "Unexpected name for attribute 'requesting-user-name': %s" % requser_attr.name)
    85104    if len(requser_attr.values) != 1:
    86105        raise err.BadRequest(
    87106            "Requesting user name attribute has too many values: %d" % len(requser_attr.values))
    88107    requser_value = requser_attr.values[0]
    89     if requser_value.tag != Tags.NAME_WITHOUT_LANGUAGE:
    90         raise err.BadRequest(
    91             "Requesting user name value tag is not NAME_WITHOUT_LANGUAGE: 0x%x" % \
    92             requser_value.tag)
     108    if requser_value.tag != operations_attribute_value_tags['requesting-user-name']:
     109        raise err.BadRequest(
     110            "Bad value tag (expected NAME_WITHOUT_LANGUAGE): 0x%x" % requser_value.tag)
     111   
    93112    return requser_value.value
    94113
     
    98117        ipp.Attribute(
    99118            'attributes-charset',
    100             [ipp.Value(ipp.Tags.CHARSET, 'utf-8')]),
     119            [(operations_attribute_value_tags['attributes-charset'], 'utf-8')]),
    101120        ipp.Attribute(
    102121            'attributes-natural-language',
    103             [ipp.Value(ipp.Tags.NATURAL_LANGUAGE, 'en-us')])
     122            [(operations_attribute_value_tags['attributes-natural-language'], 'en-us')])
    104123        ]
    105124    # Put the operation attributes in a group
     
    205224    """
    206225
     226
    207227    # generic operations verification
    208228    verify_operations(request)
    209 
     229    # requested printer uri
     230    printeruri = verify_printer_uri(request.attribute_groups[0].attributes[2])
    210231    # requesting username
    211     requser = verify_requesting_username(request.attributes[2])
    212     out = {'requesting-user-name': requser}
    213 
     232    requser = verify_requesting_username(request.attribute_groups[0].attributes[3])
    214233    # make the rest of the attributes into a dictionary
    215     attrs = dict([(attr.name, attr.values) for attr in request.attributes[3:]])
     234    attrs = dict([(attr.name, attr.values) for attr in request.attributes[4:]])
    216235   
     236    out = {
     237        'printer-uri': printeruri,
     238        'requesting-user-name': requser
     239        }
     240
    217241    if 'limit' in attrs:
    218242        out['limit'] = None # XXX
     
    230254
    231255def make_get_jobs_response(self, request):
    232     """3.2.6.2 Get-Jobs Response
     256    """RFC 2911: 3.2.6.2 Get-Jobs Response
    233257       
    234258    The Printer object returns all of the Job objects up to the number
Note: See TracChangeset for help on using the changeset viewer.