kepconfig.structures
structures provides general data structures to help manage
various objects for Kepware's configuration
1# ------------------------------------------------------------------------- 2# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved. 3# See License.txt in the project root for 4# license information. 5# -------------------------------------------------------------------------- 6 7r"""`structures` provides general data structures to help manage 8various objects for Kepware's configuration 9""" 10from enum import Enum 11 12class KepServiceResponse: 13 '''A class to represent a return object when calling a "service" API of Kepware. This is 14 used to return the responses when a "service" is executed appropriately 15 16 :param code: HTTP code returned 17 18 :param message: return from the "service" call 19 20 :param href: URL reference to the JOB that is created by the service API 21 ''' 22 23 def __init__(self, code: str = '', message: str = '', href: str = ''): 24 self.code = code 25 self.message = message 26 self.href = href 27 28 def __str__(self): 29 return '{"code": %s, "message": %s, "href": %s}' % (self.code, self.message, self.href) 30 31class KepServiceStatus: 32 '''A class to represent a status object when checking on a "service" API job state in Kepware. This is 33 used to return the status of a "service" job 34 35 :param complete: Boolean of service job completion status 36 37 :param status: Status code of job 38 39 :param message: Error message if service job fails 40 41 ''' 42 def __init__(self, complete: bool = False, status: str = '', message: str = ''): 43 self.status = status 44 self.message = message 45 self.complete = complete 46 47 def __str__(self): 48 return '{"complete": %s, "status": %s, "message": %s}' % (self.complete, self.status, self.message) 49 50class _HttpDataAbstract: 51 def __init__(self): 52 self.payload = '' 53 self.code = '' 54 self.reason = '' 55 56class FilterModifierEnum(Enum): 57 '''Enum class to represent the various filter types that can be used in the Kepware API''' 58 EQUAL = "eq" 59 NOTEQUAL = "neq" 60 GREATERTHAN = "gt" 61 LESSTTHAN = "lt" 62 GREATERTHANEQUAL = "gte" 63 LESSTHANEQUAL = "lte" 64 CONTAINS = "contains" 65 NOTCONTAINS = "ncontains" 66 STARTSWITH = "starts_with" 67 NOTSTARTSWITH = "nstarts_with" 68 ENDSWITH = "ends_with" 69 NOTENDSWITH = "nends_with" 70 71class FilterFieldEnum(Enum): 72 ID = "id" 73 TIMESTAMP = "timestamp" 74 ACTION = "action" 75 USER = "user" 76 INTERFACE = "interface" 77 DETAILS = "details" 78 DATA = "data" 79 80class Filter: 81 '''A class to represent a filter object when calling the Kepware API. This is used to 82 filter the results of a GET request for Audit Logs. 83 84 :param name: Name of the object to filter on 85 86 :param type: Type of filter to apply 87 88 :param value: Value to filter on 89 ''' 90 def __init__(self, field: FilterFieldEnum = FilterFieldEnum.ID, modifier: FilterModifierEnum = FilterModifierEnum.EQUAL, value: str = ''): 91 self.field = field 92 self.modifier = modifier 93 self.value = value 94 95 def __str__(self): 96 return '{"field": %s, "modifier": %s, "value": %s}' % (self.field, self.modifier, self.value)
13class KepServiceResponse: 14 '''A class to represent a return object when calling a "service" API of Kepware. This is 15 used to return the responses when a "service" is executed appropriately 16 17 :param code: HTTP code returned 18 19 :param message: return from the "service" call 20 21 :param href: URL reference to the JOB that is created by the service API 22 ''' 23 24 def __init__(self, code: str = '', message: str = '', href: str = ''): 25 self.code = code 26 self.message = message 27 self.href = href 28 29 def __str__(self): 30 return '{"code": %s, "message": %s, "href": %s}' % (self.code, self.message, self.href)
A class to represent a return object when calling a "service" API of Kepware. This is used to return the responses when a "service" is executed appropriately
Parameters
code: HTTP code returned
message: return from the "service" call
href: URL reference to the JOB that is created by the service API
32class KepServiceStatus: 33 '''A class to represent a status object when checking on a "service" API job state in Kepware. This is 34 used to return the status of a "service" job 35 36 :param complete: Boolean of service job completion status 37 38 :param status: Status code of job 39 40 :param message: Error message if service job fails 41 42 ''' 43 def __init__(self, complete: bool = False, status: str = '', message: str = ''): 44 self.status = status 45 self.message = message 46 self.complete = complete 47 48 def __str__(self): 49 return '{"complete": %s, "status": %s, "message": %s}' % (self.complete, self.status, self.message)
A class to represent a status object when checking on a "service" API job state in Kepware. This is used to return the status of a "service" job
Parameters
complete: Boolean of service job completion status
status: Status code of job
message: Error message if service job fails
57class FilterModifierEnum(Enum): 58 '''Enum class to represent the various filter types that can be used in the Kepware API''' 59 EQUAL = "eq" 60 NOTEQUAL = "neq" 61 GREATERTHAN = "gt" 62 LESSTTHAN = "lt" 63 GREATERTHANEQUAL = "gte" 64 LESSTHANEQUAL = "lte" 65 CONTAINS = "contains" 66 NOTCONTAINS = "ncontains" 67 STARTSWITH = "starts_with" 68 NOTSTARTSWITH = "nstarts_with" 69 ENDSWITH = "ends_with" 70 NOTENDSWITH = "nends_with"
Enum class to represent the various filter types that can be used in the Kepware API
Inherited Members
- enum.Enum
- name
- value
72class FilterFieldEnum(Enum): 73 ID = "id" 74 TIMESTAMP = "timestamp" 75 ACTION = "action" 76 USER = "user" 77 INTERFACE = "interface" 78 DETAILS = "details" 79 DATA = "data"
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum):
... RED = 1
... BLUE = 2
... GREEN = 3
Access them by:
- attribute access::
>>> Color.RED
<Color.RED: 1>
- value lookup:
>>> Color(1)
<Color.RED: 1>
- name lookup:
>>> Color['RED']
<Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.
Inherited Members
- enum.Enum
- name
- value
81class Filter: 82 '''A class to represent a filter object when calling the Kepware API. This is used to 83 filter the results of a GET request for Audit Logs. 84 85 :param name: Name of the object to filter on 86 87 :param type: Type of filter to apply 88 89 :param value: Value to filter on 90 ''' 91 def __init__(self, field: FilterFieldEnum = FilterFieldEnum.ID, modifier: FilterModifierEnum = FilterModifierEnum.EQUAL, value: str = ''): 92 self.field = field 93 self.modifier = modifier 94 self.value = value 95 96 def __str__(self): 97 return '{"field": %s, "modifier": %s, "value": %s}' % (self.field, self.modifier, self.value)
A class to represent a filter object when calling the Kepware API. This is used to filter the results of a GET request for Audit Logs.
Parameters
name: Name of the object to filter on
type: Type of filter to apply
value: Value to filter on