pax_global_header00006660000000000000000000000064146504046220014515gustar00rootroot0000000000000052 comment=be55fa00a9051baa1c8ccfdead8f4dfaf0057ea5 python-ms-cv-0.1.1/000077500000000000000000000000001465040462200140605ustar00rootroot00000000000000python-ms-cv-0.1.1/.github/000077500000000000000000000000001465040462200154205ustar00rootroot00000000000000python-ms-cv-0.1.1/.github/workflows/000077500000000000000000000000001465040462200174555ustar00rootroot00000000000000python-ms-cv-0.1.1/.github/workflows/build.yml000066400000000000000000000023321465040462200212770ustar00rootroot00000000000000name: build on: ['push', 'pull_request'] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.6 - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install -e . - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 ms_cv --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 ms_cv --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | pytest - name: Build sdist if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') run: | python setup.py sdist - name: Deploy if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@v1.3.1 with: password: ${{ secrets.PYPI_API_KEY }} python-ms-cv-0.1.1/.gitignore000066400000000000000000000004731465040462200160540ustar00rootroot00000000000000*.py[cod] # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 __pycache__ # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject python-ms-cv-0.1.1/LICENSE000066400000000000000000000020621465040462200150650ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2020 OpenXbox Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.python-ms-cv-0.1.1/README.md000066400000000000000000000017701465040462200153440ustar00rootroot00000000000000# ms_cv - Correlation Vector [![GitHub Workflow - Build](https://img.shields.io/github/workflow/status/OpenXbox/ms_cv/build?label=build)](https://github.com/OpenXbox/ms_cv/actions?query=workflow%3Abuild) [![PyPi](https://img.shields.io/pypi/v/ms_cv.svg)](https://pypi.python.org/pypi/ms_cv) A correlation vector implementation in python, based on Microsoft's implementation. ## Usage ```py import ms_cv cll_vec = ms_cv.CorrelationVector() print('Initial cll vector: {}'.format(cll_vec.get_value())) print('Next iteration: {}'.format(cll_vec.increment())) ``` ## Installation ```sh pip install ms_cv ``` ## Requirements * None ## Compatibility * Python 3 ## License MIT LICENSE ## Authors `ms_cv` was written by `OpenXbox `. Based on the implementation by Microsoft: python-ms-cv-0.1.1/ms_cv/000077500000000000000000000000001465040462200151675ustar00rootroot00000000000000python-ms-cv-0.1.1/ms_cv/__init__.py000066400000000000000000000046221465040462200173040ustar00rootroot00000000000000""" ms_cv - Microsoft Correlation Vector, used for telemetry purposes by Microsoft Web APIs Source: https://github.com/Microsoft/Telemetry-Client-for-Android/blob/master/AndroidCll/src/main/java/com/microsoft/cll/android/CorrelationVector.java """ __version__ = '0.1.1' __author__ = 'OpenXbox ' __all__ = [] import re import math import random class CorrelationVector(object): MAX_CORRELATION_VECTOR_LENGTH = 20 CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ID0_LENGTH = 16 INT_MAX_VALUE = 2147483647 def __init__(self): self.base_vector = self.seed_correlation_vector() self.current_vector = 1 def can_extend(self): vector_size = math.floor(math.log10(self.current_vector) + 1) if len(self.base_vector) + 1 + vector_size + 1 + 1 > self.MAX_CORRELATION_VECTOR_LENGTH: return False else: return True def can_increment(self, new_vector): if new_vector - 1 == self.INT_MAX_VALUE: return False vector_size = math.floor(math.log10(new_vector) + 1) if len(self.base_vector) + vector_size + 1 > self.MAX_CORRELATION_VECTOR_LENGTH: return False else: return True def extend(self): if self.can_extend(): self.base_vector = self.get_value() self.current_vector = 1 return self.get_value() def get_value(self): return '%s.%s' % (self.base_vector, self.current_vector) def increment(self): new_vector = self.current_vector + 1 if self.can_increment(new_vector): self.current_vector = new_vector return self.get_value() def is_valid(self, vector): if len(vector) > self.MAX_CORRELATION_VECTOR_LENGTH: return False validation_pattern = re.compile('^[' + self.CHARSET + ']{16}(.[0-9]+)+$') if not validation_pattern.match(vector): return False else: return True def seed_correlation_vector(self): return ''.join([random.choice(self.CHARSET) for i in range(self.ID0_LENGTH)]) def set_value(self, vector): if self.is_valid(vector): base, current = vector.split('.') self.base_vector = base self.current_vector = int(current) else: raise Exception('Cannot set invalid correlation vector value')python-ms-cv-0.1.1/setup.cfg000066400000000000000000000007171465040462200157060ustar00rootroot00000000000000[bumpversion] current_version = 0.1.1 commit = True tag = True [metadata] description-file = README.md [bumpversion:file:setup.py] search = version="{current_version}" replace = version="{new_version}" [bumpversion:file:ms_cv/__init__.py] search = __version__ = '{current_version}' replace = __version__ = '{new_version}' [bdist_wheel] universal = 1 [flake8] exclude = docs ignore = E501 [aliases] test = pytest [tool:pytest] collect_ignore = ['setup.py'] python-ms-cv-0.1.1/setup.py000066400000000000000000000017751465040462200156040ustar00rootroot00000000000000import io import os import re from setuptools import setup with open("README.md", "r") as fh: long_description = fh.read() setup( name="ms_cv", version="0.1.1", url="https://github.com/OpenXbox/ms_cv", license='MIT', author="OpenXbox", author_email="noreply@openxbox.org", description="A correlation vector implementation in python", long_description=long_description, long_description_content_type="text/markdown", packages=['ms_cv'], install_requires=[], setup_requires=['pytest-runner'], tests_require=[ 'pytest', 'flake8' ], classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', ], ) python-ms-cv-0.1.1/tests/000077500000000000000000000000001465040462200152225ustar00rootroot00000000000000python-ms-cv-0.1.1/tests/test_sample.py000066400000000000000000000001421465040462200201110ustar00rootroot00000000000000# Sample Test passing with nose and pytest def test_pass(): assert True, "dummy sample test" python-ms-cv-0.1.1/tox.ini000066400000000000000000000001331465040462200153700ustar00rootroot00000000000000[tox] envlist = py27,py34,py35,py36,py37 [testenv] commands = py.test ms_cv deps = pytest